< prev index next >

src/hotspot/share/opto/type.cpp

Print this page

   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/javaClasses.hpp"
  29 #include "classfile/symbolTable.hpp"
  30 #include "compiler/compileLog.hpp"
  31 #include "libadt/dict.hpp"
  32 #include "memory/oopFactory.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "oops/instanceKlass.hpp"
  35 #include "oops/instanceMirrorKlass.hpp"
  36 #include "oops/objArrayKlass.hpp"
  37 #include "oops/typeArrayKlass.hpp"
  38 #include "opto/matcher.hpp"
  39 #include "opto/node.hpp"
  40 #include "opto/opcodes.hpp"
  41 #include "opto/type.hpp"
  42 #include "utilities/powerOfTwo.hpp"
  43 #include "utilities/stringUtils.hpp"
  44 
  45 // Portions of code courtesy of Clifford Click
  46 
  47 // Optimization - Graph Style
  48 
  49 // Dictionary of types shared among compilations.
  50 Dict* Type::_shared_type_dict = NULL;














































  51 
  52 // Array which maps compiler types to Basic Types
  53 const Type::TypeInfo Type::_type_info[Type::lastype] = {
  54   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
  55   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
  56   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
  57   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
  58   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
  59   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
  60   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
  61   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
  62   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
  63   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
  64 
  65 #if defined(PPC64)
  66   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
  67   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
  68   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
  69   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
  70   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
  71   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
  72   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
  73 #elif defined(S390)
  74   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
  75   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
  76   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
  77   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
  78   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
  79   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
  80   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
  81 #else // all other
  82   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
  83   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
  84   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
  85   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
  86   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
  87   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
  88   { Bad,             T_ILLEGAL,    "vectorz:",      false, Op_VecZ,              relocInfo::none          },  // VectorZ
  89 #endif

  90   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
  91   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
  92   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
  93   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
  94   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
  95   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
  96   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
  97   { Bad,             T_METADATA,   "instklass:",    false, Op_RegP,              relocInfo::metadata_type },  // InstKlassPtr
  98   { Bad,             T_METADATA,   "aryklass:",     false, Op_RegP,              relocInfo::metadata_type },  // AryKlassPtr
  99   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
 100   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
 101   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
 102   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
 103   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
 104   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
 105   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
 106   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
 107   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
 108   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
 109   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom

 202   case ciTypeFlow::StateVector::T_NULL:
 203     assert(type == ciTypeFlow::StateVector::null_type(), "");
 204     return TypePtr::NULL_PTR;
 205 
 206   case ciTypeFlow::StateVector::T_LONG2:
 207     // The ciTypeFlow pass pushes a long, then the half.
 208     // We do the same.
 209     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 210     return TypeInt::TOP;
 211 
 212   case ciTypeFlow::StateVector::T_DOUBLE2:
 213     // The ciTypeFlow pass pushes double, then the half.
 214     // Our convention is the same.
 215     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 216     return Type::TOP;
 217 
 218   case T_ADDRESS:
 219     assert(type->is_return_address(), "");
 220     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 221 










 222   default:
 223     // make sure we did not mix up the cases:
 224     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 225     assert(type != ciTypeFlow::StateVector::top_type(), "");
 226     assert(type != ciTypeFlow::StateVector::null_type(), "");
 227     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 228     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 229     assert(!type->is_return_address(), "");
 230 
 231     return Type::get_const_type(type);
 232   }
 233 }
 234 
 235 
 236 //-----------------------make_from_constant------------------------------------
 237 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 238                                      int stable_dimension, bool is_narrow_oop,
 239                                      bool is_autobox_cache) {
 240   switch (constant.basic_type()) {
 241     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
 242     case T_CHAR:     return TypeInt::make(constant.as_char());
 243     case T_BYTE:     return TypeInt::make(constant.as_byte());
 244     case T_SHORT:    return TypeInt::make(constant.as_short());
 245     case T_INT:      return TypeInt::make(constant.as_int());
 246     case T_LONG:     return TypeLong::make(constant.as_long());
 247     case T_FLOAT:    return TypeF::make(constant.as_float());
 248     case T_DOUBLE:   return TypeD::make(constant.as_double());
 249     case T_ARRAY:

 250     case T_OBJECT: {
 251         const Type* con_type = NULL;
 252         ciObject* oop_constant = constant.as_object();
 253         if (oop_constant->is_null_object()) {
 254           con_type = Type::get_zero_type(T_OBJECT);
 255         } else {
 256           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 257           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 258           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 259             con_type = con_type->is_aryptr()->cast_to_autobox_cache();
 260           }
 261           if (stable_dimension > 0) {
 262             assert(FoldStableValues, "sanity");
 263             assert(!con_type->is_zero_type(), "default value for stable field");
 264             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 265           }
 266         }
 267         if (is_narrow_oop) {
 268           con_type = con_type->make_narrowoop();
 269         }
 270         return con_type;
 271       }
 272     case T_ILLEGAL:
 273       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 274       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 275       return NULL;
 276     default:
 277       // Fall through to failure
 278       return NULL;
 279   }
 280 }
 281 
 282 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 283   BasicType conbt = con.basic_type();
 284   switch (conbt) {
 285     case T_BOOLEAN: conbt = T_BYTE;   break;
 286     case T_ARRAY:   conbt = T_OBJECT; break;

 287     default:                          break;
 288   }
 289   switch (loadbt) {
 290     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 291     case T_NARROWOOP: loadbt = T_OBJECT; break;
 292     case T_ARRAY:     loadbt = T_OBJECT; break;

 293     case T_ADDRESS:   loadbt = T_OBJECT; break;
 294     default:                             break;
 295   }
 296   if (conbt == loadbt) {
 297     if (is_unsigned && conbt == T_BYTE) {
 298       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 299       return ciConstant(T_INT, con.as_int() & 0xFF);
 300     } else {
 301       return con;
 302     }
 303   }
 304   if (conbt == T_SHORT && loadbt == T_CHAR) {
 305     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 306     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 307   }
 308   return ciConstant(); // T_ILLEGAL
 309 }
 310 
 311 // Try to constant-fold a stable array element.
 312 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,

 508   const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 509   ffalse[0] = Type::CONTROL;
 510   ffalse[1] = Type::TOP;
 511   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 512 
 513   const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 514   fneither[0] = Type::TOP;
 515   fneither[1] = Type::TOP;
 516   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 517 
 518   const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 519   ftrue[0] = Type::TOP;
 520   ftrue[1] = Type::CONTROL;
 521   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 522 
 523   const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 524   floop[0] = Type::CONTROL;
 525   floop[1] = TypeInt::INT;
 526   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 527 
 528   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
 529   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
 530   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
 531 
 532   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 533   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 534 
 535   const Type **fmembar = TypeTuple::fields(0);
 536   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 537 
 538   const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 539   fsc[0] = TypeInt::CC;
 540   fsc[1] = Type::MEMORY;
 541   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 542 
 543   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 544   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 545   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 546   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 547                                            false, 0, oopDesc::mark_offset_in_bytes());
 548   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 549                                            false, 0, oopDesc::klass_offset_in_bytes());
 550   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);


 551 
 552   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, OffsetBot);
 553 
 554   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 555   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 556 
 557   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 558 
 559   mreg2type[Op_Node] = Type::BOTTOM;
 560   mreg2type[Op_Set ] = 0;
 561   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 562   mreg2type[Op_RegI] = TypeInt::INT;
 563   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 564   mreg2type[Op_RegF] = Type::FLOAT;
 565   mreg2type[Op_RegD] = Type::DOUBLE;
 566   mreg2type[Op_RegL] = TypeLong::LONG;
 567   mreg2type[Op_RegFlags] = TypeInt::CC;
 568 
 569   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
 570 
 571   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
 572 
 573 #ifdef _LP64
 574   if (UseCompressedOops) {
 575     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 576     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 577   } else
 578 #endif
 579   {
 580     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 581     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
 582   }
 583   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
 584   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
 585   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
 586   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
 587   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
 588   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
 589   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);

 590 
 591   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 592   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 593   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;

 594   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 595   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 596   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 597   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 598   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 599   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 600   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 601   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 602   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 603 
 604   TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), 0);
 605   TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 0);
 606 
 607   const Type **fi2c = TypeTuple::fields(2);
 608   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 609   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 610   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 611 
 612   const Type **intpair = TypeTuple::fields(2);
 613   intpair[0] = TypeInt::INT;
 614   intpair[1] = TypeInt::INT;
 615   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 616 
 617   const Type **longpair = TypeTuple::fields(2);
 618   longpair[0] = TypeLong::LONG;
 619   longpair[1] = TypeLong::LONG;
 620   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 621 
 622   const Type **intccpair = TypeTuple::fields(2);
 623   intccpair[0] = TypeInt::INT;
 624   intccpair[1] = TypeInt::CC;
 625   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 626 
 627   const Type **longccpair = TypeTuple::fields(2);
 628   longccpair[0] = TypeLong::LONG;
 629   longccpair[1] = TypeInt::CC;
 630   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 631 
 632   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 633   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 634   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 635   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 636   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 637   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 638   _const_basic_type[T_INT]         = TypeInt::INT;
 639   _const_basic_type[T_LONG]        = TypeLong::LONG;
 640   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 641   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 642   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 643   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays

 644   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 645   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 646   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 647 
 648   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 649   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 650   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 651   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 652   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 653   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 654   _zero_type[T_INT]         = TypeInt::ZERO;
 655   _zero_type[T_LONG]        = TypeLong::ZERO;
 656   _zero_type[T_FLOAT]       = TypeF::ZERO;
 657   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 658   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 659   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop

 660   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 661   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 662 
 663   // get_zero_type() should not happen for T_CONFLICT
 664   _zero_type[T_CONFLICT]= NULL;
 665 
 666   TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
 667   mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
 668 
 669   if (Matcher::supports_scalable_vector()) {
 670     TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
 671   }
 672 
 673   // Vector predefined types, it needs initialized _const_basic_type[].
 674   if (Matcher::vector_size_supported(T_BYTE,4)) {
 675     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 676   }
 677   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 678     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 679   }

 931     return t->xmeet(this);
 932 
 933   case InstPtr:
 934     return t->xmeet(this);
 935 
 936   case MetadataPtr:
 937   case KlassPtr:
 938   case InstKlassPtr:
 939   case AryKlassPtr:
 940     return t->xmeet(this);
 941 
 942   case AryPtr:
 943     return t->xmeet(this);
 944 
 945   case NarrowOop:
 946     return t->xmeet(this);
 947 
 948   case NarrowKlass:
 949     return t->xmeet(this);
 950 



 951   case Bad:                     // Type check
 952   default:                      // Bogus type not in lattice
 953     typerr(t);
 954     return Type::BOTTOM;
 955 
 956   case Bottom:                  // Ye Olde Default
 957     return t;
 958 
 959   case FloatTop:
 960     if( _base == FloatTop ) return this;
 961   case FloatBot:                // Float
 962     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
 963     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
 964     typerr(t);
 965     return Type::BOTTOM;
 966 
 967   case DoubleTop:
 968     if( _base == DoubleTop ) return this;
 969   case DoubleBot:               // Double
 970     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;

1100     case Type::VectorY:
1101     case Type::VectorZ:
1102     case Type::VectorMask:
1103     case Type::AnyPtr:
1104     case Type::RawPtr:
1105     case Type::OopPtr:
1106     case Type::InstPtr:
1107     case Type::AryPtr:
1108     case Type::MetadataPtr:
1109     case Type::KlassPtr:
1110     case Type::InstKlassPtr:
1111     case Type::AryKlassPtr:
1112     case Type::Function:
1113     case Type::Return_Address:
1114     case Type::FloatTop:
1115     case Type::FloatCon:
1116     case Type::FloatBot:
1117     case Type::DoubleTop:
1118     case Type::DoubleCon:
1119     case Type::DoubleBot:

1120       return Category::Data;
1121     case Type::Memory:
1122       return Category::Memory;
1123     case Type::Control:
1124       return Category::Control;
1125     case Type::Top:
1126     case Type::Abio:
1127     case Type::Bottom:
1128       return Category::Other;
1129     case Type::Bad:
1130     case Type::lastype:
1131       return Category::Undef;
1132     case Type::Tuple:
1133       // Recursive case. Return CatMixed if the tuple contains types of
1134       // different categories (e.g. CallStaticJavaNode's type), or the specific
1135       // category if all types are of the same category (e.g. IfNode's type).
1136       tuple = is_tuple();
1137       if (tuple->cnt() == 0) {
1138         return Category::Undef;
1139       } else {

1514   // Currently "this->_base" is a TypeInt
1515   switch (t->base()) {          // Switch on original type
1516   case AnyPtr:                  // Mixing with oops happens when javac
1517   case RawPtr:                  // reuses local variables
1518   case OopPtr:
1519   case InstPtr:
1520   case AryPtr:
1521   case MetadataPtr:
1522   case KlassPtr:
1523   case InstKlassPtr:
1524   case AryKlassPtr:
1525   case NarrowOop:
1526   case NarrowKlass:
1527   case Long:
1528   case FloatTop:
1529   case FloatCon:
1530   case FloatBot:
1531   case DoubleTop:
1532   case DoubleCon:
1533   case DoubleBot:

1534   case Bottom:                  // Ye Olde Default
1535     return Type::BOTTOM;
1536   default:                      // All else is a mistake
1537     typerr(t);
1538   case Top:                     // No change
1539     return this;
1540   case Int:                     // Int vs Int?
1541     break;
1542   }
1543 
1544   // Expand covered set
1545   const TypeInt *r = t->is_int();
1546   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1547 }
1548 
1549 //------------------------------xdual------------------------------------------
1550 // Dual: reverse hi & lo; flip widen
1551 const Type *TypeInt::xdual() const {
1552   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1553   return new TypeInt(_hi,_lo,w);

2001 
2002 bool TypeLong::empty(void) const {
2003   return _lo > _hi;
2004 }
2005 
2006 //=============================================================================
2007 // Convenience common pre-built types.
2008 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2009 const TypeTuple *TypeTuple::IFFALSE;
2010 const TypeTuple *TypeTuple::IFTRUE;
2011 const TypeTuple *TypeTuple::IFNEITHER;
2012 const TypeTuple *TypeTuple::LOOPBODY;
2013 const TypeTuple *TypeTuple::MEMBAR;
2014 const TypeTuple *TypeTuple::STORECONDITIONAL;
2015 const TypeTuple *TypeTuple::START_I2C;
2016 const TypeTuple *TypeTuple::INT_PAIR;
2017 const TypeTuple *TypeTuple::LONG_PAIR;
2018 const TypeTuple *TypeTuple::INT_CC_PAIR;
2019 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2020 












2021 //------------------------------make-------------------------------------------
2022 // Make a TypeTuple from the range of a method signature
2023 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
2024   ciType* return_type = sig->return_type();
2025   uint arg_cnt = return_type->size();








2026   const Type **field_array = fields(arg_cnt);
2027   switch (return_type->basic_type()) {
2028   case T_LONG:
2029     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2030     field_array[TypeFunc::Parms+1] = Type::HALF;
2031     break;
2032   case T_DOUBLE:
2033     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2034     field_array[TypeFunc::Parms+1] = Type::HALF;
2035     break;
2036   case T_OBJECT:
2037   case T_ARRAY:
2038   case T_BOOLEAN:
2039   case T_CHAR:
2040   case T_FLOAT:
2041   case T_BYTE:
2042   case T_SHORT:
2043   case T_INT:
2044     field_array[TypeFunc::Parms] = get_const_type(return_type);
2045     break;













2046   case T_VOID:
2047     break;
2048   default:
2049     ShouldNotReachHere();
2050   }
2051   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2052 }
2053 
2054 // Make a TypeTuple from the domain of a method signature
2055 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
2056   uint arg_cnt = sig->size();








2057 
2058   uint pos = TypeFunc::Parms;
2059   const Type **field_array;
2060   if (recv != NULL) {
2061     arg_cnt++;
2062     field_array = fields(arg_cnt);
2063     // Use get_const_type here because it respects UseUniqueSubclasses:
2064     field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2065   } else {
2066     field_array = fields(arg_cnt);
2067   }
2068 
2069   int i = 0;
2070   while (pos < TypeFunc::Parms + arg_cnt) {
2071     ciType* type = sig->type_at(i);

2072 
2073     switch (type->basic_type()) {
2074     case T_LONG:
2075       field_array[pos++] = TypeLong::LONG;
2076       field_array[pos++] = Type::HALF;
2077       break;
2078     case T_DOUBLE:
2079       field_array[pos++] = Type::DOUBLE;
2080       field_array[pos++] = Type::HALF;
2081       break;
2082     case T_OBJECT:
2083     case T_ARRAY:
2084     case T_FLOAT:
2085     case T_INT:
2086       field_array[pos++] = get_const_type(type);
2087       break;
2088     case T_BOOLEAN:
2089     case T_CHAR:
2090     case T_BYTE:
2091     case T_SHORT:
2092       field_array[pos++] = TypeInt::INT;
2093       break;












2094     default:
2095       ShouldNotReachHere();
2096     }
2097     i++;
2098   }

2099 
2100   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2101 }
2102 
2103 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2104   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2105 }
2106 
2107 //------------------------------fields-----------------------------------------
2108 // Subroutine call type with space allocated for argument types
2109 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2110 const Type **TypeTuple::fields( uint arg_cnt ) {
2111   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2112   flds[TypeFunc::Control  ] = Type::CONTROL;
2113   flds[TypeFunc::I_O      ] = Type::ABIO;
2114   flds[TypeFunc::Memory   ] = Type::MEMORY;
2115   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2116   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2117 
2118   return flds;

2213     if (_fields[i]->empty())  return true;
2214   }
2215   return false;
2216 }
2217 
2218 //=============================================================================
2219 // Convenience common pre-built types.
2220 
2221 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2222   // Certain normalizations keep us sane when comparing types.
2223   // We do not want arrayOop variables to differ only by the wideness
2224   // of their index types.  Pick minimum wideness, since that is the
2225   // forced wideness of small ranges anyway.
2226   if (size->_widen != Type::WidenMin)
2227     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2228   else
2229     return size;
2230 }
2231 
2232 //------------------------------make-------------------------------------------
2233 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {

2234   if (UseCompressedOops && elem->isa_oopptr()) {
2235     elem = elem->make_narrowoop();
2236   }
2237   size = normalize_array_size(size);
2238   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2239 }
2240 
2241 //------------------------------meet-------------------------------------------
2242 // Compute the MEET of two types.  It returns a new Type object.
2243 const Type *TypeAry::xmeet( const Type *t ) const {
2244   // Perform a fast test for common case; meeting the same types together.
2245   if( this == t ) return this;  // Meeting same type-rep?
2246 
2247   // Current "this->_base" is Ary
2248   switch (t->base()) {          // switch on original type
2249 
2250   case Bottom:                  // Ye Olde Default
2251     return t;
2252 
2253   default:                      // All else is a mistake
2254     typerr(t);
2255 
2256   case Array: {                 // Meeting 2 arrays?
2257     const TypeAry *a = t->is_ary();
2258     return TypeAry::make(_elem->meet_speculative(a->_elem),
2259                          _size->xmeet(a->_size)->is_int(),
2260                          _stable && a->_stable);


2261   }
2262   case Top:
2263     break;
2264   }
2265   return this;                  // Return the double constant
2266 }
2267 
2268 //------------------------------xdual------------------------------------------
2269 // Dual: compute field-by-field dual
2270 const Type *TypeAry::xdual() const {
2271   const TypeInt* size_dual = _size->dual()->is_int();
2272   size_dual = normalize_array_size(size_dual);
2273   return new TypeAry(_elem->dual(), size_dual, !_stable);
2274 }
2275 
2276 //------------------------------eq---------------------------------------------
2277 // Structural equality check for Type representations
2278 bool TypeAry::eq( const Type *t ) const {
2279   const TypeAry *a = (const TypeAry*)t;
2280   return _elem == a->_elem &&
2281     _stable == a->_stable &&
2282     _size == a->_size;



2283 }
2284 
2285 //------------------------------hash-------------------------------------------
2286 // Type-specific hashing function.
2287 int TypeAry::hash(void) const {
2288   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2289 }
2290 
2291 /**
2292  * Return same type without a speculative part in the element
2293  */
2294 const TypeAry* TypeAry::remove_speculative() const {
2295   return make(_elem->remove_speculative(), _size, _stable);
2296 }
2297 
2298 /**
2299  * Return same type with cleaned up speculative part of element
2300  */
2301 const Type* TypeAry::cleanup_speculative() const {
2302   return make(_elem->cleanup_speculative(), _size, _stable);
2303 }
2304 
2305 /**
2306  * Return same type but with a different inline depth (used for speculation)
2307  *
2308  * @param depth  depth to meet with
2309  */
2310 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2311   if (!UseInlineDepthForSpeculativeTypes) {
2312     return this;
2313   }
2314   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2315 }
2316 
2317 //----------------------interface_vs_oop---------------------------------------
2318 #ifdef ASSERT
2319 bool TypeAry::interface_vs_oop(const Type *t) const {
2320   const TypeAry* t_ary = t->is_ary();
2321   if (t_ary) {
2322     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2323     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
2324     if(this_ptr != NULL && t_ptr != NULL) {
2325       return this_ptr->interface_vs_oop(t_ptr);
2326     }
2327   }
2328   return false;
2329 }
2330 #endif
2331 
2332 //------------------------------dump2------------------------------------------
2333 #ifndef PRODUCT
2334 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2335   if (_stable)  st->print("stable:");




2336   _elem->dump2(d, depth, st);
2337   st->print("[");
2338   _size->dump2(d, depth, st);
2339   st->print("]");
2340 }
2341 #endif
2342 
2343 //------------------------------singleton--------------------------------------
2344 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2345 // constants (Ldi nodes).  Singletons are integer, float or double constants
2346 // or a single symbol.
2347 bool TypeAry::singleton(void) const {
2348   return false;                 // Never a singleton
2349 }
2350 
2351 bool TypeAry::empty(void) const {
2352   return _elem->empty() || _size->empty();
2353 }
2354 
2355 //--------------------------ary_must_be_exact----------------------------------

2357   // This logic looks at the element type of an array, and returns true
2358   // if the element type is either a primitive or a final instance class.
2359   // In such cases, an array built on this ary must have no subclasses.
2360   if (_elem == BOTTOM)      return false;  // general array not exact
2361   if (_elem == TOP   )      return false;  // inverted general array not exact
2362   const TypeOopPtr*  toop = NULL;
2363   if (UseCompressedOops && _elem->isa_narrowoop()) {
2364     toop = _elem->make_ptr()->isa_oopptr();
2365   } else {
2366     toop = _elem->isa_oopptr();
2367   }
2368   if (!toop)                return true;   // a primitive type, like int
2369   ciKlass* tklass = toop->klass();
2370   if (tklass == NULL)       return false;  // unloaded class
2371   if (!tklass->is_loaded()) return false;  // unloaded class
2372   const TypeInstPtr* tinst;
2373   if (_elem->isa_narrowoop())
2374     tinst = _elem->make_ptr()->isa_instptr();
2375   else
2376     tinst = _elem->isa_instptr();
2377   if (tinst)
2378     return tklass->as_instance_klass()->is_final();








2379   const TypeAryPtr*  tap;
2380   if (_elem->isa_narrowoop())
2381     tap = _elem->make_ptr()->isa_aryptr();
2382   else
2383     tap = _elem->isa_aryptr();
2384   if (tap)
2385     return tap->ary()->ary_must_be_exact();
2386   return false;
2387 }
2388 































































































































2389 //==============================TypeVect=======================================
2390 // Convenience common pre-built types.
2391 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2392 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2393 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2394 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2395 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2396 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2397 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2398 
2399 //------------------------------make-------------------------------------------
2400 const TypeVect* TypeVect::make(const Type *elem, uint length, bool is_mask) {
2401   if (is_mask) {
2402     return makemask(elem, length);
2403   }
2404   BasicType elem_bt = elem->array_element_basic_type();
2405   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2406   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2407   int size = length * type2aelembytes(elem_bt);
2408   switch (Matcher::vector_ideal_reg(size)) {

2554 
2555 //=============================================================================
2556 // Convenience common pre-built types.
2557 const TypePtr *TypePtr::NULL_PTR;
2558 const TypePtr *TypePtr::NOTNULL;
2559 const TypePtr *TypePtr::BOTTOM;
2560 
2561 //------------------------------meet-------------------------------------------
2562 // Meet over the PTR enum
2563 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2564   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2565   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2566   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2567   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2568   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2569   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2570   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2571 };
2572 
2573 //------------------------------make-------------------------------------------
2574 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2575   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2576 }
2577 
2578 //------------------------------cast_to_ptr_type-------------------------------
2579 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2580   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2581   if( ptr == _ptr ) return this;
2582   return make(_base, ptr, _offset, _speculative, _inline_depth);
2583 }
2584 
2585 //------------------------------get_con----------------------------------------
2586 intptr_t TypePtr::get_con() const {
2587   assert( _ptr == Null, "" );
2588   return _offset;
2589 }
2590 
2591 //------------------------------meet-------------------------------------------
2592 // Compute the MEET of two types.  It returns a new Type object.
2593 const Type *TypePtr::xmeet(const Type *t) const {
2594   const Type* res = xmeet_helper(t);
2595   if (res->isa_ptr() == NULL) {
2596     return res;
2597   }
2598 
2599   const TypePtr* res_ptr = res->is_ptr();
2600   if (res_ptr->speculative() != NULL) {
2601     // type->speculative() == NULL means that speculation is no better
2602     // than type, i.e. type->speculative() == type. So there are 2
2603     // ways to represent the fact that we have no useful speculative
2604     // data and we should use a single one to be able to test for
2605     // equality between types. Check whether type->speculative() ==
2606     // type and set speculative to NULL if it is the case.
2607     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2608       return res_ptr->remove_speculative();

2630   case NarrowKlass:
2631   case Bottom:                  // Ye Olde Default
2632     return Type::BOTTOM;
2633   case Top:
2634     return this;
2635 
2636   case AnyPtr: {                // Meeting to AnyPtrs
2637     const TypePtr *tp = t->is_ptr();
2638     const TypePtr* speculative = xmeet_speculative(tp);
2639     int depth = meet_inline_depth(tp->inline_depth());
2640     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2641   }
2642   case RawPtr:                  // For these, flip the call around to cut down
2643   case OopPtr:
2644   case InstPtr:                 // on the cases I have to handle.
2645   case AryPtr:
2646   case MetadataPtr:
2647   case KlassPtr:
2648   case InstKlassPtr:
2649   case AryKlassPtr:

2650     return t->xmeet(this);      // Call in reverse direction
2651   default:                      // All else is a mistake
2652     typerr(t);
2653 
2654   }
2655   return this;
2656 }
2657 
2658 //------------------------------meet_offset------------------------------------
2659 int TypePtr::meet_offset( int offset ) const {
2660   // Either is 'TOP' offset?  Return the other offset!
2661   if( _offset == OffsetTop ) return offset;
2662   if( offset == OffsetTop ) return _offset;
2663   // If either is different, return 'BOTTOM' offset
2664   if( _offset != offset ) return OffsetBot;
2665   return _offset;
2666 }
2667 
2668 //------------------------------dual_offset------------------------------------
2669 int TypePtr::dual_offset( ) const {
2670   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2671   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2672   return _offset;               // Map everything else into self
2673 }
2674 
2675 //------------------------------xdual------------------------------------------
2676 // Dual: compute field-by-field dual
2677 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2678   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2679 };
2680 const Type *TypePtr::xdual() const {
2681   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2682 }
2683 
2684 //------------------------------xadd_offset------------------------------------
2685 int TypePtr::xadd_offset( intptr_t offset ) const {
2686   // Adding to 'TOP' offset?  Return 'TOP'!
2687   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2688   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2689   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2690   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2691   offset += (intptr_t)_offset;
2692   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2693 
2694   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2695   // It is possible to construct a negative offset during PhaseCCP
2696 
2697   return (int)offset;        // Sum valid offsets
2698 }
2699 
2700 //------------------------------add_offset-------------------------------------
2701 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2702   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2703 }
2704 
2705 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2706   return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2707 }
2708 
2709 //------------------------------eq---------------------------------------------
2710 // Structural equality check for Type representations
2711 bool TypePtr::eq( const Type *t ) const {
2712   const TypePtr *a = (const TypePtr*)t;
2713   return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2714 }
2715 
2716 //------------------------------hash-------------------------------------------
2717 // Type-specific hashing function.
2718 int TypePtr::hash(void) const {
2719   return java_add(java_add((jint)_ptr, (jint)_offset), java_add((jint)hash_speculative(), (jint)_inline_depth));
2720 ;
2721 }
2722 
2723 /**
2724  * Return same type without a speculative part
2725  */
2726 const TypePtr* TypePtr::remove_speculative() const {
2727   if (_speculative == NULL) {
2728     return this;
2729   }
2730   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2731   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2732 }
2733 
2734 /**
2735  * Return same type but drop speculative part if we know we won't use
2736  * it
2737  */
2738 const Type* TypePtr::cleanup_speculative() const {
2739   if (speculative() == NULL) {

2966   }
2967   // We already know the speculative type is always null
2968   if (speculative_always_null()) {
2969     return false;
2970   }
2971   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
2972     return false;
2973   }
2974   return true;
2975 }
2976 
2977 //------------------------------dump2------------------------------------------
2978 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2979   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2980 };
2981 
2982 #ifndef PRODUCT
2983 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2984   if( _ptr == Null ) st->print("NULL");
2985   else st->print("%s *", ptr_msg[_ptr]);
2986   if( _offset == OffsetTop ) st->print("+top");
2987   else if( _offset == OffsetBot ) st->print("+bot");
2988   else if( _offset ) st->print("+%d", _offset);
2989   dump_inline_depth(st);
2990   dump_speculative(st);
2991 }
2992 
2993 /**
2994  *dump the speculative part of the type
2995  */
2996 void TypePtr::dump_speculative(outputStream *st) const {
2997   if (_speculative != NULL) {
2998     st->print(" (speculative=");
2999     _speculative->dump_on(st);
3000     st->print(")");
3001   }
3002 }
3003 
3004 /**
3005  *dump the inline depth of the type
3006  */
3007 void TypePtr::dump_inline_depth(outputStream *st) const {
3008   if (_inline_depth != InlineDepthBottom) {
3009     if (_inline_depth == InlineDepthTop) {
3010       st->print(" (inline_depth=InlineDepthTop)");
3011     } else {
3012       st->print(" (inline_depth=%d)", _inline_depth);
3013     }
3014   }
3015 }
3016 #endif
3017 
3018 //------------------------------singleton--------------------------------------
3019 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3020 // constants
3021 bool TypePtr::singleton(void) const {
3022   // TopPTR, Null, AnyNull, Constant are all singletons
3023   return (_offset != OffsetBot) && !below_centerline(_ptr);
3024 }
3025 
3026 bool TypePtr::empty(void) const {
3027   return (_offset == OffsetTop) || above_centerline(_ptr);
3028 }
3029 
3030 //=============================================================================
3031 // Convenience common pre-built types.
3032 const TypeRawPtr *TypeRawPtr::BOTTOM;
3033 const TypeRawPtr *TypeRawPtr::NOTNULL;
3034 
3035 //------------------------------make-------------------------------------------
3036 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3037   assert( ptr != Constant, "what is the constant?" );
3038   assert( ptr != Null, "Use TypePtr for NULL" );
3039   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3040 }
3041 
3042 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3043   assert( bits, "Use TypePtr for NULL" );
3044   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3045 }
3046 
3047 //------------------------------cast_to_ptr_type-------------------------------

3151 // Type-specific hashing function.
3152 int TypeRawPtr::hash(void) const {
3153   return (intptr_t)_bits + TypePtr::hash();
3154 }
3155 
3156 //------------------------------dump2------------------------------------------
3157 #ifndef PRODUCT
3158 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3159   if( _ptr == Constant )
3160     st->print(INTPTR_FORMAT, p2i(_bits));
3161   else
3162     st->print("rawptr:%s", ptr_msg[_ptr]);
3163 }
3164 #endif
3165 
3166 //=============================================================================
3167 // Convenience common pre-built type.
3168 const TypeOopPtr *TypeOopPtr::BOTTOM;
3169 
3170 //------------------------------TypeOopPtr-------------------------------------
3171 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset,
3172                        int instance_id, const TypePtr* speculative, int inline_depth)
3173   : TypePtr(t, ptr, offset, speculative, inline_depth),
3174     _const_oop(o), _klass(k),
3175     _klass_is_exact(xk),
3176     _is_ptr_to_narrowoop(false),
3177     _is_ptr_to_narrowklass(false),
3178     _is_ptr_to_boxed_value(false),
3179     _instance_id(instance_id) {
3180   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3181       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
3182     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3183   }
3184 #ifdef _LP64
3185   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3186     if (_offset == oopDesc::klass_offset_in_bytes()) {
3187       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3188     } else if (klass() == NULL) {
3189       // Array with unknown body type
3190       assert(this->isa_aryptr(), "only arrays without klass");
3191       _is_ptr_to_narrowoop = UseCompressedOops;
3192     } else if (this->isa_aryptr()) {
3193       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3194                              _offset != arrayOopDesc::length_offset_in_bytes());









