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