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 const TypeOopPtr *TypeOopPtr::cast_to_nonconst() const {
3050   return this;
3051 }
3052 
3053 //-----------------------------cast_to_exactness-------------------------------
3054 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3055   // There is no such thing as an exact general oop.
3056   // Return self unchanged.
3057   return this;
3058 }
3059 
3060 
3061 //------------------------------as_klass_type----------------------------------
3062 // Return the klass type corresponding to this instance or array type.
3063 // It is the type that is loaded from an object of this type.
3064 const TypeKlassPtr* TypeOopPtr::as_klass_type() const {
3065   ciKlass* k = klass();
3066   bool    xk = klass_is_exact();
3067   if (k == NULL)
3068     return TypeKlassPtr::OBJECT;
3069   else
3070     return TypeKlassPtr::make(xk? Constant: NotNull, k, 0);
3071 }
3072 
3073 //------------------------------meet-------------------------------------------
3074 // Compute the MEET of two types.  It returns a new Type object.
3075 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3076   // Perform a fast test for common case; meeting the same types together.
3077   if( this == t ) return this;  // Meeting same type-rep?
3078 
3079   // Current "this->_base" is OopPtr
3080   switch (t->base()) {          // switch on original type
3081 
3082   case Int:                     // Mixing ints & oops happens when javac
3083   case Long:                    // reuses local variables
3084   case FloatTop:
3085   case FloatCon:
3086   case FloatBot:
3087   case DoubleTop:
3088   case DoubleCon:
3089   case DoubleBot:
3090   case NarrowOop:
3091   case NarrowKlass:
3092   case Bottom:                  // Ye Olde Default
3093     return Type::BOTTOM;
3094   case Top:
3095     return this;
3096 
3097   default:                      // All else is a mistake
3098     typerr(t);
3099 
3100   case RawPtr:
3101   case MetadataPtr:
3102   case KlassPtr:
3103     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3104 
3105   case AnyPtr: {
3106     // Found an AnyPtr type vs self-OopPtr type
3107     const TypePtr *tp = t->is_ptr();
3108     int offset = meet_offset(tp->offset());
3109     PTR ptr = meet_ptr(tp->ptr());
3110     const TypePtr* speculative = xmeet_speculative(tp);
3111     int depth = meet_inline_depth(tp->inline_depth());
3112     switch (tp->ptr()) {
3113     case Null:
3114       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3115       // else fall through:
3116     case TopPTR:
3117     case AnyNull: {
3118       int instance_id = meet_instance_id(InstanceTop);
3119       return make(ptr, offset, instance_id, speculative, depth);
3120     }
3121     case BotPTR:
3122     case NotNull:
3123       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3124     default: typerr(t);
3125     }
3126   }
3127 
3128   case OopPtr: {                 // Meeting to other OopPtrs
3129     const TypeOopPtr *tp = t->is_oopptr();
3130     int instance_id = meet_instance_id(tp->instance_id());
3131     const TypePtr* speculative = xmeet_speculative(tp);
3132     int depth = meet_inline_depth(tp->inline_depth());
3133     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3134   }
3135 
3136   case InstPtr:                  // For these, flip the call around to cut down
3137   case AryPtr:
3138     return t->xmeet(this);      // Call in reverse direction
3139 
3140   } // End of switch
3141   return this;                  // Return the double constant
3142 }
3143 
3144 
3145 //------------------------------xdual------------------------------------------
3146 // Dual of a pure heap pointer.  No relevant klass or oop information.
3147 const Type *TypeOopPtr::xdual() const {
3148   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3149   assert(const_oop() == NULL,             "no constants here");
3150   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3151 }
3152 
3153 //--------------------------make_from_klass_common-----------------------------
3154 // Computes the element-type given a klass.
3155 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3156   if (klass->is_instance_klass()) {
3157     Compile* C = Compile::current();
3158     Dependencies* deps = C->dependencies();
3159     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3160     // Element is an instance
3161     bool klass_is_exact = false;
3162     if (klass->is_loaded()) {
3163       // Try to set klass_is_exact.
3164       ciInstanceKlass* ik = klass->as_instance_klass();
3165       klass_is_exact = ik->is_final();
3166       if (!klass_is_exact && klass_change
3167           && deps != NULL && UseUniqueSubclasses) {
3168         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3169         if (sub != NULL) {
3170           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3171           klass = ik = sub;
3172           klass_is_exact = sub->is_final();
3173         }
3174       }
3175       if (!klass_is_exact && try_for_exact
3176           && deps != NULL && UseExactTypes) {
3177         if (!ik->is_interface() && !ik->has_subklass()) {
3178           // Add a dependence; if concrete subclass added we need to recompile
3179           deps->assert_leaf_type(ik);
3180           klass_is_exact = true;
3181         }
3182       }
3183     }
3184     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
3185   } else if (klass->is_obj_array_klass()) {
3186     // Element is an object array. Recursively call ourself.
3187     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
3188     bool xk = etype->klass_is_exact();
3189     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3190     // We used to pass NotNull in here, asserting that the sub-arrays
3191     // are all not-null.  This is not true in generally, as code can
3192     // slam NULLs down in the subarrays.
3193     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
3194     return arr;
3195   } else if (klass->is_type_array_klass()) {
3196     // Element is an typeArray
3197     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3198     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);
3199     // We used to pass NotNull in here, asserting that the array pointer
3200     // is not-null. That was not true in general.
3201     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3202     return arr;
3203   } else {
3204     ShouldNotReachHere();
3205     return NULL;
3206   }
3207 }
3208 
3209 //------------------------------make_from_constant-----------------------------
3210 // Make a java pointer from an oop constant
3211 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3212   assert(!o->is_null_object(), "null object not yet handled here.");
3213   ciKlass* klass = o->klass();
3214   if (klass->is_instance_klass()) {
3215     // Element is an instance
3216     if (require_constant) {
3217       if (!o->can_be_constant())  return NULL;
3218     } else if (!o->should_be_constant()) {
3219       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3220     }
3221     return TypeInstPtr::make(o);
3222   } else if (klass->is_obj_array_klass()) {
3223     // Element is an object array. Recursively call ourself.
3224     const TypeOopPtr *etype =
3225       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
3226     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3227     // We used to pass NotNull in here, asserting that the sub-arrays
3228     // are all not-null.  This is not true in generally, as code can
3229     // slam NULLs down in the subarrays.
3230     if (require_constant) {
3231       if (!o->can_be_constant())  return NULL;
3232     } else if (!o->should_be_constant()) {
3233       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3234     }
3235     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3236     return arr;
3237   } else if (klass->is_type_array_klass()) {
3238     // Element is an typeArray
3239     const Type* etype =
3240       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3241     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3242     // We used to pass NotNull in here, asserting that the array pointer
3243     // is not-null. That was not true in general.
3244     if (require_constant) {
3245       if (!o->can_be_constant())  return NULL;
3246     } else if (!o->should_be_constant()) {
3247       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3248     }
3249     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3250     return arr;
3251   }
3252 
3253   fatal("unhandled object type");
3254   return NULL;
3255 }
3256 
3257 //------------------------------get_con----------------------------------------
3258 intptr_t TypeOopPtr::get_con() const {
3259   assert( _ptr == Null || _ptr == Constant, "" );
3260   assert( _offset >= 0, "" );
3261 
3262   if (_offset != 0) {
3263     // After being ported to the compiler interface, the compiler no longer
3264     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3265     // to a handle at compile time.  This handle is embedded in the generated
3266     // code and dereferenced at the time the nmethod is made.  Until that time,
3267     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3268     // have access to the addresses!).  This does not seem to currently happen,
3269     // but this assertion here is to help prevent its occurence.
3270     tty->print_cr("Found oop constant with non-zero offset");
3271     ShouldNotReachHere();
3272   }
3273 
3274   return (intptr_t)const_oop()->constant_encoding();
3275 }
3276 
3277 
3278 //-----------------------------filter------------------------------------------
3279 // Do not allow interface-vs.-noninterface joins to collapse to top.
3280 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3281 
3282   const Type* ft = join_helper(kills, include_speculative);
3283   const TypeInstPtr* ftip = ft->isa_instptr();
3284   const TypeInstPtr* ktip = kills->isa_instptr();
3285 
3286   if (ft->empty()) {
3287     // Check for evil case of 'this' being a class and 'kills' expecting an
3288     // interface.  This can happen because the bytecodes do not contain
3289     // enough type info to distinguish a Java-level interface variable
3290     // from a Java-level object variable.  If we meet 2 classes which
3291     // both implement interface I, but their meet is at 'j/l/O' which
3292     // doesn't implement I, we have no way to tell if the result should
3293     // be 'I' or 'j/l/O'.  Thus we'll pick 'j/l/O'.  If this then flows
3294     // into a Phi which "knows" it's an Interface type we'll have to
3295     // uplift the type.
3296     if (!empty()) {
3297       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3298         return kills;           // Uplift to interface
3299       }
3300       // Also check for evil cases of 'this' being a class array
3301       // and 'kills' expecting an array of interfaces.
3302       Type::get_arrays_base_elements(ft, kills, NULL, &ktip);
3303       if (ktip != NULL && ktip->is_loaded() && ktip->klass()->is_interface()) {
3304         return kills;           // Uplift to array of interface
3305       }
3306     }
3307 
3308     return Type::TOP;           // Canonical empty value
3309   }
3310 
3311   // If we have an interface-typed Phi or cast and we narrow to a class type,
3312   // the join should report back the class.  However, if we have a J/L/Object
3313   // class-typed Phi and an interface flows in, it's possible that the meet &
3314   // join report an interface back out.  This isn't possible but happens
3315   // because the type system doesn't interact well with interfaces.
3316   if (ftip != NULL && ktip != NULL &&
3317       ftip->is_loaded() &&  ftip->klass()->is_interface() &&
3318       ktip->is_loaded() && !ktip->klass()->is_interface()) {
3319     assert(!ftip->klass_is_exact(), "interface could not be exact");
3320     return ktip->cast_to_ptr_type(ftip->ptr());
3321   }
3322 
3323   return ft;
3324 }
3325 
3326 //------------------------------eq---------------------------------------------
3327 // Structural equality check for Type representations
3328 bool TypeOopPtr::eq( const Type *t ) const {
3329   const TypeOopPtr *a = (const TypeOopPtr*)t;
3330   if (_klass_is_exact != a->_klass_is_exact ||
3331       _instance_id != a->_instance_id)  return false;
3332   ciObject* one = const_oop();
3333   ciObject* two = a->const_oop();
3334   if (one == NULL || two == NULL) {
3335     return (one == two) && TypePtr::eq(t);
3336   } else {
3337     return one->equals(two) && TypePtr::eq(t);
3338   }
3339 }
3340 
3341 //------------------------------hash-------------------------------------------
3342 // Type-specific hashing function.
3343 int TypeOopPtr::hash(void) const {
3344   return
3345     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3346              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3347 }
3348 
3349 //------------------------------dump2------------------------------------------
3350 #ifndef PRODUCT
3351 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3352   st->print("oopptr:%s", ptr_msg[_ptr]);
3353   if( _klass_is_exact ) st->print(":exact");
3354   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3355   switch( _offset ) {
3356   case OffsetTop: st->print("+top"); break;
3357   case OffsetBot: st->print("+any"); break;
3358   case         0: break;
3359   default:        st->print("+%d",_offset); break;
3360   }
3361   if (_instance_id == InstanceTop)
3362     st->print(",iid=top");
3363   else if (_instance_id != InstanceBot)
3364     st->print(",iid=%d",_instance_id);
3365 
3366   dump_inline_depth(st);
3367   dump_speculative(st);
3368 }
3369 #endif
3370 
3371 //------------------------------singleton--------------------------------------
3372 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3373 // constants
3374 bool TypeOopPtr::singleton(void) const {
3375   // detune optimizer to not generate constant oop + constant offset as a constant!
3376   // TopPTR, Null, AnyNull, Constant are all singletons
3377   return (_offset == 0) && !below_centerline(_ptr);
3378 }
3379 
3380 //------------------------------add_offset-------------------------------------
3381 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3382   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3383 }
3384 
3385 /**
3386  * Return same type without a speculative part
3387  */
3388 const Type* TypeOopPtr::remove_speculative() const {
3389   if (_speculative == NULL) {
3390     return this;
3391   }
3392   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3393   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3394 }
3395 
3396 /**
3397  * Return same type but drop speculative part if we know we won't use
3398  * it
3399  */
3400 const Type* TypeOopPtr::cleanup_speculative() const {
3401   // If the klass is exact and the ptr is not null then there's
3402   // nothing that the speculative type can help us with
3403   if (klass_is_exact() && !maybe_null()) {
3404     return remove_speculative();
3405   }
3406   return TypePtr::cleanup_speculative();
3407 }
3408 
3409 /**
3410  * Return same type but with a different inline depth (used for speculation)
3411  *
3412  * @param depth  depth to meet with
3413  */
3414 const TypePtr* TypeOopPtr::with_inline_depth(int depth) const {
3415   if (!UseInlineDepthForSpeculativeTypes) {
3416     return this;
3417   }
3418   return make(_ptr, _offset, _instance_id, _speculative, depth);
3419 }
3420 
3421 //------------------------------meet_instance_id--------------------------------
3422 int TypeOopPtr::meet_instance_id( int instance_id ) const {
3423   // Either is 'TOP' instance?  Return the other instance!
3424   if( _instance_id == InstanceTop ) return  instance_id;
3425   if(  instance_id == InstanceTop ) return _instance_id;
3426   // If either is different, return 'BOTTOM' instance
3427   if( _instance_id != instance_id ) return InstanceBot;
3428   return _instance_id;
3429 }
3430 
3431 //------------------------------dual_instance_id--------------------------------
3432 int TypeOopPtr::dual_instance_id( ) const {
3433   if( _instance_id == InstanceTop ) return InstanceBot; // Map TOP into BOTTOM
3434   if( _instance_id == InstanceBot ) return InstanceTop; // Map BOTTOM into TOP
3435   return _instance_id;              // Map everything else into self
3436 }
3437 
3438 /**
3439  * Check whether new profiling would improve speculative type
3440  *
3441  * @param   exact_kls    class from profiling
3442  * @param   inline_depth inlining depth of profile point
3443  *
3444  * @return  true if type profile is valuable
3445  */
3446 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3447   // no way to improve an already exact type
3448   if (klass_is_exact()) {
3449     return false;
3450   }
3451   return TypePtr::would_improve_type(exact_kls, inline_depth);
3452 }
3453 
3454 //=============================================================================
3455 // Convenience common pre-built types.
3456 const TypeInstPtr *TypeInstPtr::NOTNULL;
3457 const TypeInstPtr *TypeInstPtr::BOTTOM;
3458 const TypeInstPtr *TypeInstPtr::MIRROR;
3459 const TypeInstPtr *TypeInstPtr::MARK;
3460 const TypeInstPtr *TypeInstPtr::KLASS;
3461 
3462 //------------------------------TypeInstPtr-------------------------------------
3463 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off,
3464                          int instance_id, const TypePtr* speculative, int inline_depth)
3465   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth),
3466     _name(k->name()) {
3467    assert(k != NULL &&
3468           (k->is_loaded() || o == NULL),
3469           "cannot have constants with non-loaded klass");
3470 };
3471 
3472 //------------------------------make-------------------------------------------
3473 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3474                                      ciKlass* k,
3475                                      bool xk,
3476                                      ciObject* o,
3477                                      int offset,
3478                                      int instance_id,
3479                                      const TypePtr* speculative,
3480                                      int inline_depth) {
3481   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3482   // Either const_oop() is NULL or else ptr is Constant
3483   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3484           "constant pointers must have a value supplied" );
3485   // Ptr is never Null
3486   assert( ptr != Null, "NULL pointers are not typed" );
3487 
3488   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
3489   if (!UseExactTypes)  xk = false;
3490   if (ptr == Constant) {
3491     // Note:  This case includes meta-object constants, such as methods.
3492     xk = true;
3493   } else if (k->is_loaded()) {
3494     ciInstanceKlass* ik = k->as_instance_klass();
3495     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3496     if (xk && ik->is_interface())  xk = false;  // no exact interface
3497   }
3498 
3499   // Now hash this baby
3500   TypeInstPtr *result =
3501     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3502 
3503   return result;
3504 }
3505 
3506 /**
3507  *  Create constant type for a constant boxed value
3508  */
3509 const Type* TypeInstPtr::get_const_boxed_value() const {
3510   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3511   assert((const_oop() != NULL), "should be called only for constant object");
3512   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3513   BasicType bt = constant.basic_type();
3514   switch (bt) {
3515     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3516     case T_INT:      return TypeInt::make(constant.as_int());
3517     case T_CHAR:     return TypeInt::make(constant.as_char());
3518     case T_BYTE:     return TypeInt::make(constant.as_byte());
3519     case T_SHORT:    return TypeInt::make(constant.as_short());
3520     case T_FLOAT:    return TypeF::make(constant.as_float());
3521     case T_DOUBLE:   return TypeD::make(constant.as_double());
3522     case T_LONG:     return TypeLong::make(constant.as_long());
3523     default:         break;
3524   }
3525   fatal("Invalid boxed value type '%s'", type2name(bt));
3526   return NULL;
3527 }
3528 
3529 //------------------------------cast_to_ptr_type-------------------------------
3530 const Type *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3531   if( ptr == _ptr ) return this;
3532   // Reconstruct _sig info here since not a problem with later lazy
3533   // construction, _sig will show up on demand.
3534   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3535 }
3536 
3537 
3538 //-----------------------------cast_to_exactness-------------------------------
3539 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3540   if( klass_is_exact == _klass_is_exact ) return this;
3541   if (!UseExactTypes)  return this;
3542   if (!_klass->is_loaded())  return this;
3543   ciInstanceKlass* ik = _klass->as_instance_klass();
3544   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3545   if( ik->is_interface() )              return this;  // cannot set xk
3546   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3547 }
3548 
3549 //-----------------------------cast_to_instance_id----------------------------
3550 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3551   if( instance_id == _instance_id ) return this;
3552   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3553 }
3554 
3555 const TypeOopPtr *TypeInstPtr::cast_to_nonconst() const {
3556   if (const_oop() == NULL) return this;
3557   return make(NotNull, klass(), _klass_is_exact, NULL, _offset, _instance_id, _speculative, _inline_depth);
3558 }
3559 
3560 //------------------------------xmeet_unloaded---------------------------------
3561 // Compute the MEET of two InstPtrs when at least one is unloaded.
3562 // Assume classes are different since called after check for same name/class-loader
3563 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3564     int off = meet_offset(tinst->offset());
3565     PTR ptr = meet_ptr(tinst->ptr());
3566     int instance_id = meet_instance_id(tinst->instance_id());
3567     const TypePtr* speculative = xmeet_speculative(tinst);
3568     int depth = meet_inline_depth(tinst->inline_depth());
3569 
3570     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3571     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3572     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3573       //
3574       // Meet unloaded class with java/lang/Object
3575       //
3576       // Meet
3577       //          |                     Unloaded Class
3578       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3579       //  ===================================================================
3580       //   TOP    | ..........................Unloaded......................|
3581       //  AnyNull |  U-AN    |................Unloaded......................|
3582       // Constant | ... O-NN .................................. |   O-BOT   |
3583       //  NotNull | ... O-NN .................................. |   O-BOT   |
3584       //  BOTTOM  | ........................Object-BOTTOM ..................|
3585       //
3586       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3587       //
3588       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3589       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3590       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3591       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3592         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3593         else                                      { return TypeInstPtr::NOTNULL; }
3594       }
3595       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3596 
3597       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3598     }
3599 
3600     // Both are unloaded, not the same class, not Object
3601     // Or meet unloaded with a different loaded class, not java/lang/Object
3602     if( ptr != TypePtr::BotPTR ) {
3603       return TypeInstPtr::NOTNULL;
3604     }
3605     return TypeInstPtr::BOTTOM;
3606 }
3607 
3608 
3609 //------------------------------meet-------------------------------------------
3610 // Compute the MEET of two types.  It returns a new Type object.
3611 const Type *TypeInstPtr::xmeet_helper(const Type *t) const {
3612   // Perform a fast test for common case; meeting the same types together.
3613   if( this == t ) return this;  // Meeting same type-rep?
3614 
3615   // Current "this->_base" is Pointer
3616   switch (t->base()) {          // switch on original type
3617 
3618   case Int:                     // Mixing ints & oops happens when javac
3619   case Long:                    // reuses local variables
3620   case FloatTop:
3621   case FloatCon:
3622   case FloatBot:
3623   case DoubleTop:
3624   case DoubleCon:
3625   case DoubleBot:
3626   case NarrowOop:
3627   case NarrowKlass:
3628   case Bottom:                  // Ye Olde Default
3629     return Type::BOTTOM;
3630   case Top:
3631     return this;
3632 
3633   default:                      // All else is a mistake
3634     typerr(t);
3635 
3636   case MetadataPtr:
3637   case KlassPtr:
3638   case RawPtr: return TypePtr::BOTTOM;
3639 
3640   case AryPtr: {                // All arrays inherit from Object class
3641     const TypeAryPtr *tp = t->is_aryptr();
3642     int offset = meet_offset(tp->offset());
3643     PTR ptr = meet_ptr(tp->ptr());
3644     int instance_id = meet_instance_id(tp->instance_id());
3645     const TypePtr* speculative = xmeet_speculative(tp);
3646     int depth = meet_inline_depth(tp->inline_depth());
3647     switch (ptr) {
3648     case TopPTR:
3649     case AnyNull:                // Fall 'down' to dual of object klass
3650       // For instances when a subclass meets a superclass we fall
3651       // below the centerline when the superclass is exact. We need to
3652       // do the same here.
3653       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3654         return TypeAryPtr::make(ptr, tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3655       } else {
3656         // cannot subclass, so the meet has to fall badly below the centerline
3657         ptr = NotNull;
3658         instance_id = InstanceBot;
3659         return TypeInstPtr::make( ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3660       }
3661     case Constant:
3662     case NotNull:
3663     case BotPTR:                // Fall down to object klass
3664       // LCA is object_klass, but if we subclass from the top we can do better
3665       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
3666         // If 'this' (InstPtr) is above the centerline and it is Object class
3667         // then we can subclass in the Java class hierarchy.
3668         // For instances when a subclass meets a superclass we fall
3669         // below the centerline when the superclass is exact. We need
3670         // to do the same here.
3671         if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
3672           // that is, tp's array type is a subtype of my klass
3673           return TypeAryPtr::make(ptr, (ptr == Constant ? tp->const_oop() : NULL),
3674                                   tp->ary(), tp->klass(), tp->klass_is_exact(), offset, instance_id, speculative, depth);
3675         }
3676       }
3677       // The other case cannot happen, since I cannot be a subtype of an array.
3678       // The meet falls down to Object class below centerline.
3679       if( ptr == Constant )
3680          ptr = NotNull;
3681       instance_id = InstanceBot;
3682       return make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
3683     default: typerr(t);
3684     }
3685   }
3686 
3687   case OopPtr: {                // Meeting to OopPtrs
3688     // Found a OopPtr type vs self-InstPtr type
3689     const TypeOopPtr *tp = t->is_oopptr();
3690     int offset = meet_offset(tp->offset());
3691     PTR ptr = meet_ptr(tp->ptr());
3692     switch (tp->ptr()) {
3693     case TopPTR:
3694     case AnyNull: {
3695       int instance_id = meet_instance_id(InstanceTop);
3696       const TypePtr* speculative = xmeet_speculative(tp);
3697       int depth = meet_inline_depth(tp->inline_depth());
3698       return make(ptr, klass(), klass_is_exact(),
3699                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3700     }
3701     case NotNull:
3702     case BotPTR: {
3703       int instance_id = meet_instance_id(tp->instance_id());
3704       const TypePtr* speculative = xmeet_speculative(tp);
3705       int depth = meet_inline_depth(tp->inline_depth());
3706       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3707     }
3708     default: typerr(t);
3709     }
3710   }
3711 
3712   case AnyPtr: {                // Meeting to AnyPtrs
3713     // Found an AnyPtr type vs self-InstPtr type
3714     const TypePtr *tp = t->is_ptr();
3715     int offset = meet_offset(tp->offset());
3716     PTR ptr = meet_ptr(tp->ptr());
3717     int instance_id = meet_instance_id(InstanceTop);
3718     const TypePtr* speculative = xmeet_speculative(tp);
3719     int depth = meet_inline_depth(tp->inline_depth());
3720     switch (tp->ptr()) {
3721     case Null:
3722       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3723       // else fall through to AnyNull
3724     case TopPTR:
3725     case AnyNull: {
3726       return make(ptr, klass(), klass_is_exact(),
3727                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3728     }
3729     case NotNull:
3730     case BotPTR:
3731       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3732     default: typerr(t);
3733     }
3734   }
3735 
3736   /*
3737                  A-top         }
3738                /   |   \       }  Tops
3739            B-top A-any C-top   }
3740               | /  |  \ |      }  Any-nulls
3741            B-any   |   C-any   }
3742               |    |    |
3743            B-con A-con C-con   } constants; not comparable across classes
3744               |    |    |
3745            B-not   |   C-not   }
3746               | \  |  / |      }  not-nulls
3747            B-bot A-not C-bot   }
3748                \   |   /       }  Bottoms
3749                  A-bot         }
3750   */
3751 
3752   case InstPtr: {                // Meeting 2 Oops?
3753     // Found an InstPtr sub-type vs self-InstPtr type
3754     const TypeInstPtr *tinst = t->is_instptr();
3755     int off = meet_offset( tinst->offset() );
3756     PTR ptr = meet_ptr( tinst->ptr() );
3757     int instance_id = meet_instance_id(tinst->instance_id());
3758     const TypePtr* speculative = xmeet_speculative(tinst);
3759     int depth = meet_inline_depth(tinst->inline_depth());
3760 
3761     // Check for easy case; klasses are equal (and perhaps not loaded!)
3762     // If we have constants, then we created oops so classes are loaded
3763     // and we can handle the constants further down.  This case handles
3764     // both-not-loaded or both-loaded classes
3765     if (ptr != Constant && klass()->equals(tinst->klass()) && klass_is_exact() == tinst->klass_is_exact()) {
3766       return make(ptr, klass(), klass_is_exact(), NULL, off, instance_id, speculative, depth);
3767     }
3768 
3769     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3770     ciKlass* tinst_klass = tinst->klass();
3771     ciKlass* this_klass  = this->klass();
3772     bool tinst_xk = tinst->klass_is_exact();
3773     bool this_xk  = this->klass_is_exact();
3774     if (!tinst_klass->is_loaded() || !this_klass->is_loaded() ) {
3775       // One of these classes has not been loaded
3776       const TypeInstPtr *unloaded_meet = xmeet_unloaded(tinst);
3777 #ifndef PRODUCT
3778       if( PrintOpto && Verbose ) {
3779         tty->print("meet of unloaded classes resulted in: "); unloaded_meet->dump(); tty->cr();
3780         tty->print("  this == "); this->dump(); tty->cr();
3781         tty->print(" tinst == "); tinst->dump(); tty->cr();
3782       }
3783 #endif
3784       return unloaded_meet;
3785     }
3786 
3787     // Handle mixing oops and interfaces first.
3788     if( this_klass->is_interface() && !(tinst_klass->is_interface() ||
3789                                         tinst_klass == ciEnv::current()->Object_klass())) {
3790       ciKlass *tmp = tinst_klass; // Swap interface around
3791       tinst_klass = this_klass;
3792       this_klass = tmp;
3793       bool tmp2 = tinst_xk;
3794       tinst_xk = this_xk;
3795       this_xk = tmp2;
3796     }
3797     if (tinst_klass->is_interface() &&
3798         !(this_klass->is_interface() ||
3799           // Treat java/lang/Object as an honorary interface,
3800           // because we need a bottom for the interface hierarchy.
3801           this_klass == ciEnv::current()->Object_klass())) {
3802       // Oop meets interface!
3803 
3804       // See if the oop subtypes (implements) interface.
3805       ciKlass *k;
3806       bool xk;
3807       if( this_klass->is_subtype_of( tinst_klass ) ) {
3808         // Oop indeed subtypes.  Now keep oop or interface depending
3809         // on whether we are both above the centerline or either is
3810         // below the centerline.  If we are on the centerline
3811         // (e.g., Constant vs. AnyNull interface), use the constant.
3812         k  = below_centerline(ptr) ? tinst_klass : this_klass;
3813         // If we are keeping this_klass, keep its exactness too.
3814         xk = below_centerline(ptr) ? tinst_xk    : this_xk;
3815       } else {                  // Does not implement, fall to Object
3816         // Oop does not implement interface, so mixing falls to Object
3817         // just like the verifier does (if both are above the
3818         // centerline fall to interface)
3819         k = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3820         xk = above_centerline(ptr) ? tinst_xk : false;
3821         // Watch out for Constant vs. AnyNull interface.
3822         if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
3823         instance_id = InstanceBot;
3824       }
3825       ciObject* o = NULL;  // the Constant value, if any
3826       if (ptr == Constant) {
3827         // Find out which constant.
3828         o = (this_klass == klass()) ? const_oop() : tinst->const_oop();
3829       }
3830       return make(ptr, k, xk, o, off, instance_id, speculative, depth);
3831     }
3832 
3833     // Either oop vs oop or interface vs interface or interface vs Object
3834 
3835     // !!! Here's how the symmetry requirement breaks down into invariants:
3836     // If we split one up & one down AND they subtype, take the down man.
3837     // If we split one up & one down AND they do NOT subtype, "fall hard".
3838     // If both are up and they subtype, take the subtype class.
3839     // If both are up and they do NOT subtype, "fall hard".
3840     // If both are down and they subtype, take the supertype class.
3841     // If both are down and they do NOT subtype, "fall hard".
3842     // Constants treated as down.
3843 
3844     // Now, reorder the above list; observe that both-down+subtype is also
3845     // "fall hard"; "fall hard" becomes the default case:
3846     // If we split one up & one down AND they subtype, take the down man.
3847     // If both are up and they subtype, take the subtype class.
3848 
3849     // If both are down and they subtype, "fall hard".
3850     // If both are down and they do NOT subtype, "fall hard".
3851     // If both are up and they do NOT subtype, "fall hard".
3852     // If we split one up & one down AND they do NOT subtype, "fall hard".
3853 
3854     // If a proper subtype is exact, and we return it, we return it exactly.
3855     // If a proper supertype is exact, there can be no subtyping relationship!
3856     // If both types are equal to the subtype, exactness is and-ed below the
3857     // centerline and or-ed above it.  (N.B. Constants are always exact.)
3858 
3859     // Check for subtyping:
3860     ciKlass *subtype = NULL;
3861     bool subtype_exact = false;
3862     if( tinst_klass->equals(this_klass) ) {
3863       subtype = this_klass;
3864       subtype_exact = below_centerline(ptr) ? (this_xk & tinst_xk) : (this_xk | tinst_xk);
3865     } else if( !tinst_xk && this_klass->is_subtype_of( tinst_klass ) ) {
3866       subtype = this_klass;     // Pick subtyping class
3867       subtype_exact = this_xk;
3868     } else if( !this_xk && tinst_klass->is_subtype_of( this_klass ) ) {
3869       subtype = tinst_klass;    // Pick subtyping class
3870       subtype_exact = tinst_xk;
3871     }
3872 
3873     if( subtype ) {
3874       if( above_centerline(ptr) ) { // both are up?
3875         this_klass = tinst_klass = subtype;
3876         this_xk = tinst_xk = subtype_exact;
3877       } else if( above_centerline(this ->_ptr) && !above_centerline(tinst->_ptr) ) {
3878         this_klass = tinst_klass; // tinst is down; keep down man
3879         this_xk = tinst_xk;
3880       } else if( above_centerline(tinst->_ptr) && !above_centerline(this ->_ptr) ) {
3881         tinst_klass = this_klass; // this is down; keep down man
3882         tinst_xk = this_xk;
3883       } else {
3884         this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
3885       }
3886     }
3887 
3888     // Check for classes now being equal
3889     if (tinst_klass->equals(this_klass)) {
3890       // If the klasses are equal, the constants may still differ.  Fall to
3891       // NotNull if they do (neither constant is NULL; that is a special case
3892       // handled elsewhere).
3893       ciObject* o = NULL;             // Assume not constant when done
3894       ciObject* this_oop  = const_oop();
3895       ciObject* tinst_oop = tinst->const_oop();
3896       if( ptr == Constant ) {
3897         if (this_oop != NULL && tinst_oop != NULL &&
3898             this_oop->equals(tinst_oop) )
3899           o = this_oop;
3900         else if (above_centerline(this ->_ptr))
3901           o = tinst_oop;
3902         else if (above_centerline(tinst ->_ptr))
3903           o = this_oop;
3904         else
3905           ptr = NotNull;
3906       }
3907       return make(ptr, this_klass, this_xk, o, off, instance_id, speculative, depth);
3908     } // Else classes are not equal
3909 
3910     // Since klasses are different, we require a LCA in the Java
3911     // class hierarchy - which means we have to fall to at least NotNull.
3912     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
3913       ptr = NotNull;
3914 
3915     instance_id = InstanceBot;
3916 
3917     // Now we find the LCA of Java classes
3918     ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
3919     return make(ptr, k, false, NULL, off, instance_id, speculative, depth);
3920   } // End of case InstPtr
3921 
3922   } // End of switch
3923   return this;                  // Return the double constant
3924 }
3925 
3926 
3927 //------------------------java_mirror_type--------------------------------------
3928 ciType* TypeInstPtr::java_mirror_type() const {
3929   // must be a singleton type
3930   if( const_oop() == NULL )  return NULL;
3931 
3932   // must be of type java.lang.Class
3933   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
3934 
3935   return const_oop()->as_instance()->java_mirror_type();
3936 }
3937 
3938 
3939 //------------------------------xdual------------------------------------------
3940 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
3941 // inheritance mechanism.
3942 const Type *TypeInstPtr::xdual() const {
3943   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3944 }
3945 
3946 //------------------------------eq---------------------------------------------
3947 // Structural equality check for Type representations
3948 bool TypeInstPtr::eq( const Type *t ) const {
3949   const TypeInstPtr *p = t->is_instptr();
3950   return
3951     klass()->equals(p->klass()) &&
3952     TypeOopPtr::eq(p);          // Check sub-type stuff
3953 }
3954 
3955 //------------------------------hash-------------------------------------------
3956 // Type-specific hashing function.
3957 int TypeInstPtr::hash(void) const {
3958   int hash = java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash());
3959   return hash;
3960 }
3961 
3962 //------------------------------dump2------------------------------------------
3963 // Dump oop Type
3964 #ifndef PRODUCT
3965 void TypeInstPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3966   // Print the name of the klass.
3967   klass()->print_name_on(st);
3968 
3969   switch( _ptr ) {
3970   case Constant:
3971     // TO DO: Make CI print the hex address of the underlying oop.
3972     if (WizardMode || Verbose) {
3973       const_oop()->print_oop(st);
3974     }
3975   case BotPTR:
3976     if (!WizardMode && !Verbose) {
3977       if( _klass_is_exact ) st->print(":exact");
3978       break;
3979     }
3980   case TopPTR:
3981   case AnyNull:
3982   case NotNull:
3983     st->print(":%s", ptr_msg[_ptr]);
3984     if( _klass_is_exact ) st->print(":exact");
3985     break;
3986   default:
3987     break;
3988   }
3989 
3990   if( _offset ) {               // Dump offset, if any
3991     if( _offset == OffsetBot )      st->print("+any");
3992     else if( _offset == OffsetTop ) st->print("+unknown");
3993     else st->print("+%d", _offset);
3994   }
3995 
3996   st->print(" *");
3997   if (_instance_id == InstanceTop)
3998     st->print(",iid=top");
3999   else if (_instance_id != InstanceBot)
4000     st->print(",iid=%d",_instance_id);
4001 
4002   dump_inline_depth(st);
4003   dump_speculative(st);
4004 }
4005 #endif
4006 
4007 //------------------------------add_offset-------------------------------------
4008 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4009   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4010               _instance_id, add_offset_speculative(offset), _inline_depth);
4011 }
4012 
4013 const Type *TypeInstPtr::remove_speculative() const {
4014   if (_speculative == NULL) {
4015     return this;
4016   }
4017   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4018   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
4019               _instance_id, NULL, _inline_depth);
4020 }
4021 
4022 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4023   if (!UseInlineDepthForSpeculativeTypes) {
4024     return this;
4025   }
4026   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4027 }
4028 
4029 //=============================================================================
4030 // Convenience common pre-built types.
4031 const TypeAryPtr *TypeAryPtr::RANGE;
4032 const TypeAryPtr *TypeAryPtr::OOPS;
4033 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4034 const TypeAryPtr *TypeAryPtr::BYTES;
4035 const TypeAryPtr *TypeAryPtr::SHORTS;
4036 const TypeAryPtr *TypeAryPtr::CHARS;
4037 const TypeAryPtr *TypeAryPtr::INTS;
4038 const TypeAryPtr *TypeAryPtr::LONGS;
4039 const TypeAryPtr *TypeAryPtr::FLOATS;
4040 const TypeAryPtr *TypeAryPtr::DOUBLES;
4041 
4042 //------------------------------make-------------------------------------------
4043 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4044                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4045   assert(!(k == NULL && ary->_elem->isa_int()),
4046          "integral arrays must be pre-equipped with a class");
4047   if (!xk)  xk = ary->ary_must_be_exact();
4048   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4049   if (!UseExactTypes)  xk = (ptr == Constant);
4050   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4051 }
4052 
4053 //------------------------------make-------------------------------------------
4054 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4055                                    int instance_id, const TypePtr* speculative, int inline_depth,
4056                                    bool is_autobox_cache) {
4057   assert(!(k == NULL && ary->_elem->isa_int()),
4058          "integral arrays must be pre-equipped with a class");
4059   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4060   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4061   assert(instance_id <= 0 || xk || !UseExactTypes, "instances are always exactly typed");
4062   if (!UseExactTypes)  xk = (ptr == Constant);
4063   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4064 }
4065 
4066 //------------------------------cast_to_ptr_type-------------------------------
4067 const Type *TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4068   if( ptr == _ptr ) return this;
4069   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4070 }
4071 
4072 
4073 //-----------------------------cast_to_exactness-------------------------------
4074 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4075   if( klass_is_exact == _klass_is_exact ) return this;
4076   if (!UseExactTypes)  return this;
4077   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4078   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4079 }
4080 
4081 //-----------------------------cast_to_instance_id----------------------------
4082 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4083   if( instance_id == _instance_id ) return this;
4084   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4085 }
4086 
4087 const TypeOopPtr *TypeAryPtr::cast_to_nonconst() const {
4088   if (const_oop() == NULL) return this;
4089   return make(NotNull, NULL, _ary, klass(), _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4090 }
4091 
4092 
4093 //-----------------------------narrow_size_type-------------------------------
4094 // Local cache for arrayOopDesc::max_array_length(etype),
4095 // which is kind of slow (and cached elsewhere by other users).
4096 static jint max_array_length_cache[T_CONFLICT+1];
4097 static jint max_array_length(BasicType etype) {
4098   jint& cache = max_array_length_cache[etype];
4099   jint res = cache;
4100   if (res == 0) {
4101     switch (etype) {
4102     case T_NARROWOOP:
4103       etype = T_OBJECT;
4104       break;
4105     case T_NARROWKLASS:
4106     case T_CONFLICT:
4107     case T_ILLEGAL:
4108     case T_VOID:
4109       etype = T_BYTE;           // will produce conservatively high value
4110       break;
4111     default:
4112       break;
4113     }
4114     cache = res = arrayOopDesc::max_array_length(etype);
4115   }
4116   return res;
4117 }
4118 
4119 // Narrow the given size type to the index range for the given array base type.
4120 // Return NULL if the resulting int type becomes empty.
4121 const TypeInt* TypeAryPtr::narrow_size_type(const TypeInt* size) const {
4122   jint hi = size->_hi;
4123   jint lo = size->_lo;
4124   jint min_lo = 0;
4125   jint max_hi = max_array_length(elem()->basic_type());
4126   //if (index_not_size)  --max_hi;     // type of a valid array index, FTR
4127   bool chg = false;
4128   if (lo < min_lo) {
4129     lo = min_lo;
4130     if (size->is_con()) {
4131       hi = lo;
4132     }
4133     chg = true;
4134   }
4135   if (hi > max_hi) {
4136     hi = max_hi;
4137     if (size->is_con()) {
4138       lo = hi;
4139     }
4140     chg = true;
4141   }
4142   // Negative length arrays will produce weird intermediate dead fast-path code
4143   if (lo > hi)
4144     return TypeInt::ZERO;
4145   if (!chg)
4146     return size;
4147   return TypeInt::make(lo, hi, Type::WidenMin);
4148 }
4149 
4150 //-------------------------------cast_to_size----------------------------------
4151 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4152   assert(new_size != NULL, "");
4153   new_size = narrow_size_type(new_size);
4154   if (new_size == size())  return this;
4155   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4156   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4157 }
4158 
4159 //------------------------------cast_to_stable---------------------------------
4160 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4161   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4162     return this;
4163 
4164   const Type* elem = this->elem();
4165   const TypePtr* elem_ptr = elem->make_ptr();
4166 
4167   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4168     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4169     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4170   }
4171 
4172   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4173 
4174   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4175 }
4176 
4177 //-----------------------------stable_dimension--------------------------------
4178 int TypeAryPtr::stable_dimension() const {
4179   if (!is_stable())  return 0;
4180   int dim = 1;
4181   const TypePtr* elem_ptr = elem()->make_ptr();
4182   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4183     dim += elem_ptr->is_aryptr()->stable_dimension();
4184   return dim;
4185 }
4186 
4187 //----------------------cast_to_autobox_cache-----------------------------------
4188 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache(bool cache) const {
4189   if (is_autobox_cache() == cache)  return this;
4190   const TypeOopPtr* etype = elem()->make_oopptr();
4191   if (etype == NULL)  return this;
4192   // The pointers in the autobox arrays are always non-null.
4193   TypePtr::PTR ptr_type = cache ? TypePtr::NotNull : TypePtr::AnyNull;
4194   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4195   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4196   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, cache);
4197 }
4198 
4199 //------------------------------eq---------------------------------------------
4200 // Structural equality check for Type representations
4201 bool TypeAryPtr::eq( const Type *t ) const {
4202   const TypeAryPtr *p = t->is_aryptr();
4203   return
4204     _ary == p->_ary &&  // Check array
4205     TypeOopPtr::eq(p);  // Check sub-parts
4206 }
4207 
4208 //------------------------------hash-------------------------------------------
4209 // Type-specific hashing function.
4210 int TypeAryPtr::hash(void) const {
4211   return (intptr_t)_ary + TypeOopPtr::hash();
4212 }
4213 
4214 //------------------------------meet-------------------------------------------
4215 // Compute the MEET of two types.  It returns a new Type object.
4216 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4217   // Perform a fast test for common case; meeting the same types together.
4218   if( this == t ) return this;  // Meeting same type-rep?
4219   // Current "this->_base" is Pointer
4220   switch (t->base()) {          // switch on original type
4221 
4222   // Mixing ints & oops happens when javac reuses local variables
4223   case Int:
4224   case Long:
4225   case FloatTop:
4226   case FloatCon:
4227   case FloatBot:
4228   case DoubleTop:
4229   case DoubleCon:
4230   case DoubleBot:
4231   case NarrowOop:
4232   case NarrowKlass:
4233   case Bottom:                  // Ye Olde Default
4234     return Type::BOTTOM;
4235   case Top:
4236     return this;
4237 
4238   default:                      // All else is a mistake
4239     typerr(t);
4240 
4241   case OopPtr: {                // Meeting to OopPtrs
4242     // Found a OopPtr type vs self-AryPtr type
4243     const TypeOopPtr *tp = t->is_oopptr();
4244     int offset = meet_offset(tp->offset());
4245     PTR ptr = meet_ptr(tp->ptr());
4246     int depth = meet_inline_depth(tp->inline_depth());
4247     const TypePtr* speculative = xmeet_speculative(tp);
4248     switch (tp->ptr()) {
4249     case TopPTR:
4250     case AnyNull: {
4251       int instance_id = meet_instance_id(InstanceTop);
4252       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4253                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4254     }
4255     case BotPTR:
4256     case NotNull: {
4257       int instance_id = meet_instance_id(tp->instance_id());
4258       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4259     }
4260     default: ShouldNotReachHere();
4261     }
4262   }
4263 
4264   case AnyPtr: {                // Meeting two AnyPtrs
4265     // Found an AnyPtr type vs self-AryPtr type
4266     const TypePtr *tp = t->is_ptr();
4267     int offset = meet_offset(tp->offset());
4268     PTR ptr = meet_ptr(tp->ptr());
4269     const TypePtr* speculative = xmeet_speculative(tp);
4270     int depth = meet_inline_depth(tp->inline_depth());
4271     switch (tp->ptr()) {
4272     case TopPTR:
4273       return this;
4274     case BotPTR:
4275     case NotNull:
4276       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4277     case Null:
4278       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4279       // else fall through to AnyNull
4280     case AnyNull: {
4281       int instance_id = meet_instance_id(InstanceTop);
4282       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4283                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4284     }
4285     default: ShouldNotReachHere();
4286     }
4287   }
4288 
4289   case MetadataPtr:
4290   case KlassPtr:
4291   case RawPtr: return TypePtr::BOTTOM;
4292 
4293   case AryPtr: {                // Meeting 2 references?
4294     const TypeAryPtr *tap = t->is_aryptr();
4295     int off = meet_offset(tap->offset());
4296     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4297     PTR ptr = meet_ptr(tap->ptr());
4298     int instance_id = meet_instance_id(tap->instance_id());
4299     const TypePtr* speculative = xmeet_speculative(tap);
4300     int depth = meet_inline_depth(tap->inline_depth());
4301     ciKlass* lazy_klass = NULL;
4302     if (tary->_elem->isa_int()) {
4303       // Integral array element types have irrelevant lattice relations.
4304       // It is the klass that determines array layout, not the element type.
4305       if (_klass == NULL)
4306         lazy_klass = tap->_klass;
4307       else if (tap->_klass == NULL || tap->_klass == _klass) {
4308         lazy_klass = _klass;
4309       } else {
4310         // Something like byte[int+] meets char[int+].
4311         // This must fall to bottom, not (int[-128..65535])[int+].
4312         instance_id = InstanceBot;
4313         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4314       }
4315     } else // Non integral arrays.
4316       // Must fall to bottom if exact klasses in upper lattice
4317       // are not equal or super klass is exact.
4318       if ((above_centerline(ptr) || ptr == Constant) && klass() != tap->klass() &&
4319           // meet with top[] and bottom[] are processed further down:
4320           tap->_klass != NULL  && this->_klass != NULL   &&
4321           // both are exact and not equal:
4322           ((tap->_klass_is_exact && this->_klass_is_exact) ||
4323            // 'tap'  is exact and super or unrelated:
4324            (tap->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
4325            // 'this' is exact and super or unrelated:
4326            (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
4327       if (above_centerline(ptr)) {
4328         tary = TypeAry::make(Type::BOTTOM, tary->_size, tary->_stable);
4329       }
4330       return make(NotNull, NULL, tary, lazy_klass, false, off, InstanceBot, speculative, depth);
4331     }
4332 
4333     bool xk = false;
4334     switch (tap->ptr()) {
4335     case AnyNull:
4336     case TopPTR:
4337       // Compute new klass on demand, do not use tap->_klass
4338       if (below_centerline(this->_ptr)) {
4339         xk = this->_klass_is_exact;
4340       } else {
4341         xk = (tap->_klass_is_exact | this->_klass_is_exact);
4342       }
4343       return make(ptr, const_oop(), tary, lazy_klass, xk, off, instance_id, speculative, depth);
4344     case Constant: {
4345       ciObject* o = const_oop();
4346       if( _ptr == Constant ) {
4347         if( tap->const_oop() != NULL && !o->equals(tap->const_oop()) ) {
4348           xk = (klass() == tap->klass());
4349           ptr = NotNull;
4350           o = NULL;
4351           instance_id = InstanceBot;
4352         } else {
4353           xk = true;
4354         }
4355       } else if(above_centerline(_ptr)) {
4356         o = tap->const_oop();
4357         xk = true;
4358       } else {
4359         // Only precise for identical arrays
4360         xk = this->_klass_is_exact && (klass() == tap->klass());
4361       }
4362       return TypeAryPtr::make(ptr, o, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4363     }
4364     case NotNull:
4365     case BotPTR:
4366       // Compute new klass on demand, do not use tap->_klass
4367       if (above_centerline(this->_ptr))
4368             xk = tap->_klass_is_exact;
4369       else  xk = (tap->_klass_is_exact & this->_klass_is_exact) &&
4370               (klass() == tap->klass()); // Only precise for identical arrays
4371       return TypeAryPtr::make(ptr, NULL, tary, lazy_klass, xk, off, instance_id, speculative, depth);
4372     default: ShouldNotReachHere();
4373     }
4374   }
4375 
4376   // All arrays inherit from Object class
4377   case InstPtr: {
4378     const TypeInstPtr *tp = t->is_instptr();
4379     int offset = meet_offset(tp->offset());
4380     PTR ptr = meet_ptr(tp->ptr());
4381     int instance_id = meet_instance_id(tp->instance_id());
4382     const TypePtr* speculative = xmeet_speculative(tp);
4383     int depth = meet_inline_depth(tp->inline_depth());
4384     switch (ptr) {
4385     case TopPTR:
4386     case AnyNull:                // Fall 'down' to dual of object klass
4387       // For instances when a subclass meets a superclass we fall
4388       // below the centerline when the superclass is exact. We need to
4389       // do the same here.
4390       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4391         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4392       } else {
4393         // cannot subclass, so the meet has to fall badly below the centerline
4394         ptr = NotNull;
4395         instance_id = InstanceBot;
4396         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4397       }
4398     case Constant:
4399     case NotNull:
4400     case BotPTR:                // Fall down to object klass
4401       // LCA is object_klass, but if we subclass from the top we can do better
4402       if (above_centerline(tp->ptr())) {
4403         // If 'tp'  is above the centerline and it is Object class
4404         // then we can subclass in the Java class hierarchy.
4405         // For instances when a subclass meets a superclass we fall
4406         // below the centerline when the superclass is exact. We need
4407         // to do the same here.
4408         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4409           // that is, my array type is a subtype of 'tp' klass
4410           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4411                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4412         }
4413       }
4414       // The other case cannot happen, since t cannot be a subtype of an array.
4415       // The meet falls down to Object class below centerline.
4416       if( ptr == Constant )
4417          ptr = NotNull;
4418       instance_id = InstanceBot;
4419       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4420     default: typerr(t);
4421     }
4422   }
4423   }
4424   return this;                  // Lint noise
4425 }
4426 
4427 //------------------------------xdual------------------------------------------
4428 // Dual: compute field-by-field dual
4429 const Type *TypeAryPtr::xdual() const {
4430   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());
4431 }
4432 
4433 //----------------------interface_vs_oop---------------------------------------
4434 #ifdef ASSERT
4435 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4436   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4437   if (t_aryptr) {
4438     return _ary->interface_vs_oop(t_aryptr->_ary);
4439   }
4440   return false;
4441 }
4442 #endif
4443 
4444 //------------------------------dump2------------------------------------------
4445 #ifndef PRODUCT
4446 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4447   _ary->dump2(d,depth,st);
4448   switch( _ptr ) {
4449   case Constant:
4450     const_oop()->print(st);
4451     break;
4452   case BotPTR:
4453     if (!WizardMode && !Verbose) {
4454       if( _klass_is_exact ) st->print(":exact");
4455       break;
4456     }
4457   case TopPTR:
4458   case AnyNull:
4459   case NotNull:
4460     st->print(":%s", ptr_msg[_ptr]);
4461     if( _klass_is_exact ) st->print(":exact");
4462     break;
4463   default:
4464     break;
4465   }
4466 
4467   if( _offset != 0 ) {
4468     int header_size = objArrayOopDesc::header_size() * wordSize;
4469     if( _offset == OffsetTop )       st->print("+undefined");
4470     else if( _offset == OffsetBot )  st->print("+any");
4471     else if( _offset < header_size ) st->print("+%d", _offset);
4472     else {
4473       BasicType basic_elem_type = elem()->basic_type();
4474       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4475       int elem_size = type2aelembytes(basic_elem_type);
4476       st->print("[%d]", (_offset - array_base)/elem_size);
4477     }
4478   }
4479   st->print(" *");
4480   if (_instance_id == InstanceTop)
4481     st->print(",iid=top");
4482   else if (_instance_id != InstanceBot)
4483     st->print(",iid=%d",_instance_id);
4484 
4485   dump_inline_depth(st);
4486   dump_speculative(st);
4487 }
4488 #endif
4489 
4490 bool TypeAryPtr::empty(void) const {
4491   if (_ary->empty())       return true;
4492   return TypeOopPtr::empty();
4493 }
4494 
4495 //------------------------------add_offset-------------------------------------
4496 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4497   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4498 }
4499 
4500 const Type *TypeAryPtr::remove_speculative() const {
4501   if (_speculative == NULL) {
4502     return this;
4503   }
4504   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4505   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);
4506 }
4507 
4508 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4509   if (!UseInlineDepthForSpeculativeTypes) {
4510     return this;
4511   }
4512   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
4513 }
4514 
4515 //=============================================================================
4516 
4517 //------------------------------hash-------------------------------------------
4518 // Type-specific hashing function.
4519 int TypeNarrowPtr::hash(void) const {
4520   return _ptrtype->hash() + 7;
4521 }
4522 
4523 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4524   return _ptrtype->singleton();
4525 }
4526 
4527 bool TypeNarrowPtr::empty(void) const {
4528   return _ptrtype->empty();
4529 }
4530 
4531 intptr_t TypeNarrowPtr::get_con() const {
4532   return _ptrtype->get_con();
4533 }
4534 
4535 bool TypeNarrowPtr::eq( const Type *t ) const {
4536   const TypeNarrowPtr* tc = isa_same_narrowptr(t);
4537   if (tc != NULL) {
4538     if (_ptrtype->base() != tc->_ptrtype->base()) {
4539       return false;
4540     }
4541     return tc->_ptrtype->eq(_ptrtype);
4542   }
4543   return false;
4544 }
4545 
4546 const Type *TypeNarrowPtr::xdual() const {    // Compute dual right now.
4547   const TypePtr* odual = _ptrtype->dual()->is_ptr();
4548   return make_same_narrowptr(odual);
4549 }
4550 
4551 
4552 const Type *TypeNarrowPtr::filter_helper(const Type *kills, bool include_speculative) const {
4553   if (isa_same_narrowptr(kills)) {
4554     const Type* ft =_ptrtype->filter_helper(is_same_narrowptr(kills)->_ptrtype, include_speculative);
4555     if (ft->empty())
4556       return Type::TOP;           // Canonical empty value
4557     if (ft->isa_ptr()) {
4558       return make_hash_same_narrowptr(ft->isa_ptr());
4559     }
4560     return ft;
4561   } else if (kills->isa_ptr()) {
4562     const Type* ft = _ptrtype->join_helper(kills, include_speculative);
4563     if (ft->empty())
4564       return Type::TOP;           // Canonical empty value
4565     return ft;
4566   } else {
4567     return Type::TOP;
4568   }
4569 }
4570 
4571 //------------------------------xmeet------------------------------------------
4572 // Compute the MEET of two types.  It returns a new Type object.
4573 const Type *TypeNarrowPtr::xmeet( const Type *t ) const {
4574   // Perform a fast test for common case; meeting the same types together.
4575   if( this == t ) return this;  // Meeting same type-rep?
4576 
4577   if (t->base() == base()) {
4578     const Type* result = _ptrtype->xmeet(t->make_ptr());
4579     if (result->isa_ptr()) {
4580       return make_hash_same_narrowptr(result->is_ptr());
4581     }
4582     return result;
4583   }
4584 
4585   // Current "this->_base" is NarrowKlass or NarrowOop
4586   switch (t->base()) {          // switch on original type
4587 
4588   case Int:                     // Mixing ints & oops happens when javac
4589   case Long:                    // reuses local variables
4590   case FloatTop:
4591   case FloatCon:
4592   case FloatBot:
4593   case DoubleTop:
4594   case DoubleCon:
4595   case DoubleBot:
4596   case AnyPtr:
4597   case RawPtr:
4598   case OopPtr:
4599   case InstPtr:
4600   case AryPtr:
4601   case MetadataPtr:
4602   case KlassPtr:
4603   case NarrowOop:
4604   case NarrowKlass:
4605 
4606   case Bottom:                  // Ye Olde Default
4607     return Type::BOTTOM;
4608   case Top:
4609     return this;
4610 
4611   default:                      // All else is a mistake
4612     typerr(t);
4613 
4614   } // End of switch
4615 
4616   return this;
4617 }
4618 
4619 #ifndef PRODUCT
4620 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4621   _ptrtype->dump2(d, depth, st);
4622 }
4623 #endif
4624 
4625 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4626 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4627 
4628 
4629 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4630   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();
4631 }
4632 
4633 const Type* TypeNarrowOop::remove_speculative() const {
4634   return make(_ptrtype->remove_speculative()->is_ptr());
4635 }
4636 
4637 const Type* TypeNarrowOop::cleanup_speculative() const {
4638   return make(_ptrtype->cleanup_speculative()->is_ptr());
4639 }
4640 
4641 #ifndef PRODUCT
4642 void TypeNarrowOop::dump2( Dict & d, uint depth, outputStream *st ) const {
4643   st->print("narrowoop: ");
4644   TypeNarrowPtr::dump2(d, depth, st);
4645 }
4646 #endif
4647 
4648 const TypeNarrowKlass *TypeNarrowKlass::NULL_PTR;
4649 
4650 const TypeNarrowKlass* TypeNarrowKlass::make(const TypePtr* type) {
4651   return (const TypeNarrowKlass*)(new TypeNarrowKlass(type))->hashcons();
4652 }
4653 
4654 #ifndef PRODUCT
4655 void TypeNarrowKlass::dump2( Dict & d, uint depth, outputStream *st ) const {
4656   st->print("narrowklass: ");
4657   TypeNarrowPtr::dump2(d, depth, st);
4658 }
4659 #endif
4660 
4661 
4662 //------------------------------eq---------------------------------------------
4663 // Structural equality check for Type representations
4664 bool TypeMetadataPtr::eq( const Type *t ) const {
4665   const TypeMetadataPtr *a = (const TypeMetadataPtr*)t;
4666   ciMetadata* one = metadata();
4667   ciMetadata* two = a->metadata();
4668   if (one == NULL || two == NULL) {
4669     return (one == two) && TypePtr::eq(t);
4670   } else {
4671     return one->equals(two) && TypePtr::eq(t);
4672   }
4673 }
4674 
4675 //------------------------------hash-------------------------------------------
4676 // Type-specific hashing function.
4677 int TypeMetadataPtr::hash(void) const {
4678   return
4679     (metadata() ? metadata()->hash() : 0) +
4680     TypePtr::hash();
4681 }
4682 
4683 //------------------------------singleton--------------------------------------
4684 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4685 // constants
4686 bool TypeMetadataPtr::singleton(void) const {
4687   // detune optimizer to not generate constant metadata + constant offset as a constant!
4688   // TopPTR, Null, AnyNull, Constant are all singletons
4689   return (_offset == 0) && !below_centerline(_ptr);
4690 }
4691 
4692 //------------------------------add_offset-------------------------------------
4693 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
4694   return make( _ptr, _metadata, xadd_offset(offset));
4695 }
4696 
4697 //-----------------------------filter------------------------------------------
4698 // Do not allow interface-vs.-noninterface joins to collapse to top.
4699 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
4700   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
4701   if (ft == NULL || ft->empty())
4702     return Type::TOP;           // Canonical empty value
4703   return ft;
4704 }
4705 
4706  //------------------------------get_con----------------------------------------
4707 intptr_t TypeMetadataPtr::get_con() const {
4708   assert( _ptr == Null || _ptr == Constant, "" );
4709   assert( _offset >= 0, "" );
4710 
4711   if (_offset != 0) {
4712     // After being ported to the compiler interface, the compiler no longer
4713     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4714     // to a handle at compile time.  This handle is embedded in the generated
4715     // code and dereferenced at the time the nmethod is made.  Until that time,
4716     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4717     // have access to the addresses!).  This does not seem to currently happen,
4718     // but this assertion here is to help prevent its occurence.
4719     tty->print_cr("Found oop constant with non-zero offset");
4720     ShouldNotReachHere();
4721   }
4722 
4723   return (intptr_t)metadata()->constant_encoding();
4724 }
4725 
4726 //------------------------------cast_to_ptr_type-------------------------------
4727 const Type *TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
4728   if( ptr == _ptr ) return this;
4729   return make(ptr, metadata(), _offset);
4730 }
4731 
4732 //------------------------------meet-------------------------------------------
4733 // Compute the MEET of two types.  It returns a new Type object.
4734 const Type *TypeMetadataPtr::xmeet( const Type *t ) const {
4735   // Perform a fast test for common case; meeting the same types together.
4736   if( this == t ) return this;  // Meeting same type-rep?
4737 
4738   // Current "this->_base" is OopPtr
4739   switch (t->base()) {          // switch on original type
4740 
4741   case Int:                     // Mixing ints & oops happens when javac
4742   case Long:                    // reuses local variables
4743   case FloatTop:
4744   case FloatCon:
4745   case FloatBot:
4746   case DoubleTop:
4747   case DoubleCon:
4748   case DoubleBot:
4749   case NarrowOop:
4750   case NarrowKlass:
4751   case Bottom:                  // Ye Olde Default
4752     return Type::BOTTOM;
4753   case Top:
4754     return this;
4755 
4756   default:                      // All else is a mistake
4757     typerr(t);
4758 
4759   case AnyPtr: {
4760     // Found an AnyPtr type vs self-OopPtr type
4761     const TypePtr *tp = t->is_ptr();
4762     int offset = meet_offset(tp->offset());
4763     PTR ptr = meet_ptr(tp->ptr());
4764     switch (tp->ptr()) {
4765     case Null:
4766       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4767       // else fall through:
4768     case TopPTR:
4769     case AnyNull: {
4770       return make(ptr, _metadata, offset);
4771     }
4772     case BotPTR:
4773     case NotNull:
4774       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4775     default: typerr(t);
4776     }
4777   }
4778 
4779   case RawPtr:
4780   case KlassPtr:
4781   case OopPtr:
4782   case InstPtr:
4783   case AryPtr:
4784     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
4785 
4786   case MetadataPtr: {
4787     const TypeMetadataPtr *tp = t->is_metadataptr();
4788     int offset = meet_offset(tp->offset());
4789     PTR tptr = tp->ptr();
4790     PTR ptr = meet_ptr(tptr);
4791     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
4792     if (tptr == TopPTR || _ptr == TopPTR ||
4793         metadata()->equals(tp->metadata())) {
4794       return make(ptr, md, offset);
4795     }
4796     // metadata is different
4797     if( ptr == Constant ) {  // Cannot be equal constants, so...
4798       if( tptr == Constant && _ptr != Constant)  return t;
4799       if( _ptr == Constant && tptr != Constant)  return this;
4800       ptr = NotNull;            // Fall down in lattice
4801     }
4802     return make(ptr, NULL, offset);
4803     break;
4804   }
4805   } // End of switch
4806   return this;                  // Return the double constant
4807 }
4808 
4809 
4810 //------------------------------xdual------------------------------------------
4811 // Dual of a pure metadata pointer.
4812 const Type *TypeMetadataPtr::xdual() const {
4813   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
4814 }
4815 
4816 //------------------------------dump2------------------------------------------
4817 #ifndef PRODUCT
4818 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4819   st->print("metadataptr:%s", ptr_msg[_ptr]);
4820   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
4821   switch( _offset ) {
4822   case OffsetTop: st->print("+top"); break;
4823   case OffsetBot: st->print("+any"); break;
4824   case         0: break;
4825   default:        st->print("+%d",_offset); break;
4826   }
4827 }
4828 #endif
4829 
4830 
4831 //=============================================================================
4832 // Convenience common pre-built type.
4833 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
4834 
4835 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
4836   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
4837 }
4838 
4839 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
4840   return make(Constant, m, 0);
4841 }
4842 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
4843   return make(Constant, m, 0);
4844 }
4845 
4846 //------------------------------make-------------------------------------------
4847 // Create a meta data constant
4848 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
4849   assert(m == NULL || !m->is_klass(), "wrong type");
4850   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
4851 }
4852 
4853 
4854 //=============================================================================
4855 // Convenience common pre-built types.
4856 
4857 // Not-null object klass or below
4858 const TypeKlassPtr *TypeKlassPtr::OBJECT;
4859 const TypeKlassPtr *TypeKlassPtr::OBJECT_OR_NULL;
4860 
4861 //------------------------------TypeKlassPtr-----------------------------------
4862 TypeKlassPtr::TypeKlassPtr( PTR ptr, ciKlass* klass, int offset )
4863   : TypePtr(KlassPtr, ptr, offset), _klass(klass), _klass_is_exact(ptr == Constant) {
4864 }
4865 
4866 //------------------------------make-------------------------------------------
4867 // ptr to klass 'k', if Constant, or possibly to a sub-klass if not a Constant
4868 const TypeKlassPtr *TypeKlassPtr::make( PTR ptr, ciKlass* k, int offset ) {
4869   assert( k != NULL, "Expect a non-NULL klass");
4870   assert(k->is_instance_klass() || k->is_array_klass(), "Incorrect type of klass oop");
4871   TypeKlassPtr *r =
4872     (TypeKlassPtr*)(new TypeKlassPtr(ptr, k, offset))->hashcons();
4873 
4874   return r;
4875 }
4876 
4877 //------------------------------eq---------------------------------------------
4878 // Structural equality check for Type representations
4879 bool TypeKlassPtr::eq( const Type *t ) const {
4880   const TypeKlassPtr *p = t->is_klassptr();
4881   return
4882     klass()->equals(p->klass()) &&
4883     TypePtr::eq(p);
4884 }
4885 
4886 //------------------------------hash-------------------------------------------
4887 // Type-specific hashing function.
4888 int TypeKlassPtr::hash(void) const {
4889   return java_add((jint)klass()->hash(), (jint)TypePtr::hash());
4890 }
4891 
4892 //------------------------------singleton--------------------------------------
4893 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4894 // constants
4895 bool TypeKlassPtr::singleton(void) const {
4896   // detune optimizer to not generate constant klass + constant offset as a constant!
4897   // TopPTR, Null, AnyNull, Constant are all singletons
4898   return (_offset == 0) && !below_centerline(_ptr);
4899 }
4900 
4901 // Do not allow interface-vs.-noninterface joins to collapse to top.
4902 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
4903   // logic here mirrors the one from TypeOopPtr::filter. See comments
4904   // there.
4905   const Type* ft = join_helper(kills, include_speculative);
4906   const TypeKlassPtr* ftkp = ft->isa_klassptr();
4907   const TypeKlassPtr* ktkp = kills->isa_klassptr();
4908 
4909   if (ft->empty()) {
4910     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
4911       return kills;             // Uplift to interface
4912 
4913     return Type::TOP;           // Canonical empty value
4914   }
4915 
4916   // Interface klass type could be exact in opposite to interface type,
4917   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
4918   if (ftkp != NULL && ktkp != NULL &&
4919       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
4920       !ftkp->klass_is_exact() && // Keep exact interface klass
4921       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
4922     return ktkp->cast_to_ptr_type(ftkp->ptr());
4923   }
4924 
4925   return ft;
4926 }
4927 
4928 //----------------------compute_klass------------------------------------------
4929 // Compute the defining klass for this class
4930 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
4931   // Compute _klass based on element type.
4932   ciKlass* k_ary = NULL;
4933   const TypeInstPtr *tinst;
4934   const TypeAryPtr *tary;
4935   const Type* el = elem();
4936   if (el->isa_narrowoop()) {
4937     el = el->make_ptr();
4938   }
4939 
4940   // Get element klass
4941   if ((tinst = el->isa_instptr()) != NULL) {
4942     // Compute array klass from element klass
4943     k_ary = ciObjArrayKlass::make(tinst->klass());
4944   } else if ((tary = el->isa_aryptr()) != NULL) {
4945     // Compute array klass from element klass
4946     ciKlass* k_elem = tary->klass();
4947     // If element type is something like bottom[], k_elem will be null.
4948     if (k_elem != NULL)
4949       k_ary = ciObjArrayKlass::make(k_elem);
4950   } else if ((el->base() == Type::Top) ||
4951              (el->base() == Type::Bottom)) {
4952     // element type of Bottom occurs from meet of basic type
4953     // and object; Top occurs when doing join on Bottom.
4954     // Leave k_ary at NULL.
4955   } else {
4956     // Cannot compute array klass directly from basic type,
4957     // since subtypes of TypeInt all have basic type T_INT.
4958 #ifdef ASSERT
4959     if (verify && el->isa_int()) {
4960       // Check simple cases when verifying klass.
4961       BasicType bt = T_ILLEGAL;
4962       if (el == TypeInt::BYTE) {
4963         bt = T_BYTE;
4964       } else if (el == TypeInt::SHORT) {
4965         bt = T_SHORT;
4966       } else if (el == TypeInt::CHAR) {
4967         bt = T_CHAR;
4968       } else if (el == TypeInt::INT) {
4969         bt = T_INT;
4970       } else {
4971         return _klass; // just return specified klass
4972       }
4973       return ciTypeArrayKlass::make(bt);
4974     }
4975 #endif
4976     assert(!el->isa_int(),
4977            "integral arrays must be pre-equipped with a class");
4978     // Compute array klass directly from basic type
4979     k_ary = ciTypeArrayKlass::make(el->basic_type());
4980   }
4981   return k_ary;
4982 }
4983 
4984 //------------------------------klass------------------------------------------
4985 // Return the defining klass for this class
4986 ciKlass* TypeAryPtr::klass() const {
4987   if( _klass ) return _klass;   // Return cached value, if possible
4988 
4989   // Oops, need to compute _klass and cache it
4990   ciKlass* k_ary = compute_klass();
4991 
4992   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
4993     // The _klass field acts as a cache of the underlying
4994     // ciKlass for this array type.  In order to set the field,
4995     // we need to cast away const-ness.
4996     //
4997     // IMPORTANT NOTE: we *never* set the _klass field for the
4998     // type TypeAryPtr::OOPS.  This Type is shared between all
4999     // active compilations.  However, the ciKlass which represents
5000     // this Type is *not* shared between compilations, so caching
5001     // this value would result in fetching a dangling pointer.
5002     //
5003     // Recomputing the underlying ciKlass for each request is
5004     // a bit less efficient than caching, but calls to
5005     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5006     ((TypeAryPtr*)this)->_klass = k_ary;
5007     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5008         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
5009       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5010     }
5011   }
5012   return k_ary;
5013 }
5014 
5015 
5016 //------------------------------add_offset-------------------------------------
5017 // Access internals of klass object
5018 const TypePtr *TypeKlassPtr::add_offset( intptr_t offset ) const {
5019   return make( _ptr, klass(), xadd_offset(offset) );
5020 }
5021 
5022 //------------------------------cast_to_ptr_type-------------------------------
5023 const Type *TypeKlassPtr::cast_to_ptr_type(PTR ptr) const {
5024   assert(_base == KlassPtr, "subclass must override cast_to_ptr_type");
5025   if( ptr == _ptr ) return this;
5026   return make(ptr, _klass, _offset);
5027 }
5028 
5029 
5030 //-----------------------------cast_to_exactness-------------------------------
5031 const Type *TypeKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5032   if( klass_is_exact == _klass_is_exact ) return this;
5033   if (!UseExactTypes)  return this;
5034   return make(klass_is_exact ? Constant : NotNull, _klass, _offset);
5035 }
5036 
5037 
5038 //-----------------------------as_instance_type--------------------------------
5039 // Corresponding type for an instance of the given class.
5040 // It will be NotNull, and exact if and only if the klass type is exact.
5041 const TypeOopPtr* TypeKlassPtr::as_instance_type() const {
5042   ciKlass* k = klass();
5043   bool    xk = klass_is_exact();
5044   //return TypeInstPtr::make(TypePtr::NotNull, k, xk, NULL, 0);
5045   const TypeOopPtr* toop = TypeOopPtr::make_from_klass_raw(k);
5046   guarantee(toop != NULL, "need type for given klass");
5047   toop = toop->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5048   return toop->cast_to_exactness(xk)->is_oopptr();
5049 }
5050 
5051 
5052 //------------------------------xmeet------------------------------------------
5053 // Compute the MEET of two types, return a new Type object.
5054 const Type    *TypeKlassPtr::xmeet( const Type *t ) const {
5055   // Perform a fast test for common case; meeting the same types together.
5056   if( this == t ) return this;  // Meeting same type-rep?
5057 
5058   // Current "this->_base" is Pointer
5059   switch (t->base()) {          // switch on original type
5060 
5061   case Int:                     // Mixing ints & oops happens when javac
5062   case Long:                    // reuses local variables
5063   case FloatTop:
5064   case FloatCon:
5065   case FloatBot:
5066   case DoubleTop:
5067   case DoubleCon:
5068   case DoubleBot:
5069   case NarrowOop:
5070   case NarrowKlass:
5071   case Bottom:                  // Ye Olde Default
5072     return Type::BOTTOM;
5073   case Top:
5074     return this;
5075 
5076   default:                      // All else is a mistake
5077     typerr(t);
5078 
5079   case AnyPtr: {                // Meeting to AnyPtrs
5080     // Found an AnyPtr type vs self-KlassPtr type
5081     const TypePtr *tp = t->is_ptr();
5082     int offset = meet_offset(tp->offset());
5083     PTR ptr = meet_ptr(tp->ptr());
5084     switch (tp->ptr()) {
5085     case TopPTR:
5086       return this;
5087     case Null:
5088       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5089     case AnyNull:
5090       return make( ptr, klass(), offset );
5091     case BotPTR:
5092     case NotNull:
5093       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5094     default: typerr(t);
5095     }
5096   }
5097 
5098   case RawPtr:
5099   case MetadataPtr:
5100   case OopPtr:
5101   case AryPtr:                  // Meet with AryPtr
5102   case InstPtr:                 // Meet with InstPtr
5103     return TypePtr::BOTTOM;
5104 
5105   //
5106   //             A-top         }
5107   //           /   |   \       }  Tops
5108   //       B-top A-any C-top   }
5109   //          | /  |  \ |      }  Any-nulls
5110   //       B-any   |   C-any   }
5111   //          |    |    |
5112   //       B-con A-con C-con   } constants; not comparable across classes
5113   //          |    |    |
5114   //       B-not   |   C-not   }
5115   //          | \  |  / |      }  not-nulls
5116   //       B-bot A-not C-bot   }
5117   //           \   |   /       }  Bottoms
5118   //             A-bot         }
5119   //
5120 
5121   case KlassPtr: {  // Meet two KlassPtr types
5122     const TypeKlassPtr *tkls = t->is_klassptr();
5123     int  off     = meet_offset(tkls->offset());
5124     PTR  ptr     = meet_ptr(tkls->ptr());
5125 
5126     // Check for easy case; klasses are equal (and perhaps not loaded!)
5127     // If we have constants, then we created oops so classes are loaded
5128     // and we can handle the constants further down.  This case handles
5129     // not-loaded classes
5130     if( ptr != Constant && tkls->klass()->equals(klass()) ) {
5131       return make( ptr, klass(), off );
5132     }
5133 
5134     // Classes require inspection in the Java klass hierarchy.  Must be loaded.
5135     ciKlass* tkls_klass = tkls->klass();
5136     ciKlass* this_klass = this->klass();
5137     assert( tkls_klass->is_loaded(), "This class should have been loaded.");
5138     assert( this_klass->is_loaded(), "This class should have been loaded.");
5139 
5140     // If 'this' type is above the centerline and is a superclass of the
5141     // other, we can treat 'this' as having the same type as the other.
5142     if ((above_centerline(this->ptr())) &&
5143         tkls_klass->is_subtype_of(this_klass)) {
5144       this_klass = tkls_klass;
5145     }
5146     // If 'tinst' type is above the centerline and is a superclass of the
5147     // other, we can treat 'tinst' as having the same type as the other.
5148     if ((above_centerline(tkls->ptr())) &&
5149         this_klass->is_subtype_of(tkls_klass)) {
5150       tkls_klass = this_klass;
5151     }
5152 
5153     // Check for classes now being equal
5154     if (tkls_klass->equals(this_klass)) {
5155       // If the klasses are equal, the constants may still differ.  Fall to
5156       // NotNull if they do (neither constant is NULL; that is a special case
5157       // handled elsewhere).
5158       if( ptr == Constant ) {
5159         if (this->_ptr == Constant && tkls->_ptr == Constant &&
5160             this->klass()->equals(tkls->klass()));
5161         else if (above_centerline(this->ptr()));
5162         else if (above_centerline(tkls->ptr()));
5163         else
5164           ptr = NotNull;
5165       }
5166       return make( ptr, this_klass, off );
5167     } // Else classes are not equal
5168 
5169     // Since klasses are different, we require the LCA in the Java
5170     // class hierarchy - which means we have to fall to at least NotNull.
5171     if( ptr == TopPTR || ptr == AnyNull || ptr == Constant )
5172       ptr = NotNull;
5173     // Now we find the LCA of Java classes
5174     ciKlass* k = this_klass->least_common_ancestor(tkls_klass);
5175     return   make( ptr, k, off );
5176   } // End of case KlassPtr
5177 
5178   } // End of switch
5179   return this;                  // Return the double constant
5180 }
5181 
5182 //------------------------------xdual------------------------------------------
5183 // Dual: compute field-by-field dual
5184 const Type    *TypeKlassPtr::xdual() const {
5185   return new TypeKlassPtr( dual_ptr(), klass(), dual_offset() );
5186 }
5187 
5188 //------------------------------get_con----------------------------------------
5189 intptr_t TypeKlassPtr::get_con() const {
5190   assert( _ptr == Null || _ptr == Constant, "" );
5191   assert( _offset >= 0, "" );
5192 
5193   if (_offset != 0) {
5194     // After being ported to the compiler interface, the compiler no longer
5195     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5196     // to a handle at compile time.  This handle is embedded in the generated
5197     // code and dereferenced at the time the nmethod is made.  Until that time,
5198     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5199     // have access to the addresses!).  This does not seem to currently happen,
5200     // but this assertion here is to help prevent its occurence.
5201     tty->print_cr("Found oop constant with non-zero offset");
5202     ShouldNotReachHere();
5203   }
5204 
5205   return (intptr_t)klass()->constant_encoding();
5206 }
5207 //------------------------------dump2------------------------------------------
5208 // Dump Klass Type
5209 #ifndef PRODUCT
5210 void TypeKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5211   switch( _ptr ) {
5212   case Constant:
5213     st->print("precise ");
5214   case NotNull:
5215     {
5216       const char *name = klass()->name()->as_utf8();
5217       if( name ) {
5218         st->print("klass %s: " INTPTR_FORMAT, name, p2i(klass()));
5219       } else {
5220         ShouldNotReachHere();
5221       }
5222     }
5223   case BotPTR:
5224     if( !WizardMode && !Verbose && !_klass_is_exact ) break;
5225   case TopPTR:
5226   case AnyNull:
5227     st->print(":%s", ptr_msg[_ptr]);
5228     if( _klass_is_exact ) st->print(":exact");
5229     break;
5230   default:
5231     break;
5232   }
5233 
5234   if( _offset ) {               // Dump offset, if any
5235     if( _offset == OffsetBot )      { st->print("+any"); }
5236     else if( _offset == OffsetTop ) { st->print("+unknown"); }
5237     else                            { st->print("+%d", _offset); }
5238   }
5239 
5240   st->print(" *");
5241 }
5242 #endif
5243 
5244 
5245 
5246 //=============================================================================
5247 // Convenience common pre-built types.
5248 
5249 //------------------------------make-------------------------------------------
5250 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5251   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();
5252 }
5253 
5254 //------------------------------make-------------------------------------------
5255 const TypeFunc *TypeFunc::make(ciMethod* method) {
5256   Compile* C = Compile::current();
5257   const TypeFunc* tf = C->last_tf(method); // check cache
5258   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5259   const TypeTuple *domain;
5260   if (method->is_static()) {
5261     domain = TypeTuple::make_domain(NULL, method->signature());
5262   } else {
5263     domain = TypeTuple::make_domain(method->holder(), method->signature());
5264   }
5265   const TypeTuple *range  = TypeTuple::make_range(method->signature());
5266   tf = TypeFunc::make(domain, range);
5267   C->set_last_tf(method, tf);  // fill cache
5268   return tf;
5269 }
5270 
5271 //------------------------------meet-------------------------------------------
5272 // Compute the MEET of two types.  It returns a new Type object.
5273 const Type *TypeFunc::xmeet( const Type *t ) const {
5274   // Perform a fast test for common case; meeting the same types together.
5275   if( this == t ) return this;  // Meeting same type-rep?
5276 
5277   // Current "this->_base" is Func
5278   switch (t->base()) {          // switch on original type
5279 
5280   case Bottom:                  // Ye Olde Default
5281     return t;
5282 
5283   default:                      // All else is a mistake
5284     typerr(t);
5285 
5286   case Top:
5287     break;
5288   }
5289   return this;                  // Return the double constant
5290 }
5291 
5292 //------------------------------xdual------------------------------------------
5293 // Dual: compute field-by-field dual
5294 const Type *TypeFunc::xdual() const {
5295   return this;
5296 }
5297 
5298 //------------------------------eq---------------------------------------------
5299 // Structural equality check for Type representations
5300 bool TypeFunc::eq( const Type *t ) const {
5301   const TypeFunc *a = (const TypeFunc*)t;
5302   return _domain == a->_domain &&
5303     _range == a->_range;
5304 }
5305 
5306 //------------------------------hash-------------------------------------------
5307 // Type-specific hashing function.
5308 int TypeFunc::hash(void) const {
5309   return (intptr_t)_domain + (intptr_t)_range;
5310 }
5311 
5312 //------------------------------dump2------------------------------------------
5313 // Dump Function Type
5314 #ifndef PRODUCT
5315 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5316   if( _range->cnt() <= Parms )
5317     st->print("void");
5318   else {
5319     uint i;
5320     for (i = Parms; i < _range->cnt()-1; i++) {
5321       _range->field_at(i)->dump2(d,depth,st);
5322       st->print("/");
5323     }
5324     _range->field_at(i)->dump2(d,depth,st);
5325   }
5326   st->print(" ");
5327   st->print("( ");
5328   if( !depth || d[this] ) {     // Check for recursive dump
5329     st->print("...)");
5330     return;
5331   }
5332   d.Insert((void*)this,(void*)this);    // Stop recursion
5333   if (Parms < _domain->cnt())
5334     _domain->field_at(Parms)->dump2(d,depth-1,st);
5335   for (uint i = Parms+1; i < _domain->cnt(); i++) {
5336     st->print(", ");
5337     _domain->field_at(i)->dump2(d,depth-1,st);
5338   }
5339   st->print(" )");
5340 }
5341 #endif
5342 
5343 //------------------------------singleton--------------------------------------
5344 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5345 // constants (Ldi nodes).  Singletons are integer, float or double constants
5346 // or a single symbol.
5347 bool TypeFunc::singleton(void) const {
5348   return false;                 // Never a singleton
5349 }
5350 
5351 bool TypeFunc::empty(void) const {
5352   return false;                 // Never empty
5353 }
5354 
5355 
5356 BasicType TypeFunc::return_type() const{
5357   if (range()->cnt() == TypeFunc::Parms) {
5358     return T_VOID;
5359   }
5360   return range()->field_at(TypeFunc::Parms)->basic_type();
5361 }