3195     } else if (klass()->is_instance_klass()) {
3196       ciInstanceKlass* ik = klass()->as_instance_klass();
3197       ciField* field = NULL;
3198       if (this->isa_klassptr()) {
3199         // Perm objects don't use compressed references
3200       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3201         // unsafe access
3202         _is_ptr_to_narrowoop = UseCompressedOops;
3203       } else {
3204         assert(this->isa_instptr(), "must be an instance ptr.");
3205 
3206         if (klass() == ciEnv::current()->Class_klass() &&
3207             (_offset == java_lang_Class::klass_offset() ||
3208              _offset == java_lang_Class::array_klass_offset())) {
3209           // Special hidden fields from the Class.
3210           assert(this->isa_instptr(), "must be an instance ptr.");
3211           _is_ptr_to_narrowoop = false;
3212         } else if (klass() == ciEnv::current()->Class_klass() &&
3213                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3214           // Static fields
3215           ciField* field = NULL;
3216           if (const_oop() != NULL) {
3217             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3218             field = k->get_field_by_offset(_offset, true);
3219           }
3220           if (field != NULL) {
3221             BasicType basic_elem_type = field->layout_type();
3222             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3223           } else {
3224             // unsafe access
3225             _is_ptr_to_narrowoop = UseCompressedOops;






3226           }
3227         } else {
3228           // Instance fields which contains a compressed oop references.
3229           field = ik->get_field_by_offset(_offset, false);

3230           if (field != NULL) {
3231             BasicType basic_elem_type = field->layout_type();
3232             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3233           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3234             // Compile::find_alias_type() cast exactness on all types to verify
3235             // that it does not affect alias type.
3236             _is_ptr_to_narrowoop = UseCompressedOops;
3237           } else {
3238             // Type for the copy start in LibraryCallKit::inline_native_clone().
3239             _is_ptr_to_narrowoop = UseCompressedOops;
3240           }
3241         }
3242       }
3243     }
3244   }
3245 #endif
3246 }
3247 
3248 //------------------------------make-------------------------------------------
3249 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3250                                      const TypePtr* speculative, int inline_depth) {
3251   assert(ptr != Constant, "no constant generic pointers");
3252   ciKlass*  k = Compile::current()->env()->Object_klass();
3253   bool      xk = false;
3254   ciObject* o = NULL;
3255   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3256 }
3257 
3258 
3259 //------------------------------cast_to_ptr_type-------------------------------
3260 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3261   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3262   if( ptr == _ptr ) return this;
3263   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3264 }
3265 
3266 //-----------------------------cast_to_instance_id----------------------------
3267 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3268   // There are no instances of a general oop.
3269   // Return self unchanged.
3270   return this;
3271 }
3272 
3273 //-----------------------------cast_to_exactness-------------------------------
3274 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3275   // There is no such thing as an exact general oop.
3276   // Return self unchanged.
3277   return this;
3278 }
3279 
3280 
3281 //------------------------------as_klass_type----------------------------------
3282 // Return the klass type corresponding to this instance or array type.
3283 // It is the type that is loaded from an object of this type.
3284 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3285   ShouldNotReachHere();
3286   return NULL;
3287 }
3288 
3289 //------------------------------meet-------------------------------------------
3290 // Compute the MEET of two types.  It returns a new Type object.
3291 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3292   // Perform a fast test for common case; meeting the same types together.
3293   if( this == t ) return this;  // Meeting same type-rep?
3294 
3295   // Current "this->_base" is OopPtr
3296   switch (t->base()) {          // switch on original type
3297 
3298   case Int:                     // Mixing ints & oops happens when javac
3299   case Long:                    // reuses local variables
3300   case FloatTop:

3306   case NarrowOop:
3307   case NarrowKlass:
3308   case Bottom:                  // Ye Olde Default
3309     return Type::BOTTOM;
3310   case Top:
3311     return this;
3312 
3313   default:                      // All else is a mistake
3314     typerr(t);
3315 
3316   case RawPtr:
3317   case MetadataPtr:
3318   case KlassPtr:
3319   case InstKlassPtr:
3320   case AryKlassPtr:
3321     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3322 
3323   case AnyPtr: {
3324     // Found an AnyPtr type vs self-OopPtr type
3325     const TypePtr *tp = t->is_ptr();
3326     int offset = meet_offset(tp->offset());
3327     PTR ptr = meet_ptr(tp->ptr());
3328     const TypePtr* speculative = xmeet_speculative(tp);
3329     int depth = meet_inline_depth(tp->inline_depth());
3330     switch (tp->ptr()) {
3331     case Null:
3332       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3333       // else fall through:
3334     case TopPTR:
3335     case AnyNull: {
3336       int instance_id = meet_instance_id(InstanceTop);
3337       return make(ptr, offset, instance_id, speculative, depth);
3338     }
3339     case BotPTR:
3340     case NotNull:
3341       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3342     default: typerr(t);
3343     }
3344   }
3345 
3346   case OopPtr: {                 // Meeting to other OopPtrs

3348     int instance_id = meet_instance_id(tp->instance_id());
3349     const TypePtr* speculative = xmeet_speculative(tp);
3350     int depth = meet_inline_depth(tp->inline_depth());
3351     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3352   }
3353 
3354   case InstPtr:                  // For these, flip the call around to cut down
3355   case AryPtr:
3356     return t->xmeet(this);      // Call in reverse direction
3357 
3358   } // End of switch
3359   return this;                  // Return the double constant
3360 }
3361 
3362 
3363 //------------------------------xdual------------------------------------------
3364 // Dual of a pure heap pointer.  No relevant klass or oop information.
3365 const Type *TypeOopPtr::xdual() const {
3366   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3367   assert(const_oop() == NULL,             "no constants here");
3368   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3369 }
3370 
3371 //--------------------------make_from_klass_common-----------------------------
3372 // Computes the element-type given a klass.
3373 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3374   if (klass->is_instance_klass()) {
3375     Compile* C = Compile::current();
3376     Dependencies* deps = C->dependencies();
3377     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3378     // Element is an instance
3379     bool klass_is_exact = false;
3380     if (klass->is_loaded()) {
3381       // Try to set klass_is_exact.
3382       ciInstanceKlass* ik = klass->as_instance_klass();
3383       klass_is_exact = ik->is_final();
3384       if (!klass_is_exact && klass_change
3385           && deps != NULL && UseUniqueSubclasses) {
3386         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3387         if (sub != NULL) {
3388           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3389           klass = ik = sub;
3390           klass_is_exact = sub->is_final();
3391         }
3392       }
3393       if (!klass_is_exact && try_for_exact && deps != NULL &&
3394           !ik->is_interface() && !ik->has_subklass()) {
3395         // Add a dependence; if concrete subclass added we need to recompile
3396         deps->assert_leaf_type(ik);
3397         klass_is_exact = true;
3398       }
3399     }
3400     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
3401   } else if (klass->is_obj_array_klass()) {
3402     // Element is an object array. Recursively call ourself.
3403     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
3404     bool xk = etype->klass_is_exact();
3405     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);














3406     // We used to pass NotNull in here, asserting that the sub-arrays
3407     // are all not-null.  This is not true in generally, as code can
3408     // slam NULLs down in the subarrays.
3409     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
3410     return arr;
3411   } else if (klass->is_type_array_klass()) {
3412     // Element is an typeArray
3413     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3414     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

3415     // We used to pass NotNull in here, asserting that the array pointer
3416     // is not-null. That was not true in general.
3417     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);





3418     return arr;
3419   } else {
3420     ShouldNotReachHere();
3421     return NULL;
3422   }
3423 }
3424 
3425 //------------------------------make_from_constant-----------------------------
3426 // Make a java pointer from an oop constant
3427 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3428   assert(!o->is_null_object(), "null object not yet handled here.");
3429 
3430   const bool make_constant = require_constant || o->should_be_constant();
3431 
3432   ciKlass* klass = o->klass();
3433   if (klass->is_instance_klass()) {
3434     // Element is an instance
3435     if (make_constant) {
3436       return TypeInstPtr::make(o);
3437     } else {
3438       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3439     }
3440   } else if (klass->is_obj_array_klass()) {
3441     // Element is an object array. Recursively call ourself.
3442     const TypeOopPtr *etype =
3443       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
3444     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));





3445     // We used to pass NotNull in here, asserting that the sub-arrays
3446     // are all not-null.  This is not true in generally, as code can
3447     // slam NULLs down in the subarrays.
3448     if (make_constant) {
3449       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3450     } else {
3451       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3452     }
3453   } else if (klass->is_type_array_klass()) {
3454     // Element is an typeArray
3455     const Type* etype =
3456       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3457     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3458     // We used to pass NotNull in here, asserting that the array pointer
3459     // is not-null. That was not true in general.
3460     if (make_constant) {
3461       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);











3462     } else {
3463       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3464     }
3465   }
3466 
3467   fatal("unhandled object type");
3468   return NULL;
3469 }
3470 
3471 //------------------------------get_con----------------------------------------
3472 intptr_t TypeOopPtr::get_con() const {
3473   assert( _ptr == Null || _ptr == Constant, "" );
3474   assert( _offset >= 0, "" );
3475 
3476   if (_offset != 0) {
3477     // After being ported to the compiler interface, the compiler no longer
3478     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3479     // to a handle at compile time.  This handle is embedded in the generated
3480     // code and dereferenced at the time the nmethod is made.  Until that time,
3481     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3482     // have access to the addresses!).  This does not seem to currently happen,
3483     // but this assertion here is to help prevent its occurrence.
3484     tty->print_cr("Found oop constant with non-zero offset");
3485     ShouldNotReachHere();
3486   }
3487 
3488   return (intptr_t)const_oop()->constant_encoding();
3489 }
3490 
3491 
3492 //-----------------------------filter------------------------------------------
3493 // Do not allow interface-vs.-noninterface joins to collapse to top.
3494 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3495 
3496   const Type* ft = join_helper(kills, include_speculative);

3549     return (one == two) && TypePtr::eq(t);
3550   } else {
3551     return one->equals(two) && TypePtr::eq(t);
3552   }
3553 }
3554 
3555 //------------------------------hash-------------------------------------------
3556 // Type-specific hashing function.
3557 int TypeOopPtr::hash(void) const {
3558   return
3559     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3560              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3561 }
3562 
3563 //------------------------------dump2------------------------------------------
3564 #ifndef PRODUCT
3565 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3566   st->print("oopptr:%s", ptr_msg[_ptr]);
3567   if( _klass_is_exact ) st->print(":exact");
3568   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3569   switch( _offset ) {
3570   case OffsetTop: st->print("+top"); break;
3571   case OffsetBot: st->print("+any"); break;
3572   case         0: break;
3573   default:        st->print("+%d",_offset); break;
3574   }
3575   if (_instance_id == InstanceTop)
3576     st->print(",iid=top");
3577   else if (_instance_id != InstanceBot)
3578     st->print(",iid=%d",_instance_id);
3579 
3580   dump_inline_depth(st);
3581   dump_speculative(st);
3582 }
3583 #endif
3584 
3585 //------------------------------singleton--------------------------------------
3586 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3587 // constants
3588 bool TypeOopPtr::singleton(void) const {
3589   // detune optimizer to not generate constant oop + constant offset as a constant!
3590   // TopPTR, Null, AnyNull, Constant are all singletons
3591   return (_offset == 0) && !below_centerline(_ptr);
3592 }
3593 
3594 //------------------------------add_offset-------------------------------------
3595 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3596   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3597 }
3598 
3599 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3600   return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3601 }
3602 
3603 /**
3604  * Return same type without a speculative part
3605  */
3606 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3607   if (_speculative == NULL) {
3608     return this;
3609   }
3610   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3611   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3612 }
3613 
3614 /**
3615  * Return same type but drop speculative part if we know we won't use
3616  * it
3617  */
3618 const Type* TypeOopPtr::cleanup_speculative() const {
3619   // If the klass is exact and the ptr is not null then there's
3620   // nothing that the speculative type can help us with

3671   // no way to improve an already exact type
3672   if (klass_is_exact()) {
3673     return false;
3674   }
3675   return TypePtr::would_improve_type(exact_kls, inline_depth);
3676 }
3677 
3678 //=============================================================================
3679 // Convenience common pre-built types.
3680 const TypeInstPtr *TypeInstPtr::NOTNULL;
3681 const TypeInstPtr *TypeInstPtr::BOTTOM;
3682 const TypeInstPtr *TypeInstPtr::MIRROR;
3683 const TypeInstPtr *TypeInstPtr::MARK;
3684 const TypeInstPtr *TypeInstPtr::KLASS;
3685 
3686 ciKlass* TypeInstPtr::exact_klass_helper() const {
3687   return _klass;
3688 }
3689 
3690 //------------------------------TypeInstPtr-------------------------------------
3691 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off,
3692                          int instance_id, const TypePtr* speculative, int inline_depth)
3693   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth) {

3694    assert(k != NULL &&
3695           (k->is_loaded() || o == NULL),
3696           "cannot have constants with non-loaded klass");


3697 };
3698 
3699 //------------------------------make-------------------------------------------
3700 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3701                                      ciKlass* k,
3702                                      bool xk,
3703                                      ciObject* o,
3704                                      int offset,

3705                                      int instance_id,
3706                                      const TypePtr* speculative,
3707                                      int inline_depth) {
3708   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3709   // Either const_oop() is NULL or else ptr is Constant
3710   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3711           "constant pointers must have a value supplied" );
3712   // Ptr is never Null
3713   assert( ptr != Null, "NULL pointers are not typed" );
3714 
3715   assert(instance_id <= 0 || xk, "instances are always exactly typed");
3716   if (ptr == Constant) {
3717     // Note:  This case includes meta-object constants, such as methods.
3718     xk = true;
3719   } else if (k->is_loaded()) {
3720     ciInstanceKlass* ik = k->as_instance_klass();
3721     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3722     if (xk && ik->is_interface())  xk = false;  // no exact interface
3723   }
3724 



3725   // Now hash this baby
3726   TypeInstPtr *result =
3727     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3728 
3729   return result;
3730 }
3731 
3732 /**
3733  *  Create constant type for a constant boxed value
3734  */
3735 const Type* TypeInstPtr::get_const_boxed_value() const {
3736   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3737   assert((const_oop() != NULL), "should be called only for constant object");
3738   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3739   BasicType bt = constant.basic_type();
3740   switch (bt) {
3741     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3742     case T_INT:      return TypeInt::make(constant.as_int());
3743     case T_CHAR:     return TypeInt::make(constant.as_char());
3744     case T_BYTE:     return TypeInt::make(constant.as_byte());
3745     case T_SHORT:    return TypeInt::make(constant.as_short());
3746     case T_FLOAT:    return TypeF::make(constant.as_float());
3747     case T_DOUBLE:   return TypeD::make(constant.as_double());
3748     case T_LONG:     return TypeLong::make(constant.as_long());
3749     default:         break;
3750   }
3751   fatal("Invalid boxed value type '%s'", type2name(bt));
3752   return NULL;
3753 }
3754 
3755 //------------------------------cast_to_ptr_type-------------------------------
3756 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3757   if( ptr == _ptr ) return this;
3758   // Reconstruct _sig info here since not a problem with later lazy
3759   // construction, _sig will show up on demand.
3760   return make(ptr, klass(), klass_is_exact(), ptr == Constant ? const_oop() : NULL, _offset, _instance_id, _speculative, _inline_depth);
3761 }
3762 
3763 
3764 //-----------------------------cast_to_exactness-------------------------------
3765 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3766   if( klass_is_exact == _klass_is_exact ) return this;
3767   if (!_klass->is_loaded())  return this;
3768   ciInstanceKlass* ik = _klass->as_instance_klass();
3769   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3770   if( ik->is_interface() )              return this;  // cannot set xk
3771   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3772 }
3773 
3774 //-----------------------------cast_to_instance_id----------------------------
3775 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
3776   if( instance_id == _instance_id ) return this;
3777   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3778 }
3779 
3780 //------------------------------xmeet_unloaded---------------------------------
3781 // Compute the MEET of two InstPtrs when at least one is unloaded.
3782 // Assume classes are different since called after check for same name/class-loader
3783 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3784     int off = meet_offset(tinst->offset());
3785     PTR ptr = meet_ptr(tinst->ptr());
3786     int instance_id = meet_instance_id(tinst->instance_id());
3787     const TypePtr* speculative = xmeet_speculative(tinst);
3788     int depth = meet_inline_depth(tinst->inline_depth());
3789 
3790     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3791     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3792     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3793       //
3794       // Meet unloaded class with java/lang/Object
3795       //
3796       // Meet
3797       //          |                     Unloaded Class
3798       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3799       //  ===================================================================
3800       //   TOP    | ..........................Unloaded......................|
3801       //  AnyNull |  U-AN    |................Unloaded......................|
3802       // Constant | ... O-NN .................................. |   O-BOT   |
3803       //  NotNull | ... O-NN .................................. |   O-BOT   |
3804       //  BOTTOM  | ........................Object-BOTTOM ..................|
3805       //
3806       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3807       //
3808       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3809       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3810       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3811       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3812         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3813         else                                      { return TypeInstPtr::NOTNULL; }
3814       }
3815       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3816 
3817       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3818     }
3819 
3820     // Both are unloaded, not the same class, not Object
3821     // Or meet unloaded with a different loaded class, not java/lang/Object
3822     if( ptr != TypePtr::BotPTR ) {
3823       return TypeInstPtr::NOTNULL;
3824     }
3825     return TypeInstPtr::BOTTOM;
3826 }
3827 
3828 
3829 //------------------------------meet-------------------------------------------

3850   case Top:
3851     return this;
3852 
3853   default:                      // All else is a mistake
3854     typerr(t);
3855 
3856   case MetadataPtr:
3857   case KlassPtr:
3858   case InstKlassPtr:
3859   case AryKlassPtr:
3860   case RawPtr: return TypePtr::BOTTOM;
3861 
3862   case AryPtr: {                // All arrays inherit from Object class
3863     // Call in reverse direction to avoid duplication
3864     return t->is_aryptr()->xmeet_helper(this);
3865   }
3866 
3867   case OopPtr: {                // Meeting to OopPtrs
3868     // Found a OopPtr type vs self-InstPtr type
3869     const TypeOopPtr *tp = t->is_oopptr();
3870     int offset = meet_offset(tp->offset());
3871     PTR ptr = meet_ptr(tp->ptr());
3872     switch (tp->ptr()) {
3873     case TopPTR:
3874     case AnyNull: {
3875       int instance_id = meet_instance_id(InstanceTop);
3876       const TypePtr* speculative = xmeet_speculative(tp);
3877       int depth = meet_inline_depth(tp->inline_depth());
3878       return make(ptr, klass(), klass_is_exact(),
3879                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3880     }
3881     case NotNull:
3882     case BotPTR: {
3883       int instance_id = meet_instance_id(tp->instance_id());
3884       const TypePtr* speculative = xmeet_speculative(tp);
3885       int depth = meet_inline_depth(tp->inline_depth());
3886       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3887     }
3888     default: typerr(t);
3889     }
3890   }
3891 
3892   case AnyPtr: {                // Meeting to AnyPtrs
3893     // Found an AnyPtr type vs self-InstPtr type
3894     const TypePtr *tp = t->is_ptr();
3895     int offset = meet_offset(tp->offset());
3896     PTR ptr = meet_ptr(tp->ptr());
3897     int instance_id = meet_instance_id(InstanceTop);
3898     const TypePtr* speculative = xmeet_speculative(tp);
3899     int depth = meet_inline_depth(tp->inline_depth());
3900     switch (tp->ptr()) {
3901     case Null:
3902       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3903       // else fall through to AnyNull
3904     case TopPTR:
3905     case AnyNull: {
3906       return make(ptr, klass(), klass_is_exact(),
3907                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3908     }
3909     case NotNull:
3910     case BotPTR:
3911       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3912     default: typerr(t);
3913     }
3914   }
3915 
3916   /*
3917                  A-top         }
3918                /   |   \       }  Tops
3919            B-top A-any C-top   }
3920               | /  |  \ |      }  Any-nulls
3921            B-any   |   C-any   }
3922               |    |    |
3923            B-con A-con C-con   } constants; not comparable across classes
3924               |    |    |
3925            B-not   |   C-not   }
3926               | \  |  / |      }  not-nulls
3927            B-bot A-not C-bot   }
3928                \   |   /       }  Bottoms
3929                  A-bot         }
3930   */
3931 
3932   case InstPtr: {                // Meeting 2 Oops?
3933     // Found an InstPtr sub-type vs self-InstPtr type
3934     const TypeInstPtr *tinst = t->is_instptr();
3935     int off = meet_offset(tinst->offset());
3936     PTR ptr = meet_ptr(tinst->ptr());
3937     int instance_id = meet_instance_id(tinst->instance_id());
3938     const TypePtr* speculative = xmeet_speculative(tinst);
3939     int depth = meet_inline_depth(tinst->inline_depth());
3940     ciKlass* tinst_klass = tinst->klass();
3941     ciKlass* this_klass  = klass();
3942     bool tinst_xk = tinst->klass_is_exact();
3943     bool this_xk  = klass_is_exact();


3944 
3945     ciKlass* res_klass = NULL;
3946     bool res_xk = false;

3947     const Type* res;
3948     MeetResult kind = meet_instptr(ptr, this_klass, tinst_klass, this_xk, tinst_xk, this->_ptr, tinst->_ptr, res_klass, res_xk);


3949     if (kind == UNLOADED) {
3950       // One of these classes has not been loaded
3951       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst);
3952 #ifndef PRODUCT
3953       if (PrintOpto && Verbose) {
3954         tty->print("meet of unloaded classes resulted in: ");
3955         unloaded_meet->dump();
3956         tty->cr();
3957         tty->print("  this == ");
3958         dump();
3959         tty->cr();
3960         tty->print(" tinst == ");
3961         tinst->dump();
3962         tty->cr();
3963       }
3964 #endif
3965       res = unloaded_meet;
3966     } else {
3967       if (kind == NOT_SUBTYPE && instance_id > 0) {
3968         instance_id = InstanceBot;
3969       } else if (kind == LCA) {
3970         instance_id = InstanceBot;
3971       }
3972       ciObject* o = NULL;             // Assume not constant when done
3973       ciObject* this_oop = const_oop();
3974       ciObject* tinst_oop = tinst->const_oop();
3975       if (ptr == Constant) {
3976         if (this_oop != NULL && tinst_oop != NULL &&
3977             this_oop->equals(tinst_oop))
3978           o = this_oop;
3979         else if (above_centerline(_ptr)) {
3980           assert(!tinst_klass->is_interface(), "");
3981           o = tinst_oop;
3982         } else if (above_centerline(tinst->_ptr)) {
3983           assert(!this_klass->is_interface(), "");
3984           o = this_oop;
3985         } else
3986           ptr = NotNull;
3987       }
3988       res = make(ptr, res_klass, res_xk, o, off, instance_id, speculative, depth);
3989     }
3990 
3991     return res;
3992 
3993   } // End of case InstPtr
3994 





















3995   } // End of switch
3996   return this;                  // Return the double constant
3997 }
3998 
3999 TypePtr::MeetResult TypePtr::meet_instptr(PTR &ptr, ciKlass* this_klass, ciKlass* tinst_klass, bool this_xk, bool tinst_xk,
4000                                           PTR this_ptr,
4001                                           PTR tinst_ptr, ciKlass*&res_klass, bool &res_xk) {



4002 
4003   // Check for easy case; klasses are equal (and perhaps not loaded!)
4004   // If we have constants, then we created oops so classes are loaded
4005   // and we can handle the constants further down.  This case handles
4006   // both-not-loaded or both-loaded classes
4007   if (ptr != Constant && this_klass->equals(tinst_klass) && this_xk == tinst_xk) {
4008     res_klass = this_klass;
4009     res_xk = this_xk;

4010     return QUICK;
4011   }
4012 
4013   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4014   if (!tinst_klass->is_loaded() || !this_klass->is_loaded()) {
4015     return UNLOADED;
4016   }
4017 
4018   // Handle mixing oops and interfaces first.
4019   if (this_klass->is_interface() && !(tinst_klass->is_interface() ||
4020                                       tinst_klass == ciEnv::current()->Object_klass())) {
4021     ciKlass *tmp = tinst_klass; // Swap interface around
4022     tinst_klass = this_klass;
4023     this_klass = tmp;
4024     bool tmp2 = tinst_xk;
4025     tinst_xk = this_xk;
4026     this_xk = tmp2;



4027   }
4028   if (tinst_klass->is_interface() &&
4029       !(this_klass->is_interface() ||
4030         // Treat java/lang/Object as an honorary interface,
4031         // because we need a bottom for the interface hierarchy.
4032         this_klass == ciEnv::current()->Object_klass())) {
4033     // Oop meets interface!
4034 
4035     // See if the oop subtypes (implements) interface.
4036     if (this_klass->is_subtype_of(tinst_klass)) {
4037       // Oop indeed subtypes.  Now keep oop or interface depending
4038       // on whether we are both above the centerline or either is
4039       // below the centerline.  If we are on the centerline
4040       // (e.g., Constant vs. AnyNull interface), use the constant.
4041       res_klass  = below_centerline(ptr) ? tinst_klass : this_klass;
4042       // If we are keeping this_klass, keep its exactness too.
4043       res_xk = below_centerline(ptr) ? tinst_xk    : this_xk;

4044       return SUBTYPE;
4045     } else {                  // Does not implement, fall to Object
4046       // Oop does not implement interface, so mixing falls to Object
4047       // just like the verifier does (if both are above the
4048       // centerline fall to interface)
4049       res_klass = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
4050       res_xk = above_centerline(ptr) ? tinst_xk : false;

4051       // Watch out for Constant vs. AnyNull interface.
4052       if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
4053       return NOT_SUBTYPE;
4054     }
4055   }
4056 
4057   // Either oop vs oop or interface vs interface or interface vs Object
4058 
4059   // !!! Here's how the symmetry requirement breaks down into invariants:
4060   // If we split one up & one down AND they subtype, take the down man.
4061   // If we split one up & one down AND they do NOT subtype, "fall hard".
4062   // If both are up and they subtype, take the subtype class.
4063   // If both are up and they do NOT subtype, "fall hard".
4064   // If both are down and they subtype, take the supertype class.
4065   // If both are down and they do NOT subtype, "fall hard".
4066   // Constants treated as down.
4067 
4068   // Now, reorder the above list; observe that both-down+subtype is also
4069   // "fall hard"; "fall hard" becomes the default case:
4070   // If we split one up & one down AND they subtype, take the down man.
4071   // If both are up and they subtype, take the subtype class.
4072 
4073   // If both are down and they subtype, "fall hard".
4074   // If both are down and they do NOT subtype, "fall hard".
4075   // If both are up and they do NOT subtype, "fall hard".
4076   // If we split one up & one down AND they do NOT subtype, "fall hard".
4077 
4078   // If a proper subtype is exact, and we return it, we return it exactly.
4079   // If a proper supertype is exact, there can be no subtyping relationship!
4080   // If both types are equal to the subtype, exactness is and-ed below the
4081   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4082 
4083   // Check for subtyping:
4084   ciKlass *subtype = NULL;
4085   bool subtype_exact = false;

4086   if (tinst_klass->equals(this_klass)) {
4087     subtype = this_klass;
4088     subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
4089   } else if (!tinst_xk && this_klass->is_subtype_of(tinst_klass)) {

4090     subtype = this_klass;     // Pick subtyping class
4091     subtype_exact = this_xk;
4092   } else if (!this_xk && tinst_klass->is_subtype_of(this_klass)) {

4093     subtype = tinst_klass;    // Pick subtyping class
4094     subtype_exact = tinst_xk;

4095   }
4096 
4097   if (subtype) {
4098     if (above_centerline(ptr)) { // both are up?
4099       this_klass = tinst_klass = subtype;
4100       this_xk = tinst_xk = subtype_exact;

4101     } else if (above_centerline(this_ptr) && !above_centerline(tinst_ptr)) {
4102       this_klass = tinst_klass; // tinst is down; keep down man
4103       this_xk = tinst_xk;

4104     } else if (above_centerline(tinst_ptr) && !above_centerline(this_ptr)) {
4105       tinst_klass = this_klass; // this is down; keep down man
4106       tinst_xk = this_xk;

4107     } else {
4108       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA

4109     }
4110   }
4111 
4112   // Check for classes now being equal
4113   if (tinst_klass->equals(this_klass)) {
4114     // If the klasses are equal, the constants may still differ.  Fall to
4115     // NotNull if they do (neither constant is NULL; that is a special case
4116     // handled elsewhere).
4117     res_klass = this_klass;
4118     res_xk = this_xk;

4119     return SUBTYPE;
4120   } // Else classes are not equal
4121 
4122   // Since klasses are different, we require a LCA in the Java
4123   // class hierarchy - which means we have to fall to at least NotNull.
4124   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4125     ptr = NotNull;
4126   }
4127 
4128   // Now we find the LCA of Java classes
4129   ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4130 
4131   res_klass = k;
4132   res_xk = false;

4133 
4134   return LCA;
4135 }
4136 
4137 
4138 //------------------------java_mirror_type--------------------------------------
4139 ciType* TypeInstPtr::java_mirror_type() const {
4140   // must be a singleton type
4141   if( const_oop() == NULL )  return NULL;
4142 
4143   // must be of type java.lang.Class
4144   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4145 
4146   return const_oop()->as_instance()->java_mirror_type();
4147 }
4148 
4149 
4150 //------------------------------xdual------------------------------------------
4151 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4152 // inheritance mechanism.
4153 const Type *TypeInstPtr::xdual() const {
4154   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4155 }
4156 
4157 //------------------------------eq---------------------------------------------
4158 // Structural equality check for Type representations
4159 bool TypeInstPtr::eq( const Type *t ) const {
4160   const TypeInstPtr *p = t->is_instptr();
4161   return
4162     klass()->equals(p->klass()) &&

4163     TypeOopPtr::eq(p);          // Check sub-type stuff
4164 }
4165 
4166 //------------------------------hash-------------------------------------------
4167 // Type-specific hashing function.
4168 int TypeInstPtr::hash(void) const {
4169   int hash = java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash());
4170   return hash;
4171 }
4172 
4173 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4174   if (!is_loaded() || !other->is_loaded()) {
4175     return false;
4176   }
4177   if (!other->isa_instptr()) {
4178     return false;
4179   }
4180 
4181   if (!other_exact) {
4182     return false;
4183   }
4184 
4185   if (other->klass()->equals(ciEnv::current()->Object_klass())) {
4186     return true;
4187   }
4188 
4189   if (!this_exact && klass()->is_interface()) {

4253       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4254       char* buf = ss.as_string(/* c_heap= */false);
4255       StringUtils::replace_no_expand(buf, "\n", "");
4256       st->print_raw(buf);
4257     }
4258   case BotPTR:
4259     if (!WizardMode && !Verbose) {
4260       if( _klass_is_exact ) st->print(":exact");
4261       break;
4262     }
4263   case TopPTR:
4264   case AnyNull:
4265   case NotNull:
4266     st->print(":%s", ptr_msg[_ptr]);
4267     if( _klass_is_exact ) st->print(":exact");
4268     break;
4269   default:
4270     break;
4271   }
4272 
4273   if( _offset ) {               // Dump offset, if any
4274     if( _offset == OffsetBot )      st->print("+any");
4275     else if( _offset == OffsetTop ) st->print("+unknown");
4276     else st->print("+%d", _offset);
4277   }
4278 
4279   st->print(" *");





4280   if (_instance_id == InstanceTop)
4281     st->print(",iid=top");
4282   else if (_instance_id != InstanceBot)
4283     st->print(",iid=%d",_instance_id);
4284 
4285   dump_inline_depth(st);
4286   dump_speculative(st);
4287 }
4288 #endif
4289 
4290 //------------------------------add_offset-------------------------------------
4291 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4292   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4293               _instance_id, add_offset_speculative(offset), _inline_depth);
4294 }
4295 
4296 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4297   return make(_ptr, klass(), klass_is_exact(), const_oop(), offset,
4298               _instance_id, with_offset_speculative(offset), _inline_depth);
4299 }
4300 
4301 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4302   if (_speculative == NULL) {
4303     return this;
4304   }
4305   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4306   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
4307               _instance_id, NULL, _inline_depth);
4308 }
4309 
4310 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4311   if (!UseInlineDepthForSpeculativeTypes) {
4312     return this;
4313   }
4314   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4315 }
4316 
4317 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4318   assert(is_known_instance(), "should be known");
4319   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);




4320 }
4321 
4322 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4323   bool xk = klass_is_exact();
4324   ciInstanceKlass* ik = klass()->as_instance_klass();
4325   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final() && !ik->is_interface()) {
4326     Compile* C = Compile::current();
4327     Dependencies* deps = C->dependencies();
4328     deps->assert_leaf_type(ik);
4329     xk = true;
4330   }
4331   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), 0);
4332 }
4333 
4334 //=============================================================================
4335 // Convenience common pre-built types.
4336 const TypeAryPtr *TypeAryPtr::RANGE;
4337 const TypeAryPtr *TypeAryPtr::OOPS;
4338 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4339 const TypeAryPtr *TypeAryPtr::BYTES;
4340 const TypeAryPtr *TypeAryPtr::SHORTS;
4341 const TypeAryPtr *TypeAryPtr::CHARS;
4342 const TypeAryPtr *TypeAryPtr::INTS;
4343 const TypeAryPtr *TypeAryPtr::LONGS;
4344 const TypeAryPtr *TypeAryPtr::FLOATS;
4345 const TypeAryPtr *TypeAryPtr::DOUBLES;

4346 
4347 //------------------------------make-------------------------------------------
4348 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4349                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4350   assert(!(k == NULL && ary->_elem->isa_int()),
4351          "integral arrays must be pre-equipped with a class");
4352   if (!xk)  xk = ary->ary_must_be_exact();
4353   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4354   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4355 }
4356 
4357 //------------------------------make-------------------------------------------
4358 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4359                                    int instance_id, const TypePtr* speculative, int inline_depth,
4360                                    bool is_autobox_cache) {
4361   assert(!(k == NULL && ary->_elem->isa_int()),
4362          "integral arrays must be pre-equipped with a class");
4363   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4364   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4365   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4366   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4367 }
4368 
4369 //------------------------------cast_to_ptr_type-------------------------------
4370 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4371   if( ptr == _ptr ) return this;
4372   return make(ptr, ptr == Constant ? const_oop() : NULL, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4373 }
4374 
4375 
4376 //-----------------------------cast_to_exactness-------------------------------
4377 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4378   if( klass_is_exact == _klass_is_exact ) return this;
4379   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4380   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);






4381 }
4382 
4383 //-----------------------------cast_to_instance_id----------------------------
4384 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4385   if( instance_id == _instance_id ) return this;
4386   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4387 }
4388 
4389 
4390 //-----------------------------max_array_length-------------------------------
4391 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4392 jint TypeAryPtr::max_array_length(BasicType etype) {
4393   if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4394     if (etype == T_NARROWOOP) {
4395       etype = T_OBJECT;
4396     } else if (etype == T_ILLEGAL) { // bottom[]
4397       etype = T_BYTE; // will produce conservatively high value
4398     } else {
4399       fatal("not an element type: %s", type2name(etype));
4400     }
4401   }
4402   return arrayOopDesc::max_array_length(etype);
4403 }
4404 
4405 //-----------------------------narrow_size_type-------------------------------
4406 // Narrow the given size type to the index range for the given array base type.

4422   if (hi > max_hi) {
4423     hi = max_hi;
4424     if (size->is_con()) {
4425       lo = hi;
4426     }
4427     chg = true;
4428   }
4429   // Negative length arrays will produce weird intermediate dead fast-path code
4430   if (lo > hi)
4431     return TypeInt::ZERO;
4432   if (!chg)
4433     return size;
4434   return TypeInt::make(lo, hi, Type::WidenMin);
4435 }
4436 
4437 //-------------------------------cast_to_size----------------------------------
4438 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4439   assert(new_size != NULL, "");
4440   new_size = narrow_size_type(new_size);
4441   if (new_size == size())  return this;
4442   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4443   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);














































