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