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