4444 }
4445 
4446 //------------------------------cast_to_stable---------------------------------
4447 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4448   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4449     return this;
4450 
4451   const Type* elem = this->elem();
4452   const TypePtr* elem_ptr = elem->make_ptr();
4453 
4454   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4455     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4456     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4457   }
4458 
4459   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4460 
4461   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4462 }
4463 
4464 //-----------------------------stable_dimension--------------------------------
4465 int TypeAryPtr::stable_dimension() const {
4466   if (!is_stable())  return 0;
4467   int dim = 1;
4468   const TypePtr* elem_ptr = elem()->make_ptr();
4469   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4470     dim += elem_ptr->is_aryptr()->stable_dimension();
4471   return dim;
4472 }
4473 
4474 //----------------------cast_to_autobox_cache-----------------------------------
4475 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4476   if (is_autobox_cache())  return this;
4477   const TypeOopPtr* etype = elem()->make_oopptr();
4478   if (etype == NULL)  return this;
4479   // The pointers in the autobox arrays are always non-null.
4480   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4481   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4482   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);




4483 }
4484 
4485 //------------------------------eq---------------------------------------------
4486 // Structural equality check for Type representations
4487 bool TypeAryPtr::eq( const Type *t ) const {
4488   const TypeAryPtr *p = t->is_aryptr();
4489   return
4490     _ary == p->_ary &&  // Check array
4491     TypeOopPtr::eq(p);  // Check sub-parts

4492 }
4493 
4494 //------------------------------hash-------------------------------------------
4495 // Type-specific hashing function.
4496 int TypeAryPtr::hash(void) const {
4497   return (intptr_t)_ary + TypeOopPtr::hash();
4498 }
4499 
4500 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4501   if (other->klass() == ciEnv::current()->Object_klass() && other_exact) {
4502     return true;
4503   }
4504 
4505   if (!is_loaded() || !other->is_loaded() || other->klass() == NULL || klass() == NULL) {
4506     return false;
4507   }
4508   if (other->isa_instptr()) {
4509     return _klass->is_subtype_of(other->_klass) && other_exact;
4510   }
4511   if (klass() == NULL) {
4512     return false;
4513   }
4514   assert(other->isa_aryptr(), "");
4515   const TypeAryPtr* other_ary = other->isa_aryptr();
4516   if (other_ary->elem()->make_oopptr() && elem()->make_oopptr()) {
4517     return elem()->make_oopptr()->is_java_subtype_of_helper(other_ary->elem()->make_oopptr(), this_exact, other_exact);

4577   case Long:
4578   case FloatTop:
4579   case FloatCon:
4580   case FloatBot:
4581   case DoubleTop:
4582   case DoubleCon:
4583   case DoubleBot:
4584   case NarrowOop:
4585   case NarrowKlass:
4586   case Bottom:                  // Ye Olde Default
4587     return Type::BOTTOM;
4588   case Top:
4589     return this;
4590 
4591   default:                      // All else is a mistake
4592     typerr(t);
4593 
4594   case OopPtr: {                // Meeting to OopPtrs
4595     // Found a OopPtr type vs self-AryPtr type
4596     const TypeOopPtr *tp = t->is_oopptr();
4597     int offset = meet_offset(tp->offset());
4598     PTR ptr = meet_ptr(tp->ptr());
4599     int depth = meet_inline_depth(tp->inline_depth());
4600     const TypePtr* speculative = xmeet_speculative(tp);
4601     switch (tp->ptr()) {
4602     case TopPTR:
4603     case AnyNull: {
4604       int instance_id = meet_instance_id(InstanceTop);
4605       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4606                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4607     }
4608     case BotPTR:
4609     case NotNull: {
4610       int instance_id = meet_instance_id(tp->instance_id());
4611       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4612     }
4613     default: ShouldNotReachHere();
4614     }
4615   }
4616 
4617   case AnyPtr: {                // Meeting two AnyPtrs
4618     // Found an AnyPtr type vs self-AryPtr type
4619     const TypePtr *tp = t->is_ptr();
4620     int offset = meet_offset(tp->offset());
4621     PTR ptr = meet_ptr(tp->ptr());
4622     const TypePtr* speculative = xmeet_speculative(tp);
4623     int depth = meet_inline_depth(tp->inline_depth());
4624     switch (tp->ptr()) {
4625     case TopPTR:
4626       return this;
4627     case BotPTR:
4628     case NotNull:
4629       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4630     case Null:
4631       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4632       // else fall through to AnyNull
4633     case AnyNull: {
4634       int instance_id = meet_instance_id(InstanceTop);
4635       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4636                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4637     }
4638     default: ShouldNotReachHere();
4639     }
4640   }
4641 
4642   case MetadataPtr:
4643   case KlassPtr:
4644   case InstKlassPtr:
4645   case AryKlassPtr:
4646   case RawPtr: return TypePtr::BOTTOM;
4647 
4648   case AryPtr: {                // Meeting 2 references?
4649     const TypeAryPtr *tap = t->is_aryptr();
4650     int off = meet_offset(tap->offset());

4651     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4652     PTR ptr = meet_ptr(tap->ptr());
4653     int instance_id = meet_instance_id(tap->instance_id());
4654     const TypePtr* speculative = xmeet_speculative(tap);
4655     int depth = meet_inline_depth(tap->inline_depth());
4656 
4657     ciKlass* res_klass = NULL;
4658     bool res_xk = false;
4659     const Type* elem = tary->_elem;
4660     if (meet_aryptr(ptr, elem, this->klass(), tap->klass(), this->klass_is_exact(), tap->klass_is_exact(), this->ptr(), tap->ptr(), res_klass, res_xk) == NOT_SUBTYPE) {






4661       instance_id = InstanceBot;











4662     }
4663 
4664     ciObject* o = NULL;             // Assume not constant when done
4665     ciObject* this_oop = const_oop();
4666     ciObject* tap_oop = tap->const_oop();
4667     if (ptr == Constant) {
4668       if (this_oop != NULL && tap_oop != NULL &&
4669           this_oop->equals(tap_oop)) {
4670         o = tap_oop;
4671       } else if (above_centerline(_ptr)) {
4672         o = tap_oop;
4673       } else if (above_centerline(tap->_ptr)) {
4674         o = this_oop;
4675       } else {
4676         ptr = NotNull;
4677       }
4678     }
4679     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4680   }
4681 
4682   // All arrays inherit from Object class
4683   case InstPtr: {
4684     const TypeInstPtr *tp = t->is_instptr();
4685     int offset = meet_offset(tp->offset());
4686     PTR ptr = meet_ptr(tp->ptr());
4687     int instance_id = meet_instance_id(tp->instance_id());
4688     const TypePtr* speculative = xmeet_speculative(tp);
4689     int depth = meet_inline_depth(tp->inline_depth());
4690     switch (ptr) {
4691     case TopPTR:
4692     case AnyNull:                // Fall 'down' to dual of object klass
4693       // For instances when a subclass meets a superclass we fall
4694       // below the centerline when the superclass is exact. We need to
4695       // do the same here.
4696       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4697         return make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4698       } else {
4699         // cannot subclass, so the meet has to fall badly below the centerline
4700         ptr = NotNull;
4701         instance_id = InstanceBot;
4702         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4703       }
4704     case Constant:
4705     case NotNull:
4706     case BotPTR:                // Fall down to object klass
4707       // LCA is object_klass, but if we subclass from the top we can do better
4708       if (above_centerline(tp->ptr())) {
4709         // If 'tp'  is above the centerline and it is Object class
4710         // then we can subclass in the Java class hierarchy.
4711         // For instances when a subclass meets a superclass we fall
4712         // below the centerline when the superclass is exact. We need
4713         // to do the same here.
4714         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4715           // that is, my array type is a subtype of 'tp' klass
4716           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4717                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4718         }
4719       }
4720       // The other case cannot happen, since t cannot be a subtype of an array.
4721       // The meet falls down to Object class below centerline.
4722       if (ptr == Constant) {
4723          ptr = NotNull;
4724       }
4725       if (instance_id > 0) {
4726         instance_id = InstanceBot;
4727       }
4728       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4729     default: typerr(t);
4730     }
4731   }













4732   }
4733   return this;                  // Lint noise
4734 }
4735 
4736 
4737 TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, ciKlass* this_klass, ciKlass* tap_klass, bool this_xk, bool tap_xk, PTR this_ptr, PTR tap_ptr, ciKlass*& res_klass, bool& res_xk) {






4738   res_klass = NULL;
4739   MeetResult result = SUBTYPE;
4740   if (elem->isa_int()) {




4741     // Integral array element types have irrelevant lattice relations.
4742     // It is the klass that determines array layout, not the element type.
4743     if (this_klass == NULL)
4744       res_klass = tap_klass;
4745     else if (tap_klass == NULL || tap_klass == this_klass) {
4746       res_klass = this_klass;
4747     } else {
4748       // Something like byte[int+] meets char[int+].
4749       // This must fall to bottom, not (int[-128..65535])[int+].
4750       // instance_id = InstanceBot;
4751       elem = Type::BOTTOM;
4752       result = NOT_SUBTYPE;
4753     }
4754   } else // Non integral arrays.
4755     // Must fall to bottom if exact klasses in upper lattice
4756     // are not equal or super klass is exact.
4757     if ((above_centerline(ptr) || ptr == Constant) && this_klass != tap_klass &&
4758         // meet with top[] and bottom[] are processed further down:
4759         tap_klass != NULL  && this_klass != NULL   &&
4760         // both are exact and not equal:
4761         ((tap_xk && this_xk) ||
4762          // 'tap'  is exact and super or unrelated:
4763          (tap_xk && !tap_klass->is_subtype_of(this_klass)) ||
4764          // 'this' is exact and super or unrelated:
4765          (this_xk && !this_klass->is_subtype_of(tap_klass)))) {
4766       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
4767         elem = Type::BOTTOM;

4768       }
4769       ptr = NotNull;
4770       res_xk = false;
4771       return NOT_SUBTYPE;
4772     }
4773 
4774   res_xk = false;
4775   switch (tap_ptr) {
4776     case AnyNull:
4777     case TopPTR:
4778       // Compute new klass on demand, do not use tap->_klass
4779       if (below_centerline(this_ptr)) {
4780         res_xk = this_xk;



4781       } else {
4782         res_xk = (tap_xk || this_xk);
4783       }
4784       return result;
4785     case Constant: {
4786       if (this_ptr == Constant) {
4787           res_xk = true;
4788       } else if(above_centerline(this_ptr)) {
4789         res_xk = true;
4790       } else {
4791         // Only precise for identical arrays
4792         res_xk = this_xk && (this_klass == tap_klass);
4793       }
4794       return result;
4795     }
4796     case NotNull:
4797     case BotPTR:
4798       // Compute new klass on demand, do not use tap->_klass
4799       if (above_centerline(this_ptr)) {
4800         res_xk = tap_xk;



4801       } else {
4802         res_xk = (tap_xk && this_xk) &&
4803           (this_klass == tap_klass); // Only precise for identical arrays
4804       }
4805       return result;
4806     default:  {
4807       ShouldNotReachHere();
4808       return result;
4809     }
4810   }

4811   return result;
4812 }
4813 
4814 
4815 //------------------------------xdual------------------------------------------
4816 // Dual: compute field-by-field dual
4817 const Type *TypeAryPtr::xdual() const {
4818   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());









4819 }
4820 
4821 //----------------------interface_vs_oop---------------------------------------
4822 #ifdef ASSERT
4823 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4824   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4825   if (t_aryptr) {
4826     return _ary->interface_vs_oop(t_aryptr->_ary);
4827   }
4828   return false;
4829 }
4830 #endif
4831 
4832 //------------------------------dump2------------------------------------------
4833 #ifndef PRODUCT
4834 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4835   _ary->dump2(d,depth,st);
4836   switch( _ptr ) {
4837   case Constant:
4838     const_oop()->print(st);
4839     break;
4840   case BotPTR:
4841     if (!WizardMode && !Verbose) {
4842       if( _klass_is_exact ) st->print(":exact");
4843       break;
4844     }
4845   case TopPTR:
4846   case AnyNull:
4847   case NotNull:
4848     st->print(":%s", ptr_msg[_ptr]);
4849     if( _klass_is_exact ) st->print(":exact");
4850     break;
4851   default:
4852     break;
4853   }
4854 
4855   if( _offset != 0 ) {





4856     int header_size = objArrayOopDesc::header_size() * wordSize;
4857     if( _offset == OffsetTop )       st->print("+undefined");
4858     else if( _offset == OffsetBot )  st->print("+any");
4859     else if( _offset < header_size ) st->print("+%d", _offset);
4860     else {
4861       BasicType basic_elem_type = elem()->basic_type();
4862       if (basic_elem_type == T_ILLEGAL) {
4863         st->print("+any");
4864       } else {
4865         int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4866         int elem_size = type2aelembytes(basic_elem_type);
4867         st->print("[%d]", (_offset - array_base)/elem_size);
4868       }
4869     }
4870   }
4871   st->print(" *");
4872   if (_instance_id == InstanceTop)
4873     st->print(",iid=top");
4874   else if (_instance_id != InstanceBot)
4875     st->print(",iid=%d",_instance_id);
4876 
4877   dump_inline_depth(st);
4878   dump_speculative(st);
4879 }
4880 #endif
4881 
4882 bool TypeAryPtr::empty(void) const {
4883   if (_ary->empty())       return true;
4884   return TypeOopPtr::empty();
4885 }
4886 
4887 //------------------------------add_offset-------------------------------------
4888 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4889   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4890 }
4891 
4892 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
4893   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
4894 }
4895 
4896 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
4897   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4898 }
4899 
4900 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
4901   if (_speculative == NULL) {
4902     return this;
4903   }
4904   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4905   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);












4906 }
4907 
4908 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4909   if (!UseInlineDepthForSpeculativeTypes) {
4910     return this;
4911   }
4912   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
















































4913 }
4914 
4915 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
4916   assert(is_known_instance(), "should be known");
4917   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4918 }
4919 
4920 //=============================================================================
4921 

4922 //------------------------------hash-------------------------------------------
4923 // Type-specific hashing function.
4924 int TypeNarrowPtr::hash(void) const {
4925   return _ptrtype->hash() + 7;
4926 }
4927 
4928 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4929   return _ptrtype->singleton();
4930 }
4931 
4932 bool TypeNarrowPtr::empty(void) const {
4933   return _ptrtype->empty();
4934 }
4935 
4936 intptr_t TypeNarrowPtr::get_con() const {
4937   return _ptrtype->get_con();
4938 }
4939 
4940 bool TypeNarrowPtr::eq( const Type *t ) const {
4941   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

4992 
4993   case Int:                     // Mixing ints & oops happens when javac
4994   case Long:                    // reuses local variables
4995   case FloatTop:
4996   case FloatCon:
4997   case FloatBot:
4998   case DoubleTop:
4999   case DoubleCon:
5000   case DoubleBot:
5001   case AnyPtr:
5002   case RawPtr:
5003   case OopPtr:
5004   case InstPtr:
5005   case AryPtr:
5006   case MetadataPtr:
5007   case KlassPtr:
5008   case InstKlassPtr:
5009   case AryKlassPtr:
5010   case NarrowOop:
5011   case NarrowKlass:
5012 
5013   case Bottom:                  // Ye Olde Default
5014     return Type::BOTTOM;
5015   case Top:
5016     return this;
5017 



5018   default:                      // All else is a mistake
5019     typerr(t);
5020 
5021   } // End of switch
5022 
5023   return this;
5024 }
5025 
5026 #ifndef PRODUCT
5027 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5028   _ptrtype->dump2(d, depth, st);
5029 }
5030 #endif
5031 
5032 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5033 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5034 
5035 
5036 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5037   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();

5076     return (one == two) && TypePtr::eq(t);
5077   } else {
5078     return one->equals(two) && TypePtr::eq(t);
5079   }
5080 }
5081 
5082 //------------------------------hash-------------------------------------------
5083 // Type-specific hashing function.
5084 int TypeMetadataPtr::hash(void) const {
5085   return
5086     (metadata() ? metadata()->hash() : 0) +
5087     TypePtr::hash();
5088 }
5089 
5090 //------------------------------singleton--------------------------------------
5091 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5092 // constants
5093 bool TypeMetadataPtr::singleton(void) const {
5094   // detune optimizer to not generate constant metadata + constant offset as a constant!
5095   // TopPTR, Null, AnyNull, Constant are all singletons
5096   return (_offset == 0) && !below_centerline(_ptr);
5097 }
5098 
5099 //------------------------------add_offset-------------------------------------
5100 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
5101   return make( _ptr, _metadata, xadd_offset(offset));
5102 }
5103 
5104 //-----------------------------filter------------------------------------------
5105 // Do not allow interface-vs.-noninterface joins to collapse to top.
5106 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5107   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5108   if (ft == NULL || ft->empty())
5109     return Type::TOP;           // Canonical empty value
5110   return ft;
5111 }
5112 
5113  //------------------------------get_con----------------------------------------
5114 intptr_t TypeMetadataPtr::get_con() const {
5115   assert( _ptr == Null || _ptr == Constant, "" );
5116   assert( _offset >= 0, "" );
5117 
5118   if (_offset != 0) {
5119     // After being ported to the compiler interface, the compiler no longer
5120     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5121     // to a handle at compile time.  This handle is embedded in the generated
5122     // code and dereferenced at the time the nmethod is made.  Until that time,
5123     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5124     // have access to the addresses!).  This does not seem to currently happen,
5125     // but this assertion here is to help prevent its occurrence.
5126     tty->print_cr("Found oop constant with non-zero offset");
5127     ShouldNotReachHere();
5128   }
5129 
5130   return (intptr_t)metadata()->constant_encoding();
5131 }
5132 
5133 //------------------------------cast_to_ptr_type-------------------------------
5134 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5135   if( ptr == _ptr ) return this;
5136   return make(ptr, metadata(), _offset);
5137 }
5138 

5149   case Long:                    // reuses local variables
5150   case FloatTop:
5151   case FloatCon:
5152   case FloatBot:
5153   case DoubleTop:
5154   case DoubleCon:
5155   case DoubleBot:
5156   case NarrowOop:
5157   case NarrowKlass:
5158   case Bottom:                  // Ye Olde Default
5159     return Type::BOTTOM;
5160   case Top:
5161     return this;
5162 
5163   default:                      // All else is a mistake
5164     typerr(t);
5165 
5166   case AnyPtr: {
5167     // Found an AnyPtr type vs self-OopPtr type
5168     const TypePtr *tp = t->is_ptr();
5169     int offset = meet_offset(tp->offset());
5170     PTR ptr = meet_ptr(tp->ptr());
5171     switch (tp->ptr()) {
5172     case Null:
5173       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5174       // else fall through:
5175     case TopPTR:
5176     case AnyNull: {
5177       return make(ptr, _metadata, offset);
5178     }
5179     case BotPTR:
5180     case NotNull:
5181       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5182     default: typerr(t);
5183     }
5184   }
5185 
5186   case RawPtr:
5187   case KlassPtr:
5188   case InstKlassPtr:
5189   case AryKlassPtr:
5190   case OopPtr:
5191   case InstPtr:
5192   case AryPtr:
5193     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5194 
5195   case MetadataPtr: {
5196     const TypeMetadataPtr *tp = t->is_metadataptr();
5197     int offset = meet_offset(tp->offset());
5198     PTR tptr = tp->ptr();
5199     PTR ptr = meet_ptr(tptr);
5200     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5201     if (tptr == TopPTR || _ptr == TopPTR ||
5202         metadata()->equals(tp->metadata())) {
5203       return make(ptr, md, offset);
5204     }
5205     // metadata is different
5206     if( ptr == Constant ) {  // Cannot be equal constants, so...
5207       if( tptr == Constant && _ptr != Constant)  return t;
5208       if( _ptr == Constant && tptr != Constant)  return this;
5209       ptr = NotNull;            // Fall down in lattice
5210     }
5211     return make(ptr, NULL, offset);
5212     break;
5213   }
5214   } // End of switch
5215   return this;                  // Return the double constant
5216 }
5217 
5218 
5219 //------------------------------xdual------------------------------------------
5220 // Dual of a pure metadata pointer.
5221 const Type *TypeMetadataPtr::xdual() const {
5222   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5223 }
5224 
5225 //------------------------------dump2------------------------------------------
5226 #ifndef PRODUCT
5227 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5228   st->print("metadataptr:%s", ptr_msg[_ptr]);
5229   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5230   switch( _offset ) {
5231   case OffsetTop: st->print("+top"); break;
5232   case OffsetBot: st->print("+any"); break;
5233   case         0: break;
5234   default:        st->print("+%d",_offset); break;
5235   }
5236 }
5237 #endif
5238 
5239 
5240 //=============================================================================
5241 // Convenience common pre-built type.
5242 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5243 
5244 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5245   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5246 }
5247 
5248 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5249   return make(Constant, m, 0);
5250 }
5251 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5252   return make(Constant, m, 0);
5253 }
5254 
5255 //------------------------------make-------------------------------------------
5256 // Create a meta data constant
5257 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5258   assert(m == NULL || !m->is_klass(), "wrong type");
5259   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5260 }
5261 
5262 
5263 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5264   const Type* elem = _ary->_elem;
5265   bool xk = klass_is_exact();
5266   if (elem->make_oopptr() != NULL) {
5267     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5268     if (elem->is_klassptr()->klass_is_exact()) {


5269       xk = true;
5270     }


5271   }
5272   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5273 }
5274 
5275 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass) {
5276   if (klass->is_instance_klass()) {
5277     return TypeInstKlassPtr::make(klass);
5278   }
5279   return TypeAryKlassPtr::make(klass);
5280 }
5281 
5282 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset) {
5283   if (klass->is_instance_klass()) {
5284     return TypeInstKlassPtr::make(ptr, klass, offset);
5285   }
5286   return TypeAryKlassPtr::make(ptr, klass, offset);
5287 }
5288 
5289 
5290 //------------------------------TypeKlassPtr-----------------------------------
5291 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, int offset)
5292   : TypePtr(t, ptr, offset), _klass(klass) {
5293 }
5294 
5295 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5296   return _klass;
5297 }
5298 
5299 //------------------------------eq---------------------------------------------
5300 // Structural equality check for Type representations
5301 bool TypeKlassPtr::eq(const Type *t) const {
5302   const TypeKlassPtr *p = t->is_klassptr();
5303   return
5304     TypePtr::eq(p);
5305 }
5306 
5307 //------------------------------hash-------------------------------------------
5308 // Type-specific hashing function.
5309 int TypeKlassPtr::hash(void) const {
5310   return TypePtr::hash();
5311 }
5312 
5313 //------------------------------singleton--------------------------------------
5314 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5315 // constants
5316 bool TypeKlassPtr::singleton(void) const {
5317   // detune optimizer to not generate constant klass + constant offset as a constant!
5318   // TopPTR, Null, AnyNull, Constant are all singletons
5319   return (_offset == 0) && !below_centerline(_ptr);
5320 }
5321 
5322 // Do not allow interface-vs.-noninterface joins to collapse to top.
5323 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5324   // logic here mirrors the one from TypeOopPtr::filter. See comments
5325   // there.
5326   const Type* ft = join_helper(kills, include_speculative);
5327   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5328   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5329 
5330   if (ft->empty()) {
5331     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
5332       return kills;             // Uplift to interface
5333 
5334     return Type::TOP;           // Canonical empty value
5335   }
5336 
5337   // Interface klass type could be exact in opposite to interface type,
5338   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5339   if (ftkp != NULL && ktkp != NULL &&
5340       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5341       !ftkp->klass_is_exact() && // Keep exact interface klass
5342       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5343     return ktkp->cast_to_ptr_type(ftkp->ptr());
5344   }
5345 
5346   return ft;
5347 }
5348 
5349 //------------------------------get_con----------------------------------------
5350 intptr_t TypeKlassPtr::get_con() const {
5351   assert( _ptr == Null || _ptr == Constant, "" );
5352   assert( _offset >= 0, "" );
5353 
5354   if (_offset != 0) {
5355     // After being ported to the compiler interface, the compiler no longer
5356     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5357     // to a handle at compile time.  This handle is embedded in the generated
5358     // code and dereferenced at the time the nmethod is made.  Until that time,
5359     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5360     // have access to the addresses!).  This does not seem to currently happen,
5361     // but this assertion here is to help prevent its occurrence.
5362     tty->print_cr("Found oop constant with non-zero offset");
5363     ShouldNotReachHere();
5364   }
5365 
5366   ciKlass* k = exact_klass();
5367 
5368   return (intptr_t)k->constant_encoding();
5369 }
5370 
5371 //------------------------------dump2------------------------------------------
5372 // Dump Klass Type
5373 #ifndef PRODUCT
5374 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5375   switch(_ptr) {
5376   case Constant:
5377     st->print("precise ");
5378   case NotNull:
5379     {
5380       const char *name = klass()->name()->as_utf8();
5381       if (name) {
5382         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5383       } else {
5384         ShouldNotReachHere();
5385       }
5386     }
5387   case BotPTR:
5388     if (!WizardMode && !Verbose && _ptr != Constant) break;
5389   case TopPTR:
5390   case AnyNull:
5391     st->print(":%s", ptr_msg[_ptr]);
5392     if (_ptr == Constant) st->print(":exact");
5393     break;
5394   default:
5395     break;
5396   }
5397 
5398   if (_offset) {               // Dump offset, if any
5399     if (_offset == OffsetBot)      { st->print("+any"); }
5400     else if (_offset == OffsetTop) { st->print("+unknown"); }
5401     else                            { st->print("+%d", _offset); }
5402   }
5403 
5404   st->print(" *");
5405 }
5406 #endif
5407 
5408 //=============================================================================
5409 // Convenience common pre-built types.
5410 
5411 // Not-null object klass or below
5412 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5413 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5414 
5415 bool TypeInstKlassPtr::eq(const Type *t) const {
5416   const TypeKlassPtr *p = t->is_klassptr();
5417   return
5418     klass()->equals(p->klass()) &&

5419     TypeKlassPtr::eq(p);
5420 }
5421 
5422 int TypeInstKlassPtr::hash(void) const {
5423   return java_add((jint)klass()->hash(), TypeKlassPtr::hash());
5424 }
5425 
5426 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, int offset) {


5427   TypeInstKlassPtr *r =
5428     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, offset))->hashcons();
5429 
5430   return r;
5431 }
5432 
5433 //------------------------------add_offset-------------------------------------
5434 // Access internals of klass object
5435 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5436   return make( _ptr, klass(), xadd_offset(offset) );
5437 }
5438 
5439 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5440   return make(_ptr, klass(), offset);
5441 }
5442 
5443 //------------------------------cast_to_ptr_type-------------------------------
5444 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5445   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5446   if( ptr == _ptr ) return this;
5447   return make(ptr, _klass, _offset);
5448 }
5449 
5450 
5451 bool TypeInstKlassPtr::must_be_exact() const {
5452   if (!_klass->is_loaded())  return false;
5453   ciInstanceKlass* ik = _klass->as_instance_klass();
5454   if (ik->is_final())  return true;  // cannot clear xk
5455   return false;
5456 }
5457 
5458 //-----------------------------cast_to_exactness-------------------------------
5459 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5460   if (klass_is_exact == (_ptr == Constant)) return this;
5461   if (must_be_exact()) return this;
5462   ciKlass* k = klass();
5463   return make(klass_is_exact ? Constant : NotNull, k, _offset);
5464 }
5465 
5466 
5467 //-----------------------------as_instance_type--------------------------------
5468 // Corresponding type for an instance of the given class.
5469 // It will be NotNull, and exact if and only if the klass type is exact.
5470 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5471   ciKlass* k = klass();
5472   bool xk = klass_is_exact();
5473   Compile* C = Compile::current();
5474   Dependencies* deps = C->dependencies();
5475   assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
5476   // Element is an instance
5477   bool klass_is_exact = false;
5478   if (k->is_loaded()) {
5479     // Try to set klass_is_exact.
5480     ciInstanceKlass* ik = k->as_instance_klass();
5481     klass_is_exact = ik->is_final();
5482     if (!klass_is_exact && klass_change
5483         && deps != NULL && UseUniqueSubclasses) {
5484       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5485       if (sub != NULL) {
5486         deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5487         k = ik = sub;
5488         xk = sub->is_final();
5489       }
5490     }
5491   }
5492   return TypeInstPtr::make(TypePtr::BotPTR, k, xk, NULL, 0);
5493 }
5494 
5495 //------------------------------xmeet------------------------------------------
5496 // Compute the MEET of two types, return a new Type object.
5497 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5498   // Perform a fast test for common case; meeting the same types together.
5499   if( this == t ) return this;  // Meeting same type-rep?
5500 
5501   // Current "this->_base" is Pointer
5502   switch (t->base()) {          // switch on original type
5503 
5504   case Int:                     // Mixing ints & oops happens when javac
5505   case Long:                    // reuses local variables
5506   case FloatTop:
5507   case FloatCon:
5508   case FloatBot:
5509   case DoubleTop:
5510   case DoubleCon:
5511   case DoubleBot:
5512   case NarrowOop:
5513   case NarrowKlass:
5514   case Bottom:                  // Ye Olde Default
5515     return Type::BOTTOM;
5516   case Top:
5517     return this;
5518 
5519   default:                      // All else is a mistake
5520     typerr(t);
5521 
5522   case AnyPtr: {                // Meeting to AnyPtrs
5523     // Found an AnyPtr type vs self-KlassPtr type
5524     const TypePtr *tp = t->is_ptr();
5525     int offset = meet_offset(tp->offset());
5526     PTR ptr = meet_ptr(tp->ptr());
5527     switch (tp->ptr()) {
5528     case TopPTR:
5529       return this;
5530     case Null:
5531       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5532     case AnyNull:
5533       return make( ptr, klass(), offset );
5534     case BotPTR:
5535     case NotNull:
5536       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5537     default: typerr(t);
5538     }
5539   }
5540 
5541   case RawPtr:
5542   case MetadataPtr:
5543   case OopPtr:
5544   case AryPtr:                  // Meet with AryPtr
5545   case InstPtr:                 // Meet with InstPtr
5546     return TypePtr::BOTTOM;
5547 
5548   //
5549   //             A-top         }
5550   //           /   |   \       }  Tops
5551   //       B-top A-any C-top   }
5552   //          | /  |  \ |      }  Any-nulls
5553   //       B-any   |   C-any   }
5554   //          |    |    |
5555   //       B-con A-con C-con   } constants; not comparable across classes
5556   //          |    |    |
5557   //       B-not   |   C-not   }
5558   //          | \  |  / |      }  not-nulls
5559   //       B-bot A-not C-bot   }
5560   //           \   |   /       }  Bottoms
5561   //             A-bot         }
5562   //
5563 
5564   case InstKlassPtr: {  // Meet two KlassPtr types
5565     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5566     int  off     = meet_offset(tkls->offset());
5567     PTR  ptr     = meet_ptr(tkls->ptr());
5568     ciKlass* tkls_klass = tkls->klass();
5569     ciKlass* this_klass  = klass();
5570     bool tkls_xk = tkls->klass_is_exact();
5571     bool this_xk  = klass_is_exact();


5572 
5573     ciKlass* res_klass = NULL;
5574     bool res_xk = false;
5575     switch(meet_instptr(ptr, this_klass, tkls_klass, this_xk, tkls_xk, this->_ptr, tkls->_ptr, res_klass, res_xk)) {


5576       case UNLOADED:
5577         ShouldNotReachHere();
5578       case SUBTYPE:
5579       case NOT_SUBTYPE:
5580       case LCA:
5581       case QUICK: {
5582         assert(res_xk == (ptr == Constant), "");
5583         const Type* res1 = make(ptr, res_klass, off);
5584         return res1;
5585       }
5586       default:
5587         ShouldNotReachHere();
5588     }
5589   } // End of case KlassPtr
5590   case AryKlassPtr: {                // All arrays inherit from Object class
5591     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5592     int offset = meet_offset(tp->offset());
5593     PTR ptr = meet_ptr(tp->ptr());
5594 
5595     switch (ptr) {
5596     case TopPTR:
5597     case AnyNull:                // Fall 'down' to dual of object klass
5598       // For instances when a subclass meets a superclass we fall
5599       // below the centerline when the superclass is exact. We need to
5600       // do the same here.
5601       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
5602         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5603       } else {
5604         // cannot subclass, so the meet has to fall badly below the centerline
5605         ptr = NotNull;
5606         return make(ptr, ciEnv::current()->Object_klass(), offset);
5607       }
5608     case Constant:
5609     case NotNull:
5610     case BotPTR:                // Fall down to object klass
5611       // LCA is object_klass, but if we subclass from the top we can do better
5612       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5613         // If 'this' (InstPtr) is above the centerline and it is Object class
5614         // then we can subclass in the Java class hierarchy.
5615         // For instances when a subclass meets a superclass we fall
5616         // below the centerline when the superclass is exact. We need
5617         // to do the same here.
5618         if (klass()->equals(ciEnv::current()->Object_klass())) {
5619           // that is, tp's array type is a subtype of my klass
5620           return TypeAryKlassPtr::make(ptr,
5621                                        tp->elem(), tp->klass(), offset);
5622         }
5623       }
5624       // The other case cannot happen, since I cannot be a subtype of an array.
5625       // The meet falls down to Object class below centerline.
5626       if( ptr == Constant )
5627          ptr = NotNull;
5628       return make(ptr, ciEnv::current()->Object_klass(), offset);
5629     default: typerr(t);
5630     }
5631   }




















5632 
5633   } // End of switch
5634   return this;                  // Return the double constant
5635 }
5636 
5637 //------------------------------xdual------------------------------------------
5638 // Dual: compute field-by-field dual
5639 const Type    *TypeInstKlassPtr::xdual() const {
5640   return new TypeInstKlassPtr(dual_ptr(), klass(), dual_offset());
5641 }
5642 
5643 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
5644   if (!is_loaded() || !other->is_loaded()) {
5645     return false;
5646   }
5647   if (!other->isa_instklassptr()) {
5648     return false;
5649   }
5650 
5651   if (!other_exact) {
5652     return false;
5653   }
5654 
5655   if (other->_klass->equals(ciEnv::current()->Object_klass())) {
5656     return true;
5657   }
5658 
5659   if (!this_exact && klass()->is_interface()) {
5660     return false;

5686     return true;
5687   }
5688 
5689   assert(other->isa_instklassptr(), "unsupported");
5690 
5691   if (this_exact && other_exact) {
5692     return is_java_subtype_of(other);
5693   }
5694 
5695   if (!_klass->is_subtype_of(other->_klass) && !other->_klass->is_subtype_of(_klass)) {
5696     return false;
5697   }
5698 
5699   if (this_exact) {
5700     return _klass->is_subtype_of(other->_klass);
5701   }
5702 
5703   return true;
5704 }
5705 
5706 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
5707   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
5708 }
5709 
5710 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* klass, int offset) {
5711   if (klass->is_obj_array_klass()) {
5712     // Element is an object array. Recursively call ourself.
5713     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
5714     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass)->cast_to_exactness(false);
5715     return TypeAryKlassPtr::make(ptr, etype, NULL, offset);








5716   } else if (klass->is_type_array_klass()) {
5717     // Element is an typeArray
5718     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
5719     return TypeAryKlassPtr::make(ptr, etype, klass, offset);




5720   } else {
5721     ShouldNotReachHere();
5722     return NULL;
5723   }
5724 }
5725 











5726 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass) {
5727   return TypeAryKlassPtr::make(Constant, klass, 0);
5728 }
5729 
5730 //------------------------------eq---------------------------------------------
5731 // Structural equality check for Type representations
5732 bool TypeAryKlassPtr::eq(const Type *t) const {
5733   const TypeAryKlassPtr *p = t->is_aryklassptr();
5734   return
5735     _elem == p->_elem &&  // Check array



5736     TypeKlassPtr::eq(p);  // Check sub-parts
5737 }
5738 
5739 //------------------------------hash-------------------------------------------
5740 // Type-specific hashing function.
5741 int TypeAryKlassPtr::hash(void) const {
5742   return (intptr_t)_elem + TypeKlassPtr::hash();
5743 }
5744 
5745 //----------------------compute_klass------------------------------------------
5746 // Compute the defining klass for this class
5747 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5748   // Compute _klass based on element type.
5749   ciKlass* k_ary = NULL;
5750   const TypeInstPtr *tinst;
5751   const TypeAryPtr *tary;
5752   const Type* el = elem();
5753   if (el->isa_narrowoop()) {
5754     el = el->make_ptr();
5755   }
5756 
5757   // Get element klass
5758   if ((tinst = el->isa_instptr()) != NULL) {
5759     // Compute array klass from element klass
5760     k_ary = ciObjArrayKlass::make(tinst->klass());






5761   } else if ((tary = el->isa_aryptr()) != NULL) {
5762     // Compute array klass from element klass
5763     ciKlass* k_elem = tary->klass();
5764     // If element type is something like bottom[], k_elem will be null.
5765     if (k_elem != NULL)
5766       k_ary = ciObjArrayKlass::make(k_elem);
5767   } else if ((el->base() == Type::Top) ||
5768              (el->base() == Type::Bottom)) {
5769     // element type of Bottom occurs from meet of basic type
5770     // and object; Top occurs when doing join on Bottom.
5771     // Leave k_ary at NULL.
5772   } else {
5773     // Cannot compute array klass directly from basic type,
5774     // since subtypes of TypeInt all have basic type T_INT.
5775 #ifdef ASSERT
5776     if (verify && el->isa_int()) {
5777       // Check simple cases when verifying klass.
5778       BasicType bt = T_ILLEGAL;
5779       if (el == TypeInt::BYTE) {
5780         bt = T_BYTE;

5805 
5806   // Oops, need to compute _klass and cache it
5807   ciKlass* k_ary = compute_klass();
5808 
5809   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5810     // The _klass field acts as a cache of the underlying
5811     // ciKlass for this array type.  In order to set the field,
5812     // we need to cast away const-ness.
5813     //
5814     // IMPORTANT NOTE: we *never* set the _klass field for the
5815     // type TypeAryPtr::OOPS.  This Type is shared between all
5816     // active compilations.  However, the ciKlass which represents
5817     // this Type is *not* shared between compilations, so caching
5818     // this value would result in fetching a dangling pointer.
5819     //
5820     // Recomputing the underlying ciKlass for each request is
5821     // a bit less efficient than caching, but calls to
5822     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5823     ((TypeAryPtr*)this)->_klass = k_ary;
5824     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5825         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes() &&
5826         _offset != arrayOopDesc::klass_offset_in_bytes()) {
5827       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5828     }
5829   }
5830   return k_ary;
5831 }
5832 
5833 ciKlass* TypeAryPtr::exact_klass_helper() const {
5834   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
5835     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
5836     if (k == NULL) {
5837       return NULL;
5838     }
5839     k = ciObjArrayKlass::make(k);
5840     return k;
5841   }
5842 
5843   return klass();
5844 }
5845 
5846 const Type* TypeAryPtr::base_element_type(int& dims) const {
5847   const Type* elem = this->elem();
5848   dims = 1;
5849   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
5850     elem = elem->make_ptr()->is_aryptr()->elem();
5851     dims++;
5852   }
5853   return elem;
5854 }
5855 
5856 //------------------------------add_offset-------------------------------------
5857 // Access internals of klass object
5858 const TypePtr *TypeAryKlassPtr::add_offset(intptr_t offset) const {
5859   return make(_ptr, elem(), klass(), xadd_offset(offset));
5860 }
5861 
5862 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
5863   return make(_ptr, elem(), klass(), offset);
5864 }
5865 
5866 //------------------------------cast_to_ptr_type-------------------------------
5867 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
5868   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
5869   if (ptr == _ptr) return this;
5870   return make(ptr, elem(), _klass, _offset);
5871 }
5872 
5873 bool TypeAryKlassPtr::must_be_exact() const {
5874   if (_elem == Type::BOTTOM) return false;
5875   if (_elem == Type::TOP   ) return false;
5876   const TypeKlassPtr*  tk = _elem->isa_klassptr();
5877   if (!tk)             return true;   // a primitive type, like int
5878   return tk->must_be_exact();
5879 }
5880 
5881 
5882 //-----------------------------cast_to_exactness-------------------------------
5883 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5884   if (must_be_exact()) return this;  // cannot clear xk
5885   ciKlass* k = _klass;
5886   const Type* elem = this->elem();
5887   if (elem->isa_klassptr() && !klass_is_exact) {
5888     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
5889   }
5890   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);














5891 }
5892 
5893 
5894 //-----------------------------as_instance_type--------------------------------
5895 // Corresponding type for an instance of the given class.
5896 // It will be NotNull, and exact if and only if the klass type is exact.
5897 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
5898   ciKlass* k = klass();

5899   bool    xk = klass_is_exact();
5900   const Type* el = NULL;
5901   if (elem()->isa_klassptr()) {
5902     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
5903     k = NULL;
5904   } else {
5905     el = elem();
5906   }
5907   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);









5908 }
5909 
5910 
5911 //------------------------------xmeet------------------------------------------
5912 // Compute the MEET of two types, return a new Type object.
5913 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
5914   // Perform a fast test for common case; meeting the same types together.
5915   if( this == t ) return this;  // Meeting same type-rep?
5916 
5917   // Current "this->_base" is Pointer
5918   switch (t->base()) {          // switch on original type
5919 
5920   case Int:                     // Mixing ints & oops happens when javac
5921   case Long:                    // reuses local variables
5922   case FloatTop:
5923   case FloatCon:
5924   case FloatBot:
5925   case DoubleTop:
5926   case DoubleCon:
5927   case DoubleBot:
5928   case NarrowOop:
5929   case NarrowKlass:
5930   case Bottom:                  // Ye Olde Default
5931     return Type::BOTTOM;
5932   case Top:
5933     return this;
5934 
5935   default:                      // All else is a mistake
5936     typerr(t);
5937 
5938   case AnyPtr: {                // Meeting to AnyPtrs
5939     // Found an AnyPtr type vs self-KlassPtr type
5940     const TypePtr *tp = t->is_ptr();
5941     int offset = meet_offset(tp->offset());
5942     PTR ptr = meet_ptr(tp->ptr());
5943     switch (tp->ptr()) {
5944     case TopPTR:
5945       return this;
5946     case Null:
5947       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5948     case AnyNull:
5949       return make( ptr, _elem, klass(), offset );
5950     case BotPTR:
5951     case NotNull:
5952       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5953     default: typerr(t);
5954     }
5955   }
5956 
5957   case RawPtr:
5958   case MetadataPtr:
5959   case OopPtr:
5960   case AryPtr:                  // Meet with AryPtr
5961   case InstPtr:                 // Meet with InstPtr
5962     return TypePtr::BOTTOM;
5963 
5964   //
5965   //             A-top         }
5966   //           /   |   \       }  Tops
5967   //       B-top A-any C-top   }
5968   //          | /  |  \ |      }  Any-nulls
5969   //       B-any   |   C-any   }
5970   //          |    |    |
5971   //       B-con A-con C-con   } constants; not comparable across classes
5972   //          |    |    |
5973   //       B-not   |   C-not   }
5974   //          | \  |  / |      }  not-nulls
5975   //       B-bot A-not C-bot   }
5976   //           \   |   /       }  Bottoms
5977   //             A-bot         }
5978   //
5979 
5980   case AryKlassPtr: {  // Meet two KlassPtr types
5981     const TypeAryKlassPtr *tap = t->is_aryklassptr();
5982     int off = meet_offset(tap->offset());
5983     const Type* elem = _elem->meet(tap->_elem);
5984 
5985     PTR ptr = meet_ptr(tap->ptr());
5986     ciKlass* res_klass = NULL;
5987     bool res_xk = false;
5988     meet_aryptr(ptr, elem, this->klass(), tap->klass(), this->klass_is_exact(), tap->klass_is_exact(), this->ptr(), tap->ptr(), res_klass, res_xk);






5989     assert(res_xk == (ptr == Constant), "");
5990     return make(ptr, elem, res_klass, off);










5991   } // End of case KlassPtr
5992   case InstKlassPtr: {
5993     const TypeInstKlassPtr *tp = t->is_instklassptr();
5994     int offset = meet_offset(tp->offset());
5995     PTR ptr = meet_ptr(tp->ptr());
5996 
5997     switch (ptr) {
5998     case TopPTR:
5999     case AnyNull:                // Fall 'down' to dual of object klass
6000       // For instances when a subclass meets a superclass we fall
6001       // below the centerline when the superclass is exact. We need to
6002       // do the same here.
6003       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6004         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6005       } else {
6006         // cannot subclass, so the meet has to fall badly below the centerline
6007         ptr = NotNull;
6008         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset);
6009       }
6010     case Constant:
6011     case NotNull:
6012     case BotPTR:                // Fall down to object klass
6013       // LCA is object_klass, but if we subclass from the top we can do better
6014       if (above_centerline(tp->ptr())) {
6015         // If 'tp'  is above the centerline and it is Object class
6016         // then we can subclass in the Java class hierarchy.
6017         // For instances when a subclass meets a superclass we fall
6018         // below the centerline when the superclass is exact. We need
6019         // to do the same here.
6020         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6021           // that is, my array type is a subtype of 'tp' klass
6022           return make(ptr, _elem, _klass, offset);
6023         }
6024       }
6025       // The other case cannot happen, since t cannot be a subtype of an array.
6026       // The meet falls down to Object class below centerline.
6027       if (ptr == Constant)
6028          ptr = NotNull;
6029       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset);
6030     default: typerr(t);
6031     }
6032   }












6033 
6034   } // End of switch
6035   return this;                  // Return the double constant
6036 }
6037 
6038 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6039   if (other->klass() == ciEnv::current()->Object_klass() && other_exact) {
6040     return true;
6041   }
6042 
6043   if (!is_loaded() || !other->is_loaded() || other->klass() == NULL || klass() == NULL) {
6044     return false;
6045   }
6046   if (other->isa_instklassptr()) {
6047     return _klass->is_subtype_of(other->_klass) && other_exact;
6048   }
6049   if (klass() == NULL) {
6050     return false;
6051   }
6052   assert(other->isa_aryklassptr(), "");
6053   const TypeAryKlassPtr* other_ary = other->isa_aryklassptr();
6054   if (other_ary->_elem->isa_klassptr() && _elem->isa_klassptr()) {



6055     return _elem->is_klassptr()->is_java_subtype_of_helper(other_ary->_elem->is_klassptr(), this_exact, other_exact);
6056   }
6057   if (!other_ary->_elem->isa_klassptr() && !_elem->isa_klassptr()) {
6058     return _klass->is_subtype_of(other->_klass);
6059   }
6060   return false;
6061 }
6062 
6063 bool TypeAryKlassPtr::is_same_java_type_as(const TypeKlassPtr* other) const {
6064   if (!other->isa_aryklassptr() ||
6065       !is_loaded() || !other->is_loaded() || klass() == NULL || other->klass() == NULL) {
6066     return false;
6067   }
6068   const TypeAryKlassPtr* other_ary = other->isa_aryklassptr();
6069   if (other_ary->_elem->isa_klassptr() && _elem->isa_klassptr()) {
6070     return _elem->is_klassptr()->is_same_java_type_as(other_ary->_elem->is_klassptr());
6071   }
6072   if (!other_ary->_elem->isa_klassptr() && !_elem->isa_klassptr()) {
6073     return _klass->equals(other->_klass);
6074   }

6087   }
6088   assert(other->isa_aryklassptr(), "");
6089 
6090   if (this_exact && other_exact) {
6091     return is_java_subtype_of(other);
6092   }
6093 
6094   const TypeAryKlassPtr* other_ary = other->isa_aryklassptr();
6095   if (other_ary->_elem->isa_klassptr() && _elem->isa_klassptr()) {
6096     return _elem->is_klassptr()->maybe_java_subtype_of_helper(other_ary->_elem->is_klassptr(), this_exact, other_exact);
6097   }
6098   if (!other_ary->_elem->isa_klassptr() && !_elem->isa_klassptr()) {
6099     return _klass->is_subtype_of(other->_klass);
6100   }
6101   return false;
6102 }
6103 
6104 //------------------------------xdual------------------------------------------
6105 // Dual: compute field-by-field dual
6106 const Type    *TypeAryKlassPtr::xdual() const {
6107   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6108 }
6109 
6110 //------------------------------get_con----------------------------------------
6111 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6112   if (elem()->isa_klassptr()) {
6113     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6114     if (k == NULL) {
6115       return NULL;
6116     }
6117     k = ciObjArrayKlass::make(k);
6118     return k;
6119   }
6120 
6121   return klass();
6122 }
6123 
6124 ciKlass* TypeAryKlassPtr::klass() const {
6125   if (_klass != NULL) {
6126     return _klass;
6127   }
6128   ciKlass* k = NULL;
6129   if (elem()->isa_klassptr()) {
6130     k = elem()->is_klassptr()->klass();
6131     if (k != NULL) {
6132       k = ciObjArrayKlass::make(k);














6133       ((TypeAryKlassPtr*)this)->_klass = k;
6134     }
6135   } else if ((elem()->base() == Type::Top) ||
6136              (elem()->base() == Type::Bottom)) {
6137   } else {
6138     k = ciTypeArrayKlass::make(elem()->basic_type());
6139   }
6140   return k;
6141 }
6142 
6143 //------------------------------dump2------------------------------------------
6144 // Dump Klass Type
6145 #ifndef PRODUCT
6146 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6147   switch( _ptr ) {
6148   case Constant:
6149     st->print("precise ");
6150   case NotNull:
6151     {
6152       st->print("[");




6153       _elem->dump2(d, depth, st);
6154       st->print(": ");
6155     }
6156   case BotPTR:
6157     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6158   case TopPTR:
6159   case AnyNull:
6160     st->print(":%s", ptr_msg[_ptr]);
6161     if( _ptr == Constant ) st->print(":exact");
6162     break;
6163   default:
6164     break;
6165   }
6166 
6167   if( _offset ) {               // Dump offset, if any
6168     if( _offset == OffsetBot )      { st->print("+any"); }
6169     else if( _offset == OffsetTop ) { st->print("+unknown"); }
6170     else                            { st->print("+%d", _offset); }
6171   }
6172 


6173   st->print(" *");
6174 }
6175 #endif
6176 
6177 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6178   const Type* elem = this->elem();
6179   dims = 1;
6180   while (elem->isa_aryklassptr()) {
6181     elem = elem->is_aryklassptr()->elem();
6182     dims++;
6183   }
6184   return elem;
6185 }
6186 
6187 //=============================================================================
6188 // Convenience common pre-built types.
6189 
6190 //------------------------------make-------------------------------------------
6191 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6192   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();












6193 }
6194 
6195 //------------------------------make-------------------------------------------
6196 const TypeFunc *TypeFunc::make(ciMethod* method) {
6197   Compile* C = Compile::current();
6198   const TypeFunc* tf = C->last_tf(method); // check cache
6199   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
6200   const TypeTuple *domain;
6201   if (method->is_static()) {
6202     domain = TypeTuple::make_domain(NULL, method->signature());
6203   } else {
6204     domain = TypeTuple::make_domain(method->holder(), method->signature());













6205   }
6206   const TypeTuple *range  = TypeTuple::make_range(method->signature());
6207   tf = TypeFunc::make(domain, range);
6208   C->set_last_tf(method, tf);  // fill cache
6209   return tf;
6210 }
6211 
6212 //------------------------------meet-------------------------------------------
6213 // Compute the MEET of two types.  It returns a new Type object.
6214 const Type *TypeFunc::xmeet( const Type *t ) const {
6215   // Perform a fast test for common case; meeting the same types together.
6216   if( this == t ) return this;  // Meeting same type-rep?
6217 
6218   // Current "this->_base" is Func
6219   switch (t->base()) {          // switch on original type
6220 
6221   case Bottom:                  // Ye Olde Default
6222     return t;
6223 
6224   default:                      // All else is a mistake
6225     typerr(t);
6226 
6227   case Top:
6228     break;
6229   }
6230   return this;                  // Return the double constant
6231 }
6232 
6233 //------------------------------xdual------------------------------------------
6234 // Dual: compute field-by-field dual
6235 const Type *TypeFunc::xdual() const {
6236   return this;
6237 }
6238 
6239 //------------------------------eq---------------------------------------------
6240 // Structural equality check for Type representations
6241 bool TypeFunc::eq( const Type *t ) const {
6242   const TypeFunc *a = (const TypeFunc*)t;
6243   return _domain == a->_domain &&
6244     _range == a->_range;


6245 }
6246 
6247 //------------------------------hash-------------------------------------------
6248 // Type-specific hashing function.
6249 int TypeFunc::hash(void) const {
6250   return (intptr_t)_domain + (intptr_t)_range;
6251 }
6252 
6253 //------------------------------dump2------------------------------------------
6254 // Dump Function Type
6255 #ifndef PRODUCT
6256 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6257   if( _range->cnt() <= Parms )
6258     st->print("void");
6259   else {
6260     uint i;
6261     for (i = Parms; i < _range->cnt()-1; i++) {
6262       _range->field_at(i)->dump2(d,depth,st);
6263       st->print("/");
6264     }
6265     _range->field_at(i)->dump2(d,depth,st);
6266   }
6267   st->print(" ");
6268   st->print("( ");
6269   if( !depth || d[this] ) {     // Check for recursive dump
6270     st->print("...)");
6271     return;
6272   }
6273   d.Insert((void*)this,(void*)this);    // Stop recursion
6274   if (Parms < _domain->cnt())
6275     _domain->field_at(Parms)->dump2(d,depth-1,st);
6276   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6277     st->print(", ");
6278     _domain->field_at(i)->dump2(d,depth-1,st);
6279   }
6280   st->print(" )");
6281 }
6282 #endif
6283 
6284 //------------------------------singleton--------------------------------------
6285 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6286 // constants (Ldi nodes).  Singletons are integer, float or double constants
6287 // or a single symbol.
6288 bool TypeFunc::singleton(void) const {
6289   return false;                 // Never a singleton
6290 }
6291 
6292 bool TypeFunc::empty(void) const {
6293   return false;                 // Never empty
6294 }
6295 
6296 
6297 BasicType TypeFunc::return_type() const{
6298   if (range()->cnt() == TypeFunc::Parms) {
6299     return T_VOID;
6300   }
6301   return range()->field_at(TypeFunc::Parms)->basic_type();
6302 }

   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/ciFlatArrayKlass.hpp"
  27 #include "ci/ciField.hpp"
  28 #include "ci/ciInlineKlass.hpp"
  29 #include "ci/ciMethodData.hpp"
  30 #include "ci/ciTypeFlow.hpp"
  31 #include "classfile/javaClasses.hpp"
  32 #include "classfile/symbolTable.hpp"
  33 #include "compiler/compileLog.hpp"
  34 #include "libadt/dict.hpp"
  35 #include "memory/oopFactory.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/instanceKlass.hpp"
  38 #include "oops/instanceMirrorKlass.hpp"
  39 #include "oops/objArrayKlass.hpp"
  40 #include "oops/typeArrayKlass.hpp"
  41 #include "opto/matcher.hpp"
  42 #include "opto/node.hpp"
  43 #include "opto/opcodes.hpp"
  44 #include "opto/type.hpp"
  45 #include "utilities/powerOfTwo.hpp"
  46 #include "utilities/stringUtils.hpp"
  47 
  48 // Portions of code courtesy of Clifford Click
  49 
  50 // Optimization - Graph Style
  51 
  52 // Dictionary of types shared among compilations.
  53 Dict* Type::_shared_type_dict = NULL;
  54 const Type::Offset Type::Offset::top(Type::OffsetTop);
  55 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
  56 
  57 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
  58   // Either is 'TOP' offset?  Return the other offset!
  59   int offset = other._offset;
  60   if (_offset == OffsetTop) return Offset(offset);
  61   if (offset == OffsetTop) return Offset(_offset);
  62   // If either is different, return 'BOTTOM' offset
  63   if (_offset != offset) return bottom;
  64   return Offset(_offset);
  65 }
  66 
  67 const Type::Offset Type::Offset::dual() const {
  68   if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
  69   if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
  70   return Offset(_offset);               // Map everything else into self
  71 }
  72 
  73 const Type::Offset Type::Offset::add(intptr_t offset) const {
  74   // Adding to 'TOP' offset?  Return 'TOP'!
  75   if (_offset == OffsetTop || offset == OffsetTop) return top;
  76   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  77   if (_offset == OffsetBot || offset == OffsetBot) return bottom;
  78   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  79   offset += (intptr_t)_offset;
  80   if (offset != (int)offset || offset == OffsetTop) return bottom;
  81 
  82   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  83   // It is possible to construct a negative offset during PhaseCCP
  84 
  85   return Offset((int)offset);        // Sum valid offsets
  86 }
  87 
  88 void Type::Offset::dump2(outputStream *st) const {
  89   if (_offset == 0) {
  90     return;
  91   } else if (_offset == OffsetTop) {
  92     st->print("+top");
  93   }
  94   else if (_offset == OffsetBot) {
  95     st->print("+bot");
  96   } else if (_offset) {
  97     st->print("+%d", _offset);
  98   }
  99 }
 100 
 101 // Array which maps compiler types to Basic Types
 102 const Type::TypeInfo Type::_type_info[Type::lastype] = {
 103   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
 104   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
 105   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
 106   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
 107   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
 108   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
 109   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
 110   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
 111   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
 112   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
 113 
 114 #if defined(PPC64)
 115   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 116   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 117   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 118   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 119   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 120   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 121   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 122 #elif defined(S390)
 123   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 124   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 125   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 126   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 127   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
 128   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 129   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 130 #else // all other
 131   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 132   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 133   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
 134   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
 135   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 136   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
 137   { Bad,             T_ILLEGAL,    "vectorz:",      false, Op_VecZ,              relocInfo::none          },  // VectorZ
 138 #endif
 139   { Bad,             T_PRIMITIVE_OBJECT, "inline:",      false, Node::NotAMachineReg, relocInfo::none          },  // InlineType
 140   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
 141   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
 142   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
 143   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
 144   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
 145   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
 146   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
 147   { Bad,             T_METADATA,   "instklass:",    false, Op_RegP,              relocInfo::metadata_type },  // InstKlassPtr
 148   { Bad,             T_METADATA,   "aryklass:",     false, Op_RegP,              relocInfo::metadata_type },  // AryKlassPtr
 149   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
 150   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
 151   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
 152   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
 153   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
 154   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
 155   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
 156   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
 157   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
 158   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
 159   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom

 252   case ciTypeFlow::StateVector::T_NULL:
 253     assert(type == ciTypeFlow::StateVector::null_type(), "");
 254     return TypePtr::NULL_PTR;
 255 
 256   case ciTypeFlow::StateVector::T_LONG2:
 257     // The ciTypeFlow pass pushes a long, then the half.
 258     // We do the same.
 259     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 260     return TypeInt::TOP;
 261 
 262   case ciTypeFlow::StateVector::T_DOUBLE2:
 263     // The ciTypeFlow pass pushes double, then the half.
 264     // Our convention is the same.
 265     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 266     return Type::TOP;
 267 
 268   case T_ADDRESS:
 269     assert(type->is_return_address(), "");
 270     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 271 
 272   case T_PRIMITIVE_OBJECT: {
 273     bool is_null_free = type->is_null_free();
 274     ciInlineKlass* vk = type->unwrap()->as_inline_klass();
 275     if (is_null_free) {
 276       return TypeInlineType::make(vk);
 277     } else {
 278       return TypeOopPtr::make_from_klass(vk)->join_speculative(is_null_free ? TypePtr::NOTNULL : TypePtr::BOTTOM);
 279     }
 280   }
 281 
 282   default:
 283     // make sure we did not mix up the cases:
 284     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 285     assert(type != ciTypeFlow::StateVector::top_type(), "");
 286     assert(type != ciTypeFlow::StateVector::null_type(), "");
 287     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 288     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 289     assert(!type->is_return_address(), "");
 290 
 291     return Type::get_const_type(type);
 292   }
 293 }
 294 
 295 
 296 //-----------------------make_from_constant------------------------------------
 297 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 298                                      int stable_dimension, bool is_narrow_oop,
 299                                      bool is_autobox_cache) {
 300   switch (constant.basic_type()) {
 301     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
 302     case T_CHAR:     return TypeInt::make(constant.as_char());
 303     case T_BYTE:     return TypeInt::make(constant.as_byte());
 304     case T_SHORT:    return TypeInt::make(constant.as_short());
 305     case T_INT:      return TypeInt::make(constant.as_int());
 306     case T_LONG:     return TypeLong::make(constant.as_long());
 307     case T_FLOAT:    return TypeF::make(constant.as_float());
 308     case T_DOUBLE:   return TypeD::make(constant.as_double());
 309     case T_ARRAY:
 310     case T_PRIMITIVE_OBJECT:
 311     case T_OBJECT: {
 312         const Type* con_type = NULL;
 313         ciObject* oop_constant = constant.as_object();
 314         if (oop_constant->is_null_object()) {
 315           con_type = Type::get_zero_type(T_OBJECT);
 316         } else {
 317           guarantee(require_constant || oop_constant->should_be_constant(), "con_type must get computed");
 318           con_type = TypeOopPtr::make_from_constant(oop_constant, require_constant);
 319           if (Compile::current()->eliminate_boxing() && is_autobox_cache) {
 320             con_type = con_type->is_aryptr()->cast_to_autobox_cache();
 321           }
 322           if (stable_dimension > 0) {
 323             assert(FoldStableValues, "sanity");
 324             assert(!con_type->is_zero_type(), "default value for stable field");
 325             con_type = con_type->is_aryptr()->cast_to_stable(true, stable_dimension);
 326           }
 327         }
 328         if (is_narrow_oop) {
 329           con_type = con_type->make_narrowoop();
 330         }
 331         return con_type;
 332       }
 333     case T_ILLEGAL:
 334       // Invalid ciConstant returned due to OutOfMemoryError in the CI
 335       assert(Compile::current()->env()->failing(), "otherwise should not see this");
 336       return NULL;
 337     default:
 338       // Fall through to failure
 339       return NULL;
 340   }
 341 }
 342 
 343 static ciConstant check_mismatched_access(ciConstant con, BasicType loadbt, bool is_unsigned) {
 344   BasicType conbt = con.basic_type();
 345   switch (conbt) {
 346     case T_BOOLEAN: conbt = T_BYTE;   break;
 347     case T_ARRAY:   conbt = T_OBJECT; break;
 348     case T_PRIMITIVE_OBJECT: conbt = T_OBJECT; break;
 349     default:                          break;
 350   }
 351   switch (loadbt) {
 352     case T_BOOLEAN:   loadbt = T_BYTE;   break;
 353     case T_NARROWOOP: loadbt = T_OBJECT; break;
 354     case T_ARRAY:     loadbt = T_OBJECT; break;
 355     case T_PRIMITIVE_OBJECT: loadbt = T_OBJECT; break;
 356     case T_ADDRESS:   loadbt = T_OBJECT; break;
 357     default:                             break;
 358   }
 359   if (conbt == loadbt) {
 360     if (is_unsigned && conbt == T_BYTE) {
 361       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 362       return ciConstant(T_INT, con.as_int() & 0xFF);
 363     } else {
 364       return con;
 365     }
 366   }
 367   if (conbt == T_SHORT && loadbt == T_CHAR) {
 368     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 369     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 370   }
 371   return ciConstant(); // T_ILLEGAL
 372 }
 373 
 374 // Try to constant-fold a stable array element.
 375 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,

 571   const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 572   ffalse[0] = Type::CONTROL;
 573   ffalse[1] = Type::TOP;
 574   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 575 
 576   const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 577   fneither[0] = Type::TOP;
 578   fneither[1] = Type::TOP;
 579   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 580 
 581   const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 582   ftrue[0] = Type::TOP;
 583   ftrue[1] = Type::CONTROL;
 584   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 585 
 586   const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 587   floop[0] = Type::CONTROL;
 588   floop[1] = TypeInt::INT;
 589   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 590 
 591   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, Offset(0));
 592   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, Offset::bottom);
 593   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, Offset::bottom);
 594 
 595   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 596   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 597 
 598   const Type **fmembar = TypeTuple::fields(0);
 599   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 600 
 601   const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 602   fsc[0] = TypeInt::CC;
 603   fsc[1] = Type::MEMORY;
 604   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 605 
 606   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 607   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 608   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 609   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 610                                            false, 0, Offset(oopDesc::mark_offset_in_bytes()));
 611   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 612                                            false, 0, Offset(oopDesc::klass_offset_in_bytes()));
 613   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, Offset::bottom, TypeOopPtr::InstanceBot);
 614 
 615   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, NULL, Offset::bottom);
 616 
 617   TypeInlineType::BOTTOM = TypeInlineType::make(NULL);
 618 
 619   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 620   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 621 
 622   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 623 
 624   mreg2type[Op_Node] = Type::BOTTOM;
 625   mreg2type[Op_Set ] = 0;
 626   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 627   mreg2type[Op_RegI] = TypeInt::INT;
 628   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 629   mreg2type[Op_RegF] = Type::FLOAT;
 630   mreg2type[Op_RegD] = Type::DOUBLE;
 631   mreg2type[Op_RegL] = TypeLong::LONG;
 632   mreg2type[Op_RegFlags] = TypeInt::CC;
 633 
 634   TypeAryPtr::RANGE   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), NULL /* current->env()->Object_klass() */, false, Offset(arrayOopDesc::length_offset_in_bytes()));
 635 
 636   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 637 
 638 #ifdef _LP64
 639   if (UseCompressedOops) {
 640     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 641     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 642   } else
 643 #endif
 644   {
 645     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 646     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), NULL /*ciArrayKlass::make(o)*/,  false,  Offset::bottom);
 647   }
 648   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Offset::bottom);
 649   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Offset::bottom);
 650   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Offset::bottom);
 651   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Offset::bottom);
 652   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Offset::bottom);
 653   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Offset::bottom);
 654   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Offset::bottom);
 655   TypeAryPtr::INLINES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInlineType::BOTTOM,TypeInt::POS), NULL, false,  Offset::bottom);
 656 
 657   // Nobody should ask _array_body_type[T_NARROWOOP]. Use NULL as assert.
 658   TypeAryPtr::_array_body_type[T_NARROWOOP] = NULL;
 659   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;
 660   TypeAryPtr::_array_body_type[T_PRIMITIVE_OBJECT] = TypeAryPtr::OOPS;
 661   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 662   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 663   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 664   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 665   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 666   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 667   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 668   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 669   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 670 
 671   TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), Offset(0), false);
 672   TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), Offset(0), false);
 673 
 674   const Type **fi2c = TypeTuple::fields(2);
 675   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 676   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 677   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 678 
 679   const Type **intpair = TypeTuple::fields(2);
 680   intpair[0] = TypeInt::INT;
 681   intpair[1] = TypeInt::INT;
 682   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 683 
 684   const Type **longpair = TypeTuple::fields(2);
 685   longpair[0] = TypeLong::LONG;
 686   longpair[1] = TypeLong::LONG;
 687   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 688 
 689   const Type **intccpair = TypeTuple::fields(2);
 690   intccpair[0] = TypeInt::INT;
 691   intccpair[1] = TypeInt::CC;
 692   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 693 
 694   const Type **longccpair = TypeTuple::fields(2);
 695   longccpair[0] = TypeLong::LONG;
 696   longccpair[1] = TypeInt::CC;
 697   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 698 
 699   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 700   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 701   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 702   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 703   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 704   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 705   _const_basic_type[T_INT]         = TypeInt::INT;
 706   _const_basic_type[T_LONG]        = TypeLong::LONG;
 707   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 708   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 709   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 710   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays
 711   _const_basic_type[T_PRIMITIVE_OBJECT] = TypeInstPtr::BOTTOM;
 712   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 713   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 714   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 715 
 716   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 717   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 718   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 719   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 720   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 721   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 722   _zero_type[T_INT]         = TypeInt::ZERO;
 723   _zero_type[T_LONG]        = TypeLong::ZERO;
 724   _zero_type[T_FLOAT]       = TypeF::ZERO;
 725   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 726   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 727   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop
 728   _zero_type[T_PRIMITIVE_OBJECT] = TypePtr::NULL_PTR;
 729   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 730   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 731 
 732   // get_zero_type() should not happen for T_CONFLICT
 733   _zero_type[T_CONFLICT]= NULL;
 734 
 735   TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
 736   mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
 737 
 738   if (Matcher::supports_scalable_vector()) {
 739     TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
 740   }
 741 
 742   // Vector predefined types, it needs initialized _const_basic_type[].
 743   if (Matcher::vector_size_supported(T_BYTE,4)) {
 744     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 745   }
 746   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 747     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 748   }

1000     return t->xmeet(this);
1001 
1002   case InstPtr:
1003     return t->xmeet(this);
1004 
1005   case MetadataPtr:
1006   case KlassPtr:
1007   case InstKlassPtr:
1008   case AryKlassPtr:
1009     return t->xmeet(this);
1010 
1011   case AryPtr:
1012     return t->xmeet(this);
1013 
1014   case NarrowOop:
1015     return t->xmeet(this);
1016 
1017   case NarrowKlass:
1018     return t->xmeet(this);
1019 
1020   case InlineType:
1021     return t->xmeet(this);
1022 
1023   case Bad:                     // Type check
1024   default:                      // Bogus type not in lattice
1025     typerr(t);
1026     return Type::BOTTOM;
1027 
1028   case Bottom:                  // Ye Olde Default
1029     return t;
1030 
1031   case FloatTop:
1032     if( _base == FloatTop ) return this;
1033   case FloatBot:                // Float
1034     if( _base == FloatBot || _base == FloatTop ) return FLOAT;
1035     if( _base == DoubleTop || _base == DoubleBot ) return Type::BOTTOM;
1036     typerr(t);
1037     return Type::BOTTOM;
1038 
1039   case DoubleTop:
1040     if( _base == DoubleTop ) return this;
1041   case DoubleBot:               // Double
1042     if( _base == DoubleBot || _base == DoubleTop ) return DOUBLE;

1172     case Type::VectorY:
1173     case Type::VectorZ:
1174     case Type::VectorMask:
1175     case Type::AnyPtr:
1176     case Type::RawPtr:
1177     case Type::OopPtr:
1178     case Type::InstPtr:
1179     case Type::AryPtr:
1180     case Type::MetadataPtr:
1181     case Type::KlassPtr:
1182     case Type::InstKlassPtr:
1183     case Type::AryKlassPtr:
1184     case Type::Function:
1185     case Type::Return_Address:
1186     case Type::FloatTop:
1187     case Type::FloatCon:
1188     case Type::FloatBot:
1189     case Type::DoubleTop:
1190     case Type::DoubleCon:
1191     case Type::DoubleBot:
1192     case Type::InlineType:
1193       return Category::Data;
1194     case Type::Memory:
1195       return Category::Memory;
1196     case Type::Control:
1197       return Category::Control;
1198     case Type::Top:
1199     case Type::Abio:
1200     case Type::Bottom:
1201       return Category::Other;
1202     case Type::Bad:
1203     case Type::lastype:
1204       return Category::Undef;
1205     case Type::Tuple:
1206       // Recursive case. Return CatMixed if the tuple contains types of
1207       // different categories (e.g. CallStaticJavaNode's type), or the specific
1208       // category if all types are of the same category (e.g. IfNode's type).
1209       tuple = is_tuple();
1210       if (tuple->cnt() == 0) {
1211         return Category::Undef;
1212       } else {

1587   // Currently "this->_base" is a TypeInt
1588   switch (t->base()) {          // Switch on original type
1589   case AnyPtr:                  // Mixing with oops happens when javac
1590   case RawPtr:                  // reuses local variables
1591   case OopPtr:
1592   case InstPtr:
1593   case AryPtr:
1594   case MetadataPtr:
1595   case KlassPtr:
1596   case InstKlassPtr:
1597   case AryKlassPtr:
1598   case NarrowOop:
1599   case NarrowKlass:
1600   case Long:
1601   case FloatTop:
1602   case FloatCon:
1603   case FloatBot:
1604   case DoubleTop:
1605   case DoubleCon:
1606   case DoubleBot:
1607   case InlineType:
1608   case Bottom:                  // Ye Olde Default
1609     return Type::BOTTOM;
1610   default:                      // All else is a mistake
1611     typerr(t);
1612   case Top:                     // No change
1613     return this;
1614   case Int:                     // Int vs Int?
1615     break;
1616   }
1617 
1618   // Expand covered set
1619   const TypeInt *r = t->is_int();
1620   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1621 }
1622 
1623 //------------------------------xdual------------------------------------------
1624 // Dual: reverse hi & lo; flip widen
1625 const Type *TypeInt::xdual() const {
1626   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1627   return new TypeInt(_hi,_lo,w);

2075 
2076 bool TypeLong::empty(void) const {
2077   return _lo > _hi;
2078 }
2079 
2080 //=============================================================================
2081 // Convenience common pre-built types.
2082 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2083 const TypeTuple *TypeTuple::IFFALSE;
2084 const TypeTuple *TypeTuple::IFTRUE;
2085 const TypeTuple *TypeTuple::IFNEITHER;
2086 const TypeTuple *TypeTuple::LOOPBODY;
2087 const TypeTuple *TypeTuple::MEMBAR;
2088 const TypeTuple *TypeTuple::STORECONDITIONAL;
2089 const TypeTuple *TypeTuple::START_I2C;
2090 const TypeTuple *TypeTuple::INT_PAIR;
2091 const TypeTuple *TypeTuple::LONG_PAIR;
2092 const TypeTuple *TypeTuple::INT_CC_PAIR;
2093 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2094 
2095 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2096   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
2097     ciField* field = vk->nonstatic_field_at(j);
2098     BasicType bt = field->type()->basic_type();
2099     const Type* ft = Type::get_const_type(field->type());
2100     field_array[pos++] = ft;
2101     if (type2size[bt] == 2) {
2102       field_array[pos++] = Type::HALF;
2103     }
2104   }
2105 }
2106 
2107 //------------------------------make-------------------------------------------
2108 // Make a TypeTuple from the range of a method signature
2109 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
2110   ciType* return_type = sig->return_type();
2111   uint arg_cnt = return_type->size();
2112   if (ret_vt_fields) {
2113     arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2114     if (!sig->returns_null_free_inline_type()) {
2115       // InlineTypeBaseNode::IsInit field used for null checking
2116       arg_cnt++;
2117     }
2118   }
2119 
2120   const Type **field_array = fields(arg_cnt);
2121   switch (return_type->basic_type()) {
2122   case T_LONG:
2123     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2124     field_array[TypeFunc::Parms+1] = Type::HALF;
2125     break;
2126   case T_DOUBLE:
2127     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2128     field_array[TypeFunc::Parms+1] = Type::HALF;
2129     break;
2130   case T_OBJECT:
2131   case T_ARRAY:
2132   case T_BOOLEAN:
2133   case T_CHAR:
2134   case T_FLOAT:
2135   case T_BYTE:
2136   case T_SHORT:
2137   case T_INT:
2138     field_array[TypeFunc::Parms] = get_const_type(return_type);
2139     break;
2140   case T_PRIMITIVE_OBJECT:
2141     if (ret_vt_fields) {
2142       uint pos = TypeFunc::Parms;
2143       field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2144       collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2145       if (!sig->returns_null_free_inline_type()) {
2146         // InlineTypeBaseNode::IsInit field used for null checking
2147         field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2148       }
2149     } else {
2150       field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(sig->returns_null_free_inline_type() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2151     }
2152     break;
2153   case T_VOID:
2154     break;
2155   default:
2156     ShouldNotReachHere();
2157   }
2158   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2159 }
2160 
2161 // Make a TypeTuple from the domain of a method signature
2162 const TypeTuple *TypeTuple::make_domain(ciMethod* method, bool vt_fields_as_args) {
2163   ciSignature* sig = method->signature();
2164   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2165   if (vt_fields_as_args) {
2166     arg_cnt = 0;
2167     assert(method->get_sig_cc() != NULL, "Should have scalarized signature");
2168     for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2169       arg_cnt += type2size[(*sig_cc)._bt];
2170     }
2171   }
2172 
2173   uint pos = TypeFunc::Parms;
2174   const Type** field_array = fields(arg_cnt);
2175   if (!method->is_static()) {
2176     ciInstanceKlass* recv = method->holder();
2177     if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields()) {
2178       collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2179     } else {
2180       field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2181     }
2182   }
2183 
2184   int i = 0;
2185   while (pos < TypeFunc::Parms + arg_cnt) {
2186     ciType* type = sig->type_at(i);
2187     BasicType bt = type->basic_type();
2188 
2189     switch (bt) {
2190     case T_LONG:
2191       field_array[pos++] = TypeLong::LONG;
2192       field_array[pos++] = Type::HALF;
2193       break;
2194     case T_DOUBLE:
2195       field_array[pos++] = Type::DOUBLE;
2196       field_array[pos++] = Type::HALF;
2197       break;
2198     case T_OBJECT:
2199     case T_ARRAY:
2200     case T_FLOAT:
2201     case T_INT:
2202       field_array[pos++] = get_const_type(type);
2203       break;
2204     case T_BOOLEAN:
2205     case T_CHAR:
2206     case T_BYTE:
2207     case T_SHORT:
2208       field_array[pos++] = TypeInt::INT;
2209       break;
2210     case T_PRIMITIVE_OBJECT: {
2211       if (vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2212         if (!sig->is_null_free_at(i)) {
2213           // InlineTypeBaseNode::IsInit field used for null checking
2214           field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2215         }
2216         collect_inline_fields(type->as_inline_klass(), field_array, pos);
2217       } else {
2218         field_array[pos++] = get_const_type(type)->join_speculative(sig->is_null_free_at(i) ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2219       }
2220       break;
2221     }
2222     default:
2223       ShouldNotReachHere();
2224     }
2225     i++;
2226   }
2227   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2228 
2229   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2230 }
2231 
2232 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2233   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2234 }
2235 
2236 //------------------------------fields-----------------------------------------
2237 // Subroutine call type with space allocated for argument types
2238 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2239 const Type **TypeTuple::fields( uint arg_cnt ) {
2240   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2241   flds[TypeFunc::Control  ] = Type::CONTROL;
2242   flds[TypeFunc::I_O      ] = Type::ABIO;
2243   flds[TypeFunc::Memory   ] = Type::MEMORY;
2244   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2245   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2246 
2247   return flds;

2342     if (_fields[i]->empty())  return true;
2343   }
2344   return false;
2345 }
2346 
2347 //=============================================================================
2348 // Convenience common pre-built types.
2349 
2350 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2351   // Certain normalizations keep us sane when comparing types.
2352   // We do not want arrayOop variables to differ only by the wideness
2353   // of their index types.  Pick minimum wideness, since that is the
2354   // forced wideness of small ranges anyway.
2355   if (size->_widen != Type::WidenMin)
2356     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2357   else
2358     return size;
2359 }
2360 
2361 //------------------------------make-------------------------------------------
2362 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2363                              bool not_flat, bool not_null_free) {
2364   if (UseCompressedOops && elem->isa_oopptr()) {
2365     elem = elem->make_narrowoop();
2366   }
2367   size = normalize_array_size(size);
2368   return (TypeAry*)(new TypeAry(elem, size, stable, not_flat, not_null_free))->hashcons();
2369 }
2370 
2371 //------------------------------meet-------------------------------------------
2372 // Compute the MEET of two types.  It returns a new Type object.
2373 const Type *TypeAry::xmeet( const Type *t ) const {
2374   // Perform a fast test for common case; meeting the same types together.
2375   if( this == t ) return this;  // Meeting same type-rep?
2376 
2377   // Current "this->_base" is Ary
2378   switch (t->base()) {          // switch on original type
2379 
2380   case Bottom:                  // Ye Olde Default
2381     return t;
2382 
2383   default:                      // All else is a mistake
2384     typerr(t);
2385 
2386   case Array: {                 // Meeting 2 arrays?
2387     const TypeAry *a = t->is_ary();
2388     return TypeAry::make(_elem->meet_speculative(a->_elem),
2389                          _size->xmeet(a->_size)->is_int(),
2390                          _stable && a->_stable,
2391                          _not_flat && a->_not_flat,
2392                          _not_null_free && a->_not_null_free);
2393   }
2394   case Top:
2395     break;
2396   }
2397   return this;                  // Return the double constant
2398 }
2399 
2400 //------------------------------xdual------------------------------------------
2401 // Dual: compute field-by-field dual
2402 const Type *TypeAry::xdual() const {
2403   const TypeInt* size_dual = _size->dual()->is_int();
2404   size_dual = normalize_array_size(size_dual);
2405   return new TypeAry(_elem->dual(), size_dual, !_stable, !_not_flat, !_not_null_free);
2406 }
2407 
2408 //------------------------------eq---------------------------------------------
2409 // Structural equality check for Type representations
2410 bool TypeAry::eq( const Type *t ) const {
2411   const TypeAry *a = (const TypeAry*)t;
2412   return _elem == a->_elem &&
2413     _stable == a->_stable &&
2414     _size == a->_size &&
2415     _not_flat == a->_not_flat &&
2416     _not_null_free == a->_not_null_free;
2417 
2418 }
2419 
2420 //------------------------------hash-------------------------------------------
2421 // Type-specific hashing function.
2422 int TypeAry::hash(void) const {
2423   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2424 }
2425 
2426 /**
2427  * Return same type without a speculative part in the element
2428  */
2429 const TypeAry* TypeAry::remove_speculative() const {
2430   return make(_elem->remove_speculative(), _size, _stable, _not_flat, _not_null_free);
2431 }
2432 
2433 /**
2434  * Return same type with cleaned up speculative part of element
2435  */
2436 const Type* TypeAry::cleanup_speculative() const {
2437   return make(_elem->cleanup_speculative(), _size, _stable, _not_flat, _not_null_free);
2438 }
2439 
2440 /**
2441  * Return same type but with a different inline depth (used for speculation)
2442  *
2443  * @param depth  depth to meet with
2444  */
2445 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2446   if (!UseInlineDepthForSpeculativeTypes) {
2447     return this;
2448   }
2449   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2450 }
2451 
2452 //----------------------interface_vs_oop---------------------------------------
2453 #ifdef ASSERT
2454 bool TypeAry::interface_vs_oop(const Type *t) const {
2455   const TypeAry* t_ary = t->is_ary();
2456   if (t_ary) {
2457     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2458     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
2459     if(this_ptr != NULL && t_ptr != NULL) {
2460       return this_ptr->interface_vs_oop(t_ptr);
2461     }
2462   }
2463   return false;
2464 }
2465 #endif
2466 
2467 //------------------------------dump2------------------------------------------
2468 #ifndef PRODUCT
2469 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2470   if (_stable)  st->print("stable:");
2471   if (Verbose) {
2472     if (_not_flat) st->print("not flat:");
2473     if (_not_null_free) st->print("not null free:");
2474   }
2475   _elem->dump2(d, depth, st);
2476   st->print("[");
2477   _size->dump2(d, depth, st);
2478   st->print("]");
2479 }
2480 #endif
2481 
2482 //------------------------------singleton--------------------------------------
2483 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2484 // constants (Ldi nodes).  Singletons are integer, float or double constants
2485 // or a single symbol.
2486 bool TypeAry::singleton(void) const {
2487   return false;                 // Never a singleton
2488 }
2489 
2490 bool TypeAry::empty(void) const {
2491   return _elem->empty() || _size->empty();
2492 }
2493 
2494 //--------------------------ary_must_be_exact----------------------------------

2496   // This logic looks at the element type of an array, and returns true
2497   // if the element type is either a primitive or a final instance class.
2498   // In such cases, an array built on this ary must have no subclasses.
2499   if (_elem == BOTTOM)      return false;  // general array not exact
2500   if (_elem == TOP   )      return false;  // inverted general array not exact
2501   const TypeOopPtr*  toop = NULL;
2502   if (UseCompressedOops && _elem->isa_narrowoop()) {
2503     toop = _elem->make_ptr()->isa_oopptr();
2504   } else {
2505     toop = _elem->isa_oopptr();
2506   }
2507   if (!toop)                return true;   // a primitive type, like int
2508   ciKlass* tklass = toop->klass();
2509   if (tklass == NULL)       return false;  // unloaded class
2510   if (!tklass->is_loaded()) return false;  // unloaded class
2511   const TypeInstPtr* tinst;
2512   if (_elem->isa_narrowoop())
2513     tinst = _elem->make_ptr()->isa_instptr();
2514   else
2515     tinst = _elem->isa_instptr();
2516   if (tinst) {
2517     if (tklass->as_instance_klass()->is_final()) {
2518       // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
2519       if (tinst->is_inlinetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2520         return false;
2521       }
2522       return true;
2523     }
2524     return false;
2525   }
2526   const TypeAryPtr*  tap;
2527   if (_elem->isa_narrowoop())
2528     tap = _elem->make_ptr()->isa_aryptr();
2529   else
2530     tap = _elem->isa_aryptr();
2531   if (tap)
2532     return tap->ary()->ary_must_be_exact();
2533   return false;
2534 }
2535 
2536 //==============================TypeInlineType=======================================
2537 
2538 const TypeInlineType* TypeInlineType::BOTTOM;
2539 
2540 //------------------------------make-------------------------------------------
2541 const TypeInlineType* TypeInlineType::make(ciInlineKlass* vk, bool larval) {
2542   return (TypeInlineType*)(new TypeInlineType(vk, larval))->hashcons();
2543 }
2544 
2545 //------------------------------meet-------------------------------------------
2546 // Compute the MEET of two types.  It returns a new Type object.
2547 const Type* TypeInlineType::xmeet(const Type* t) const {
2548   // Perform a fast test for common case; meeting the same types together.
2549   if(this == t) return this;  // Meeting same type-rep?
2550 
2551   // Current "this->_base" is InlineType
2552   switch (t->base()) {          // switch on original type
2553 
2554   case Int:
2555   case Long:
2556   case FloatTop:
2557   case FloatCon:
2558   case FloatBot:
2559   case DoubleTop:
2560   case DoubleCon:
2561   case DoubleBot:
2562   case NarrowKlass:
2563   case Bottom:
2564     return Type::BOTTOM;
2565 
2566   case OopPtr:
2567   case MetadataPtr:
2568   case KlassPtr:
2569   case RawPtr:
2570   case AnyPtr:
2571     return TypePtr::BOTTOM;
2572 
2573   case Top:
2574     return this;
2575 
2576   case NarrowOop: {
2577     const Type* res = t->make_ptr()->xmeet(this);
2578     if (res->isa_ptr()) {
2579       return res->make_narrowoop();
2580     }
2581     return res;
2582   }
2583 
2584   case InstKlassPtr:
2585   case AryKlassPtr:
2586   case AryPtr:
2587   case InstPtr: {
2588     return t->xmeet(this);
2589   }
2590 
2591   case InlineType: {
2592     // All inline types inherit from Object
2593     const TypeInlineType* other = t->is_inlinetype();
2594     if (_vk == NULL) {
2595       return this;
2596     } else if (other->_vk == NULL) {
2597       return other;
2598     } else if (_vk == other->_vk) {
2599       if (_larval == other->_larval ||
2600           !_larval) {
2601         return this;
2602       } else {
2603         return t;
2604       }
2605     }
2606     return TypeInstPtr::NOTNULL;
2607   }
2608 
2609   default:                      // All else is a mistake
2610     typerr(t);
2611 
2612   }
2613   return this;
2614 }
2615 
2616 //------------------------------xdual------------------------------------------
2617 const Type* TypeInlineType::xdual() const {
2618   return this;
2619 }
2620 
2621 //------------------------------eq---------------------------------------------
2622 // Structural equality check for Type representations
2623 bool TypeInlineType::eq(const Type* t) const {
2624   const TypeInlineType* vt = t->is_inlinetype();
2625   return (_vk == vt->inline_klass() && _larval == vt->larval());
2626 }
2627 
2628 //------------------------------hash-------------------------------------------
2629 // Type-specific hashing function.
2630 int TypeInlineType::hash(void) const {
2631   return (intptr_t)_vk;
2632 }
2633 
2634 //------------------------------singleton--------------------------------------
2635 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants.
2636 bool TypeInlineType::singleton(void) const {
2637   return false;
2638 }
2639 
2640 //------------------------------empty------------------------------------------
2641 // TRUE if Type is a type with no values, FALSE otherwise.
2642 bool TypeInlineType::empty(void) const {
2643   return false;
2644 }
2645 
2646 //------------------------------dump2------------------------------------------
2647 #ifndef PRODUCT
2648 void TypeInlineType::dump2(Dict &d, uint depth, outputStream* st) const {
2649   if (_vk == NULL) {
2650     st->print("BOTTOM inlinetype");
2651     return;
2652   }
2653   int count = _vk->nof_declared_nonstatic_fields();
2654   st->print("inlinetype[%d]:{", count);
2655   st->print("%s", count != 0 ? _vk->declared_nonstatic_field_at(0)->type()->name() : "empty");
2656   for (int i = 1; i < count; ++i) {
2657     st->print(", %s", _vk->declared_nonstatic_field_at(i)->type()->name());
2658   }
2659   st->print("}%s", _larval?" : larval":"");
2660 }
2661 #endif
2662 
2663 //==============================TypeVect=======================================
2664 // Convenience common pre-built types.
2665 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2666 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2667 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2668 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2669 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2670 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2671 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2672 
2673 //------------------------------make-------------------------------------------
2674 const TypeVect* TypeVect::make(const Type *elem, uint length, bool is_mask) {
2675   if (is_mask) {
2676     return makemask(elem, length);
2677   }
2678   BasicType elem_bt = elem->array_element_basic_type();
2679   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2680   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2681   int size = length * type2aelembytes(elem_bt);
2682   switch (Matcher::vector_ideal_reg(size)) {

2828 
2829 //=============================================================================
2830 // Convenience common pre-built types.
2831 const TypePtr *TypePtr::NULL_PTR;
2832 const TypePtr *TypePtr::NOTNULL;
2833 const TypePtr *TypePtr::BOTTOM;
2834 
2835 //------------------------------meet-------------------------------------------
2836 // Meet over the PTR enum
2837 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2838   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2839   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2840   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2841   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2842   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2843   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2844   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2845 };
2846 
2847 //------------------------------make-------------------------------------------
2848 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2849   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2850 }
2851 
2852 //------------------------------cast_to_ptr_type-------------------------------
2853 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2854   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2855   if( ptr == _ptr ) return this;
2856   return make(_base, ptr, _offset, _speculative, _inline_depth);
2857 }
2858 
2859 //------------------------------get_con----------------------------------------
2860 intptr_t TypePtr::get_con() const {
2861   assert( _ptr == Null, "" );
2862   return offset();
2863 }
2864 
2865 //------------------------------meet-------------------------------------------
2866 // Compute the MEET of two types.  It returns a new Type object.
2867 const Type *TypePtr::xmeet(const Type *t) const {
2868   const Type* res = xmeet_helper(t);
2869   if (res->isa_ptr() == NULL) {
2870     return res;
2871   }
2872 
2873   const TypePtr* res_ptr = res->is_ptr();
2874   if (res_ptr->speculative() != NULL) {
2875     // type->speculative() == NULL means that speculation is no better
2876     // than type, i.e. type->speculative() == type. So there are 2
2877     // ways to represent the fact that we have no useful speculative
2878     // data and we should use a single one to be able to test for
2879     // equality between types. Check whether type->speculative() ==
2880     // type and set speculative to NULL if it is the case.
2881     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2882       return res_ptr->remove_speculative();

2904   case NarrowKlass:
2905   case Bottom:                  // Ye Olde Default
2906     return Type::BOTTOM;
2907   case Top:
2908     return this;
2909 
2910   case AnyPtr: {                // Meeting to AnyPtrs
2911     const TypePtr *tp = t->is_ptr();
2912     const TypePtr* speculative = xmeet_speculative(tp);
2913     int depth = meet_inline_depth(tp->inline_depth());
2914     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2915   }
2916   case RawPtr:                  // For these, flip the call around to cut down
2917   case OopPtr:
2918   case InstPtr:                 // on the cases I have to handle.
2919   case AryPtr:
2920   case MetadataPtr:
2921   case KlassPtr:
2922   case InstKlassPtr:
2923   case AryKlassPtr:
2924   case InlineType:
2925     return t->xmeet(this);      // Call in reverse direction
2926   default:                      // All else is a mistake
2927     typerr(t);
2928 
2929   }
2930   return this;
2931 }
2932 
2933 //------------------------------meet_offset------------------------------------
2934 Type::Offset TypePtr::meet_offset(int offset) const {
2935   return _offset.meet(Offset(offset));





2936 }
2937 
2938 //------------------------------dual_offset------------------------------------
2939 Type::Offset TypePtr::dual_offset() const {
2940   return _offset.dual();


2941 }
2942 
2943 //------------------------------xdual------------------------------------------
2944 // Dual: compute field-by-field dual
2945 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2946   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2947 };
2948 const Type *TypePtr::xdual() const {
2949   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2950 }
2951 
2952 //------------------------------xadd_offset------------------------------------
2953 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2954   return _offset.add(offset);











2955 }
2956 
2957 //------------------------------add_offset-------------------------------------
2958 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2959   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2960 }
2961 
2962 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2963   return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2964 }
2965 
2966 //------------------------------eq---------------------------------------------
2967 // Structural equality check for Type representations
2968 bool TypePtr::eq( const Type *t ) const {
2969   const TypePtr *a = (const TypePtr*)t;
2970   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2971 }
2972 
2973 //------------------------------hash-------------------------------------------
2974 // Type-specific hashing function.
2975 int TypePtr::hash(void) const {
2976   return java_add(java_add((jint)_ptr, (jint)offset()), java_add((jint)hash_speculative(), (jint)_inline_depth));
2977 ;
2978 }
2979 
2980 /**
2981  * Return same type without a speculative part
2982  */
2983 const TypePtr* TypePtr::remove_speculative() const {
2984   if (_speculative == NULL) {
2985     return this;
2986   }
2987   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2988   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2989 }
2990 
2991 /**
2992  * Return same type but drop speculative part if we know we won't use
2993  * it
2994  */
2995 const Type* TypePtr::cleanup_speculative() const {
2996   if (speculative() == NULL) {

3223   }
3224   // We already know the speculative type is always null
3225   if (speculative_always_null()) {
3226     return false;
3227   }
3228   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
3229     return false;
3230   }
3231   return true;
3232 }
3233 
3234 //------------------------------dump2------------------------------------------
3235 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3236   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
3237 };
3238 
3239 #ifndef PRODUCT
3240 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3241   if( _ptr == Null ) st->print("NULL");
3242   else st->print("%s *", ptr_msg[_ptr]);
3243   _offset.dump2(st);


3244   dump_inline_depth(st);
3245   dump_speculative(st);
3246 }
3247 
3248 /**
3249  *dump the speculative part of the type
3250  */
3251 void TypePtr::dump_speculative(outputStream *st) const {
3252   if (_speculative != NULL) {
3253     st->print(" (speculative=");
3254     _speculative->dump_on(st);
3255     st->print(")");
3256   }
3257 }
3258 
3259 /**
3260  *dump the inline depth of the type
3261  */
3262 void TypePtr::dump_inline_depth(outputStream *st) const {
3263   if (_inline_depth != InlineDepthBottom) {
3264     if (_inline_depth == InlineDepthTop) {
3265       st->print(" (inline_depth=InlineDepthTop)");
3266     } else {
3267       st->print(" (inline_depth=%d)", _inline_depth);
3268     }
3269   }
3270 }
3271 #endif
3272 
3273 //------------------------------singleton--------------------------------------
3274 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3275 // constants
3276 bool TypePtr::singleton(void) const {
3277   // TopPTR, Null, AnyNull, Constant are all singletons
3278   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3279 }
3280 
3281 bool TypePtr::empty(void) const {
3282   return (_offset == Offset::top) || above_centerline(_ptr);
3283 }
3284 
3285 //=============================================================================
3286 // Convenience common pre-built types.
3287 const TypeRawPtr *TypeRawPtr::BOTTOM;
3288 const TypeRawPtr *TypeRawPtr::NOTNULL;
3289 
3290 //------------------------------make-------------------------------------------
3291 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3292   assert( ptr != Constant, "what is the constant?" );
3293   assert( ptr != Null, "Use TypePtr for NULL" );
3294   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3295 }
3296 
3297 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3298   assert( bits, "Use TypePtr for NULL" );
3299   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3300 }
3301 
3302 //------------------------------cast_to_ptr_type-------------------------------

3406 // Type-specific hashing function.
3407 int TypeRawPtr::hash(void) const {
3408   return (intptr_t)_bits + TypePtr::hash();
3409 }
3410 
3411 //------------------------------dump2------------------------------------------
3412 #ifndef PRODUCT
3413 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3414   if( _ptr == Constant )
3415     st->print(INTPTR_FORMAT, p2i(_bits));
3416   else
3417     st->print("rawptr:%s", ptr_msg[_ptr]);
3418 }
3419 #endif
3420 
3421 //=============================================================================
3422 // Convenience common pre-built type.
3423 const TypeOopPtr *TypeOopPtr::BOTTOM;
3424 
3425 //------------------------------TypeOopPtr-------------------------------------
3426 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset,
3427                        int instance_id, const TypePtr* speculative, int inline_depth)
3428   : TypePtr(t, ptr, offset, speculative, inline_depth),
3429     _const_oop(o), _klass(k),
3430     _klass_is_exact(xk),
3431     _is_ptr_to_narrowoop(false),
3432     _is_ptr_to_narrowklass(false),
3433     _is_ptr_to_boxed_value(false),
3434     _instance_id(instance_id) {
3435   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3436       (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3437     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3438   }
3439 #ifdef _LP64
3440   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3441     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3442       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3443     } else if (klass() == NULL) {
3444       // Array with unknown body type
3445       assert(this->isa_aryptr(), "only arrays without klass");
3446       _is_ptr_to_narrowoop = UseCompressedOops;
3447     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3448       if (klass()->is_obj_array_klass()) {
3449         _is_ptr_to_narrowoop = true;
3450       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3451         // Check if the field of the inline type array element contains oops
3452         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3453         int foffset = field_offset.get() + vk->first_field_offset();
3454         ciField* field = vk->get_field_by_offset(foffset, false);
3455         assert(field != NULL, "missing field");
3456         BasicType bt = field->layout_type();
3457         _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(bt);
3458       }
3459     } else if (klass()->is_instance_klass()) {


3460       if (this->isa_klassptr()) {
3461         // Perm objects don't use compressed references
3462       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3463         // unsafe access
3464         _is_ptr_to_narrowoop = UseCompressedOops;
3465       } else {
3466         assert(this->isa_instptr(), "must be an instance ptr.");

3467         if (klass() == ciEnv::current()->Class_klass() &&
3468             (this->offset() == java_lang_Class::klass_offset() ||
3469              this->offset() == java_lang_Class::array_klass_offset())) {
3470           // Special hidden fields from the Class.
3471           assert(this->isa_instptr(), "must be an instance ptr.");
3472           _is_ptr_to_narrowoop = false;
3473         } else if (klass() == ciEnv::current()->Class_klass() &&
3474                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3475           // Static fields
3476           ciField* field = NULL;
3477           if (const_oop() != NULL) {
3478             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3479             if (k->is_inlinetype() && this->offset() == k->as_inline_klass()->default_value_offset()) {
3480               // Special hidden field that contains the oop of the default inline type
3481               // basic_elem_type = T_PRIMITIVE_OBJECT;
3482              _is_ptr_to_narrowoop = UseCompressedOops;
3483             } else {
3484               field = k->get_field_by_offset(this->offset(), true);
3485               if (field != NULL) {
3486                 BasicType basic_elem_type = field->layout_type();
3487                 _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3488               } else {
3489                 // unsafe access
3490                 _is_ptr_to_narrowoop = UseCompressedOops;
3491               }
3492             }
3493           }
3494         } else {
3495           // Instance fields which contains a compressed oop references.
3496           ciInstanceKlass* ik = klass()->as_instance_klass();
3497           ciField* field = ik->get_field_by_offset(this->offset(), false);
3498           if (field != NULL) {
3499             BasicType basic_elem_type = field->layout_type();
3500             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3501           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3502             // Compile::find_alias_type() cast exactness on all types to verify
3503             // that it does not affect alias type.
3504             _is_ptr_to_narrowoop = UseCompressedOops;
3505           } else {
3506             // Type for the copy start in LibraryCallKit::inline_native_clone().
3507             _is_ptr_to_narrowoop = UseCompressedOops;
3508           }
3509         }
3510       }
3511     }
3512   }
3513 #endif
3514 }
3515 
3516 //------------------------------make-------------------------------------------
3517 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3518                                    const TypePtr* speculative, int inline_depth) {
3519   assert(ptr != Constant, "no constant generic pointers");
3520   ciKlass*  k = Compile::current()->env()->Object_klass();
3521   bool      xk = false;
3522   ciObject* o = NULL;
3523   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3524 }
3525 
3526 
3527 //------------------------------cast_to_ptr_type-------------------------------
3528 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3529   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3530   if( ptr == _ptr ) return this;
3531   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3532 }
3533 
3534 //-----------------------------cast_to_instance_id----------------------------
3535 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3536   // There are no instances of a general oop.
3537   // Return self unchanged.
3538   return this;
3539 }
3540 
3541 //-----------------------------cast_to_exactness-------------------------------
3542 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3543   // There is no such thing as an exact general oop.
3544   // Return self unchanged.
3545   return this;
3546 }
3547 

3548 //------------------------------as_klass_type----------------------------------
3549 // Return the klass type corresponding to this instance or array type.
3550 // It is the type that is loaded from an object of this type.
3551 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3552   ShouldNotReachHere();
3553   return NULL;
3554 }
3555 
3556 //------------------------------meet-------------------------------------------
3557 // Compute the MEET of two types.  It returns a new Type object.
3558 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3559   // Perform a fast test for common case; meeting the same types together.
3560   if( this == t ) return this;  // Meeting same type-rep?
3561 
3562   // Current "this->_base" is OopPtr
3563   switch (t->base()) {          // switch on original type
3564 
3565   case Int:                     // Mixing ints & oops happens when javac
3566   case Long:                    // reuses local variables
3567   case FloatTop:

3573   case NarrowOop:
3574   case NarrowKlass:
3575   case Bottom:                  // Ye Olde Default
3576     return Type::BOTTOM;
3577   case Top:
3578     return this;
3579 
3580   default:                      // All else is a mistake
3581     typerr(t);
3582 
3583   case RawPtr:
3584   case MetadataPtr:
3585   case KlassPtr:
3586   case InstKlassPtr:
3587   case AryKlassPtr:
3588     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3589 
3590   case AnyPtr: {
3591     // Found an AnyPtr type vs self-OopPtr type
3592     const TypePtr *tp = t->is_ptr();
3593     Offset offset = meet_offset(tp->offset());
3594     PTR ptr = meet_ptr(tp->ptr());
3595     const TypePtr* speculative = xmeet_speculative(tp);
3596     int depth = meet_inline_depth(tp->inline_depth());
3597     switch (tp->ptr()) {
3598     case Null:
3599       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3600       // else fall through:
3601     case TopPTR:
3602     case AnyNull: {
3603       int instance_id = meet_instance_id(InstanceTop);
3604       return make(ptr, offset, instance_id, speculative, depth);
3605     }
3606     case BotPTR:
3607     case NotNull:
3608       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3609     default: typerr(t);
3610     }
3611   }
3612 
3613   case OopPtr: {                 // Meeting to other OopPtrs

3615     int instance_id = meet_instance_id(tp->instance_id());
3616     const TypePtr* speculative = xmeet_speculative(tp);
3617     int depth = meet_inline_depth(tp->inline_depth());
3618     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3619   }
3620 
3621   case InstPtr:                  // For these, flip the call around to cut down
3622   case AryPtr:
3623     return t->xmeet(this);      // Call in reverse direction
3624 
3625   } // End of switch
3626   return this;                  // Return the double constant
3627 }
3628 
3629 
3630 //------------------------------xdual------------------------------------------
3631 // Dual of a pure heap pointer.  No relevant klass or oop information.
3632 const Type *TypeOopPtr::xdual() const {
3633   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3634   assert(const_oop() == NULL,             "no constants here");
3635   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3636 }
3637 
3638 //--------------------------make_from_klass_common-----------------------------
3639 // Computes the element-type given a klass.
3640 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3641   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3642     Compile* C = Compile::current();
3643     Dependencies* deps = C->dependencies();
3644     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3645     // Element is an instance
3646     bool klass_is_exact = false;
3647     if (klass->is_loaded()) {
3648       // Try to set klass_is_exact.
3649       ciInstanceKlass* ik = klass->as_instance_klass();
3650       klass_is_exact = ik->is_final();
3651       if (!klass_is_exact && klass_change
3652           && deps != NULL && UseUniqueSubclasses) {
3653         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3654         if (sub != NULL) {
3655           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3656           klass = ik = sub;
3657           klass_is_exact = sub->is_final();
3658         }
3659       }
3660       if (!klass_is_exact && try_for_exact && deps != NULL &&
3661           !ik->is_interface() && !ik->has_subklass()) {
3662         // Add a dependence; if concrete subclass added we need to recompile
3663         deps->assert_leaf_type(ik);
3664         klass_is_exact = true;
3665       }
3666     }
3667     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3668   } else if (klass->is_obj_array_klass()) {
3669     // Element is an object or inline type array. Recursively call ourself.
3670     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact);
3671     bool null_free = klass->as_array_klass()->is_elem_null_free();
3672     if (null_free) {
3673       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3674     }
3675     // Determine null-free/flattened properties
3676     const TypeOopPtr* exact_etype = etype;
3677     if (etype->can_be_inline_type()) {
3678       // Use exact type if element can be an inline type
3679       exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true);
3680     }
3681     bool not_null_free = !exact_etype->can_be_inline_type();
3682     bool not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flatten_array());
3683 
3684     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
3685     bool xk = etype->klass_is_exact() && (!etype->is_inlinetypeptr() || null_free);
3686     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, false, not_flat, not_null_free);
3687     // We used to pass NotNull in here, asserting that the sub-arrays
3688     // are all not-null.  This is not true in generally, as code can
3689     // slam NULLs down in the subarrays.
3690     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3691     return arr;
3692   } else if (klass->is_type_array_klass()) {
3693     // Element is an typeArray
3694     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3695     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3696                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3697     // We used to pass NotNull in here, asserting that the array pointer
3698     // is not-null. That was not true in general.
3699     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3700     return arr;
3701   } else if (klass->is_flat_array_klass()) {
3702     ciInlineKlass* vk = klass->as_array_klass()->element_klass()->as_inline_klass();
3703     const TypeAry* arr0 = TypeAry::make(TypeInlineType::make(vk), TypeInt::POS);
3704     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3705     return arr;
3706   } else {
3707     ShouldNotReachHere();
3708     return NULL;
3709   }
3710 }
3711 
3712 //------------------------------make_from_constant-----------------------------
3713 // Make a java pointer from an oop constant
3714 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3715   assert(!o->is_null_object(), "null object not yet handled here.");
3716 
3717   const bool make_constant = require_constant || o->should_be_constant();
3718 
3719   ciKlass* klass = o->klass();
3720   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3721     // Element is an instance or inline type
3722     if (make_constant) {
3723       return TypeInstPtr::make(o);
3724     } else {
3725       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3726     }
3727   } else if (klass->is_obj_array_klass()) {
3728     // Element is an object array. Recursively call ourself.
3729     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3730     bool null_free = false;
3731     if (klass->as_array_klass()->is_elem_null_free()) {
3732       null_free = true;
3733       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3734     }
3735     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3736                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ !null_free);
3737     // We used to pass NotNull in here, asserting that the sub-arrays
3738     // are all not-null.  This is not true in generally, as code can
3739     // slam NULLs down in the subarrays.
3740     if (make_constant) {
3741       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3742     } else {
3743       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3744     }
3745   } else if (klass->is_type_array_klass()) {
3746     // Element is an typeArray
3747     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3748     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3749                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3750     // We used to pass NotNull in here, asserting that the array pointer
3751     // is not-null. That was not true in general.
3752     if (make_constant) {
3753       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3754     } else {
3755       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3756     }
3757   } else if (klass->is_flat_array_klass()) {
3758     ciInlineKlass* vk = klass->as_array_klass()->element_klass()->as_inline_klass();
3759     const TypeAry* arr0 = TypeAry::make(TypeInlineType::make(vk), TypeInt::make(o->as_array()->length()));
3760     // We used to pass NotNull in here, asserting that the sub-arrays
3761     // are all not-null.  This is not true in generally, as code can
3762     // slam NULLs down in the subarrays.
3763     if (make_constant) {
3764       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3765     } else {
3766       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3767     }
3768   }
3769 
3770   fatal("unhandled object type");
3771   return NULL;
3772 }
3773 
3774 //------------------------------get_con----------------------------------------
3775 intptr_t TypeOopPtr::get_con() const {
3776   assert( _ptr == Null || _ptr == Constant, "" );
3777   assert(offset() >= 0, "");
3778 
3779   if (offset() != 0) {
3780     // After being ported to the compiler interface, the compiler no longer
3781     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3782     // to a handle at compile time.  This handle is embedded in the generated
3783     // code and dereferenced at the time the nmethod is made.  Until that time,
3784     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3785     // have access to the addresses!).  This does not seem to currently happen,
3786     // but this assertion here is to help prevent its occurrence.
3787     tty->print_cr("Found oop constant with non-zero offset");
3788     ShouldNotReachHere();
3789   }
3790 
3791   return (intptr_t)const_oop()->constant_encoding();
3792 }
3793 
3794 
3795 //-----------------------------filter------------------------------------------
3796 // Do not allow interface-vs.-noninterface joins to collapse to top.
3797 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3798 
3799   const Type* ft = join_helper(kills, include_speculative);

3852     return (one == two) && TypePtr::eq(t);
3853   } else {
3854     return one->equals(two) && TypePtr::eq(t);
3855   }
3856 }
3857 
3858 //------------------------------hash-------------------------------------------
3859 // Type-specific hashing function.
3860 int TypeOopPtr::hash(void) const {
3861   return
3862     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3863              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3864 }
3865 
3866 //------------------------------dump2------------------------------------------
3867 #ifndef PRODUCT
3868 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3869   st->print("oopptr:%s", ptr_msg[_ptr]);
3870   if( _klass_is_exact ) st->print(":exact");
3871   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3872   _offset.dump2(st);





3873   if (_instance_id == InstanceTop)
3874     st->print(",iid=top");
3875   else if (_instance_id != InstanceBot)
3876     st->print(",iid=%d",_instance_id);
3877 
3878   dump_inline_depth(st);
3879   dump_speculative(st);
3880 }
3881 #endif
3882 
3883 //------------------------------singleton--------------------------------------
3884 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3885 // constants
3886 bool TypeOopPtr::singleton(void) const {
3887   // detune optimizer to not generate constant oop + constant offset as a constant!
3888   // TopPTR, Null, AnyNull, Constant are all singletons
3889   return (offset() == 0) && !below_centerline(_ptr);
3890 }
3891 
3892 //------------------------------add_offset-------------------------------------
3893 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3894   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3895 }
3896 
3897 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3898   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
3899 }
3900 
3901 /**
3902  * Return same type without a speculative part
3903  */
3904 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3905   if (_speculative == NULL) {
3906     return this;
3907   }
3908   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3909   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3910 }
3911 
3912 /**
3913  * Return same type but drop speculative part if we know we won't use
3914  * it
3915  */
3916 const Type* TypeOopPtr::cleanup_speculative() const {
3917   // If the klass is exact and the ptr is not null then there's
3918   // nothing that the speculative type can help us with

3969   // no way to improve an already exact type
3970   if (klass_is_exact()) {
3971     return false;
3972   }
3973   return TypePtr::would_improve_type(exact_kls, inline_depth);
3974 }
3975 
3976 //=============================================================================
3977 // Convenience common pre-built types.
3978 const TypeInstPtr *TypeInstPtr::NOTNULL;
3979 const TypeInstPtr *TypeInstPtr::BOTTOM;
3980 const TypeInstPtr *TypeInstPtr::MIRROR;
3981 const TypeInstPtr *TypeInstPtr::MARK;
3982 const TypeInstPtr *TypeInstPtr::KLASS;
3983 
3984 ciKlass* TypeInstPtr::exact_klass_helper() const {
3985   return _klass;
3986 }
3987 
3988 //------------------------------TypeInstPtr-------------------------------------
3989 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3990                          bool flatten_array, int instance_id, const TypePtr* speculative, int inline_depth)
3991   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
3992     _flatten_array(flatten_array) {
3993    assert(k != NULL &&
3994           (k->is_loaded() || o == NULL),
3995           "cannot have constants with non-loaded klass");
3996    assert(!klass()->flatten_array() || flatten_array, "Should be flat in array");
3997    assert(!flatten_array || can_be_inline_type(), "Only inline types can be flat in array");
3998 };
3999 
4000 //------------------------------make-------------------------------------------
4001 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4002                                      ciKlass* k,
4003                                      bool xk,
4004                                      ciObject* o,
4005                                      Offset offset,
4006                                      bool flatten_array,
4007                                      int instance_id,
4008                                      const TypePtr* speculative,
4009                                      int inline_depth) {
4010   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4011   // Either const_oop() is NULL or else ptr is Constant
4012   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4013           "constant pointers must have a value supplied" );
4014   // Ptr is never Null
4015   assert( ptr != Null, "NULL pointers are not typed" );
4016 
4017   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4018   if (ptr == Constant) {
4019     // Note:  This case includes meta-object constants, such as methods.
4020     xk = true;
4021   } else if (k->is_loaded()) {
4022     ciInstanceKlass* ik = k->as_instance_klass();
4023     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4024     if (xk && ik->is_interface())  xk = false;  // no exact interface
4025   }
4026 
4027   // Check if this type is known to be flat in arrays
4028   flatten_array = flatten_array || k->flatten_array();
4029 
4030   // Now hash this baby
4031   TypeInstPtr *result =
4032     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o, offset, flatten_array, instance_id, speculative, inline_depth))->hashcons();
4033 
4034   return result;
4035 }
4036 
4037 /**
4038  *  Create constant type for a constant boxed value
4039  */
4040 const Type* TypeInstPtr::get_const_boxed_value() const {
4041   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
4042   assert((const_oop() != NULL), "should be called only for constant object");
4043   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
4044   BasicType bt = constant.basic_type();
4045   switch (bt) {
4046     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4047     case T_INT:      return TypeInt::make(constant.as_int());
4048     case T_CHAR:     return TypeInt::make(constant.as_char());
4049     case T_BYTE:     return TypeInt::make(constant.as_byte());
4050     case T_SHORT:    return TypeInt::make(constant.as_short());
4051     case T_FLOAT:    return TypeF::make(constant.as_float());
4052     case T_DOUBLE:   return TypeD::make(constant.as_double());
4053     case T_LONG:     return TypeLong::make(constant.as_long());
4054     default:         break;
4055   }
4056   fatal("Invalid boxed value type '%s'", type2name(bt));
4057   return NULL;
4058 }
4059 
4060 //------------------------------cast_to_ptr_type-------------------------------
4061 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4062   if( ptr == _ptr ) return this;
4063   // Reconstruct _sig info here since not a problem with later lazy
4064   // construction, _sig will show up on demand.
4065   return make(ptr, klass(), klass_is_exact(), ptr == Constant ? const_oop() : NULL, _offset, _flatten_array, _instance_id, _speculative, _inline_depth);
4066 }
4067 
4068 
4069 //-----------------------------cast_to_exactness-------------------------------
4070 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4071   if( klass_is_exact == _klass_is_exact ) return this;
4072   if (!_klass->is_loaded())  return this;
4073   ciInstanceKlass* ik = _klass->as_instance_klass();
4074   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4075   if( ik->is_interface() )              return this;  // cannot set xk
4076   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _flatten_array, _instance_id, _speculative, _inline_depth);
4077 }
4078 
4079 //-----------------------------cast_to_instance_id----------------------------
4080 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4081   if( instance_id == _instance_id ) return this;
4082   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, _flatten_array, instance_id, _speculative, _inline_depth);
4083 }
4084 
4085 //------------------------------xmeet_unloaded---------------------------------
4086 // Compute the MEET of two InstPtrs when at least one is unloaded.
4087 // Assume classes are different since called after check for same name/class-loader
4088 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
4089     Offset off = meet_offset(tinst->offset());
4090     PTR ptr = meet_ptr(tinst->ptr());
4091     int instance_id = meet_instance_id(tinst->instance_id());
4092     const TypePtr* speculative = xmeet_speculative(tinst);
4093     int depth = meet_inline_depth(tinst->inline_depth());
4094 
4095     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4096     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4097     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4098       //
4099       // Meet unloaded class with java/lang/Object
4100       //
4101       // Meet
4102       //          |                     Unloaded Class
4103       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4104       //  ===================================================================
4105       //   TOP    | ..........................Unloaded......................|
4106       //  AnyNull |  U-AN    |................Unloaded......................|
4107       // Constant | ... O-NN .................................. |   O-BOT   |
4108       //  NotNull | ... O-NN .................................. |   O-BOT   |
4109       //  BOTTOM  | ........................Object-BOTTOM ..................|
4110       //
4111       assert(loaded->ptr() != TypePtr::Null, "insanity check");
4112       //
4113       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
4114       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, false, instance_id, speculative, depth); }
4115       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
4116       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4117         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
4118         else                                      { return TypeInstPtr::NOTNULL; }
4119       }
4120       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
4121 
4122       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4123     }
4124 
4125     // Both are unloaded, not the same class, not Object
4126     // Or meet unloaded with a different loaded class, not java/lang/Object
4127     if( ptr != TypePtr::BotPTR ) {
4128       return TypeInstPtr::NOTNULL;
4129     }
4130     return TypeInstPtr::BOTTOM;
4131 }
4132 
4133 
4134 //------------------------------meet-------------------------------------------

4155   case Top:
4156     return this;
4157 
4158   default:                      // All else is a mistake
4159     typerr(t);
4160 
4161   case MetadataPtr:
4162   case KlassPtr:
4163   case InstKlassPtr:
4164   case AryKlassPtr:
4165   case RawPtr: return TypePtr::BOTTOM;
4166 
4167   case AryPtr: {                // All arrays inherit from Object class
4168     // Call in reverse direction to avoid duplication
4169     return t->is_aryptr()->xmeet_helper(this);
4170   }
4171 
4172   case OopPtr: {                // Meeting to OopPtrs
4173     // Found a OopPtr type vs self-InstPtr type
4174     const TypeOopPtr *tp = t->is_oopptr();
4175     Offset offset = meet_offset(tp->offset());
4176     PTR ptr = meet_ptr(tp->ptr());
4177     switch (tp->ptr()) {
4178     case TopPTR:
4179     case AnyNull: {
4180       int instance_id = meet_instance_id(InstanceTop);
4181       const TypePtr* speculative = xmeet_speculative(tp);
4182       int depth = meet_inline_depth(tp->inline_depth());
4183       return make(ptr, klass(), klass_is_exact(),
4184                   (ptr == Constant ? const_oop() : NULL), offset, flatten_array(), instance_id, speculative, depth);
4185     }
4186     case NotNull:
4187     case BotPTR: {
4188       int instance_id = meet_instance_id(tp->instance_id());
4189       const TypePtr* speculative = xmeet_speculative(tp);
4190       int depth = meet_inline_depth(tp->inline_depth());
4191       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4192     }
4193     default: typerr(t);
4194     }
4195   }
4196 
4197   case AnyPtr: {                // Meeting to AnyPtrs
4198     // Found an AnyPtr type vs self-InstPtr type
4199     const TypePtr *tp = t->is_ptr();
4200     Offset offset = meet_offset(tp->offset());
4201     PTR ptr = meet_ptr(tp->ptr());
4202     int instance_id = meet_instance_id(InstanceTop);
4203     const TypePtr* speculative = xmeet_speculative(tp);
4204     int depth = meet_inline_depth(tp->inline_depth());
4205     switch (tp->ptr()) {
4206     case Null:
4207       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4208       // else fall through to AnyNull
4209     case TopPTR:
4210     case AnyNull: {
4211       return make(ptr, klass(), klass_is_exact(),
4212                   (ptr == Constant ? const_oop() : NULL), offset, flatten_array(), instance_id, speculative, depth);
4213     }
4214     case NotNull:
4215     case BotPTR:
4216       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4217     default: typerr(t);
4218     }
4219   }
4220 
4221   /*
4222                  A-top         }
4223                /   |   \       }  Tops
4224            B-top A-any C-top   }
4225               | /  |  \ |      }  Any-nulls
4226            B-any   |   C-any   }
4227               |    |    |
4228            B-con A-con C-con   } constants; not comparable across classes
4229               |    |    |
4230            B-not   |   C-not   }
4231               | \  |  / |      }  not-nulls
4232            B-bot A-not C-bot   }
4233                \   |   /       }  Bottoms
4234                  A-bot         }
4235   */
4236 
4237   case InstPtr: {                // Meeting 2 Oops?
4238     // Found an InstPtr sub-type vs self-InstPtr type
4239     const TypeInstPtr *tinst = t->is_instptr();
4240     Offset off = meet_offset(tinst->offset());
4241     PTR ptr = meet_ptr(tinst->ptr());
4242     int instance_id = meet_instance_id(tinst->instance_id());
4243     const TypePtr* speculative = xmeet_speculative(tinst);
4244     int depth = meet_inline_depth(tinst->inline_depth());
4245     ciKlass* tinst_klass = tinst->klass();
4246     ciKlass* this_klass  = klass();
4247     bool tinst_xk = tinst->klass_is_exact();
4248     bool this_xk  = this->klass_is_exact();
4249     bool tinst_flatten_array = tinst->flatten_array();
4250     bool this_flatten_array  = this->flatten_array();
4251 
4252     ciKlass* res_klass = NULL;
4253     bool res_xk = false;
4254     bool res_flatten_array = false;
4255     const Type* res;
4256     MeetResult kind = meet_instptr(ptr, this_klass, tinst_klass, this_xk, tinst_xk, this->_ptr, tinst->_ptr,
4257                                    this_flatten_array, tinst_flatten_array,
4258                                    res_klass, res_xk, res_flatten_array);
4259     if (kind == UNLOADED) {
4260       // One of these classes has not been loaded
4261       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst);
4262 #ifndef PRODUCT
4263       if (PrintOpto && Verbose) {
4264         tty->print("meet of unloaded classes resulted in: ");
4265         unloaded_meet->dump();
4266         tty->cr();
4267         tty->print("  this == ");
4268         dump();
4269         tty->cr();
4270         tty->print(" tinst == ");
4271         tinst->dump();
4272         tty->cr();
4273       }
4274 #endif
4275       res = unloaded_meet;
4276     } else {
4277       if (kind == NOT_SUBTYPE && instance_id > 0) {
4278         instance_id = InstanceBot;
4279       } else if (kind == LCA) {
4280         instance_id = InstanceBot;
4281       }
4282       ciObject* o = NULL;             // Assume not constant when done
4283       ciObject* this_oop = const_oop();
4284       ciObject* tinst_oop = tinst->const_oop();
4285       if (ptr == Constant) {
4286         if (this_oop != NULL && tinst_oop != NULL &&
4287             this_oop->equals(tinst_oop))
4288           o = this_oop;
4289         else if (above_centerline(_ptr)) {
4290           assert(!tinst_klass->is_interface(), "");
4291           o = tinst_oop;
4292         } else if (above_centerline(tinst->_ptr)) {
4293           assert(!this_klass->is_interface(), "");
4294           o = this_oop;
4295         } else
4296           ptr = NotNull;
4297       }
4298       res = make(ptr, res_klass, res_xk, o, off, res_flatten_array, instance_id, speculative, depth);
4299     }
4300 
4301     return res;
4302 
4303   } // End of case InstPtr
4304 
4305   case InlineType: {
4306     const TypeInlineType* tv = t->is_inlinetype();
4307     if (above_centerline(ptr())) {
4308       if (tv->inline_klass()->is_subtype_of(_klass)) {
4309         return t;
4310       } else {
4311         return TypeInstPtr::NOTNULL;
4312       }
4313     } else {
4314       PTR ptr = this->_ptr;
4315       if (ptr == Constant) {
4316         ptr = NotNull;
4317       }
4318       if (tv->inline_klass()->is_subtype_of(_klass)) {
4319         return make(ptr, _klass, false, NULL, Offset(0), _flatten_array, InstanceBot, _speculative);
4320       } else {
4321         return make(ptr, ciEnv::current()->Object_klass());
4322       }
4323     }
4324   }
4325 
4326   } // End of switch
4327   return this;                  // Return the double constant
4328 }
4329 
4330 TypePtr::MeetResult TypePtr::meet_instptr(PTR &ptr, ciKlass* this_klass, ciKlass* tinst_klass, bool this_xk, bool tinst_xk,
4331                                           PTR this_ptr, PTR tinst_ptr, bool this_flatten_array, bool tinst_flatten_array,
4332                                           ciKlass*&res_klass, bool &res_xk, bool& res_flatten_array) {
4333 
4334   bool this_flatten_array_orig = this_flatten_array;
4335   bool tinst_flatten_array_orig = tinst_flatten_array;
4336 
4337   // Check for easy case; klasses are equal (and perhaps not loaded!)
4338   // If we have constants, then we created oops so classes are loaded
4339   // and we can handle the constants further down.  This case handles
4340   // both-not-loaded or both-loaded classes
4341   if (ptr != Constant && this_klass->equals(tinst_klass) && this_xk == tinst_xk && this_flatten_array == tinst_flatten_array) {
4342     res_klass = this_klass;
4343     res_xk = this_xk;
4344     res_flatten_array = this_flatten_array;
4345     return QUICK;
4346   }
4347 
4348   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4349   if (!tinst_klass->is_loaded() || !this_klass->is_loaded()) {
4350     return UNLOADED;
4351   }
4352 
4353   // Handle mixing oops and interfaces first.
4354   if (this_klass->is_interface() && !(tinst_klass->is_interface() ||
4355                                       tinst_klass == ciEnv::current()->Object_klass())) {
4356     ciKlass *tmp = tinst_klass; // Swap interface around
4357     tinst_klass = this_klass;
4358     this_klass = tmp;
4359     bool tmp2 = tinst_xk;
4360     tinst_xk = this_xk;
4361     this_xk = tmp2;
4362     tmp2 = tinst_flatten_array;
4363     tinst_flatten_array = this_flatten_array;
4364     this_flatten_array = tmp2;
4365   }
4366   if (tinst_klass->is_interface() &&
4367       !(this_klass->is_interface() ||
4368         // Treat java/lang/Object as an honorary interface,
4369         // because we need a bottom for the interface hierarchy.
4370         this_klass == ciEnv::current()->Object_klass())) {
4371     // Oop meets interface!
4372 
4373     // See if the oop subtypes (implements) interface.
4374     if (this_klass->is_subtype_of(tinst_klass)) {
4375       // Oop indeed subtypes.  Now keep oop or interface depending
4376       // on whether we are both above the centerline or either is
4377       // below the centerline.  If we are on the centerline
4378       // (e.g., Constant vs. AnyNull interface), use the constant.
4379       res_klass  = below_centerline(ptr) ? tinst_klass : this_klass;
4380       // If we are keeping this_klass, keep its exactness too.
4381       res_xk = below_centerline(ptr) ? tinst_xk    : this_xk;
4382       res_flatten_array = below_centerline(ptr) ? tinst_flatten_array    : this_flatten_array;
4383       return SUBTYPE;
4384     } else {                  // Does not implement, fall to Object
4385       // Oop does not implement interface, so mixing falls to Object
4386       // just like the verifier does (if both are above the
4387       // centerline fall to interface)
4388       res_klass = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
4389       res_xk = above_centerline(ptr) ? tinst_xk : false;
4390       res_flatten_array = above_centerline(ptr) ? tinst_flatten_array : false;
4391       // Watch out for Constant vs. AnyNull interface.
4392       if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
4393       return NOT_SUBTYPE;
4394     }
4395   }
4396 
4397   // Either oop vs oop or interface vs interface or interface vs Object
4398 
4399   // !!! Here's how the symmetry requirement breaks down into invariants:
4400   // If we split one up & one down AND they subtype, take the down man.
4401   // If we split one up & one down AND they do NOT subtype, "fall hard".
4402   // If both are up and they subtype, take the subtype class.
4403   // If both are up and they do NOT subtype, "fall hard".
4404   // If both are down and they subtype, take the supertype class.
4405   // If both are down and they do NOT subtype, "fall hard".
4406   // Constants treated as down.
4407 
4408   // Now, reorder the above list; observe that both-down+subtype is also
4409   // "fall hard"; "fall hard" becomes the default case:
4410   // If we split one up & one down AND they subtype, take the down man.
4411   // If both are up and they subtype, take the subtype class.
4412 
4413   // If both are down and they subtype, "fall hard".
4414   // If both are down and they do NOT subtype, "fall hard".
4415   // If both are up and they do NOT subtype, "fall hard".
4416   // If we split one up & one down AND they do NOT subtype, "fall hard".
4417 
4418   // If a proper subtype is exact, and we return it, we return it exactly.
4419   // If a proper supertype is exact, there can be no subtyping relationship!
4420   // If both types are equal to the subtype, exactness is and-ed below the
4421   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4422 
4423   // Check for subtyping:
4424   ciKlass *subtype = NULL;
4425   bool subtype_exact = false;
4426   bool flat_array = false;
4427   if (tinst_klass->equals(this_klass)) {
4428     subtype = this_klass;
4429     subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
4430     flat_array = below_centerline(ptr) ? (this_flatten_array && tinst_flatten_array) : (this_flatten_array || tinst_flatten_array);
4431   } else if (!tinst_xk && this_klass->is_subtype_of(tinst_klass) && (!tinst_flatten_array || this_flatten_array)) {
4432     subtype = this_klass;     // Pick subtyping class
4433     subtype_exact = this_xk;
4434     flat_array = this_flatten_array;
4435   } else if (!this_xk && tinst_klass->is_subtype_of(this_klass) && (!this_flatten_array || tinst_flatten_array)) {
4436     subtype = tinst_klass;    // Pick subtyping class
4437     subtype_exact = tinst_xk;
4438     flat_array = tinst_flatten_array;
4439   }
4440 
4441   if (subtype) {
4442     if (above_centerline(ptr)) { // both are up?
4443       this_klass = tinst_klass = subtype;
4444       this_xk = tinst_xk = subtype_exact;
4445       this_flatten_array = tinst_flatten_array = flat_array;
4446     } else if (above_centerline(this_ptr) && !above_centerline(tinst_ptr)) {
4447       this_klass = tinst_klass; // tinst is down; keep down man
4448       this_xk = tinst_xk;
4449       this_flatten_array = tinst_flatten_array;
4450     } else if (above_centerline(tinst_ptr) && !above_centerline(this_ptr)) {
4451       tinst_klass = this_klass; // this is down; keep down man
4452       tinst_xk = this_xk;
4453       tinst_flatten_array = this_flatten_array;
4454     } else {
4455       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4456       this_flatten_array = flat_array;
4457     }
4458   }
4459 
4460   // Check for classes now being equal
4461   if (tinst_klass->equals(this_klass)) {
4462     // If the klasses are equal, the constants may still differ.  Fall to
4463     // NotNull if they do (neither constant is NULL; that is a special case
4464     // handled elsewhere).
4465     res_klass = this_klass;
4466     res_xk = this_xk;
4467     res_flatten_array = this_flatten_array;
4468     return SUBTYPE;
4469   } // Else classes are not equal
4470 
4471   // Since klasses are different, we require a LCA in the Java
4472   // class hierarchy - which means we have to fall to at least NotNull.
4473   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4474     ptr = NotNull;
4475   }
4476 
4477   // Now we find the LCA of Java classes
4478   ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4479 
4480   res_klass = k;
4481   res_xk = false;
4482   res_flatten_array = this_flatten_array_orig && tinst_flatten_array_orig;
4483 
4484   return LCA;
4485 }
4486 
4487 
4488 //------------------------java_mirror_type--------------------------------------
4489 ciType* TypeInstPtr::java_mirror_type(bool* is_val_mirror) const {
4490   // must be a singleton type
4491   if( const_oop() == NULL )  return NULL;
4492 
4493   // must be of type java.lang.Class
4494   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4495   return const_oop()->as_instance()->java_mirror_type(is_val_mirror);

4496 }
4497 
4498 
4499 //------------------------------xdual------------------------------------------
4500 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4501 // inheritance mechanism.
4502 const Type *TypeInstPtr::xdual() const {
4503   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), flatten_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4504 }
4505 
4506 //------------------------------eq---------------------------------------------
4507 // Structural equality check for Type representations
4508 bool TypeInstPtr::eq( const Type *t ) const {
4509   const TypeInstPtr *p = t->is_instptr();
4510   return
4511     klass()->equals(p->klass()) &&
4512     flatten_array() == p->flatten_array() &&
4513     TypeOopPtr::eq(p);          // Check sub-type stuff
4514 }
4515 
4516 //------------------------------hash-------------------------------------------
4517 // Type-specific hashing function.
4518 int TypeInstPtr::hash(void) const {
4519   int hash = java_add(java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()), (jint)flatten_array());
4520   return hash;
4521 }
4522 
4523 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4524   if (!is_loaded() || !other->is_loaded()) {
4525     return false;
4526   }
4527   if (!other->isa_instptr()) {
4528     return false;
4529   }
4530 
4531   if (!other_exact) {
4532     return false;
4533   }
4534 
4535   if (other->klass()->equals(ciEnv::current()->Object_klass())) {
4536     return true;
4537   }
4538 
4539   if (!this_exact && klass()->is_interface()) {

4603       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4604       char* buf = ss.as_string(/* c_heap= */false);
4605       StringUtils::replace_no_expand(buf, "\n", "");
4606       st->print_raw(buf);
4607     }
4608   case BotPTR:
4609     if (!WizardMode && !Verbose) {
4610       if( _klass_is_exact ) st->print(":exact");
4611       break;
4612     }
4613   case TopPTR:
4614   case AnyNull:
4615   case NotNull:
4616     st->print(":%s", ptr_msg[_ptr]);
4617     if( _klass_is_exact ) st->print(":exact");
4618     break;
4619   default:
4620     break;
4621   }
4622 
4623   _offset.dump2(st);




4624 
4625   st->print(" *");
4626 
4627   if (flatten_array() && !klass()->is_inlinetype()) {
4628     st->print(" (flatten array)");
4629   }
4630 
4631   if (_instance_id == InstanceTop)
4632     st->print(",iid=top");
4633   else if (_instance_id != InstanceBot)
4634     st->print(",iid=%d",_instance_id);
4635 
4636   dump_inline_depth(st);
4637   dump_speculative(st);
4638 }
4639 #endif
4640 
4641 //------------------------------add_offset-------------------------------------
4642 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4643   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), flatten_array(),
4644               _instance_id, add_offset_speculative(offset), _inline_depth);
4645 }
4646 
4647 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4648   return make(_ptr, klass(), klass_is_exact(), const_oop(), Offset(offset), flatten_array(),
4649               _instance_id, with_offset_speculative(offset), _inline_depth);
4650 }
4651 
4652 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4653   if (_speculative == NULL) {
4654     return this;
4655   }
4656   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4657   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(),
4658               _instance_id, NULL, _inline_depth);
4659 }
4660 
4661 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4662   if (!UseInlineDepthForSpeculativeTypes) {
4663     return this;
4664   }
4665   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(), _instance_id, _speculative, depth);
4666 }
4667 
4668 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4669   assert(is_known_instance(), "should be known");
4670   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(), instance_id, _speculative, _inline_depth);
4671 }
4672 
4673 const TypeInstPtr *TypeInstPtr::cast_to_flatten_array() const {
4674   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4675 }
4676 
4677 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4678   bool xk = klass_is_exact();
4679   ciInstanceKlass* ik = klass()->as_instance_klass();
4680   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final() && !ik->is_interface()) {
4681     Compile* C = Compile::current();
4682     Dependencies* deps = C->dependencies();
4683     deps->assert_leaf_type(ik);
4684     xk = true;
4685   }
4686   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), Offset(0), flatten_array());
4687 }
4688 
4689 //=============================================================================
4690 // Convenience common pre-built types.
4691 const TypeAryPtr *TypeAryPtr::RANGE;
4692 const TypeAryPtr *TypeAryPtr::OOPS;
4693 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4694 const TypeAryPtr *TypeAryPtr::BYTES;
4695 const TypeAryPtr *TypeAryPtr::SHORTS;
4696 const TypeAryPtr *TypeAryPtr::CHARS;
4697 const TypeAryPtr *TypeAryPtr::INTS;
4698 const TypeAryPtr *TypeAryPtr::LONGS;
4699 const TypeAryPtr *TypeAryPtr::FLOATS;
4700 const TypeAryPtr *TypeAryPtr::DOUBLES;
4701 const TypeAryPtr *TypeAryPtr::INLINES;
4702 
4703 //------------------------------make-------------------------------------------
4704 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4705                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4706   assert(!(k == NULL && ary->_elem->isa_int()),
4707          "integral arrays must be pre-equipped with a class");
4708   if (!xk)  xk = ary->ary_must_be_exact();
4709   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4710   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4711 }
4712 
4713 //------------------------------make-------------------------------------------
4714 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4715                                    int instance_id, const TypePtr* speculative, int inline_depth,
4716                                    bool is_autobox_cache) {
4717   assert(!(k == NULL && ary->_elem->isa_int()),
4718          "integral arrays must be pre-equipped with a class");
4719   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4720   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4721   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4722   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4723 }
4724 
4725 //------------------------------cast_to_ptr_type-------------------------------
4726 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4727   if( ptr == _ptr ) return this;
4728   return make(ptr, ptr == Constant ? const_oop() : NULL, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4729 }
4730 
4731 
4732 //-----------------------------cast_to_exactness-------------------------------
4733 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4734   if( klass_is_exact == _klass_is_exact ) return this;
4735   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4736 
4737   const TypeAry* new_ary = _ary;
4738   if (klass() != NULL && klass()->is_obj_array_klass() && klass_is_exact) {
4739     // An object array can't be flat or null-free if the klass is exact
4740     new_ary = TypeAry::make(elem(), size(), is_stable(), /* not_flat= */ true, /* not_null_free= */ true);
4741   }
4742   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4743 }
4744 
4745 //-----------------------------cast_to_instance_id----------------------------
4746 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4747   if( instance_id == _instance_id ) return this;
4748   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4749 }
4750 
4751 
4752 //-----------------------------max_array_length-------------------------------
4753 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4754 jint TypeAryPtr::max_array_length(BasicType etype) {
4755   if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4756     if (etype == T_NARROWOOP) {
4757       etype = T_OBJECT;
4758     } else if (etype == T_ILLEGAL) { // bottom[]
4759       etype = T_BYTE; // will produce conservatively high value
4760     } else {
4761       fatal("not an element type: %s", type2name(etype));
4762     }
4763   }
4764   return arrayOopDesc::max_array_length(etype);
4765 }
4766 
4767 //-----------------------------narrow_size_type-------------------------------
4768 // Narrow the given size type to the index range for the given array base type.

4784   if (hi > max_hi) {
4785     hi = max_hi;
4786     if (size->is_con()) {
4787       lo = hi;
4788     }
4789     chg = true;
4790   }
4791   // Negative length arrays will produce weird intermediate dead fast-path code
4792   if (lo > hi)
4793     return TypeInt::ZERO;
4794   if (!chg)
4795     return size;
4796   return TypeInt::make(lo, hi, Type::WidenMin);
4797 }
4798 
4799 //-------------------------------cast_to_size----------------------------------
4800 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4801   assert(new_size != NULL, "");
4802   new_size = narrow_size_type(new_size);
4803   if (new_size == size())  return this;
4804   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_not_flat(), is_not_null_free());
4805   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4806 }
4807 
4808 //-------------------------------cast_to_not_flat------------------------------
4809 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
4810   if (not_flat == is_not_flat()) {
4811     return this;
4812   }
4813   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_flat, is_not_null_free());
4814   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4815 }
4816 
4817 //-------------------------------cast_to_not_null_free-------------------------
4818 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
4819   if (not_null_free == is_not_null_free()) {
4820     return this;
4821   }
4822   // Not null free implies not flat
4823   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_null_free ? true : is_not_flat(), not_null_free);
4824   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4825 }
4826 
4827 //---------------------------------update_properties---------------------------
4828 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
4829   if ((from->is_flat()          && is_not_flat()) ||
4830       (from->is_not_flat()      && is_flat()) ||
4831       (from->is_null_free()     && is_not_null_free()) ||
4832       (from->is_not_null_free() && is_null_free())) {
4833     return NULL; // Inconsistent properties
4834   } else if (from->is_not_null_free()) {
4835     return cast_to_not_null_free(); // Implies not flat
4836   } else if (from->is_not_flat()) {
4837     return cast_to_not_flat();
4838   }
4839   return this;
4840 }
4841 
4842 jint TypeAryPtr::flat_layout_helper() const {
4843   return klass()->as_flat_array_klass()->layout_helper();
4844 }
4845 
4846 int TypeAryPtr::flat_elem_size() const {
4847   return klass()->as_flat_array_klass()->element_byte_size();
4848 }
4849 
4850 int TypeAryPtr::flat_log_elem_size() const {
4851   return klass()->as_flat_array_klass()->log2_element_size();
4852 }
4853 
4854 //------------------------------cast_to_stable---------------------------------
4855 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4856   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4857     return this;
4858 
4859   const Type* elem = this->elem();
4860   const TypePtr* elem_ptr = elem->make_ptr();
4861 
4862   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4863     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4864     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4865   }
4866 
4867   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_not_flat(), is_not_null_free());
4868 
4869   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4870 }
4871 
4872 //-----------------------------stable_dimension--------------------------------
4873 int TypeAryPtr::stable_dimension() const {
4874   if (!is_stable())  return 0;
4875   int dim = 1;
4876   const TypePtr* elem_ptr = elem()->make_ptr();
4877   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4878     dim += elem_ptr->is_aryptr()->stable_dimension();
4879   return dim;
4880 }
4881 
4882 //----------------------cast_to_autobox_cache-----------------------------------
4883 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4884   if (is_autobox_cache())  return this;
4885   const TypeOopPtr* etype = elem()->make_oopptr();
4886   if (etype == NULL)  return this;
4887   // TODO fix with JDK-8284164
4888   // Ignore inline types to not confuse logic in TypeAryPtr::compute_klass
4889   if (!etype->is_inlinetypeptr()) {
4890     // The pointers in the autobox arrays are always non-null.
4891     etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4892   }
4893   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_not_flat(), is_not_null_free());
4894   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4895 }
4896 
4897 //------------------------------eq---------------------------------------------
4898 // Structural equality check for Type representations
4899 bool TypeAryPtr::eq( const Type *t ) const {
4900   const TypeAryPtr *p = t->is_aryptr();
4901   return
4902     _ary == p->_ary &&  // Check array
4903     TypeOopPtr::eq(p) &&// Check sub-parts
4904     _field_offset == p->_field_offset;
4905 }
4906 
4907 //------------------------------hash-------------------------------------------
4908 // Type-specific hashing function.
4909 int TypeAryPtr::hash(void) const {
4910   return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
4911 }
4912 
4913 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4914   if (other->klass() == ciEnv::current()->Object_klass() && other_exact) {
4915     return true;
4916   }
4917 
4918   if (!is_loaded() || !other->is_loaded() || other->klass() == NULL || klass() == NULL) {
4919     return false;
4920   }
4921   if (other->isa_instptr()) {
4922     return _klass->is_subtype_of(other->_klass) && other_exact;
4923   }
4924   if (klass() == NULL) {
4925     return false;
4926   }
4927   assert(other->isa_aryptr(), "");
4928   const TypeAryPtr* other_ary = other->isa_aryptr();
4929   if (other_ary->elem()->make_oopptr() && elem()->make_oopptr()) {
4930     return elem()->make_oopptr()->is_java_subtype_of_helper(other_ary->elem()->make_oopptr(), this_exact, other_exact);

4990   case Long:
4991   case FloatTop:
4992   case FloatCon:
4993   case FloatBot:
4994   case DoubleTop:
4995   case DoubleCon:
4996   case DoubleBot:
4997   case NarrowOop:
4998   case NarrowKlass:
4999   case Bottom:                  // Ye Olde Default
5000     return Type::BOTTOM;
5001   case Top:
5002     return this;
5003 
5004   default:                      // All else is a mistake
5005     typerr(t);
5006 
5007   case OopPtr: {                // Meeting to OopPtrs
5008     // Found a OopPtr type vs self-AryPtr type
5009     const TypeOopPtr *tp = t->is_oopptr();
5010     Offset offset = meet_offset(tp->offset());
5011     PTR ptr = meet_ptr(tp->ptr());
5012     int depth = meet_inline_depth(tp->inline_depth());
5013     const TypePtr* speculative = xmeet_speculative(tp);
5014     switch (tp->ptr()) {
5015     case TopPTR:
5016     case AnyNull: {
5017       int instance_id = meet_instance_id(InstanceTop);
5018       return make(ptr, (ptr == Constant ? const_oop() : NULL),
5019                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5020     }
5021     case BotPTR:
5022     case NotNull: {
5023       int instance_id = meet_instance_id(tp->instance_id());
5024       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5025     }
5026     default: ShouldNotReachHere();
5027     }
5028   }
5029 
5030   case AnyPtr: {                // Meeting two AnyPtrs
5031     // Found an AnyPtr type vs self-AryPtr type
5032     const TypePtr *tp = t->is_ptr();
5033     Offset offset = meet_offset(tp->offset());
5034     PTR ptr = meet_ptr(tp->ptr());
5035     const TypePtr* speculative = xmeet_speculative(tp);
5036     int depth = meet_inline_depth(tp->inline_depth());
5037     switch (tp->ptr()) {
5038     case TopPTR:
5039       return this;
5040     case BotPTR:
5041     case NotNull:
5042       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5043     case Null:
5044       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5045       // else fall through to AnyNull
5046     case AnyNull: {
5047       int instance_id = meet_instance_id(InstanceTop);
5048       return make(ptr, (ptr == Constant ? const_oop() : NULL),
5049                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5050     }
5051     default: ShouldNotReachHere();
5052     }
5053   }
5054 
5055   case MetadataPtr:
5056   case KlassPtr:
5057   case InstKlassPtr:
5058   case AryKlassPtr:
5059   case RawPtr: return TypePtr::BOTTOM;
5060 
5061   case AryPtr: {                // Meeting 2 references?
5062     const TypeAryPtr *tap = t->is_aryptr();
5063     Offset off = meet_offset(tap->offset());
5064     Offset field_off = meet_field_offset(tap->field_offset());
5065     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5066     PTR ptr = meet_ptr(tap->ptr());
5067     int instance_id = meet_instance_id(tap->instance_id());
5068     const TypePtr* speculative = xmeet_speculative(tap);
5069     int depth = meet_inline_depth(tap->inline_depth());
5070 
5071     ciKlass* res_klass = NULL;
5072     bool res_xk = false;
5073     bool res_not_flat = false;
5074     bool res_not_null_free = false;
5075     const Type* res_elem = NULL;
5076     if (meet_aryptr(ptr, _ary->_elem, tap->_ary->_elem, this->klass(), tap->klass(),
5077                     this->klass_is_exact(), tap->klass_is_exact(), this->ptr(), tap->ptr(),
5078                     this->is_not_flat(), tap->is_not_flat(),
5079                     this->is_not_null_free(), tap->is_not_null_free(),
5080                     res_elem, res_klass, res_xk, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
5081       instance_id = InstanceBot;
5082     } else if (klass() != NULL && tap->klass() != NULL && klass()->is_flat_array_klass() != tap->klass()->is_flat_array_klass()) {
5083       // Meeting flattened inline type array with non-flattened array. Adjust (field) offset accordingly.
5084       if (tary->_elem->isa_inlinetype()) {
5085         // Result is flattened
5086         off = Offset(is_flat() ? offset() : tap->offset());
5087         field_off = is_flat() ? field_offset() : tap->field_offset();
5088       } else if (tary->_elem->make_oopptr() != NULL && tary->_elem->make_oopptr()->isa_instptr() && below_centerline(ptr)) {
5089         // Result is non-flattened
5090         off = Offset(flattened_offset()).meet(Offset(tap->flattened_offset()));
5091         field_off = Offset::bottom;
5092       }
5093     }
5094 
5095     ciObject* o = NULL;             // Assume not constant when done
5096     ciObject* this_oop = const_oop();
5097     ciObject* tap_oop = tap->const_oop();
5098     if (ptr == Constant) {
5099       if (this_oop != NULL && tap_oop != NULL &&
5100           this_oop->equals(tap_oop)) {
5101         o = tap_oop;
5102       } else if (above_centerline(_ptr)) {
5103         o = tap_oop;
5104       } else if (above_centerline(tap->_ptr)) {
5105         o = this_oop;
5106       } else {
5107         ptr = NotNull;
5108       }
5109     }
5110     return make(ptr, o, TypeAry::make(res_elem, tary->_size, tary->_stable, res_not_flat, res_not_null_free), res_klass, res_xk, off, field_off, instance_id, speculative, depth);
5111   }
5112 
5113   // All arrays inherit from Object class
5114   case InstPtr: {
5115     const TypeInstPtr *tp = t->is_instptr();
5116     Offset offset = meet_offset(tp->offset());
5117     PTR ptr = meet_ptr(tp->ptr());
5118     int instance_id = meet_instance_id(tp->instance_id());
5119     const TypePtr* speculative = xmeet_speculative(tp);
5120     int depth = meet_inline_depth(tp->inline_depth());
5121     switch (ptr) {
5122     case TopPTR:
5123     case AnyNull:                // Fall 'down' to dual of object klass
5124       // For instances when a subclass meets a superclass we fall
5125       // below the centerline when the superclass is exact. We need to
5126       // do the same here.
5127       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact() && !tp->flatten_array()) {
5128         return make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5129       } else {
5130         // cannot subclass, so the meet has to fall badly below the centerline
5131         ptr = NotNull;
5132         instance_id = InstanceBot;
5133         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
5134       }
5135     case Constant:
5136     case NotNull:
5137     case BotPTR:                // Fall down to object klass
5138       // LCA is object_klass, but if we subclass from the top we can do better
5139       if (above_centerline(tp->ptr())) {
5140         // If 'tp'  is above the centerline and it is Object class
5141         // then we can subclass in the Java class hierarchy.
5142         // For instances when a subclass meets a superclass we fall
5143         // below the centerline when the superclass is exact. We need
5144         // to do the same here.
5145         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact() && !tp->flatten_array()) {
5146           // that is, my array type is a subtype of 'tp' klass
5147           return make(ptr, (ptr == Constant ? const_oop() : NULL),
5148                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5149         }
5150       }
5151       // The other case cannot happen, since t cannot be a subtype of an array.
5152       // The meet falls down to Object class below centerline.
5153       if (ptr == Constant) {
5154          ptr = NotNull;
5155       }
5156       if (instance_id > 0) {
5157         instance_id = InstanceBot;
5158       }
5159       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
5160     default: typerr(t);
5161     }
5162   }
5163 
5164   case InlineType: {
5165     const TypeInlineType* tv = t->is_inlinetype();
5166     if (above_centerline(ptr())) {
5167       return TypeInstPtr::NOTNULL;
5168     } else {
5169       PTR ptr = this->_ptr;
5170       if (ptr == Constant) {
5171         ptr = NotNull;
5172       }
5173       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
5174     }
5175   }
5176   }
5177   return this;                  // Lint noise
5178 }
5179 
5180 
5181 TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type* this_elem, const Type* tap_elem,
5182                                          ciKlass* this_klass, ciKlass* tap_klass,
5183                                          bool this_xk, bool tap_xk, PTR this_ptr, PTR tap_ptr,
5184                                          bool this_not_flat, bool tap_not_flat,
5185                                          bool this_not_null_free, bool tap_not_null_free,
5186                                          const Type*& res_elem, ciKlass*& res_klass,
5187                                          bool& res_xk, bool& res_not_flat, bool& res_not_null_free) {
5188   res_klass = NULL;
5189   MeetResult result = SUBTYPE;
5190   res_elem = this_elem->meet(tap_elem);
5191   res_not_flat = this_not_flat && tap_not_flat;
5192   res_not_null_free = this_not_null_free && tap_not_null_free;
5193 
5194   if (res_elem->isa_int()) {
5195     // Integral array element types have irrelevant lattice relations.
5196     // It is the klass that determines array layout, not the element type.
5197     if (this_klass == NULL) {
5198       res_klass = tap_klass;
5199     } else if (tap_klass == NULL || tap_klass == this_klass) {
5200       res_klass = this_klass;
5201     } else {
5202       // Something like byte[int+] meets char[int+].
5203       // This must fall to bottom, not (int[-128..65535])[int+].
5204       // instance_id = InstanceBot;
5205       res_elem = Type::BOTTOM;
5206       result = NOT_SUBTYPE;
5207     }
5208   } else // Non integral arrays.
5209     // Must fall to bottom if exact klasses in upper lattice
5210     // are not equal or super klass is exact.
5211     if ((above_centerline(ptr) || ptr == Constant) && this_klass != tap_klass &&
5212         // meet with top[] and bottom[] are processed further down:
5213         tap_klass != NULL  && this_klass != NULL   &&
5214         // both are exact and not equal:
5215         ((tap_xk && this_xk) ||
5216          // 'tap'  is exact and super or unrelated:
5217          (tap_xk && !tap_klass->is_subtype_of(this_klass)) ||
5218          // 'this' is exact and super or unrelated:
5219          (this_xk && !this_klass->is_subtype_of(tap_klass)))) {
5220       if (above_centerline(ptr) || (res_elem->make_ptr() && above_centerline(res_elem->make_ptr()->_ptr)) ||
5221           res_elem->isa_inlinetype()) {
5222         res_elem = Type::BOTTOM;
5223       }
5224       ptr = NotNull;
5225       res_xk = false;
5226       return NOT_SUBTYPE;
5227     }
5228 
5229   res_xk = false;
5230   switch (tap_ptr) {
5231     case AnyNull:
5232     case TopPTR:
5233       // Compute new klass on demand, do not use tap->_klass
5234       if (below_centerline(this_ptr)) {
5235         res_xk = this_xk;
5236         if (this_elem->isa_inlinetype()) {
5237           res_elem = this_elem;
5238         }
5239       } else {
5240         res_xk = (tap_xk || this_xk);
5241       }
5242       break;
5243     case Constant: {
5244       if (this_ptr == Constant) {
5245         res_xk = true;
5246       } else if(above_centerline(this_ptr)) {
5247         res_xk = true;
5248       } else {
5249         // Only precise for identical arrays
5250         res_xk = this_xk && (this_klass == tap_klass);
5251       }
5252       break;
5253     }
5254     case NotNull:
5255     case BotPTR:
5256       // Compute new klass on demand, do not use tap->_klass
5257       if (above_centerline(this_ptr)) {
5258         res_xk = tap_xk;
5259         if (tap_elem->isa_inlinetype()) {
5260           res_elem = tap_elem;
5261         }
5262       } else {
5263         res_xk = (tap_xk && this_xk) &&
5264           (this_klass == tap_klass); // Only precise for identical arrays
5265       }
5266       break;
5267     default:  {
5268       ShouldNotReachHere();
5269       return result;
5270     }
5271   }
5272 
5273   return result;
5274 }
5275 
5276 
5277 //------------------------------xdual------------------------------------------
5278 // Dual: compute field-by-field dual
5279 const Type *TypeAryPtr::xdual() const {
5280   return new TypeAryPtr(dual_ptr(), _const_oop, _ary->dual()->is_ary(), _klass, _klass_is_exact, dual_offset(), dual_field_offset(), dual_instance_id(), is_autobox_cache(), dual_speculative(), dual_inline_depth());
5281 }
5282 
5283 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5284   return _field_offset.meet(offset);
5285 }
5286 
5287 //------------------------------dual_offset------------------------------------
5288 Type::Offset TypeAryPtr::dual_field_offset() const {
5289   return _field_offset.dual();
5290 }
5291 
5292 //----------------------interface_vs_oop---------------------------------------
5293 #ifdef ASSERT
5294 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
5295   const TypeAryPtr* t_aryptr = t->isa_aryptr();
5296   if (t_aryptr) {
5297     return _ary->interface_vs_oop(t_aryptr->_ary);
5298   }
5299   return false;
5300 }
5301 #endif
5302 
5303 //------------------------------dump2------------------------------------------
5304 #ifndef PRODUCT
5305 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5306   _ary->dump2(d,depth,st);
5307   switch( _ptr ) {
5308   case Constant:
5309     const_oop()->print(st);
5310     break;
5311   case BotPTR:
5312     if (!WizardMode && !Verbose) {
5313       if( _klass_is_exact ) st->print(":exact");
5314       break;
5315     }
5316   case TopPTR:
5317   case AnyNull:
5318   case NotNull:
5319     st->print(":%s", ptr_msg[_ptr]);
5320     if( _klass_is_exact ) st->print(":exact");
5321     break;
5322   default:
5323     break;
5324   }
5325 
5326   if (is_flat()) {
5327     st->print("(");
5328     _field_offset.dump2(st);
5329     st->print(")");
5330   }
5331   if (offset() != 0) {
5332     int header_size = objArrayOopDesc::header_size() * wordSize;
5333     if( _offset == Offset::top )       st->print("+undefined");
5334     else if( _offset == Offset::bottom )  st->print("+any");
5335     else if( offset() < header_size ) st->print("+%d", offset());
5336     else {
5337       BasicType basic_elem_type = elem()->basic_type();
5338       if (basic_elem_type == T_ILLEGAL) {
5339         st->print("+any");
5340       } else {
5341         int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5342         int elem_size = type2aelembytes(basic_elem_type);
5343         st->print("[%d]", (offset() - array_base)/elem_size);
5344       }
5345     }
5346   }
5347   st->print(" *");
5348   if (_instance_id == InstanceTop)
5349     st->print(",iid=top");
5350   else if (_instance_id != InstanceBot)
5351     st->print(",iid=%d",_instance_id);
5352 
5353   dump_inline_depth(st);
5354   dump_speculative(st);
5355 }
5356 #endif
5357 
5358 bool TypeAryPtr::empty(void) const {
5359   if (_ary->empty())       return true;
5360   return TypeOopPtr::empty();
5361 }
5362 
5363 //------------------------------add_offset-------------------------------------
5364 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
5365   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _field_offset, _instance_id, add_offset_speculative(offset), _inline_depth, _is_autobox_cache);
5366 }
5367 
5368 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5369   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, Offset(offset), _field_offset, _instance_id, with_offset_speculative(offset), _inline_depth, _is_autobox_cache);
5370 }
5371 
5372 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5373   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5374 }
5375 
5376 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5377   if (_speculative == NULL) {
5378     return this;
5379   }
5380   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5381   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, NULL, _inline_depth, _is_autobox_cache);
5382 }
5383 
5384 const Type* TypeAryPtr::cleanup_speculative() const {
5385   if (speculative() == NULL) {
5386     return this;
5387   }
5388   // Keep speculative part if it contains information about flat-/nullability
5389   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5390   if (spec_aryptr != NULL && (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5391     return this;
5392   }
5393   return TypeOopPtr::cleanup_speculative();
5394 }
5395 
5396 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
5397   if (!UseInlineDepthForSpeculativeTypes) {
5398     return this;
5399   }
5400   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5401 }
5402 
5403 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5404   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, Offset(offset), _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5405 }
5406 
5407 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5408   int adj = 0;
5409   if (offset != Type::OffsetBot && offset != Type::OffsetTop) {
5410     const Type* elemtype = elem();
5411     if (elemtype->isa_inlinetype()) {
5412       if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5413         adj = _offset.get();
5414         offset += _offset.get();
5415       }
5416       uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5417       if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5418         offset += _field_offset.get();
5419         if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5420           offset += header;
5421         }
5422       }
5423       if (offset >= (intptr_t)header || offset < 0) {
5424         // Try to get the field of the inline type array element we are pointing to
5425         ciKlass* arytype_klass = klass();
5426         ciFlatArrayKlass* vak = arytype_klass->as_flat_array_klass();
5427         ciInlineKlass* vk = vak->element_klass()->as_inline_klass();
5428         int shift = vak->log2_element_size();
5429         int mask = (1 << shift) - 1;
5430         intptr_t field_offset = ((offset - header) & mask);
5431         ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
5432         if (field != NULL) {
5433           return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5434         }
5435       }
5436     }
5437   }
5438   return add_offset(offset - adj);
5439 }
5440 
5441 // Return offset incremented by field_offset for flattened inline type arrays
5442 const int TypeAryPtr::flattened_offset() const {
5443   int offset = _offset.get();
5444   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5445       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5446     offset += _field_offset.get();
5447   }
5448   return offset;
5449 }
5450 
5451 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
5452   assert(is_known_instance(), "should be known");
5453   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5454 }
5455 
5456 //=============================================================================
5457 
5458 
5459 //------------------------------hash-------------------------------------------
5460 // Type-specific hashing function.
5461 int TypeNarrowPtr::hash(void) const {
5462   return _ptrtype->hash() + 7;
5463 }
5464 
5465 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5466   return _ptrtype->singleton();
5467 }
5468 
5469 bool TypeNarrowPtr::empty(void) const {
5470   return _ptrtype->empty();
5471 }
5472 
5473 intptr_t TypeNarrowPtr::get_con() const {
5474   return _ptrtype->get_con();
5475 }
5476 
5477 bool TypeNarrowPtr::eq( const Type *t ) const {
5478   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5529 
5530   case Int:                     // Mixing ints & oops happens when javac
5531   case Long:                    // reuses local variables
5532   case FloatTop:
5533   case FloatCon:
5534   case FloatBot:
5535   case DoubleTop:
5536   case DoubleCon:
5537   case DoubleBot:
5538   case AnyPtr:
5539   case RawPtr:
5540   case OopPtr:
5541   case InstPtr:
5542   case AryPtr:
5543   case MetadataPtr:
5544   case KlassPtr:
5545   case InstKlassPtr:
5546   case AryKlassPtr:
5547   case NarrowOop:
5548   case NarrowKlass:

5549   case Bottom:                  // Ye Olde Default
5550     return Type::BOTTOM;
5551   case Top:
5552     return this;
5553 
5554   case InlineType:
5555     return t->xmeet(this);
5556 
5557   default:                      // All else is a mistake
5558     typerr(t);
5559 
5560   } // End of switch
5561 
5562   return this;
5563 }
5564 
5565 #ifndef PRODUCT
5566 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5567   _ptrtype->dump2(d, depth, st);
5568 }
5569 #endif
5570 
5571 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5572 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5573 
5574 
5575 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5576   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();

5615     return (one == two) && TypePtr::eq(t);
5616   } else {
5617     return one->equals(two) && TypePtr::eq(t);
5618   }
5619 }
5620 
5621 //------------------------------hash-------------------------------------------
5622 // Type-specific hashing function.
5623 int TypeMetadataPtr::hash(void) const {
5624   return
5625     (metadata() ? metadata()->hash() : 0) +
5626     TypePtr::hash();
5627 }
5628 
5629 //------------------------------singleton--------------------------------------
5630 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5631 // constants
5632 bool TypeMetadataPtr::singleton(void) const {
5633   // detune optimizer to not generate constant metadata + constant offset as a constant!
5634   // TopPTR, Null, AnyNull, Constant are all singletons
5635   return (offset() == 0) && !below_centerline(_ptr);
5636 }
5637 
5638 //------------------------------add_offset-------------------------------------
5639 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
5640   return make( _ptr, _metadata, xadd_offset(offset));
5641 }
5642 
5643 //-----------------------------filter------------------------------------------
5644 // Do not allow interface-vs.-noninterface joins to collapse to top.
5645 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5646   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5647   if (ft == NULL || ft->empty())
5648     return Type::TOP;           // Canonical empty value
5649   return ft;
5650 }
5651 
5652  //------------------------------get_con----------------------------------------
5653 intptr_t TypeMetadataPtr::get_con() const {
5654   assert( _ptr == Null || _ptr == Constant, "" );
5655   assert(offset() >= 0, "");
5656 
5657   if (offset() != 0) {
5658     // After being ported to the compiler interface, the compiler no longer
5659     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5660     // to a handle at compile time.  This handle is embedded in the generated
5661     // code and dereferenced at the time the nmethod is made.  Until that time,
5662     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5663     // have access to the addresses!).  This does not seem to currently happen,
5664     // but this assertion here is to help prevent its occurrence.
5665     tty->print_cr("Found oop constant with non-zero offset");
5666     ShouldNotReachHere();
5667   }
5668 
5669   return (intptr_t)metadata()->constant_encoding();
5670 }
5671 
5672 //------------------------------cast_to_ptr_type-------------------------------
5673 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5674   if( ptr == _ptr ) return this;
5675   return make(ptr, metadata(), _offset);
5676 }
5677 

5688   case Long:                    // reuses local variables
5689   case FloatTop:
5690   case FloatCon:
5691   case FloatBot:
5692   case DoubleTop:
5693   case DoubleCon:
5694   case DoubleBot:
5695   case NarrowOop:
5696   case NarrowKlass:
5697   case Bottom:                  // Ye Olde Default
5698     return Type::BOTTOM;
5699   case Top:
5700     return this;
5701 
5702   default:                      // All else is a mistake
5703     typerr(t);
5704 
5705   case AnyPtr: {
5706     // Found an AnyPtr type vs self-OopPtr type
5707     const TypePtr *tp = t->is_ptr();
5708     Offset offset = meet_offset(tp->offset());
5709     PTR ptr = meet_ptr(tp->ptr());
5710     switch (tp->ptr()) {
5711     case Null:
5712       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5713       // else fall through:
5714     case TopPTR:
5715     case AnyNull: {
5716       return make(ptr, _metadata, offset);
5717     }
5718     case BotPTR:
5719     case NotNull:
5720       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5721     default: typerr(t);
5722     }
5723   }
5724 
5725   case RawPtr:
5726   case KlassPtr:
5727   case InstKlassPtr:
5728   case AryKlassPtr:
5729   case OopPtr:
5730   case InstPtr:
5731   case AryPtr:
5732     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5733 
5734   case MetadataPtr: {
5735     const TypeMetadataPtr *tp = t->is_metadataptr();
5736     Offset offset = meet_offset(tp->offset());
5737     PTR tptr = tp->ptr();
5738     PTR ptr = meet_ptr(tptr);
5739     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5740     if (tptr == TopPTR || _ptr == TopPTR ||
5741         metadata()->equals(tp->metadata())) {
5742       return make(ptr, md, offset);
5743     }
5744     // metadata is different
5745     if( ptr == Constant ) {  // Cannot be equal constants, so...
5746       if( tptr == Constant && _ptr != Constant)  return t;
5747       if( _ptr == Constant && tptr != Constant)  return this;
5748       ptr = NotNull;            // Fall down in lattice
5749     }
5750     return make(ptr, NULL, offset);
5751     break;
5752   }
5753   } // End of switch
5754   return this;                  // Return the double constant
5755 }
5756 
5757 
5758 //------------------------------xdual------------------------------------------
5759 // Dual of a pure metadata pointer.
5760 const Type *TypeMetadataPtr::xdual() const {
5761   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5762 }
5763 
5764 //------------------------------dump2------------------------------------------
5765 #ifndef PRODUCT
5766 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5767   st->print("metadataptr:%s", ptr_msg[_ptr]);
5768   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5769   switch (offset()) {
5770   case OffsetTop: st->print("+top"); break;
5771   case OffsetBot: st->print("+any"); break;
5772   case         0: break;
5773   default:        st->print("+%d",offset()); break;
5774   }
5775 }
5776 #endif
5777 
5778 
5779 //=============================================================================
5780 // Convenience common pre-built type.
5781 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5782 
5783 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5784   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5785 }
5786 
5787 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5788   return make(Constant, m, Offset(0));
5789 }
5790 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5791   return make(Constant, m, Offset(0));
5792 }
5793 
5794 //------------------------------make-------------------------------------------
5795 // Create a meta data constant
5796 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5797   assert(m == NULL || !m->is_klass(), "wrong type");
5798   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5799 }
5800 
5801 
5802 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5803   const Type* elem = _ary->_elem;
5804   bool xk = klass_is_exact();
5805   if (elem->make_oopptr() != NULL) {
5806     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5807     if (elem->is_klassptr()->klass_is_exact() &&
5808         // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5809         (is_null_free() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
5810       xk = true;
5811     }
5812   } else if (elem->isa_inlinetype() != NULL) {
5813     elem = TypeKlassPtr::make(elem->inline_klass());
5814   }
5815   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
5816 }
5817 
5818 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass) {
5819   if (klass->is_instance_klass()) {
5820     return TypeInstKlassPtr::make(klass);
5821   }
5822   return TypeAryKlassPtr::make(klass);
5823 }
5824 
5825 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset) {
5826   if (klass->is_instance_klass()) {
5827     return TypeInstKlassPtr::make(ptr, klass, offset);
5828   }
5829   return TypeAryKlassPtr::make(ptr, klass, offset);
5830 }
5831 

5832 //------------------------------TypeKlassPtr-----------------------------------
5833 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, Offset offset)
5834   : TypePtr(t, ptr, offset), _klass(klass) {
5835 }
5836 
5837 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5838   return _klass;
5839 }
5840 
5841 //------------------------------eq---------------------------------------------
5842 // Structural equality check for Type representations
5843 bool TypeKlassPtr::eq(const Type *t) const {
5844   const TypeKlassPtr *p = t->is_klassptr();
5845   return
5846     TypePtr::eq(p);
5847 }
5848 
5849 //------------------------------hash-------------------------------------------
5850 // Type-specific hashing function.
5851 int TypeKlassPtr::hash(void) const {
5852   return TypePtr::hash();
5853 }
5854 
5855 //------------------------------singleton--------------------------------------
5856 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5857 // constants
5858 bool TypeKlassPtr::singleton(void) const {
5859   // detune optimizer to not generate constant klass + constant offset as a constant!
5860   // TopPTR, Null, AnyNull, Constant are all singletons
5861   return (offset() == 0) && !below_centerline(_ptr);
5862 }
5863 
5864 // Do not allow interface-vs.-noninterface joins to collapse to top.
5865 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5866   // logic here mirrors the one from TypeOopPtr::filter. See comments
5867   // there.
5868   const Type* ft = join_helper(kills, include_speculative);
5869   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5870   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5871 
5872   if (ft->empty()) {
5873     if (!empty() && ktkp != NULL && ktkp->is_loaded() && ktkp->klass()->is_interface())
5874       return kills;             // Uplift to interface
5875 
5876     return Type::TOP;           // Canonical empty value
5877   }
5878 
5879   // Interface klass type could be exact in opposite to interface type,
5880   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5881   if (ftkp != NULL && ktkp != NULL &&
5882       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5883       !ftkp->klass_is_exact() && // Keep exact interface klass
5884       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5885     return ktkp->cast_to_ptr_type(ftkp->ptr());
5886   }
5887 
5888   return ft;
5889 }
5890 
5891 //------------------------------get_con----------------------------------------
5892 intptr_t TypeKlassPtr::get_con() const {
5893   assert( _ptr == Null || _ptr == Constant, "" );
5894   assert( offset() >= 0, "" );
5895 
5896   if (offset() != 0) {
5897     // After being ported to the compiler interface, the compiler no longer
5898     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5899     // to a handle at compile time.  This handle is embedded in the generated
5900     // code and dereferenced at the time the nmethod is made.  Until that time,
5901     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5902     // have access to the addresses!).  This does not seem to currently happen,
5903     // but this assertion here is to help prevent its occurrence.
5904     tty->print_cr("Found oop constant with non-zero offset");
5905     ShouldNotReachHere();
5906   }
5907 
5908   ciKlass* k = exact_klass();
5909 
5910   return (intptr_t)k->constant_encoding();
5911 }
5912 
5913 //------------------------------dump2------------------------------------------
5914 // Dump Klass Type
5915 #ifndef PRODUCT
5916 void TypeInstKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5917   switch(_ptr) {
5918   case Constant:
5919     st->print("precise ");
5920   case NotNull:
5921     {
5922       const char *name = klass()->name()->as_utf8();
5923       if (name) {
5924         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5925       } else {
5926         ShouldNotReachHere();
5927       }
5928     }
5929   case BotPTR:
5930     if (!WizardMode && !Verbose && _ptr != Constant) break;
5931   case TopPTR:
5932   case AnyNull:
5933     st->print(":%s", ptr_msg[_ptr]);
5934     if (_ptr == Constant) st->print(":exact");
5935     break;
5936   default:
5937     break;
5938   }
5939   if (Verbose) {
5940     if (_flatten_array) st->print(":flatten array");



5941   }
5942   _offset.dump2(st);
5943   st->print(" *");
5944 }
5945 #endif
5946 
5947 //=============================================================================
5948 // Convenience common pre-built types.
5949 
5950 // Not-null object klass or below
5951 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5952 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5953 
5954 bool TypeInstKlassPtr::eq(const Type *t) const {
5955   const TypeKlassPtr *p = t->is_klassptr();
5956   return
5957     klass()->equals(p->klass()) &&
5958     flatten_array() == p->flatten_array() &&
5959     TypeKlassPtr::eq(p);
5960 }
5961 
5962 int TypeInstKlassPtr::hash(void) const {
5963   return java_add(java_add((jint)klass()->hash(), TypeKlassPtr::hash()), (jint)flatten_array());
5964 }
5965 
5966 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, bool flatten_array) {
5967   flatten_array = flatten_array || k->flatten_array();
5968 
5969   TypeInstKlassPtr *r =
5970     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, offset, flatten_array))->hashcons();
5971 
5972   return r;
5973 }
5974 
5975 //------------------------------add_offset-------------------------------------
5976 // Access internals of klass object
5977 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5978   return make(_ptr, klass(), xadd_offset(offset), flatten_array());
5979 }
5980 
5981 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5982   return make(_ptr, klass(), Offset(offset), flatten_array());
5983 }
5984 
5985 //------------------------------cast_to_ptr_type-------------------------------
5986 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5987   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5988   if( ptr == _ptr ) return this;
5989   return make(ptr, _klass, _offset, flatten_array());
5990 }
5991 
5992 
5993 bool TypeInstKlassPtr::must_be_exact() const {
5994   if (!_klass->is_loaded())  return false;
5995   ciInstanceKlass* ik = _klass->as_instance_klass();
5996   if (ik->is_final())  return true;  // cannot clear xk
5997   return false;
5998 }
5999 
6000 //-----------------------------cast_to_exactness-------------------------------
6001 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6002   if (klass_is_exact == (_ptr == Constant)) return this;
6003   if (must_be_exact()) return this;
6004   ciKlass* k = klass();
6005   return make(klass_is_exact ? Constant : NotNull, k, _offset, flatten_array());
6006 }
6007 
6008 
6009 //-----------------------------as_instance_type--------------------------------
6010 // Corresponding type for an instance of the given class.
6011 // It will be NotNull, and exact if and only if the klass type is exact.
6012 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6013   ciKlass* k = klass();
6014   bool xk = klass_is_exact();
6015   Compile* C = Compile::current();
6016   Dependencies* deps = C->dependencies();
6017   assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
6018   // Element is an instance
6019   bool klass_is_exact = false;
6020   if (k->is_loaded()) {
6021     // Try to set klass_is_exact.
6022     ciInstanceKlass* ik = k->as_instance_klass();
6023     klass_is_exact = ik->is_final();
6024     if (!klass_is_exact && klass_change
6025         && deps != NULL && UseUniqueSubclasses) {
6026       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6027       if (sub != NULL) {
6028         deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6029         k = ik = sub;
6030         xk = sub->is_final();
6031       }
6032     }
6033   }
6034   return TypeInstPtr::make(TypePtr::BotPTR, k, xk, NULL, Offset(0), flatten_array() && !klass()->is_inlinetype());
6035 }
6036 
6037 //------------------------------xmeet------------------------------------------
6038 // Compute the MEET of two types, return a new Type object.
6039 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6040   // Perform a fast test for common case; meeting the same types together.
6041   if( this == t ) return this;  // Meeting same type-rep?
6042 
6043   // Current "this->_base" is Pointer
6044   switch (t->base()) {          // switch on original type
6045 
6046   case Int:                     // Mixing ints & oops happens when javac
6047   case Long:                    // reuses local variables
6048   case FloatTop:
6049   case FloatCon:
6050   case FloatBot:
6051   case DoubleTop:
6052   case DoubleCon:
6053   case DoubleBot:
6054   case NarrowOop:
6055   case NarrowKlass:
6056   case Bottom:                  // Ye Olde Default
6057     return Type::BOTTOM;
6058   case Top:
6059     return this;
6060 
6061   default:                      // All else is a mistake
6062     typerr(t);
6063 
6064   case AnyPtr: {                // Meeting to AnyPtrs
6065     // Found an AnyPtr type vs self-KlassPtr type
6066     const TypePtr *tp = t->is_ptr();
6067     Offset offset = meet_offset(tp->offset());
6068     PTR ptr = meet_ptr(tp->ptr());
6069     switch (tp->ptr()) {
6070     case TopPTR:
6071       return this;
6072     case Null:
6073       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6074     case AnyNull:
6075       return make(ptr, klass(), offset, flatten_array());
6076     case BotPTR:
6077     case NotNull:
6078       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6079     default: typerr(t);
6080     }
6081   }
6082 
6083   case RawPtr:
6084   case MetadataPtr:
6085   case OopPtr:
6086   case AryPtr:                  // Meet with AryPtr
6087   case InstPtr:                 // Meet with InstPtr
6088       return TypePtr::BOTTOM;
6089 
6090   //
6091   //             A-top         }
6092   //           /   |   \       }  Tops
6093   //       B-top A-any C-top   }
6094   //          | /  |  \ |      }  Any-nulls
6095   //       B-any   |   C-any   }
6096   //          |    |    |
6097   //       B-con A-con C-con   } constants; not comparable across classes
6098   //          |    |    |
6099   //       B-not   |   C-not   }
6100   //          | \  |  / |      }  not-nulls
6101   //       B-bot A-not C-bot   }
6102   //           \   |   /       }  Bottoms
6103   //             A-bot         }
6104   //
6105 
6106   case InstKlassPtr: {  // Meet two KlassPtr types
6107     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6108     Offset  off     = meet_offset(tkls->offset());
6109     PTR  ptr     = meet_ptr(tkls->ptr());
6110     ciKlass* tkls_klass = tkls->klass();
6111     ciKlass* this_klass  = klass();
6112     bool tkls_xk = tkls->klass_is_exact();
6113     bool this_xk  = klass_is_exact();
6114     bool tkls_flatten_array = tkls->flatten_array();
6115     bool this_flatten_array  = this->flatten_array();
6116 
6117     ciKlass* res_klass = NULL;
6118     bool res_xk = false;
6119     bool res_flatten_array = false;
6120     switch(meet_instptr(ptr, this_klass, tkls_klass, this_xk, tkls_xk, this->_ptr, tkls->_ptr,
6121                         this_flatten_array, tkls_flatten_array, res_klass, res_xk, res_flatten_array)) {
6122       case UNLOADED:
6123         ShouldNotReachHere();
6124       case SUBTYPE:
6125       case NOT_SUBTYPE:
6126       case LCA:
6127       case QUICK: {
6128         assert(res_xk == (ptr == Constant), "");
6129         const Type* res1 = make(ptr, res_klass, off, res_flatten_array);
6130         return res1;
6131       }
6132       default:
6133         ShouldNotReachHere();
6134     }
6135   } // End of case KlassPtr
6136   case AryKlassPtr: {                // All arrays inherit from Object class
6137     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6138     Offset offset = meet_offset(tp->offset());
6139     PTR ptr = meet_ptr(tp->ptr());
6140 
6141     switch (ptr) {
6142     case TopPTR:
6143     case AnyNull:                // Fall 'down' to dual of object klass
6144       // For instances when a subclass meets a superclass we fall
6145       // below the centerline when the superclass is exact. We need to
6146       // do the same here.
6147       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
6148         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6149       } else {
6150         // cannot subclass, so the meet has to fall badly below the centerline
6151         ptr = NotNull;
6152         return make(ptr, ciEnv::current()->Object_klass(), offset, false);
6153       }
6154     case Constant:
6155     case NotNull:
6156     case BotPTR:                // Fall down to object klass
6157       // LCA is object_klass, but if we subclass from the top we can do better
6158       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6159         // If 'this' (InstPtr) is above the centerline and it is Object class
6160         // then we can subclass in the Java class hierarchy.
6161         // For instances when a subclass meets a superclass we fall
6162         // below the centerline when the superclass is exact. We need
6163         // to do the same here.
6164         if (klass()->equals(ciEnv::current()->Object_klass())) {
6165           // that is, tp's array type is a subtype of my klass
6166           return TypeAryKlassPtr::make(ptr,
6167                                        tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6168         }
6169       }
6170       // The other case cannot happen, since I cannot be a subtype of an array.
6171       // The meet falls down to Object class below centerline.
6172       if( ptr == Constant )
6173          ptr = NotNull;
6174       return make(ptr, ciEnv::current()->Object_klass(), offset, false);
6175     default: typerr(t);
6176     }
6177   }
6178   case InlineType: {
6179     const TypeInlineType* tv = t->is_inlinetype();
6180     if (above_centerline(ptr())) {
6181       if (tv->inline_klass()->is_subtype_of(_klass)) {
6182         return t;
6183       } else {
6184         return TypeInstPtr::NOTNULL;
6185       }
6186     } else {
6187       PTR ptr = this->_ptr;
6188       if (ptr == Constant) {
6189         ptr = NotNull;
6190       }
6191       if (tv->inline_klass()->is_subtype_of(_klass)) {
6192         return make(ptr, _klass, Offset(0), _flatten_array);
6193       } else {
6194         return make(ptr, ciEnv::current()->Object_klass(), Offset(0));
6195       }
6196     }
6197   }
6198 
6199   } // End of switch
6200   return this;                  // Return the double constant
6201 }
6202 
6203 //------------------------------xdual------------------------------------------
6204 // Dual: compute field-by-field dual
6205 const Type    *TypeInstKlassPtr::xdual() const {
6206   return new TypeInstKlassPtr(dual_ptr(), klass(), dual_offset(), flatten_array());
6207 }
6208 
6209 bool TypeInstKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6210   if (!is_loaded() || !other->is_loaded()) {
6211     return false;
6212   }
6213   if (!other->isa_instklassptr()) {
6214     return false;
6215   }
6216 
6217   if (!other_exact) {
6218     return false;
6219   }
6220 
6221   if (other->_klass->equals(ciEnv::current()->Object_klass())) {
6222     return true;
6223   }
6224 
6225   if (!this_exact && klass()->is_interface()) {
6226     return false;

6252     return true;
6253   }
6254 
6255   assert(other->isa_instklassptr(), "unsupported");
6256 
6257   if (this_exact && other_exact) {
6258     return is_java_subtype_of(other);
6259   }
6260 
6261   if (!_klass->is_subtype_of(other->_klass) && !other->_klass->is_subtype_of(_klass)) {
6262     return false;
6263   }
6264 
6265   if (this_exact) {
6266     return _klass->is_subtype_of(other->_klass);
6267   }
6268 
6269   return true;
6270 }
6271 
6272 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
6273   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, null_free))->hashcons();
6274 }
6275 
6276 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
6277   if (klass->is_obj_array_klass()) {
6278     // Element is an object array. Recursively call ourself.
6279     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
6280     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass)->cast_to_exactness(false);
6281 
6282     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
6283     if (etype->klass_is_exact() && etype->isa_instklassptr() && etype->is_instklassptr()->klass()->is_inlinetype() && !null_free) {
6284       etype = TypeInstKlassPtr::make(NotNull, etype->is_instklassptr()->klass(), Offset(etype->is_instklassptr()->offset()), etype->is_instklassptr()->flatten_array());
6285     }
6286 
6287     const TypeAryKlassPtr* res = TypeAryKlassPtr::make(ptr, etype, NULL, offset, not_flat, not_null_free, null_free);
6288     assert(res->klass() == klass, "");
6289     return res;
6290   } else if (klass->is_type_array_klass()) {
6291     // Element is an typeArray
6292     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
6293     return TypeAryKlassPtr::make(ptr, etype, klass, offset, not_flat, not_null_free, null_free);
6294   } else if (klass->is_flat_array_klass()) {
6295     ciKlass* eklass = klass->as_flat_array_klass()->element_klass();
6296     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass);
6297     return TypeAryKlassPtr::make(ptr, etype, klass, offset, not_flat, not_null_free, null_free);
6298   } else {
6299     ShouldNotReachHere();
6300     return NULL;
6301   }
6302 }
6303 
6304 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset) {
6305   bool null_free = k->as_array_klass()->is_elem_null_free();
6306   bool not_null_free = (ptr == Constant) ? !null_free : !k->is_flat_array_klass() && (k->is_type_array_klass() || !k->as_array_klass()->element_klass()->can_be_inline_klass(false));
6307 
6308   bool not_flat = !UseFlatArray || not_null_free || (k->as_array_klass()->element_klass() != NULL &&
6309                                                      k->as_array_klass()->element_klass()->is_inlinetype() &&
6310                                                      !k->as_array_klass()->element_klass()->flatten_array());
6311 
6312   return TypeAryKlassPtr::make(ptr, k, offset, not_flat, not_null_free, null_free);
6313 }
6314 
6315 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass) {
6316   return TypeAryKlassPtr::make(Constant, klass, Offset(0));
6317 }
6318 
6319 //------------------------------eq---------------------------------------------
6320 // Structural equality check for Type representations
6321 bool TypeAryKlassPtr::eq(const Type *t) const {
6322   const TypeAryKlassPtr *p = t->is_aryklassptr();
6323   return
6324     _elem == p->_elem &&  // Check array
6325     _not_flat == p->_not_flat &&
6326     _not_null_free == p->_not_null_free &&
6327     _null_free == p->_null_free &&
6328     TypeKlassPtr::eq(p);  // Check sub-parts
6329 }
6330 
6331 //------------------------------hash-------------------------------------------
6332 // Type-specific hashing function.
6333 int TypeAryKlassPtr::hash(void) const {
6334   return (intptr_t)_elem + TypeKlassPtr::hash();
6335 }
6336 
6337 //----------------------compute_klass------------------------------------------
6338 // Compute the defining klass for this class
6339 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
6340   // Compute _klass based on element type.
6341   ciKlass* k_ary = NULL;

6342   const TypeAryPtr *tary;
6343   const Type* el = elem();
6344   if (el->isa_narrowoop()) {
6345     el = el->make_ptr();
6346   }
6347 
6348   // Get element klass
6349   if (el->isa_instptr()) {
6350     // Compute object array klass from element klass
6351     bool null_free = el->is_inlinetypeptr() && el->isa_instptr()->ptr() != TypePtr::TopPTR && !el->isa_instptr()->maybe_null();
6352     k_ary = ciArrayKlass::make(el->is_oopptr()->klass(), null_free);
6353   } else if (el->isa_inlinetype()) {
6354     // If element type is TypeInlineType::BOTTOM, inline_klass() will be null.
6355     if (el->inline_klass() != NULL) {
6356       k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6357     }
6358   } else if ((tary = el->isa_aryptr()) != NULL) {
6359     // Compute array klass from element klass
6360     ciKlass* k_elem = tary->klass();
6361     // If element type is something like bottom[], k_elem will be null.
6362     if (k_elem != NULL)
6363       k_ary = ciObjArrayKlass::make(k_elem);
6364   } else if ((el->base() == Type::Top) ||
6365              (el->base() == Type::Bottom)) {
6366     // element type of Bottom occurs from meet of basic type
6367     // and object; Top occurs when doing join on Bottom.
6368     // Leave k_ary at NULL.
6369   } else {
6370     // Cannot compute array klass directly from basic type,
6371     // since subtypes of TypeInt all have basic type T_INT.
6372 #ifdef ASSERT
6373     if (verify && el->isa_int()) {
6374       // Check simple cases when verifying klass.
6375       BasicType bt = T_ILLEGAL;
6376       if (el == TypeInt::BYTE) {
6377         bt = T_BYTE;

6402 
6403   // Oops, need to compute _klass and cache it
6404   ciKlass* k_ary = compute_klass();
6405 
6406   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6407     // The _klass field acts as a cache of the underlying
6408     // ciKlass for this array type.  In order to set the field,
6409     // we need to cast away const-ness.
6410     //
6411     // IMPORTANT NOTE: we *never* set the _klass field for the
6412     // type TypeAryPtr::OOPS.  This Type is shared between all
6413     // active compilations.  However, the ciKlass which represents
6414     // this Type is *not* shared between compilations, so caching
6415     // this value would result in fetching a dangling pointer.
6416     //
6417     // Recomputing the underlying ciKlass for each request is
6418     // a bit less efficient than caching, but calls to
6419     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6420     ((TypeAryPtr*)this)->_klass = k_ary;
6421     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
6422         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes() &&
6423         offset() != arrayOopDesc::klass_offset_in_bytes()) {
6424       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
6425     }
6426   }
6427   return k_ary;
6428 }
6429 
6430 ciKlass* TypeAryPtr::exact_klass_helper() const {
6431   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6432     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6433     if (k == NULL) {
6434       return NULL;
6435     }
6436     k = ciArrayKlass::make(k, is_null_free());
6437     return k;
6438   }
6439 
6440   return klass();
6441 }
6442 
6443 const Type* TypeAryPtr::base_element_type(int& dims) const {
6444   const Type* elem = this->elem();
6445   dims = 1;
6446   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6447     elem = elem->make_ptr()->is_aryptr()->elem();
6448     dims++;
6449   }
6450   return elem;
6451 }
6452 
6453 //------------------------------add_offset-------------------------------------
6454 // Access internals of klass object
6455 const TypePtr *TypeAryKlassPtr::add_offset(intptr_t offset) const {
6456   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6457 }
6458 
6459 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6460   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6461 }
6462 
6463 //------------------------------cast_to_ptr_type-------------------------------
6464 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6465   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6466   if (ptr == _ptr) return this;
6467   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6468 }
6469 
6470 bool TypeAryKlassPtr::must_be_exact() const {
6471   if (_elem == Type::BOTTOM) return false;
6472   if (_elem == Type::TOP   ) return false;
6473   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6474   if (!tk)             return true;   // a primitive type, like int
6475   return tk->must_be_exact();
6476 }
6477 
6478 
6479 //-----------------------------cast_to_exactness-------------------------------
6480 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6481   if (must_be_exact() && !klass_is_exact) return this;  // cannot clear xk
6482   ciKlass* k = _klass;
6483   const Type* elem = this->elem();
6484   if (elem->isa_klassptr() && !klass_is_exact) {
6485     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6486   }
6487   bool not_flat = is_not_flat();
6488   bool not_null_free = is_not_null_free();
6489   if (k != NULL && k->is_obj_array_klass()) {
6490     if (klass_is_exact) {
6491       // An object array can't be flat or null-free if the klass is exact
6492       not_flat = true;
6493       not_null_free = true;
6494     } else {
6495       // Klass is not exact (anymore), re-compute null-free/flat properties
6496       const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(k->as_array_klass()->element_klass());
6497       not_null_free = !exact_etype->can_be_inline_type();
6498       not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flatten_array());
6499     }
6500   }
6501   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6502 }
6503 
6504 
6505 //-----------------------------as_instance_type--------------------------------
6506 // Corresponding type for an instance of the given class.
6507 // It will be NotNull, and exact if and only if the klass type is exact.
6508 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6509   ciKlass* k = klass();
6510   assert(k != NULL, "klass should not be NULL");
6511   bool    xk = klass_is_exact();
6512   const Type* el = NULL;
6513   if (elem()->isa_klassptr()) {
6514     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6515     k = NULL;
6516   } else {
6517     el = elem();
6518   }
6519   bool null_free = _null_free;
6520   if (null_free && el->isa_ptr()) {
6521     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6522   }
6523   bool not_flat = is_not_flat();
6524   bool not_null_free = is_not_null_free();
6525   if (is_flat()) {
6526     el = TypeInlineType::make(el->inline_klass());
6527   }
6528   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, not_flat, not_null_free), k, xk, Offset(0));
6529 }
6530 
6531 
6532 //------------------------------xmeet------------------------------------------
6533 // Compute the MEET of two types, return a new Type object.
6534 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6535   // Perform a fast test for common case; meeting the same types together.
6536   if( this == t ) return this;  // Meeting same type-rep?
6537 
6538   // Current "this->_base" is Pointer
6539   switch (t->base()) {          // switch on original type
6540 
6541   case Int:                     // Mixing ints & oops happens when javac
6542   case Long:                    // reuses local variables
6543   case FloatTop:
6544   case FloatCon:
6545   case FloatBot:
6546   case DoubleTop:
6547   case DoubleCon:
6548   case DoubleBot:
6549   case NarrowOop:
6550   case NarrowKlass:
6551   case Bottom:                  // Ye Olde Default
6552     return Type::BOTTOM;
6553   case Top:
6554     return this;
6555 
6556   default:                      // All else is a mistake
6557     typerr(t);
6558 
6559   case AnyPtr: {                // Meeting to AnyPtrs
6560     // Found an AnyPtr type vs self-KlassPtr type
6561     const TypePtr *tp = t->is_ptr();
6562     Offset offset = meet_offset(tp->offset());
6563     PTR ptr = meet_ptr(tp->ptr());
6564     switch (tp->ptr()) {
6565     case TopPTR:
6566       return this;
6567     case Null:
6568       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6569     case AnyNull:
6570       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), _null_free);
6571     case BotPTR:
6572     case NotNull:
6573       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6574     default: typerr(t);
6575     }
6576   }
6577 
6578   case RawPtr:
6579   case MetadataPtr:
6580   case OopPtr:
6581   case AryPtr:                  // Meet with AryPtr
6582   case InstPtr:                 // Meet with InstPtr
6583     return TypePtr::BOTTOM;
6584 
6585   //
6586   //             A-top         }
6587   //           /   |   \       }  Tops
6588   //       B-top A-any C-top   }
6589   //          | /  |  \ |      }  Any-nulls
6590   //       B-any   |   C-any   }
6591   //          |    |    |
6592   //       B-con A-con C-con   } constants; not comparable across classes
6593   //          |    |    |
6594   //       B-not   |   C-not   }
6595   //          | \  |  / |      }  not-nulls
6596   //       B-bot A-not C-bot   }
6597   //           \   |   /       }  Bottoms
6598   //             A-bot         }
6599   //
6600 
6601   case AryKlassPtr: {  // Meet two KlassPtr types
6602     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6603     Offset off = meet_offset(tap->offset());
6604     const Type* res_elem = NULL;

6605     PTR ptr = meet_ptr(tap->ptr());
6606     ciKlass* res_klass = NULL;
6607     bool res_xk = false;
6608     bool res_not_flat = false;
6609     bool res_not_null_free = false;
6610     MeetResult res = meet_aryptr(ptr, _elem, tap->_elem, this->klass(), tap->klass(),
6611                                  this->klass_is_exact(), tap->klass_is_exact(),
6612                                  this->ptr(), tap->ptr(), this->is_not_flat(), tap->is_not_flat(),
6613                                  this->is_not_null_free(), tap->is_not_null_free(),
6614                                  res_elem, res_klass, res_xk, res_not_flat, res_not_null_free);
6615     assert(res_xk == (ptr == Constant), "");
6616     bool null_free = meet_null_free(tap->_null_free);
6617     if (res == NOT_SUBTYPE) {
6618       null_free = false;
6619     } else if (res == SUBTYPE) {
6620       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6621         null_free = _null_free;
6622       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6623         null_free = tap->_null_free;
6624       }
6625     }
6626     return make(ptr, res_elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
6627   } // End of case KlassPtr
6628   case InstKlassPtr: {
6629     const TypeInstKlassPtr *tp = t->is_instklassptr();
6630     Offset offset = meet_offset(tp->offset());
6631     PTR ptr = meet_ptr(tp->ptr());
6632 
6633     switch (ptr) {
6634     case TopPTR:
6635     case AnyNull:                // Fall 'down' to dual of object klass
6636       // For instances when a subclass meets a superclass we fall
6637       // below the centerline when the superclass is exact. We need to
6638       // do the same here.
6639       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6640         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), _null_free);
6641       } else {
6642         // cannot subclass, so the meet has to fall badly below the centerline
6643         ptr = NotNull;
6644         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset, false);
6645       }
6646     case Constant:
6647     case NotNull:
6648     case BotPTR:                // Fall down to object klass
6649       // LCA is object_klass, but if we subclass from the top we can do better
6650       if (above_centerline(tp->ptr())) {
6651         // If 'tp'  is above the centerline and it is Object class
6652         // then we can subclass in the Java class hierarchy.
6653         // For instances when a subclass meets a superclass we fall
6654         // below the centerline when the superclass is exact. We need
6655         // to do the same here.
6656         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6657           // that is, my array type is a subtype of 'tp' klass
6658           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), _null_free);
6659         }
6660       }
6661       // The other case cannot happen, since t cannot be a subtype of an array.
6662       // The meet falls down to Object class below centerline.
6663       if (ptr == Constant)
6664          ptr = NotNull;
6665       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset, false);
6666     default: typerr(t);
6667     }
6668   }
6669   case InlineType: {
6670     const TypeInlineType* tv = t->is_inlinetype();
6671     if (above_centerline(ptr())) {
6672       return TypeInstKlassPtr::BOTTOM;
6673     } else {
6674       PTR ptr = this->_ptr;
6675       if (ptr == Constant) {
6676         ptr = NotNull;
6677       }
6678       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), Offset(0));
6679     }
6680   }
6681 
6682   } // End of switch
6683   return this;                  // Return the double constant
6684 }
6685 
6686 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6687   if (other->klass() == ciEnv::current()->Object_klass() && other_exact) {
6688     return true;
6689   }
6690 
6691   if (!is_loaded() || !other->is_loaded() || other->klass() == NULL || klass() == NULL) {
6692     return false;
6693   }
6694   if (other->isa_instklassptr()) {
6695     return _klass->is_subtype_of(other->_klass) && other_exact;
6696   }
6697   if (klass() == NULL) {
6698     return false;
6699   }
6700   assert(other->isa_aryklassptr(), "");
6701   const TypeAryKlassPtr* other_ary = other->isa_aryklassptr();
6702   if (other_ary->_elem->isa_klassptr() && _elem->isa_klassptr()) {
6703     if (other->is_null_free() && !is_null_free()) {
6704       return false; // [LMyValue is not a subtype of [QMyValue
6705     }
6706     return _elem->is_klassptr()->is_java_subtype_of_helper(other_ary->_elem->is_klassptr(), this_exact, other_exact);
6707   }
6708   if (!other_ary->_elem->isa_klassptr() && !_elem->isa_klassptr()) {
6709     return _klass->is_subtype_of(other->_klass);
6710   }
6711   return false;
6712 }
6713 
6714 bool TypeAryKlassPtr::is_same_java_type_as(const TypeKlassPtr* other) const {
6715   if (!other->isa_aryklassptr() ||
6716       !is_loaded() || !other->is_loaded() || klass() == NULL || other->klass() == NULL) {
6717     return false;
6718   }
6719   const TypeAryKlassPtr* other_ary = other->isa_aryklassptr();
6720   if (other_ary->_elem->isa_klassptr() && _elem->isa_klassptr()) {
6721     return _elem->is_klassptr()->is_same_java_type_as(other_ary->_elem->is_klassptr());
6722   }
6723   if (!other_ary->_elem->isa_klassptr() && !_elem->isa_klassptr()) {
6724     return _klass->equals(other->_klass);
6725   }

6738   }
6739   assert(other->isa_aryklassptr(), "");
6740 
6741   if (this_exact && other_exact) {
6742     return is_java_subtype_of(other);
6743   }
6744 
6745   const TypeAryKlassPtr* other_ary = other->isa_aryklassptr();
6746   if (other_ary->_elem->isa_klassptr() && _elem->isa_klassptr()) {
6747     return _elem->is_klassptr()->maybe_java_subtype_of_helper(other_ary->_elem->is_klassptr(), this_exact, other_exact);
6748   }
6749   if (!other_ary->_elem->isa_klassptr() && !_elem->isa_klassptr()) {
6750     return _klass->is_subtype_of(other->_klass);
6751   }
6752   return false;
6753 }
6754 
6755 //------------------------------xdual------------------------------------------
6756 // Dual: compute field-by-field dual
6757 const Type    *TypeAryKlassPtr::xdual() const {
6758   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
6759 }
6760 
6761 //------------------------------get_con----------------------------------------
6762 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6763   if (elem()->isa_klassptr()) {
6764     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6765     if (k == NULL) {
6766       return NULL;
6767     }
6768     k = ciArrayKlass::make(k, _null_free);
6769     return k;
6770   }
6771 
6772   return klass();
6773 }
6774 
6775 ciKlass* TypeAryKlassPtr::klass() const {
6776   if (_klass != NULL) {
6777     return _klass;
6778   }
6779   ciKlass* k = NULL;
6780   const Type* el = elem();
6781   if (el->isa_instklassptr()) {
6782     // Compute object array klass from element klass
6783     bool null_free = el->is_instklassptr()->klass()->is_inlinetype() && el->isa_instklassptr()->ptr() != TypePtr::TopPTR && (_null_free != 0);
6784     k = ciArrayKlass::make(el->is_klassptr()->klass(), null_free);
6785     ((TypeAryKlassPtr*)this)->_klass = k;
6786   } else if (el->isa_inlinetype()) {
6787     // If element type is TypeInlineType::BOTTOM, inline_klass() will be null.
6788     if (el->inline_klass() != NULL) {
6789       k = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6790       ((TypeAryKlassPtr*)this)->_klass = k;
6791     }
6792   } else if (el->isa_aryklassptr() != NULL) {
6793     // Compute array klass from element klass
6794     ciKlass* k_elem = el->is_aryklassptr()->klass();
6795     // If element type is something like bottom[], k_elem will be null.
6796     if (k_elem != NULL) {
6797       k = ciObjArrayKlass::make(k_elem);
6798       ((TypeAryKlassPtr*)this)->_klass = k;
6799     }
6800   } else if ((elem()->base() == Type::Top) ||
6801              (elem()->base() == Type::Bottom)) {
6802   } else {
6803     k = ciTypeArrayKlass::make(elem()->basic_type());
6804   }
6805   return k;
6806 }
6807 
6808 //------------------------------dump2------------------------------------------
6809 // Dump Klass Type
6810 #ifndef PRODUCT
6811 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6812   switch( _ptr ) {
6813   case Constant:
6814     st->print("precise ");
6815   case NotNull:
6816     {
6817       st->print("[");
6818       if (_elem->isa_inlinetype()) {
6819         const char *name = _elem->is_inlinetype()->inline_klass()->name()->as_utf8();
6820         st->print("precise %s: " INTPTR_FORMAT " ", name, p2i(klass()));
6821       }
6822       _elem->dump2(d, depth, st);
6823       st->print(": ");
6824     }
6825   case BotPTR:
6826     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6827   case TopPTR:
6828   case AnyNull:
6829     st->print(":%s", ptr_msg[_ptr]);
6830     if( _ptr == Constant ) st->print(":exact");
6831     break;
6832   default:
6833     break;
6834   }
6835   if (Verbose) {
6836     if (is_flat()) st->print(":flat");
6837     if (_not_flat) st->print(":not flat");
6838     if (_not_null_free) st->print(":not null free");
6839     if (_null_free) st->print(":null free");
6840   }
6841 
6842   _offset.dump2(st);
6843 
6844   st->print(" *");
6845 }
6846 #endif
6847 
6848 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6849   const Type* elem = this->elem();
6850   dims = 1;
6851   while (elem->isa_aryklassptr()) {
6852     elem = elem->is_aryklassptr()->elem();
6853     dims++;
6854   }
6855   return elem;
6856 }
6857 
6858 //=============================================================================
6859 // Convenience common pre-built types.
6860 
6861 //------------------------------make-------------------------------------------
6862 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
6863                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
6864   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
6865 }
6866 
6867 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
6868   return make(domain, domain, range, range);
6869 }
6870 
6871 //------------------------------osr_domain-----------------------------
6872 const TypeTuple* osr_domain() {
6873   const Type **fields = TypeTuple::fields(2);
6874   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
6875   return TypeTuple::make(TypeFunc::Parms+1, fields);
6876 }
6877 
6878 //------------------------------make-------------------------------------------
6879 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
6880   Compile* C = Compile::current();
6881   const TypeFunc* tf = NULL;
6882   if (!is_osr_compilation) {
6883     tf = C->last_tf(method); // check cache
6884     if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
6885   }
6886   // Inline types are not passed/returned by reference, instead each field of
6887   // the inline type is passed/returned as an argument. We maintain two views of
6888   // the argument/return list here: one based on the signature (with an inline
6889   // type argument/return as a single slot), one based on the actual calling
6890   // convention (with an inline type argument/return as a list of its fields).
6891   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
6892   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, false);
6893   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, true) : domain_sig;
6894   ciSignature* sig = method->signature();
6895   bool has_scalar_ret = sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
6896   const TypeTuple* range_sig = TypeTuple::make_range(sig, false);
6897   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, true) : range_sig;
6898   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
6899   if (!is_osr_compilation) {
6900     C->set_last_tf(method, tf);  // fill cache
6901   }



6902   return tf;
6903 }
6904 
6905 //------------------------------meet-------------------------------------------
6906 // Compute the MEET of two types.  It returns a new Type object.
6907 const Type *TypeFunc::xmeet( const Type *t ) const {
6908   // Perform a fast test for common case; meeting the same types together.
6909   if( this == t ) return this;  // Meeting same type-rep?
6910 
6911   // Current "this->_base" is Func
6912   switch (t->base()) {          // switch on original type
6913 
6914   case Bottom:                  // Ye Olde Default
6915     return t;
6916 
6917   default:                      // All else is a mistake
6918     typerr(t);
6919 
6920   case Top:
6921     break;
6922   }
6923   return this;                  // Return the double constant
6924 }
6925 
6926 //------------------------------xdual------------------------------------------
6927 // Dual: compute field-by-field dual
6928 const Type *TypeFunc::xdual() const {
6929   return this;
6930 }
6931 
6932 //------------------------------eq---------------------------------------------
6933 // Structural equality check for Type representations
6934 bool TypeFunc::eq( const Type *t ) const {
6935   const TypeFunc *a = (const TypeFunc*)t;
6936   return _domain_sig == a->_domain_sig &&
6937     _domain_cc == a->_domain_cc &&
6938     _range_sig == a->_range_sig &&
6939     _range_cc == a->_range_cc;
6940 }
6941 
6942 //------------------------------hash-------------------------------------------
6943 // Type-specific hashing function.
6944 int TypeFunc::hash(void) const {
6945   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
6946 }
6947 
6948 //------------------------------dump2------------------------------------------
6949 // Dump Function Type
6950 #ifndef PRODUCT
6951 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6952   if( _range_sig->cnt() <= Parms )
6953     st->print("void");
6954   else {
6955     uint i;
6956     for (i = Parms; i < _range_sig->cnt()-1; i++) {
6957       _range_sig->field_at(i)->dump2(d,depth,st);
6958       st->print("/");
6959     }
6960     _range_sig->field_at(i)->dump2(d,depth,st);
6961   }
6962   st->print(" ");
6963   st->print("( ");
6964   if( !depth || d[this] ) {     // Check for recursive dump
6965     st->print("...)");
6966     return;
6967   }
6968   d.Insert((void*)this,(void*)this);    // Stop recursion
6969   if (Parms < _domain_sig->cnt())
6970     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
6971   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
6972     st->print(", ");
6973     _domain_sig->field_at(i)->dump2(d,depth-1,st);
6974   }
6975   st->print(" )");
6976 }
6977 #endif
6978 
6979 //------------------------------singleton--------------------------------------
6980 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6981 // constants (Ldi nodes).  Singletons are integer, float or double constants
6982 // or a single symbol.
6983 bool TypeFunc::singleton(void) const {
6984   return false;                 // Never a singleton
6985 }
6986 
6987 bool TypeFunc::empty(void) const {
6988   return false;                 // Never empty
6989 }
6990 
6991 
6992 BasicType TypeFunc::return_type() const{
6993   if (range_sig()->cnt() == TypeFunc::Parms) {
6994     return T_VOID;
6995   }
6996   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
6997 }
< prev index next >