< 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;

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

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

1476   // Currently "this->_base" is a TypeInt
1477   switch (t->base()) {          // Switch on original type
1478   case AnyPtr:                  // Mixing with oops happens when javac
1479   case RawPtr:                  // reuses local variables
1480   case OopPtr:
1481   case InstPtr:
1482   case AryPtr:
1483   case MetadataPtr:
1484   case KlassPtr:
1485   case InstKlassPtr:
1486   case AryKlassPtr:
1487   case NarrowOop:
1488   case NarrowKlass:
1489   case Long:
1490   case FloatTop:
1491   case FloatCon:
1492   case FloatBot:
1493   case DoubleTop:
1494   case DoubleCon:
1495   case DoubleBot:

1496   case Bottom:                  // Ye Olde Default
1497     return Type::BOTTOM;
1498   default:                      // All else is a mistake
1499     typerr(t);
1500   case Top:                     // No change
1501     return this;
1502   case Int:                     // Int vs Int?
1503     break;
1504   }
1505 
1506   // Expand covered set
1507   const TypeInt *r = t->is_int();
1508   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1509 }
1510 
1511 //------------------------------xdual------------------------------------------
1512 // Dual: reverse hi & lo; flip widen
1513 const Type *TypeInt::xdual() const {
1514   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1515   return new TypeInt(_hi,_lo,w);

1963 
1964 bool TypeLong::empty(void) const {
1965   return _lo > _hi;
1966 }
1967 
1968 //=============================================================================
1969 // Convenience common pre-built types.
1970 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1971 const TypeTuple *TypeTuple::IFFALSE;
1972 const TypeTuple *TypeTuple::IFTRUE;
1973 const TypeTuple *TypeTuple::IFNEITHER;
1974 const TypeTuple *TypeTuple::LOOPBODY;
1975 const TypeTuple *TypeTuple::MEMBAR;
1976 const TypeTuple *TypeTuple::STORECONDITIONAL;
1977 const TypeTuple *TypeTuple::START_I2C;
1978 const TypeTuple *TypeTuple::INT_PAIR;
1979 const TypeTuple *TypeTuple::LONG_PAIR;
1980 const TypeTuple *TypeTuple::INT_CC_PAIR;
1981 const TypeTuple *TypeTuple::LONG_CC_PAIR;
1982 












1983 //------------------------------make-------------------------------------------
1984 // Make a TypeTuple from the range of a method signature
1985 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
1986   ciType* return_type = sig->return_type();
1987   uint arg_cnt = return_type->size();




1988   const Type **field_array = fields(arg_cnt);
1989   switch (return_type->basic_type()) {
1990   case T_LONG:
1991     field_array[TypeFunc::Parms]   = TypeLong::LONG;
1992     field_array[TypeFunc::Parms+1] = Type::HALF;
1993     break;
1994   case T_DOUBLE:
1995     field_array[TypeFunc::Parms]   = Type::DOUBLE;
1996     field_array[TypeFunc::Parms+1] = Type::HALF;
1997     break;
1998   case T_OBJECT:
1999   case T_ARRAY:
2000   case T_BOOLEAN:
2001   case T_CHAR:
2002   case T_FLOAT:
2003   case T_BYTE:
2004   case T_SHORT:
2005   case T_INT:
2006     field_array[TypeFunc::Parms] = get_const_type(return_type);
2007     break;









2008   case T_VOID:
2009     break;
2010   default:
2011     ShouldNotReachHere();
2012   }
2013   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2014 }
2015 
2016 // Make a TypeTuple from the domain of a method signature
2017 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
2018   uint arg_cnt = sig->size();







2019 
2020   uint pos = TypeFunc::Parms;
2021   const Type **field_array;
2022   if (recv != NULL) {
2023     arg_cnt++;
2024     field_array = fields(arg_cnt);
2025     // Use get_const_type here because it respects UseUniqueSubclasses:
2026     field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2027   } else {
2028     field_array = fields(arg_cnt);
2029   }
2030 
2031   int i = 0;
2032   while (pos < TypeFunc::Parms + arg_cnt) {
2033     ciType* type = sig->type_at(i);

2034 
2035     switch (type->basic_type()) {
2036     case T_LONG:
2037       field_array[pos++] = TypeLong::LONG;
2038       field_array[pos++] = Type::HALF;
2039       break;
2040     case T_DOUBLE:
2041       field_array[pos++] = Type::DOUBLE;
2042       field_array[pos++] = Type::HALF;
2043       break;
2044     case T_OBJECT:
2045     case T_ARRAY:
2046     case T_FLOAT:
2047     case T_INT:
2048       field_array[pos++] = get_const_type(type);
2049       break;
2050     case T_BOOLEAN:
2051     case T_CHAR:
2052     case T_BYTE:
2053     case T_SHORT:
2054       field_array[pos++] = TypeInt::INT;
2055       break;









2056     default:
2057       ShouldNotReachHere();
2058     }
2059     i++;
2060   }

2061 
2062   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2063 }
2064 
2065 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2066   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2067 }
2068 
2069 //------------------------------fields-----------------------------------------
2070 // Subroutine call type with space allocated for argument types
2071 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2072 const Type **TypeTuple::fields( uint arg_cnt ) {
2073   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2074   flds[TypeFunc::Control  ] = Type::CONTROL;
2075   flds[TypeFunc::I_O      ] = Type::ABIO;
2076   flds[TypeFunc::Memory   ] = Type::MEMORY;
2077   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2078   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2079 
2080   return flds;

2175     if (_fields[i]->empty())  return true;
2176   }
2177   return false;
2178 }
2179 
2180 //=============================================================================
2181 // Convenience common pre-built types.
2182 
2183 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2184   // Certain normalizations keep us sane when comparing types.
2185   // We do not want arrayOop variables to differ only by the wideness
2186   // of their index types.  Pick minimum wideness, since that is the
2187   // forced wideness of small ranges anyway.
2188   if (size->_widen != Type::WidenMin)
2189     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2190   else
2191     return size;
2192 }
2193 
2194 //------------------------------make-------------------------------------------
2195 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {

2196   if (UseCompressedOops && elem->isa_oopptr()) {
2197     elem = elem->make_narrowoop();
2198   }
2199   size = normalize_array_size(size);
2200   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2201 }
2202 
2203 //------------------------------meet-------------------------------------------
2204 // Compute the MEET of two types.  It returns a new Type object.
2205 const Type *TypeAry::xmeet( const Type *t ) const {
2206   // Perform a fast test for common case; meeting the same types together.
2207   if( this == t ) return this;  // Meeting same type-rep?
2208 
2209   // Current "this->_base" is Ary
2210   switch (t->base()) {          // switch on original type
2211 
2212   case Bottom:                  // Ye Olde Default
2213     return t;
2214 
2215   default:                      // All else is a mistake
2216     typerr(t);
2217 
2218   case Array: {                 // Meeting 2 arrays?
2219     const TypeAry *a = t->is_ary();
2220     return TypeAry::make(_elem->meet_speculative(a->_elem),
2221                          _size->xmeet(a->_size)->is_int(),
2222                          _stable && a->_stable);


2223   }
2224   case Top:
2225     break;
2226   }
2227   return this;                  // Return the double constant
2228 }
2229 
2230 //------------------------------xdual------------------------------------------
2231 // Dual: compute field-by-field dual
2232 const Type *TypeAry::xdual() const {
2233   const TypeInt* size_dual = _size->dual()->is_int();
2234   size_dual = normalize_array_size(size_dual);
2235   return new TypeAry(_elem->dual(), size_dual, !_stable);
2236 }
2237 
2238 //------------------------------eq---------------------------------------------
2239 // Structural equality check for Type representations
2240 bool TypeAry::eq( const Type *t ) const {
2241   const TypeAry *a = (const TypeAry*)t;
2242   return _elem == a->_elem &&
2243     _stable == a->_stable &&
2244     _size == a->_size;



2245 }
2246 
2247 //------------------------------hash-------------------------------------------
2248 // Type-specific hashing function.
2249 int TypeAry::hash(void) const {
2250   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2251 }
2252 
2253 /**
2254  * Return same type without a speculative part in the element
2255  */
2256 const Type* TypeAry::remove_speculative() const {
2257   return make(_elem->remove_speculative(), _size, _stable);
2258 }
2259 
2260 /**
2261  * Return same type with cleaned up speculative part of element
2262  */
2263 const Type* TypeAry::cleanup_speculative() const {
2264   return make(_elem->cleanup_speculative(), _size, _stable);
2265 }
2266 
2267 /**
2268  * Return same type but with a different inline depth (used for speculation)
2269  *
2270  * @param depth  depth to meet with
2271  */
2272 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2273   if (!UseInlineDepthForSpeculativeTypes) {
2274     return this;
2275   }
2276   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2277 }
2278 
2279 //----------------------interface_vs_oop---------------------------------------
2280 #ifdef ASSERT
2281 bool TypeAry::interface_vs_oop(const Type *t) const {
2282   const TypeAry* t_ary = t->is_ary();
2283   if (t_ary) {
2284     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2285     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
2286     if(this_ptr != NULL && t_ptr != NULL) {
2287       return this_ptr->interface_vs_oop(t_ptr);
2288     }
2289   }
2290   return false;
2291 }
2292 #endif
2293 
2294 //------------------------------dump2------------------------------------------
2295 #ifndef PRODUCT
2296 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2297   if (_stable)  st->print("stable:");




2298   _elem->dump2(d, depth, st);
2299   st->print("[");
2300   _size->dump2(d, depth, st);
2301   st->print("]");
2302 }
2303 #endif
2304 
2305 //------------------------------singleton--------------------------------------
2306 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2307 // constants (Ldi nodes).  Singletons are integer, float or double constants
2308 // or a single symbol.
2309 bool TypeAry::singleton(void) const {
2310   return false;                 // Never a singleton
2311 }
2312 
2313 bool TypeAry::empty(void) const {
2314   return _elem->empty() || _size->empty();
2315 }
2316 
2317 //--------------------------ary_must_be_exact----------------------------------

2319   // This logic looks at the element type of an array, and returns true
2320   // if the element type is either a primitive or a final instance class.
2321   // In such cases, an array built on this ary must have no subclasses.
2322   if (_elem == BOTTOM)      return false;  // general array not exact
2323   if (_elem == TOP   )      return false;  // inverted general array not exact
2324   const TypeOopPtr*  toop = NULL;
2325   if (UseCompressedOops && _elem->isa_narrowoop()) {
2326     toop = _elem->make_ptr()->isa_oopptr();
2327   } else {
2328     toop = _elem->isa_oopptr();
2329   }
2330   if (!toop)                return true;   // a primitive type, like int
2331   ciKlass* tklass = toop->klass();
2332   if (tklass == NULL)       return false;  // unloaded class
2333   if (!tklass->is_loaded()) return false;  // unloaded class
2334   const TypeInstPtr* tinst;
2335   if (_elem->isa_narrowoop())
2336     tinst = _elem->make_ptr()->isa_instptr();
2337   else
2338     tinst = _elem->isa_instptr();
2339   if (tinst)
2340     return tklass->as_instance_klass()->is_final();








2341   const TypeAryPtr*  tap;
2342   if (_elem->isa_narrowoop())
2343     tap = _elem->make_ptr()->isa_aryptr();
2344   else
2345     tap = _elem->isa_aryptr();
2346   if (tap)
2347     return tap->ary()->ary_must_be_exact();
2348   return false;
2349 }
2350 































































































































2351 //==============================TypeVect=======================================
2352 // Convenience common pre-built types.
2353 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2354 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2355 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2356 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2357 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2358 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2359 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2360 
2361 //------------------------------make-------------------------------------------
2362 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2363   BasicType elem_bt = elem->array_element_basic_type();
2364   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2365   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2366   int size = length * type2aelembytes(elem_bt);
2367   switch (Matcher::vector_ideal_reg(size)) {
2368   case Op_VecA:
2369     return (TypeVect*)(new TypeVectA(elem, length))->hashcons();
2370   case Op_VecS:

2503 
2504 //=============================================================================
2505 // Convenience common pre-built types.
2506 const TypePtr *TypePtr::NULL_PTR;
2507 const TypePtr *TypePtr::NOTNULL;
2508 const TypePtr *TypePtr::BOTTOM;
2509 
2510 //------------------------------meet-------------------------------------------
2511 // Meet over the PTR enum
2512 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2513   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2514   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2515   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2516   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2517   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2518   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2519   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2520 };
2521 
2522 //------------------------------make-------------------------------------------
2523 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2524   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2525 }
2526 
2527 //------------------------------cast_to_ptr_type-------------------------------
2528 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2529   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2530   if( ptr == _ptr ) return this;
2531   return make(_base, ptr, _offset, _speculative, _inline_depth);
2532 }
2533 
2534 //------------------------------get_con----------------------------------------
2535 intptr_t TypePtr::get_con() const {
2536   assert( _ptr == Null, "" );
2537   return _offset;
2538 }
2539 
2540 //------------------------------meet-------------------------------------------
2541 // Compute the MEET of two types.  It returns a new Type object.
2542 const Type *TypePtr::xmeet(const Type *t) const {
2543   const Type* res = xmeet_helper(t);
2544   if (res->isa_ptr() == NULL) {
2545     return res;
2546   }
2547 
2548   const TypePtr* res_ptr = res->is_ptr();
2549   if (res_ptr->speculative() != NULL) {
2550     // type->speculative() == NULL means that speculation is no better
2551     // than type, i.e. type->speculative() == type. So there are 2
2552     // ways to represent the fact that we have no useful speculative
2553     // data and we should use a single one to be able to test for
2554     // equality between types. Check whether type->speculative() ==
2555     // type and set speculative to NULL if it is the case.
2556     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2557       return res_ptr->remove_speculative();

2579   case NarrowKlass:
2580   case Bottom:                  // Ye Olde Default
2581     return Type::BOTTOM;
2582   case Top:
2583     return this;
2584 
2585   case AnyPtr: {                // Meeting to AnyPtrs
2586     const TypePtr *tp = t->is_ptr();
2587     const TypePtr* speculative = xmeet_speculative(tp);
2588     int depth = meet_inline_depth(tp->inline_depth());
2589     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2590   }
2591   case RawPtr:                  // For these, flip the call around to cut down
2592   case OopPtr:
2593   case InstPtr:                 // on the cases I have to handle.
2594   case AryPtr:
2595   case MetadataPtr:
2596   case KlassPtr:
2597   case InstKlassPtr:
2598   case AryKlassPtr:

2599     return t->xmeet(this);      // Call in reverse direction
2600   default:                      // All else is a mistake
2601     typerr(t);
2602 
2603   }
2604   return this;
2605 }
2606 
2607 //------------------------------meet_offset------------------------------------
2608 int TypePtr::meet_offset( int offset ) const {
2609   // Either is 'TOP' offset?  Return the other offset!
2610   if( _offset == OffsetTop ) return offset;
2611   if( offset == OffsetTop ) return _offset;
2612   // If either is different, return 'BOTTOM' offset
2613   if( _offset != offset ) return OffsetBot;
2614   return _offset;
2615 }
2616 
2617 //------------------------------dual_offset------------------------------------
2618 int TypePtr::dual_offset( ) const {
2619   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2620   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2621   return _offset;               // Map everything else into self
2622 }
2623 
2624 //------------------------------xdual------------------------------------------
2625 // Dual: compute field-by-field dual
2626 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2627   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2628 };
2629 const Type *TypePtr::xdual() const {
2630   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2631 }
2632 
2633 //------------------------------xadd_offset------------------------------------
2634 int TypePtr::xadd_offset( intptr_t offset ) const {
2635   // Adding to 'TOP' offset?  Return 'TOP'!
2636   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2637   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2638   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2639   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2640   offset += (intptr_t)_offset;
2641   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2642 
2643   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2644   // It is possible to construct a negative offset during PhaseCCP
2645 
2646   return (int)offset;        // Sum valid offsets
2647 }
2648 
2649 //------------------------------add_offset-------------------------------------
2650 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2651   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2652 }
2653 
2654 //------------------------------eq---------------------------------------------
2655 // Structural equality check for Type representations
2656 bool TypePtr::eq( const Type *t ) const {
2657   const TypePtr *a = (const TypePtr*)t;
2658   return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2659 }
2660 
2661 //------------------------------hash-------------------------------------------
2662 // Type-specific hashing function.
2663 int TypePtr::hash(void) const {
2664   return java_add(java_add((jint)_ptr, (jint)_offset), java_add((jint)hash_speculative(), (jint)_inline_depth));
2665 ;
2666 }
2667 
2668 /**
2669  * Return same type without a speculative part
2670  */
2671 const Type* TypePtr::remove_speculative() const {
2672   if (_speculative == NULL) {
2673     return this;
2674   }
2675   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2676   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2677 }
2678 
2679 /**
2680  * Return same type but drop speculative part if we know we won't use
2681  * it
2682  */
2683 const Type* TypePtr::cleanup_speculative() const {
2684   if (speculative() == NULL) {

2904   }
2905   // We already know the speculative type is always null
2906   if (speculative_always_null()) {
2907     return false;
2908   }
2909   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
2910     return false;
2911   }
2912   return true;
2913 }
2914 
2915 //------------------------------dump2------------------------------------------
2916 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2917   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2918 };
2919 
2920 #ifndef PRODUCT
2921 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2922   if( _ptr == Null ) st->print("NULL");
2923   else st->print("%s *", ptr_msg[_ptr]);
2924   if( _offset == OffsetTop ) st->print("+top");
2925   else if( _offset == OffsetBot ) st->print("+bot");
2926   else if( _offset ) st->print("+%d", _offset);
2927   dump_inline_depth(st);
2928   dump_speculative(st);
2929 }
2930 
2931 /**
2932  *dump the speculative part of the type
2933  */
2934 void TypePtr::dump_speculative(outputStream *st) const {
2935   if (_speculative != NULL) {
2936     st->print(" (speculative=");
2937     _speculative->dump_on(st);
2938     st->print(")");
2939   }
2940 }
2941 
2942 /**
2943  *dump the inline depth of the type
2944  */
2945 void TypePtr::dump_inline_depth(outputStream *st) const {
2946   if (_inline_depth != InlineDepthBottom) {
2947     if (_inline_depth == InlineDepthTop) {
2948       st->print(" (inline_depth=InlineDepthTop)");
2949     } else {
2950       st->print(" (inline_depth=%d)", _inline_depth);
2951     }
2952   }
2953 }
2954 #endif
2955 
2956 //------------------------------singleton--------------------------------------
2957 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2958 // constants
2959 bool TypePtr::singleton(void) const {
2960   // TopPTR, Null, AnyNull, Constant are all singletons
2961   return (_offset != OffsetBot) && !below_centerline(_ptr);
2962 }
2963 
2964 bool TypePtr::empty(void) const {
2965   return (_offset == OffsetTop) || above_centerline(_ptr);
2966 }
2967 
2968 //=============================================================================
2969 // Convenience common pre-built types.
2970 const TypeRawPtr *TypeRawPtr::BOTTOM;
2971 const TypeRawPtr *TypeRawPtr::NOTNULL;
2972 
2973 //------------------------------make-------------------------------------------
2974 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
2975   assert( ptr != Constant, "what is the constant?" );
2976   assert( ptr != Null, "Use TypePtr for NULL" );
2977   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
2978 }
2979 
2980 const TypeRawPtr *TypeRawPtr::make( address bits ) {
2981   assert( bits, "Use TypePtr for NULL" );
2982   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
2983 }
2984 
2985 //------------------------------cast_to_ptr_type-------------------------------

3089 // Type-specific hashing function.
3090 int TypeRawPtr::hash(void) const {
3091   return (intptr_t)_bits + TypePtr::hash();
3092 }
3093 
3094 //------------------------------dump2------------------------------------------
3095 #ifndef PRODUCT
3096 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3097   if( _ptr == Constant )
3098     st->print(INTPTR_FORMAT, p2i(_bits));
3099   else
3100     st->print("rawptr:%s", ptr_msg[_ptr]);
3101 }
3102 #endif
3103 
3104 //=============================================================================
3105 // Convenience common pre-built type.
3106 const TypeOopPtr *TypeOopPtr::BOTTOM;
3107 
3108 //------------------------------TypeOopPtr-------------------------------------
3109 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset,
3110                        int instance_id, const TypePtr* speculative, int inline_depth)
3111   : TypePtr(t, ptr, offset, speculative, inline_depth),
3112     _const_oop(o), _klass(k),
3113     _klass_is_exact(xk),
3114     _is_ptr_to_narrowoop(false),
3115     _is_ptr_to_narrowklass(false),
3116     _is_ptr_to_boxed_value(false),
3117     _instance_id(instance_id) {
3118   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3119       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
3120     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3121   }
3122 #ifdef _LP64
3123   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3124     if (_offset == oopDesc::klass_offset_in_bytes()) {
3125       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3126     } else if (klass() == NULL) {
3127       // Array with unknown body type
3128       assert(this->isa_aryptr(), "only arrays without klass");
3129       _is_ptr_to_narrowoop = UseCompressedOops;
3130     } else if (this->isa_aryptr()) {
3131       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3132                              _offset != arrayOopDesc::length_offset_in_bytes());









3133     } else if (klass()->is_instance_klass()) {
3134       ciInstanceKlass* ik = klass()->as_instance_klass();
3135       ciField* field = NULL;
3136       if (this->isa_klassptr()) {
3137         // Perm objects don't use compressed references
3138       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3139         // unsafe access
3140         _is_ptr_to_narrowoop = UseCompressedOops;
3141       } else {
3142         assert(this->isa_instptr(), "must be an instance ptr.");
3143 
3144         if (klass() == ciEnv::current()->Class_klass() &&
3145             (_offset == java_lang_Class::klass_offset() ||
3146              _offset == java_lang_Class::array_klass_offset())) {
3147           // Special hidden fields from the Class.
3148           assert(this->isa_instptr(), "must be an instance ptr.");
3149           _is_ptr_to_narrowoop = false;
3150         } else if (klass() == ciEnv::current()->Class_klass() &&
3151                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3152           // Static fields
3153           ciField* field = NULL;
3154           if (const_oop() != NULL) {
3155             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3156             field = k->get_field_by_offset(_offset, true);
3157           }
3158           if (field != NULL) {
3159             BasicType basic_elem_type = field->layout_type();
3160             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3161           } else {
3162             // unsafe access
3163             _is_ptr_to_narrowoop = UseCompressedOops;






3164           }
3165         } else {
3166           // Instance fields which contains a compressed oop references.
3167           field = ik->get_field_by_offset(_offset, false);

3168           if (field != NULL) {
3169             BasicType basic_elem_type = field->layout_type();
3170             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3171           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3172             // Compile::find_alias_type() cast exactness on all types to verify
3173             // that it does not affect alias type.
3174             _is_ptr_to_narrowoop = UseCompressedOops;
3175           } else {
3176             // Type for the copy start in LibraryCallKit::inline_native_clone().
3177             _is_ptr_to_narrowoop = UseCompressedOops;
3178           }
3179         }
3180       }
3181     }
3182   }
3183 #endif
3184 }
3185 
3186 //------------------------------make-------------------------------------------
3187 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3188                                      const TypePtr* speculative, int inline_depth) {
3189   assert(ptr != Constant, "no constant generic pointers");
3190   ciKlass*  k = Compile::current()->env()->Object_klass();
3191   bool      xk = false;
3192   ciObject* o = NULL;
3193   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3194 }
3195 
3196 
3197 //------------------------------cast_to_ptr_type-------------------------------
3198 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3199   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3200   if( ptr == _ptr ) return this;
3201   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3202 }
3203 
3204 //-----------------------------cast_to_instance_id----------------------------
3205 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3206   // There are no instances of a general oop.
3207   // Return self unchanged.
3208   return this;
3209 }
3210 
3211 //-----------------------------cast_to_exactness-------------------------------
3212 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3213   // There is no such thing as an exact general oop.
3214   // Return self unchanged.
3215   return this;
3216 }
3217 
3218 
3219 //------------------------------as_klass_type----------------------------------
3220 // Return the klass type corresponding to this instance or array type.
3221 // It is the type that is loaded from an object of this type.
3222 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3223   ShouldNotReachHere();
3224   return NULL;
3225 }
3226 
3227 //------------------------------meet-------------------------------------------
3228 // Compute the MEET of two types.  It returns a new Type object.
3229 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3230   // Perform a fast test for common case; meeting the same types together.
3231   if( this == t ) return this;  // Meeting same type-rep?
3232 
3233   // Current "this->_base" is OopPtr
3234   switch (t->base()) {          // switch on original type
3235 
3236   case Int:                     // Mixing ints & oops happens when javac
3237   case Long:                    // reuses local variables
3238   case FloatTop:

3244   case NarrowOop:
3245   case NarrowKlass:
3246   case Bottom:                  // Ye Olde Default
3247     return Type::BOTTOM;
3248   case Top:
3249     return this;
3250 
3251   default:                      // All else is a mistake
3252     typerr(t);
3253 
3254   case RawPtr:
3255   case MetadataPtr:
3256   case KlassPtr:
3257   case InstKlassPtr:
3258   case AryKlassPtr:
3259     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3260 
3261   case AnyPtr: {
3262     // Found an AnyPtr type vs self-OopPtr type
3263     const TypePtr *tp = t->is_ptr();
3264     int offset = meet_offset(tp->offset());
3265     PTR ptr = meet_ptr(tp->ptr());
3266     const TypePtr* speculative = xmeet_speculative(tp);
3267     int depth = meet_inline_depth(tp->inline_depth());
3268     switch (tp->ptr()) {
3269     case Null:
3270       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3271       // else fall through:
3272     case TopPTR:
3273     case AnyNull: {
3274       int instance_id = meet_instance_id(InstanceTop);
3275       return make(ptr, offset, instance_id, speculative, depth);
3276     }
3277     case BotPTR:
3278     case NotNull:
3279       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3280     default: typerr(t);
3281     }
3282   }
3283 
3284   case OopPtr: {                 // Meeting to other OopPtrs

3286     int instance_id = meet_instance_id(tp->instance_id());
3287     const TypePtr* speculative = xmeet_speculative(tp);
3288     int depth = meet_inline_depth(tp->inline_depth());
3289     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3290   }
3291 
3292   case InstPtr:                  // For these, flip the call around to cut down
3293   case AryPtr:
3294     return t->xmeet(this);      // Call in reverse direction
3295 
3296   } // End of switch
3297   return this;                  // Return the double constant
3298 }
3299 
3300 
3301 //------------------------------xdual------------------------------------------
3302 // Dual of a pure heap pointer.  No relevant klass or oop information.
3303 const Type *TypeOopPtr::xdual() const {
3304   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3305   assert(const_oop() == NULL,             "no constants here");
3306   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3307 }
3308 
3309 //--------------------------make_from_klass_common-----------------------------
3310 // Computes the element-type given a klass.
3311 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3312   if (klass->is_instance_klass()) {
3313     Compile* C = Compile::current();
3314     Dependencies* deps = C->dependencies();
3315     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3316     // Element is an instance
3317     bool klass_is_exact = false;
3318     if (klass->is_loaded()) {
3319       // Try to set klass_is_exact.
3320       ciInstanceKlass* ik = klass->as_instance_klass();
3321       klass_is_exact = ik->is_final();
3322       if (!klass_is_exact && klass_change
3323           && deps != NULL && UseUniqueSubclasses) {
3324         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3325         if (sub != NULL) {
3326           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3327           klass = ik = sub;
3328           klass_is_exact = sub->is_final();
3329         }
3330       }
3331       if (!klass_is_exact && try_for_exact && deps != NULL &&
3332           !ik->is_interface() && !ik->has_subklass()) {
3333         // Add a dependence; if concrete subclass added we need to recompile
3334         deps->assert_leaf_type(ik);
3335         klass_is_exact = true;
3336       }
3337     }
3338     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
3339   } else if (klass->is_obj_array_klass()) {
3340     // Element is an object array. Recursively call ourself.
3341     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
3342     bool xk = etype->klass_is_exact();
3343     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);














3344     // We used to pass NotNull in here, asserting that the sub-arrays
3345     // are all not-null.  This is not true in generally, as code can
3346     // slam NULLs down in the subarrays.
3347     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
3348     return arr;
3349   } else if (klass->is_type_array_klass()) {
3350     // Element is an typeArray
3351     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3352     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

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





3356     return arr;
3357   } else {
3358     ShouldNotReachHere();
3359     return NULL;
3360   }
3361 }
3362 
3363 //------------------------------make_from_constant-----------------------------
3364 // Make a java pointer from an oop constant
3365 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3366   assert(!o->is_null_object(), "null object not yet handled here.");
3367 
3368   const bool make_constant = require_constant || o->should_be_constant();
3369 
3370   ciKlass* klass = o->klass();
3371   if (klass->is_instance_klass()) {
3372     // Element is an instance
3373     if (make_constant) {
3374       return TypeInstPtr::make(o);
3375     } else {
3376       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3377     }
3378   } else if (klass->is_obj_array_klass()) {
3379     // Element is an object array. Recursively call ourself.
3380     const TypeOopPtr *etype =
3381       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
3382     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));





3383     // We used to pass NotNull in here, asserting that the sub-arrays
3384     // are all not-null.  This is not true in generally, as code can
3385     // slam NULLs down in the subarrays.
3386     if (make_constant) {
3387       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3388     } else {
3389       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3390     }
3391   } else if (klass->is_type_array_klass()) {
3392     // Element is an typeArray
3393     const Type* etype =
3394       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3395     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3396     // We used to pass NotNull in here, asserting that the array pointer
3397     // is not-null. That was not true in general.
3398     if (make_constant) {
3399       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3400     } else {
3401       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);











3402     }
3403   }
3404 
3405   fatal("unhandled object type");
3406   return NULL;
3407 }
3408 
3409 //------------------------------get_con----------------------------------------
3410 intptr_t TypeOopPtr::get_con() const {
3411   assert( _ptr == Null || _ptr == Constant, "" );
3412   assert( _offset >= 0, "" );
3413 
3414   if (_offset != 0) {
3415     // After being ported to the compiler interface, the compiler no longer
3416     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3417     // to a handle at compile time.  This handle is embedded in the generated
3418     // code and dereferenced at the time the nmethod is made.  Until that time,
3419     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3420     // have access to the addresses!).  This does not seem to currently happen,
3421     // but this assertion here is to help prevent its occurence.
3422     tty->print_cr("Found oop constant with non-zero offset");
3423     ShouldNotReachHere();
3424   }
3425 
3426   return (intptr_t)const_oop()->constant_encoding();
3427 }
3428 
3429 
3430 //-----------------------------filter------------------------------------------
3431 // Do not allow interface-vs.-noninterface joins to collapse to top.
3432 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3433 
3434   const Type* ft = join_helper(kills, include_speculative);

3487     return (one == two) && TypePtr::eq(t);
3488   } else {
3489     return one->equals(two) && TypePtr::eq(t);
3490   }
3491 }
3492 
3493 //------------------------------hash-------------------------------------------
3494 // Type-specific hashing function.
3495 int TypeOopPtr::hash(void) const {
3496   return
3497     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3498              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3499 }
3500 
3501 //------------------------------dump2------------------------------------------
3502 #ifndef PRODUCT
3503 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3504   st->print("oopptr:%s", ptr_msg[_ptr]);
3505   if( _klass_is_exact ) st->print(":exact");
3506   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3507   switch( _offset ) {
3508   case OffsetTop: st->print("+top"); break;
3509   case OffsetBot: st->print("+any"); break;
3510   case         0: break;
3511   default:        st->print("+%d",_offset); break;
3512   }
3513   if (_instance_id == InstanceTop)
3514     st->print(",iid=top");
3515   else if (_instance_id != InstanceBot)
3516     st->print(",iid=%d",_instance_id);
3517 
3518   dump_inline_depth(st);
3519   dump_speculative(st);
3520 }
3521 #endif
3522 
3523 //------------------------------singleton--------------------------------------
3524 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3525 // constants
3526 bool TypeOopPtr::singleton(void) const {
3527   // detune optimizer to not generate constant oop + constant offset as a constant!
3528   // TopPTR, Null, AnyNull, Constant are all singletons
3529   return (_offset == 0) && !below_centerline(_ptr);
3530 }
3531 
3532 //------------------------------add_offset-------------------------------------
3533 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3534   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3535 }
3536 
3537 /**
3538  * Return same type without a speculative part
3539  */
3540 const Type* TypeOopPtr::remove_speculative() const {
3541   if (_speculative == NULL) {
3542     return this;
3543   }
3544   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3545   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3546 }
3547 
3548 /**
3549  * Return same type but drop speculative part if we know we won't use

3601  *
3602  * @return  true if type profile is valuable
3603  */
3604 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3605   // no way to improve an already exact type
3606   if (klass_is_exact()) {
3607     return false;
3608   }
3609   return TypePtr::would_improve_type(exact_kls, inline_depth);
3610 }
3611 
3612 //=============================================================================
3613 // Convenience common pre-built types.
3614 const TypeInstPtr *TypeInstPtr::NOTNULL;
3615 const TypeInstPtr *TypeInstPtr::BOTTOM;
3616 const TypeInstPtr *TypeInstPtr::MIRROR;
3617 const TypeInstPtr *TypeInstPtr::MARK;
3618 const TypeInstPtr *TypeInstPtr::KLASS;
3619 
3620 //------------------------------TypeInstPtr-------------------------------------
3621 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off,
3622                          int instance_id, const TypePtr* speculative, int inline_depth)
3623   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth),
3624     _name(k->name()) {
3625    assert(k != NULL &&
3626           (k->is_loaded() || o == NULL),
3627           "cannot have constants with non-loaded klass");



3628 };
3629 
3630 //------------------------------make-------------------------------------------
3631 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3632                                      ciKlass* k,
3633                                      bool xk,
3634                                      ciObject* o,
3635                                      int offset,

3636                                      int instance_id,
3637                                      const TypePtr* speculative,
3638                                      int inline_depth) {
3639   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3640   // Either const_oop() is NULL or else ptr is Constant
3641   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3642           "constant pointers must have a value supplied" );
3643   // Ptr is never Null
3644   assert( ptr != Null, "NULL pointers are not typed" );
3645 
3646   assert(instance_id <= 0 || xk, "instances are always exactly typed");
3647   if (ptr == Constant) {
3648     // Note:  This case includes meta-object constants, such as methods.
3649     xk = true;
3650   } else if (k->is_loaded()) {
3651     ciInstanceKlass* ik = k->as_instance_klass();
3652     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3653     if (xk && ik->is_interface())  xk = false;  // no exact interface
3654   }
3655 



3656   // Now hash this baby
3657   TypeInstPtr *result =
3658     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3659 
3660   return result;
3661 }
3662 
3663 /**
3664  *  Create constant type for a constant boxed value
3665  */
3666 const Type* TypeInstPtr::get_const_boxed_value() const {
3667   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3668   assert((const_oop() != NULL), "should be called only for constant object");
3669   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3670   BasicType bt = constant.basic_type();
3671   switch (bt) {
3672     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3673     case T_INT:      return TypeInt::make(constant.as_int());
3674     case T_CHAR:     return TypeInt::make(constant.as_char());
3675     case T_BYTE:     return TypeInt::make(constant.as_byte());
3676     case T_SHORT:    return TypeInt::make(constant.as_short());
3677     case T_FLOAT:    return TypeF::make(constant.as_float());
3678     case T_DOUBLE:   return TypeD::make(constant.as_double());
3679     case T_LONG:     return TypeLong::make(constant.as_long());
3680     default:         break;
3681   }
3682   fatal("Invalid boxed value type '%s'", type2name(bt));
3683   return NULL;
3684 }
3685 
3686 //------------------------------cast_to_ptr_type-------------------------------
3687 const TypeInstPtr *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3688   if( ptr == _ptr ) return this;
3689   // Reconstruct _sig info here since not a problem with later lazy
3690   // construction, _sig will show up on demand.
3691   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3692 }
3693 
3694 
3695 //-----------------------------cast_to_exactness-------------------------------
3696 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3697   if( klass_is_exact == _klass_is_exact ) return this;
3698   if (!_klass->is_loaded())  return this;
3699   ciInstanceKlass* ik = _klass->as_instance_klass();
3700   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3701   if( ik->is_interface() )              return this;  // cannot set xk
3702   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
3703 }
3704 
3705 //-----------------------------cast_to_instance_id----------------------------
3706 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
3707   if( instance_id == _instance_id ) return this;
3708   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
3709 }
3710 
3711 //------------------------------xmeet_unloaded---------------------------------
3712 // Compute the MEET of two InstPtrs when at least one is unloaded.
3713 // Assume classes are different since called after check for same name/class-loader
3714 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
3715     int off = meet_offset(tinst->offset());
3716     PTR ptr = meet_ptr(tinst->ptr());
3717     int instance_id = meet_instance_id(tinst->instance_id());
3718     const TypePtr* speculative = xmeet_speculative(tinst);
3719     int depth = meet_inline_depth(tinst->inline_depth());
3720 
3721     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
3722     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
3723     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
3724       //
3725       // Meet unloaded class with java/lang/Object
3726       //
3727       // Meet
3728       //          |                     Unloaded Class
3729       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
3730       //  ===================================================================
3731       //   TOP    | ..........................Unloaded......................|
3732       //  AnyNull |  U-AN    |................Unloaded......................|
3733       // Constant | ... O-NN .................................. |   O-BOT   |
3734       //  NotNull | ... O-NN .................................. |   O-BOT   |
3735       //  BOTTOM  | ........................Object-BOTTOM ..................|
3736       //
3737       assert(loaded->ptr() != TypePtr::Null, "insanity check");
3738       //
3739       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
3740       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, instance_id, speculative, depth); }
3741       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
3742       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
3743         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
3744         else                                      { return TypeInstPtr::NOTNULL; }
3745       }
3746       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
3747 
3748       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
3749     }
3750 
3751     // Both are unloaded, not the same class, not Object
3752     // Or meet unloaded with a different loaded class, not java/lang/Object
3753     if( ptr != TypePtr::BotPTR ) {
3754       return TypeInstPtr::NOTNULL;
3755     }
3756     return TypeInstPtr::BOTTOM;
3757 }
3758 
3759 
3760 //------------------------------meet-------------------------------------------

3781   case Top:
3782     return this;
3783 
3784   default:                      // All else is a mistake
3785     typerr(t);
3786 
3787   case MetadataPtr:
3788   case KlassPtr:
3789   case InstKlassPtr:
3790   case AryKlassPtr:
3791   case RawPtr: return TypePtr::BOTTOM;
3792 
3793   case AryPtr: {                // All arrays inherit from Object class
3794     // Call in reverse direction to avoid duplication
3795     return t->is_aryptr()->xmeet_helper(this);
3796   }
3797 
3798   case OopPtr: {                // Meeting to OopPtrs
3799     // Found a OopPtr type vs self-InstPtr type
3800     const TypeOopPtr *tp = t->is_oopptr();
3801     int offset = meet_offset(tp->offset());
3802     PTR ptr = meet_ptr(tp->ptr());
3803     switch (tp->ptr()) {
3804     case TopPTR:
3805     case AnyNull: {
3806       int instance_id = meet_instance_id(InstanceTop);
3807       const TypePtr* speculative = xmeet_speculative(tp);
3808       int depth = meet_inline_depth(tp->inline_depth());
3809       return make(ptr, klass(), klass_is_exact(),
3810                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3811     }
3812     case NotNull:
3813     case BotPTR: {
3814       int instance_id = meet_instance_id(tp->instance_id());
3815       const TypePtr* speculative = xmeet_speculative(tp);
3816       int depth = meet_inline_depth(tp->inline_depth());
3817       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3818     }
3819     default: typerr(t);
3820     }
3821   }
3822 
3823   case AnyPtr: {                // Meeting to AnyPtrs
3824     // Found an AnyPtr type vs self-InstPtr type
3825     const TypePtr *tp = t->is_ptr();
3826     int offset = meet_offset(tp->offset());
3827     PTR ptr = meet_ptr(tp->ptr());
3828     int instance_id = meet_instance_id(InstanceTop);
3829     const TypePtr* speculative = xmeet_speculative(tp);
3830     int depth = meet_inline_depth(tp->inline_depth());
3831     switch (tp->ptr()) {
3832     case Null:
3833       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3834       // else fall through to AnyNull
3835     case TopPTR:
3836     case AnyNull: {
3837       return make(ptr, klass(), klass_is_exact(),
3838                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3839     }
3840     case NotNull:
3841     case BotPTR:
3842       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3843     default: typerr(t);
3844     }
3845   }
3846 
3847   /*
3848                  A-top         }
3849                /   |   \       }  Tops
3850            B-top A-any C-top   }
3851               | /  |  \ |      }  Any-nulls
3852            B-any   |   C-any   }
3853               |    |    |
3854            B-con A-con C-con   } constants; not comparable across classes
3855               |    |    |
3856            B-not   |   C-not   }
3857               | \  |  / |      }  not-nulls
3858            B-bot A-not C-bot   }
3859                \   |   /       }  Bottoms
3860                  A-bot         }
3861   */
3862 
3863   case InstPtr: {                // Meeting 2 Oops?
3864     // Found an InstPtr sub-type vs self-InstPtr type
3865     const TypeInstPtr *tinst = t->is_instptr();
3866     int off = meet_offset(tinst->offset());
3867     PTR ptr = meet_ptr(tinst->ptr());
3868     int instance_id = meet_instance_id(tinst->instance_id());
3869     const TypePtr* speculative = xmeet_speculative(tinst);
3870     int depth = meet_inline_depth(tinst->inline_depth());
3871     ciKlass* tinst_klass = tinst->klass();
3872     ciKlass* this_klass  = klass();
3873     bool tinst_xk = tinst->klass_is_exact();
3874     bool this_xk  = klass_is_exact();


3875 
3876     ciKlass* res_klass = NULL;
3877     bool res_xk = false;

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


3880     if (kind == UNLOADED) {
3881       // One of these classes has not been loaded
3882       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst);
3883 #ifndef PRODUCT
3884       if (PrintOpto && Verbose) {
3885         tty->print("meet of unloaded classes resulted in: ");
3886         unloaded_meet->dump();
3887         tty->cr();
3888         tty->print("  this == ");
3889         dump();
3890         tty->cr();
3891         tty->print(" tinst == ");
3892         tinst->dump();
3893         tty->cr();
3894       }
3895 #endif
3896       res = unloaded_meet;
3897     } else {
3898       if (kind == NOT_SUBTYPE && instance_id > 0) {
3899         instance_id = InstanceBot;
3900       } else if (kind == LCA) {
3901         instance_id = InstanceBot;
3902       }
3903       ciObject* o = NULL;             // Assume not constant when done
3904       ciObject* this_oop = const_oop();
3905       ciObject* tinst_oop = tinst->const_oop();
3906       if (ptr == Constant) {
3907         if (this_oop != NULL && tinst_oop != NULL &&
3908             this_oop->equals(tinst_oop))
3909           o = this_oop;
3910         else if (above_centerline(_ptr)) {
3911           assert(!tinst_klass->is_interface(), "");
3912           o = tinst_oop;
3913         } else if (above_centerline(tinst->_ptr)) {
3914           assert(!this_klass->is_interface(), "");
3915           o = this_oop;
3916         } else
3917           ptr = NotNull;
3918       }
3919       res = make(ptr, res_klass, res_xk, o, off, instance_id, speculative, depth);
3920     }
3921 
3922     return res;
3923 
3924   } // End of case InstPtr
3925 





















3926   } // End of switch
3927   return this;                  // Return the double constant
3928 }
3929 
3930 TypePtr::MeetResult TypePtr::meet_instptr(PTR &ptr, ciKlass* this_klass, ciKlass* tinst_klass, bool this_xk, bool tinst_xk,
3931                                           PTR this_ptr,
3932                                           PTR tinst_ptr, ciKlass*&res_klass, bool &res_xk) {



3933 
3934   // Check for easy case; klasses are equal (and perhaps not loaded!)
3935   // If we have constants, then we created oops so classes are loaded
3936   // and we can handle the constants further down.  This case handles
3937   // both-not-loaded or both-loaded classes
3938   if (ptr != Constant && this_klass->equals(tinst_klass) && this_xk == tinst_xk) {
3939     res_klass = this_klass;
3940     res_xk = this_xk;

3941     return QUICK;
3942   }
3943 
3944   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3945   if (!tinst_klass->is_loaded() || !this_klass->is_loaded()) {
3946     return UNLOADED;
3947   }
3948 
3949   // Handle mixing oops and interfaces first.
3950   if (this_klass->is_interface() && !(tinst_klass->is_interface() ||
3951                                       tinst_klass == ciEnv::current()->Object_klass())) {
3952     ciKlass *tmp = tinst_klass; // Swap interface around
3953     tinst_klass = this_klass;
3954     this_klass = tmp;
3955     bool tmp2 = tinst_xk;
3956     tinst_xk = this_xk;
3957     this_xk = tmp2;



3958   }
3959   if (tinst_klass->is_interface() &&
3960       !(this_klass->is_interface() ||
3961         // Treat java/lang/Object as an honorary interface,
3962         // because we need a bottom for the interface hierarchy.
3963         this_klass == ciEnv::current()->Object_klass())) {
3964     // Oop meets interface!
3965 
3966     // See if the oop subtypes (implements) interface.
3967     if (this_klass->is_subtype_of(tinst_klass)) {
3968       // Oop indeed subtypes.  Now keep oop or interface depending
3969       // on whether we are both above the centerline or either is
3970       // below the centerline.  If we are on the centerline
3971       // (e.g., Constant vs. AnyNull interface), use the constant.
3972       res_klass  = below_centerline(ptr) ? tinst_klass : this_klass;
3973       // If we are keeping this_klass, keep its exactness too.
3974       res_xk = below_centerline(ptr) ? tinst_xk    : this_xk;

3975       return SUBTYPE;
3976     } else {                  // Does not implement, fall to Object
3977       // Oop does not implement interface, so mixing falls to Object
3978       // just like the verifier does (if both are above the
3979       // centerline fall to interface)
3980       res_klass = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
3981       res_xk = above_centerline(ptr) ? tinst_xk : false;

3982       // Watch out for Constant vs. AnyNull interface.
3983       if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
3984       return NOT_SUBTYPE;
3985     }
3986   }
3987 
3988   // Either oop vs oop or interface vs interface or interface vs Object
3989 
3990   // !!! Here's how the symmetry requirement breaks down into invariants:
3991   // If we split one up & one down AND they subtype, take the down man.
3992   // If we split one up & one down AND they do NOT subtype, "fall hard".
3993   // If both are up and they subtype, take the subtype class.
3994   // If both are up and they do NOT subtype, "fall hard".
3995   // If both are down and they subtype, take the supertype class.
3996   // If both are down and they do NOT subtype, "fall hard".
3997   // Constants treated as down.
3998 
3999   // Now, reorder the above list; observe that both-down+subtype is also
4000   // "fall hard"; "fall hard" becomes the default case:
4001   // If we split one up & one down AND they subtype, take the down man.
4002   // If both are up and they subtype, take the subtype class.
4003 
4004   // If both are down and they subtype, "fall hard".
4005   // If both are down and they do NOT subtype, "fall hard".
4006   // If both are up and they do NOT subtype, "fall hard".
4007   // If we split one up & one down AND they do NOT subtype, "fall hard".
4008 
4009   // If a proper subtype is exact, and we return it, we return it exactly.
4010   // If a proper supertype is exact, there can be no subtyping relationship!
4011   // If both types are equal to the subtype, exactness is and-ed below the
4012   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4013 
4014   // Check for subtyping:
4015   ciKlass *subtype = NULL;
4016   bool subtype_exact = false;

4017   if (tinst_klass->equals(this_klass)) {
4018     subtype = this_klass;
4019     subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
4020   } else if (!tinst_xk && this_klass->is_subtype_of(tinst_klass)) {

4021     subtype = this_klass;     // Pick subtyping class
4022     subtype_exact = this_xk;
4023   } else if (!this_xk && tinst_klass->is_subtype_of(this_klass)) {

4024     subtype = tinst_klass;    // Pick subtyping class
4025     subtype_exact = tinst_xk;

4026   }
4027 
4028   if (subtype) {
4029     if (above_centerline(ptr)) { // both are up?
4030       this_klass = tinst_klass = subtype;
4031       this_xk = tinst_xk = subtype_exact;

4032     } else if (above_centerline(this_ptr) && !above_centerline(tinst_ptr)) {
4033       this_klass = tinst_klass; // tinst is down; keep down man
4034       this_xk = tinst_xk;

4035     } else if (above_centerline(tinst_ptr) && !above_centerline(this_ptr)) {
4036       tinst_klass = this_klass; // this is down; keep down man
4037       tinst_xk = this_xk;

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

4040     }
4041   }
4042 
4043   // Check for classes now being equal
4044   if (tinst_klass->equals(this_klass)) {
4045     // If the klasses are equal, the constants may still differ.  Fall to
4046     // NotNull if they do (neither constant is NULL; that is a special case
4047     // handled elsewhere).
4048     res_klass = this_klass;
4049     res_xk = this_xk;

4050     return SUBTYPE;
4051   } // Else classes are not equal
4052 
4053   // Since klasses are different, we require a LCA in the Java
4054   // class hierarchy - which means we have to fall to at least NotNull.
4055   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4056     ptr = NotNull;
4057   }
4058 
4059   // Now we find the LCA of Java classes
4060   ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4061 
4062   res_klass = k;
4063   res_xk = false;

4064 
4065   return LCA;
4066 }
4067 
4068 
4069 //------------------------java_mirror_type--------------------------------------
4070 ciType* TypeInstPtr::java_mirror_type() const {
4071   // must be a singleton type
4072   if( const_oop() == NULL )  return NULL;
4073 
4074   // must be of type java.lang.Class
4075   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4076 
4077   return const_oop()->as_instance()->java_mirror_type();
4078 }
4079 
4080 
4081 //------------------------------xdual------------------------------------------
4082 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4083 // inheritance mechanism.
4084 const Type *TypeInstPtr::xdual() const {
4085   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4086 }
4087 
4088 //------------------------------eq---------------------------------------------
4089 // Structural equality check for Type representations
4090 bool TypeInstPtr::eq( const Type *t ) const {
4091   const TypeInstPtr *p = t->is_instptr();
4092   return
4093     klass()->equals(p->klass()) &&

4094     TypeOopPtr::eq(p);          // Check sub-type stuff
4095 }
4096 
4097 //------------------------------hash-------------------------------------------
4098 // Type-specific hashing function.
4099 int TypeInstPtr::hash(void) const {
4100   int hash = java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash());
4101   return hash;
4102 }
4103 
4104 //------------------------------dump2------------------------------------------
4105 // Dump oop Type
4106 #ifndef PRODUCT
4107 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4108   // Print the name of the klass.
4109   klass()->print_name_on(st);
4110 
4111   switch( _ptr ) {
4112   case Constant:
4113     if (WizardMode || Verbose) {
4114       ResourceMark rm;
4115       stringStream ss;
4116 
4117       st->print(" ");
4118       const_oop()->print_oop(&ss);
4119       // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4120       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4121       char* buf = ss.as_string(/* c_heap= */false);
4122       StringUtils::replace_no_expand(buf, "\n", "");
4123       st->print_raw(buf);
4124     }
4125   case BotPTR:
4126     if (!WizardMode && !Verbose) {
4127       if( _klass_is_exact ) st->print(":exact");
4128       break;
4129     }
4130   case TopPTR:
4131   case AnyNull:
4132   case NotNull:
4133     st->print(":%s", ptr_msg[_ptr]);
4134     if( _klass_is_exact ) st->print(":exact");
4135     break;
4136   default:
4137     break;
4138   }
4139 
4140   if( _offset ) {               // Dump offset, if any
4141     if( _offset == OffsetBot )      st->print("+any");
4142     else if( _offset == OffsetTop ) st->print("+unknown");
4143     else st->print("+%d", _offset);
4144   }
4145 
4146   st->print(" *");





4147   if (_instance_id == InstanceTop)
4148     st->print(",iid=top");
4149   else if (_instance_id != InstanceBot)
4150     st->print(",iid=%d",_instance_id);
4151 
4152   dump_inline_depth(st);
4153   dump_speculative(st);
4154 }
4155 #endif
4156 
4157 //------------------------------add_offset-------------------------------------
4158 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4159   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4160               _instance_id, add_offset_speculative(offset), _inline_depth);
4161 }
4162 
4163 const Type *TypeInstPtr::remove_speculative() const {
4164   if (_speculative == NULL) {
4165     return this;
4166   }
4167   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4168   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
4169               _instance_id, NULL, _inline_depth);
4170 }
4171 
4172 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4173   if (!UseInlineDepthForSpeculativeTypes) {
4174     return this;
4175   }
4176   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4177 }
4178 
4179 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4180   assert(is_known_instance(), "should be known");
4181   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);




4182 }
4183 
4184 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4185   bool xk = klass_is_exact();
4186   ciInstanceKlass* ik = klass()->as_instance_klass();
4187   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final() && !ik->is_interface()) {
4188     Compile* C = Compile::current();
4189     Dependencies* deps = C->dependencies();
4190     deps->assert_leaf_type(ik);
4191     xk = true;
4192   }
4193   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), 0);
4194 }
4195 
4196 //=============================================================================
4197 // Convenience common pre-built types.
4198 const TypeAryPtr *TypeAryPtr::RANGE;
4199 const TypeAryPtr *TypeAryPtr::OOPS;
4200 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4201 const TypeAryPtr *TypeAryPtr::BYTES;
4202 const TypeAryPtr *TypeAryPtr::SHORTS;
4203 const TypeAryPtr *TypeAryPtr::CHARS;
4204 const TypeAryPtr *TypeAryPtr::INTS;
4205 const TypeAryPtr *TypeAryPtr::LONGS;
4206 const TypeAryPtr *TypeAryPtr::FLOATS;
4207 const TypeAryPtr *TypeAryPtr::DOUBLES;

4208 
4209 //------------------------------make-------------------------------------------
4210 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4211                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4212   assert(!(k == NULL && ary->_elem->isa_int()),
4213          "integral arrays must be pre-equipped with a class");
4214   if (!xk)  xk = ary->ary_must_be_exact();
4215   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4216   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4217 }
4218 
4219 //------------------------------make-------------------------------------------
4220 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4221                                    int instance_id, const TypePtr* speculative, int inline_depth,
4222                                    bool is_autobox_cache) {
4223   assert(!(k == NULL && ary->_elem->isa_int()),
4224          "integral arrays must be pre-equipped with a class");
4225   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4226   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4227   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4228   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4229 }
4230 
4231 //------------------------------cast_to_ptr_type-------------------------------
4232 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4233   if( ptr == _ptr ) return this;
4234   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4235 }
4236 
4237 
4238 //-----------------------------cast_to_exactness-------------------------------
4239 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4240   if( klass_is_exact == _klass_is_exact ) return this;
4241   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4242   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);






4243 }
4244 
4245 //-----------------------------cast_to_instance_id----------------------------
4246 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4247   if( instance_id == _instance_id ) return this;
4248   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4249 }
4250 
4251 
4252 //-----------------------------max_array_length-------------------------------
4253 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4254 jint TypeAryPtr::max_array_length(BasicType etype) {
4255   if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4256     if (etype == T_NARROWOOP) {
4257       etype = T_OBJECT;
4258     } else if (etype == T_ILLEGAL) { // bottom[]
4259       etype = T_BYTE; // will produce conservatively high value
4260     } else {
4261       fatal("not an element type: %s", type2name(etype));
4262     }
4263   }
4264   return arrayOopDesc::max_array_length(etype);
4265 }
4266 
4267 //-----------------------------narrow_size_type-------------------------------
4268 // Narrow the given size type to the index range for the given array base type.

4284   if (hi > max_hi) {
4285     hi = max_hi;
4286     if (size->is_con()) {
4287       lo = hi;
4288     }
4289     chg = true;
4290   }
4291   // Negative length arrays will produce weird intermediate dead fast-path code
4292   if (lo > hi)
4293     return TypeInt::ZERO;
4294   if (!chg)
4295     return size;
4296   return TypeInt::make(lo, hi, Type::WidenMin);
4297 }
4298 
4299 //-------------------------------cast_to_size----------------------------------
4300 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4301   assert(new_size != NULL, "");
4302   new_size = narrow_size_type(new_size);
4303   if (new_size == size())  return this;
4304   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4305   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);


































4306 }
4307 
4308 //------------------------------cast_to_stable---------------------------------
4309 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4310   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4311     return this;
4312 
4313   const Type* elem = this->elem();
4314   const TypePtr* elem_ptr = elem->make_ptr();
4315 
4316   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4317     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4318     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4319   }
4320 
4321   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4322 
4323   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4324 }
4325 
4326 //-----------------------------stable_dimension--------------------------------
4327 int TypeAryPtr::stable_dimension() const {
4328   if (!is_stable())  return 0;
4329   int dim = 1;
4330   const TypePtr* elem_ptr = elem()->make_ptr();
4331   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4332     dim += elem_ptr->is_aryptr()->stable_dimension();
4333   return dim;
4334 }
4335 
4336 //----------------------cast_to_autobox_cache-----------------------------------
4337 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4338   if (is_autobox_cache())  return this;
4339   const TypeOopPtr* etype = elem()->make_oopptr();
4340   if (etype == NULL)  return this;
4341   // The pointers in the autobox arrays are always non-null.
4342   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4343   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4344   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4345 }
4346 
4347 //------------------------------eq---------------------------------------------
4348 // Structural equality check for Type representations
4349 bool TypeAryPtr::eq( const Type *t ) const {
4350   const TypeAryPtr *p = t->is_aryptr();
4351   return
4352     _ary == p->_ary &&  // Check array
4353     TypeOopPtr::eq(p);  // Check sub-parts

4354 }
4355 
4356 //------------------------------hash-------------------------------------------
4357 // Type-specific hashing function.
4358 int TypeAryPtr::hash(void) const {
4359   return (intptr_t)_ary + TypeOopPtr::hash();
4360 }
4361 
4362 //------------------------------meet-------------------------------------------
4363 // Compute the MEET of two types.  It returns a new Type object.
4364 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4365   // Perform a fast test for common case; meeting the same types together.
4366   if( this == t ) return this;  // Meeting same type-rep?
4367   // Current "this->_base" is Pointer
4368   switch (t->base()) {          // switch on original type
4369 
4370   // Mixing ints & oops happens when javac reuses local variables
4371   case Int:
4372   case Long:
4373   case FloatTop:
4374   case FloatCon:
4375   case FloatBot:
4376   case DoubleTop:
4377   case DoubleCon:
4378   case DoubleBot:
4379   case NarrowOop:
4380   case NarrowKlass:
4381   case Bottom:                  // Ye Olde Default
4382     return Type::BOTTOM;
4383   case Top:
4384     return this;
4385 
4386   default:                      // All else is a mistake
4387     typerr(t);
4388 
4389   case OopPtr: {                // Meeting to OopPtrs
4390     // Found a OopPtr type vs self-AryPtr type
4391     const TypeOopPtr *tp = t->is_oopptr();
4392     int offset = meet_offset(tp->offset());
4393     PTR ptr = meet_ptr(tp->ptr());
4394     int depth = meet_inline_depth(tp->inline_depth());
4395     const TypePtr* speculative = xmeet_speculative(tp);
4396     switch (tp->ptr()) {
4397     case TopPTR:
4398     case AnyNull: {
4399       int instance_id = meet_instance_id(InstanceTop);
4400       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4401                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4402     }
4403     case BotPTR:
4404     case NotNull: {
4405       int instance_id = meet_instance_id(tp->instance_id());
4406       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4407     }
4408     default: ShouldNotReachHere();
4409     }
4410   }
4411 
4412   case AnyPtr: {                // Meeting two AnyPtrs
4413     // Found an AnyPtr type vs self-AryPtr type
4414     const TypePtr *tp = t->is_ptr();
4415     int offset = meet_offset(tp->offset());
4416     PTR ptr = meet_ptr(tp->ptr());
4417     const TypePtr* speculative = xmeet_speculative(tp);
4418     int depth = meet_inline_depth(tp->inline_depth());
4419     switch (tp->ptr()) {
4420     case TopPTR:
4421       return this;
4422     case BotPTR:
4423     case NotNull:
4424       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4425     case Null:
4426       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4427       // else fall through to AnyNull
4428     case AnyNull: {
4429       int instance_id = meet_instance_id(InstanceTop);
4430       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4431                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4432     }
4433     default: ShouldNotReachHere();
4434     }
4435   }
4436 
4437   case MetadataPtr:
4438   case KlassPtr:
4439   case InstKlassPtr:
4440   case AryKlassPtr:
4441   case RawPtr: return TypePtr::BOTTOM;
4442 
4443   case AryPtr: {                // Meeting 2 references?
4444     const TypeAryPtr *tap = t->is_aryptr();
4445     int off = meet_offset(tap->offset());

4446     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4447     PTR ptr = meet_ptr(tap->ptr());
4448     int instance_id = meet_instance_id(tap->instance_id());
4449     const TypePtr* speculative = xmeet_speculative(tap);
4450     int depth = meet_inline_depth(tap->inline_depth());
4451 
4452     ciKlass* res_klass = NULL;
4453     bool res_xk = false;
4454     const Type* elem = tary->_elem;
4455     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) {






4456       instance_id = InstanceBot;











4457     }
4458 
4459     ciObject* o = NULL;             // Assume not constant when done
4460     ciObject* this_oop = const_oop();
4461     ciObject* tap_oop = tap->const_oop();
4462     if (ptr == Constant) {
4463       if (this_oop != NULL && tap_oop != NULL &&
4464           this_oop->equals(tap_oop)) {
4465         o = tap_oop;
4466       } else if (above_centerline(_ptr)) {
4467         o = tap_oop;
4468       } else if (above_centerline(tap->_ptr)) {
4469         o = this_oop;
4470       } else {
4471         ptr = NotNull;
4472       }
4473     }
4474     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4475   }
4476 
4477   // All arrays inherit from Object class
4478   case InstPtr: {
4479     const TypeInstPtr *tp = t->is_instptr();
4480     int offset = meet_offset(tp->offset());
4481     PTR ptr = meet_ptr(tp->ptr());
4482     int instance_id = meet_instance_id(tp->instance_id());
4483     const TypePtr* speculative = xmeet_speculative(tp);
4484     int depth = meet_inline_depth(tp->inline_depth());
4485     switch (ptr) {
4486     case TopPTR:
4487     case AnyNull:                // Fall 'down' to dual of object klass
4488       // For instances when a subclass meets a superclass we fall
4489       // below the centerline when the superclass is exact. We need to
4490       // do the same here.
4491       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4492         return make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4493       } else {
4494         // cannot subclass, so the meet has to fall badly below the centerline
4495         ptr = NotNull;
4496         instance_id = InstanceBot;
4497         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4498       }
4499     case Constant:
4500     case NotNull:
4501     case BotPTR:                // Fall down to object klass
4502       // LCA is object_klass, but if we subclass from the top we can do better
4503       if (above_centerline(tp->ptr())) {
4504         // If 'tp'  is above the centerline and it is Object class
4505         // then we can subclass in the Java class hierarchy.
4506         // For instances when a subclass meets a superclass we fall
4507         // below the centerline when the superclass is exact. We need
4508         // to do the same here.
4509         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4510           // that is, my array type is a subtype of 'tp' klass
4511           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4512                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4513         }
4514       }
4515       // The other case cannot happen, since t cannot be a subtype of an array.
4516       // The meet falls down to Object class below centerline.
4517       if (ptr == Constant) {
4518          ptr = NotNull;
4519       }
4520       if (instance_id > 0) {
4521         instance_id = InstanceBot;
4522       }
4523       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4524     default: typerr(t);
4525     }
4526   }













4527   }
4528   return this;                  // Lint noise
4529 }
4530 
4531 
4532 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) {






4533   res_klass = NULL;
4534   MeetResult result = SUBTYPE;
4535   if (elem->isa_int()) {




4536     // Integral array element types have irrelevant lattice relations.
4537     // It is the klass that determines array layout, not the element type.
4538     if (this_klass == NULL)
4539       res_klass = tap_klass;
4540     else if (tap_klass == NULL || tap_klass == this_klass) {
4541       res_klass = this_klass;
4542     } else {
4543       // Something like byte[int+] meets char[int+].
4544       // This must fall to bottom, not (int[-128..65535])[int+].
4545       // instance_id = InstanceBot;
4546       elem = Type::BOTTOM;
4547       result = NOT_SUBTYPE;
4548     }
4549   } else // Non integral arrays.
4550     // Must fall to bottom if exact klasses in upper lattice
4551     // are not equal or super klass is exact.
4552     if ((above_centerline(ptr) || ptr == Constant) && this_klass != tap_klass &&
4553         // meet with top[] and bottom[] are processed further down:
4554         tap_klass != NULL  && this_klass != NULL   &&
4555         // both are exact and not equal:
4556         ((tap_xk && this_xk) ||
4557          // 'tap'  is exact and super or unrelated:
4558          (tap_xk && !tap_klass->is_subtype_of(this_klass)) ||
4559          // 'this' is exact and super or unrelated:
4560          (this_xk && !this_klass->is_subtype_of(tap_klass)))) {
4561       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
4562         elem = Type::BOTTOM;

4563       }
4564       ptr = NotNull;
4565       res_xk = false;
4566       return NOT_SUBTYPE;
4567     }
4568 
4569   res_xk = false;
4570   switch (tap_ptr) {
4571     case AnyNull:
4572     case TopPTR:
4573       // Compute new klass on demand, do not use tap->_klass
4574       if (below_centerline(this_ptr)) {
4575         res_xk = this_xk;



4576       } else {
4577         res_xk = (tap_xk || this_xk);
4578       }
4579       return result;
4580     case Constant: {
4581       if (this_ptr == Constant) {
4582           res_xk = true;
4583       } else if(above_centerline(this_ptr)) {
4584         res_xk = true;
4585       } else {
4586         // Only precise for identical arrays
4587         res_xk = this_xk && (this_klass == tap_klass);
4588       }
4589       return result;
4590     }
4591     case NotNull:
4592     case BotPTR:
4593       // Compute new klass on demand, do not use tap->_klass
4594       if (above_centerline(this_ptr)) {
4595         res_xk = tap_xk;



4596       } else {
4597         res_xk = (tap_xk && this_xk) &&
4598           (this_klass == tap_klass); // Only precise for identical arrays
4599       }
4600       return result;
4601     default:  {
4602       ShouldNotReachHere();
4603       return result;
4604     }
4605   }

4606   return result;
4607 }
4608 
4609 
4610 //------------------------------xdual------------------------------------------
4611 // Dual: compute field-by-field dual
4612 const Type *TypeAryPtr::xdual() const {
4613   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());









4614 }
4615 
4616 //----------------------interface_vs_oop---------------------------------------
4617 #ifdef ASSERT
4618 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4619   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4620   if (t_aryptr) {
4621     return _ary->interface_vs_oop(t_aryptr->_ary);
4622   }
4623   return false;
4624 }
4625 #endif
4626 
4627 //------------------------------dump2------------------------------------------
4628 #ifndef PRODUCT
4629 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4630   _ary->dump2(d,depth,st);
4631   switch( _ptr ) {
4632   case Constant:
4633     const_oop()->print(st);
4634     break;
4635   case BotPTR:
4636     if (!WizardMode && !Verbose) {
4637       if( _klass_is_exact ) st->print(":exact");
4638       break;
4639     }
4640   case TopPTR:
4641   case AnyNull:
4642   case NotNull:
4643     st->print(":%s", ptr_msg[_ptr]);
4644     if( _klass_is_exact ) st->print(":exact");
4645     break;
4646   default:
4647     break;
4648   }
4649 
4650   if( _offset != 0 ) {





4651     int header_size = objArrayOopDesc::header_size() * wordSize;
4652     if( _offset == OffsetTop )       st->print("+undefined");
4653     else if( _offset == OffsetBot )  st->print("+any");
4654     else if( _offset < header_size ) st->print("+%d", _offset);
4655     else {
4656       BasicType basic_elem_type = elem()->basic_type();
4657       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4658       int elem_size = type2aelembytes(basic_elem_type);
4659       st->print("[%d]", (_offset - array_base)/elem_size);
4660     }
4661   }
4662   st->print(" *");
4663   if (_instance_id == InstanceTop)
4664     st->print(",iid=top");
4665   else if (_instance_id != InstanceBot)
4666     st->print(",iid=%d",_instance_id);
4667 
4668   dump_inline_depth(st);
4669   dump_speculative(st);
4670 }
4671 #endif
4672 
4673 bool TypeAryPtr::empty(void) const {
4674   if (_ary->empty())       return true;
4675   return TypeOopPtr::empty();
4676 }
4677 
4678 //------------------------------add_offset-------------------------------------
4679 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4680   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4681 }
4682 
4683 const Type *TypeAryPtr::remove_speculative() const {
4684   if (_speculative == NULL) {
4685     return this;
4686   }
4687   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4688   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);












4689 }
4690 
4691 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4692   if (!UseInlineDepthForSpeculativeTypes) {
4693     return this;
4694   }
4695   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);



















































4696 }
4697 
4698 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
4699   assert(is_known_instance(), "should be known");
4700   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4701 }
4702 
4703 //=============================================================================
4704 

4705 //------------------------------hash-------------------------------------------
4706 // Type-specific hashing function.
4707 int TypeNarrowPtr::hash(void) const {
4708   return _ptrtype->hash() + 7;
4709 }
4710 
4711 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4712   return _ptrtype->singleton();
4713 }
4714 
4715 bool TypeNarrowPtr::empty(void) const {
4716   return _ptrtype->empty();
4717 }
4718 
4719 intptr_t TypeNarrowPtr::get_con() const {
4720   return _ptrtype->get_con();
4721 }
4722 
4723 bool TypeNarrowPtr::eq( const Type *t ) const {
4724   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

4775 
4776   case Int:                     // Mixing ints & oops happens when javac
4777   case Long:                    // reuses local variables
4778   case FloatTop:
4779   case FloatCon:
4780   case FloatBot:
4781   case DoubleTop:
4782   case DoubleCon:
4783   case DoubleBot:
4784   case AnyPtr:
4785   case RawPtr:
4786   case OopPtr:
4787   case InstPtr:
4788   case AryPtr:
4789   case MetadataPtr:
4790   case KlassPtr:
4791   case InstKlassPtr:
4792   case AryKlassPtr:
4793   case NarrowOop:
4794   case NarrowKlass:
4795 
4796   case Bottom:                  // Ye Olde Default
4797     return Type::BOTTOM;
4798   case Top:
4799     return this;
4800 



4801   default:                      // All else is a mistake
4802     typerr(t);
4803 
4804   } // End of switch
4805 
4806   return this;
4807 }
4808 
4809 #ifndef PRODUCT
4810 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4811   _ptrtype->dump2(d, depth, st);
4812 }
4813 #endif
4814 
4815 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4816 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4817 
4818 
4819 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4820   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();

4859     return (one == two) && TypePtr::eq(t);
4860   } else {
4861     return one->equals(two) && TypePtr::eq(t);
4862   }
4863 }
4864 
4865 //------------------------------hash-------------------------------------------
4866 // Type-specific hashing function.
4867 int TypeMetadataPtr::hash(void) const {
4868   return
4869     (metadata() ? metadata()->hash() : 0) +
4870     TypePtr::hash();
4871 }
4872 
4873 //------------------------------singleton--------------------------------------
4874 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4875 // constants
4876 bool TypeMetadataPtr::singleton(void) const {
4877   // detune optimizer to not generate constant metadata + constant offset as a constant!
4878   // TopPTR, Null, AnyNull, Constant are all singletons
4879   return (_offset == 0) && !below_centerline(_ptr);
4880 }
4881 
4882 //------------------------------add_offset-------------------------------------
4883 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
4884   return make( _ptr, _metadata, xadd_offset(offset));
4885 }
4886 
4887 //-----------------------------filter------------------------------------------
4888 // Do not allow interface-vs.-noninterface joins to collapse to top.
4889 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
4890   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
4891   if (ft == NULL || ft->empty())
4892     return Type::TOP;           // Canonical empty value
4893   return ft;
4894 }
4895 
4896  //------------------------------get_con----------------------------------------
4897 intptr_t TypeMetadataPtr::get_con() const {
4898   assert( _ptr == Null || _ptr == Constant, "" );
4899   assert( _offset >= 0, "" );
4900 
4901   if (_offset != 0) {
4902     // After being ported to the compiler interface, the compiler no longer
4903     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4904     // to a handle at compile time.  This handle is embedded in the generated
4905     // code and dereferenced at the time the nmethod is made.  Until that time,
4906     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4907     // have access to the addresses!).  This does not seem to currently happen,
4908     // but this assertion here is to help prevent its occurence.
4909     tty->print_cr("Found oop constant with non-zero offset");
4910     ShouldNotReachHere();
4911   }
4912 
4913   return (intptr_t)metadata()->constant_encoding();
4914 }
4915 
4916 //------------------------------cast_to_ptr_type-------------------------------
4917 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
4918   if( ptr == _ptr ) return this;
4919   return make(ptr, metadata(), _offset);
4920 }
4921 

4932   case Long:                    // reuses local variables
4933   case FloatTop:
4934   case FloatCon:
4935   case FloatBot:
4936   case DoubleTop:
4937   case DoubleCon:
4938   case DoubleBot:
4939   case NarrowOop:
4940   case NarrowKlass:
4941   case Bottom:                  // Ye Olde Default
4942     return Type::BOTTOM;
4943   case Top:
4944     return this;
4945 
4946   default:                      // All else is a mistake
4947     typerr(t);
4948 
4949   case AnyPtr: {
4950     // Found an AnyPtr type vs self-OopPtr type
4951     const TypePtr *tp = t->is_ptr();
4952     int offset = meet_offset(tp->offset());
4953     PTR ptr = meet_ptr(tp->ptr());
4954     switch (tp->ptr()) {
4955     case Null:
4956       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4957       // else fall through:
4958     case TopPTR:
4959     case AnyNull: {
4960       return make(ptr, _metadata, offset);
4961     }
4962     case BotPTR:
4963     case NotNull:
4964       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
4965     default: typerr(t);
4966     }
4967   }
4968 
4969   case RawPtr:
4970   case KlassPtr:
4971   case InstKlassPtr:
4972   case AryKlassPtr:
4973   case OopPtr:
4974   case InstPtr:
4975   case AryPtr:
4976     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
4977 
4978   case MetadataPtr: {
4979     const TypeMetadataPtr *tp = t->is_metadataptr();
4980     int offset = meet_offset(tp->offset());
4981     PTR tptr = tp->ptr();
4982     PTR ptr = meet_ptr(tptr);
4983     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
4984     if (tptr == TopPTR || _ptr == TopPTR ||
4985         metadata()->equals(tp->metadata())) {
4986       return make(ptr, md, offset);
4987     }
4988     // metadata is different
4989     if( ptr == Constant ) {  // Cannot be equal constants, so...
4990       if( tptr == Constant && _ptr != Constant)  return t;
4991       if( _ptr == Constant && tptr != Constant)  return this;
4992       ptr = NotNull;            // Fall down in lattice
4993     }
4994     return make(ptr, NULL, offset);
4995     break;
4996   }
4997   } // End of switch
4998   return this;                  // Return the double constant
4999 }
5000 
5001 
5002 //------------------------------xdual------------------------------------------
5003 // Dual of a pure metadata pointer.
5004 const Type *TypeMetadataPtr::xdual() const {
5005   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5006 }
5007 
5008 //------------------------------dump2------------------------------------------
5009 #ifndef PRODUCT
5010 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5011   st->print("metadataptr:%s", ptr_msg[_ptr]);
5012   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5013   switch( _offset ) {
5014   case OffsetTop: st->print("+top"); break;
5015   case OffsetBot: st->print("+any"); break;
5016   case         0: break;
5017   default:        st->print("+%d",_offset); break;
5018   }
5019 }
5020 #endif
5021 
5022 
5023 //=============================================================================
5024 // Convenience common pre-built type.
5025 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5026 
5027 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5028   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5029 }
5030 
5031 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5032   return make(Constant, m, 0);
5033 }
5034 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5035   return make(Constant, m, 0);
5036 }
5037 
5038 //------------------------------make-------------------------------------------
5039 // Create a meta data constant
5040 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5041   assert(m == NULL || !m->is_klass(), "wrong type");
5042   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5043 }
5044 
5045 
5046 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5047   const Type* elem = _ary->_elem;
5048   bool xk = klass_is_exact();
5049   if (elem->make_oopptr() != NULL) {
5050     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5051     if (elem->is_klassptr()->klass_is_exact()) {
5052       xk = true;
5053     }
5054   }
5055   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5056 }
5057 
5058 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass) {
5059   if (klass->is_instance_klass()) {
5060     return TypeInstKlassPtr::make(klass);
5061   }
5062   return TypeAryKlassPtr::make(klass);
5063 }
5064 
5065 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset) {
5066   if (klass->is_instance_klass()) {
5067     return TypeInstKlassPtr::make(ptr, klass, offset);
5068   }
5069   return TypeAryKlassPtr::make(ptr, klass, offset);
5070 }
5071 
5072 
5073 //------------------------------TypeKlassPtr-----------------------------------
5074 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, int offset)
5075   : TypePtr(t, ptr, offset), _klass(klass) {
5076 }
5077 
5078 //------------------------------eq---------------------------------------------
5079 // Structural equality check for Type representations
5080 bool TypeKlassPtr::eq(const Type *t) const {
5081   const TypeKlassPtr *p = t->is_klassptr();
5082   return
5083     TypePtr::eq(p);
5084 }
5085 
5086 //------------------------------hash-------------------------------------------
5087 // Type-specific hashing function.
5088 int TypeKlassPtr::hash(void) const {
5089   return TypePtr::hash();
5090 }
5091 
5092 //------------------------------singleton--------------------------------------
5093 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5094 // constants
5095 bool TypeKlassPtr::singleton(void) const {
5096   // detune optimizer to not generate constant klass + constant offset as a constant!
5097   // TopPTR, Null, AnyNull, Constant are all singletons
5098   return (_offset == 0) && !below_centerline(_ptr);
5099 }
5100 
5101 // Do not allow interface-vs.-noninterface joins to collapse to top.
5102 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5103   // logic here mirrors the one from TypeOopPtr::filter. See comments
5104   // there.
5105   const Type* ft = join_helper(kills, include_speculative);
5106   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5107   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5108 
5109   if (ft->empty()) {
5110     if (!empty() && ktkp != NULL && ktkp->klass()->is_loaded() && ktkp->klass()->is_interface())
5111       return kills;             // Uplift to interface
5112 
5113     return Type::TOP;           // Canonical empty value
5114   }
5115 
5116   // Interface klass type could be exact in opposite to interface type,
5117   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5118   if (ftkp != NULL && ktkp != NULL &&
5119       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5120       !ftkp->klass_is_exact() && // Keep exact interface klass
5121       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5122     return ktkp->cast_to_ptr_type(ftkp->ptr());
5123   }
5124 
5125   return ft;
5126 }
5127 
5128 //------------------------------get_con----------------------------------------
5129 intptr_t TypeKlassPtr::get_con() const {
5130   assert( _ptr == Null || _ptr == Constant, "" );
5131   assert( _offset >= 0, "" );
5132 
5133   if (_offset != 0) {
5134     // After being ported to the compiler interface, the compiler no longer
5135     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5136     // to a handle at compile time.  This handle is embedded in the generated
5137     // code and dereferenced at the time the nmethod is made.  Until that time,
5138     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5139     // have access to the addresses!).  This does not seem to currently happen,
5140     // but this assertion here is to help prevent its occurence.
5141     tty->print_cr("Found oop constant with non-zero offset");
5142     ShouldNotReachHere();
5143   }
5144 
5145   return (intptr_t)klass()->constant_encoding();
5146 }
5147 
5148 //------------------------------dump2------------------------------------------
5149 // Dump Klass Type
5150 #ifndef PRODUCT
5151 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5152   switch(_ptr) {
5153   case Constant:
5154     st->print("precise ");
5155   case NotNull:
5156     {
5157       const char *name = klass()->name()->as_utf8();
5158       if (name) {
5159         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5160       } else {
5161         ShouldNotReachHere();
5162       }
5163     }
5164   case BotPTR:
5165     if (!WizardMode && !Verbose && _ptr != Constant) break;
5166   case TopPTR:
5167   case AnyNull:
5168     st->print(":%s", ptr_msg[_ptr]);
5169     if (_ptr == Constant) st->print(":exact");
5170     break;
5171   default:
5172     break;
5173   }
5174 
5175   if (_offset) {               // Dump offset, if any
5176     if (_offset == OffsetBot)      { st->print("+any"); }
5177     else if (_offset == OffsetTop) { st->print("+unknown"); }
5178     else                            { st->print("+%d", _offset); }
5179   }
5180 
5181   st->print(" *");
5182 }
5183 #endif
5184 
5185 //=============================================================================
5186 // Convenience common pre-built types.
5187 
5188 // Not-null object klass or below
5189 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5190 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5191 
5192 bool TypeInstKlassPtr::eq(const Type *t) const {
5193   const TypeKlassPtr *p = t->is_klassptr();
5194   return
5195     klass()->equals(p->klass()) &&

5196     TypeKlassPtr::eq(p);
5197 }
5198 
5199 int TypeInstKlassPtr::hash(void) const {
5200   return java_add((jint)klass()->hash(), TypeKlassPtr::hash());
5201 }
5202 
5203 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, int offset) {


5204   TypeInstKlassPtr *r =
5205     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, offset))->hashcons();
5206 
5207   return r;
5208 }
5209 
5210 //------------------------------add_offset-------------------------------------
5211 // Access internals of klass object
5212 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5213   return make( _ptr, klass(), xadd_offset(offset) );
5214 }
5215 
5216 const TypeKlassPtr *TypeInstKlassPtr::with_offset(intptr_t offset) const {
5217   return make(_ptr, klass(), offset);
5218 }
5219 
5220 //------------------------------cast_to_ptr_type-------------------------------
5221 const TypePtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5222   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5223   if( ptr == _ptr ) return this;
5224   return make(ptr, _klass, _offset);
5225 }
5226 
5227 
5228 bool TypeInstKlassPtr::must_be_exact() const {
5229   if (!_klass->is_loaded())  return false;
5230   ciInstanceKlass* ik = _klass->as_instance_klass();
5231   if (ik->is_final())  return true;  // cannot clear xk
5232   return false;
5233 }
5234 
5235 //-----------------------------cast_to_exactness-------------------------------
5236 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5237   if (klass_is_exact == (_ptr == Constant)) return this;
5238   if (must_be_exact()) return this;
5239   ciKlass* k = klass();
5240   return make(klass_is_exact ? Constant : NotNull, k, _offset);
5241 }
5242 
5243 
5244 //-----------------------------as_instance_type--------------------------------
5245 // Corresponding type for an instance of the given class.
5246 // It will be NotNull, and exact if and only if the klass type is exact.
5247 const TypeOopPtr* TypeInstKlassPtr::as_instance_type() const {
5248   ciKlass* k = klass();
5249   bool    xk = klass_is_exact();
5250   return TypeInstPtr::make(TypePtr::BotPTR, k, xk, NULL, 0);
5251 }
5252 
5253 //------------------------------xmeet------------------------------------------
5254 // Compute the MEET of two types, return a new Type object.
5255 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5256   // Perform a fast test for common case; meeting the same types together.
5257   if( this == t ) return this;  // Meeting same type-rep?
5258 
5259   // Current "this->_base" is Pointer
5260   switch (t->base()) {          // switch on original type
5261 
5262   case Int:                     // Mixing ints & oops happens when javac
5263   case Long:                    // reuses local variables
5264   case FloatTop:
5265   case FloatCon:
5266   case FloatBot:
5267   case DoubleTop:
5268   case DoubleCon:
5269   case DoubleBot:
5270   case NarrowOop:
5271   case NarrowKlass:
5272   case Bottom:                  // Ye Olde Default
5273     return Type::BOTTOM;
5274   case Top:
5275     return this;
5276 
5277   default:                      // All else is a mistake
5278     typerr(t);
5279 
5280   case AnyPtr: {                // Meeting to AnyPtrs
5281     // Found an AnyPtr type vs self-KlassPtr type
5282     const TypePtr *tp = t->is_ptr();
5283     int offset = meet_offset(tp->offset());
5284     PTR ptr = meet_ptr(tp->ptr());
5285     switch (tp->ptr()) {
5286     case TopPTR:
5287       return this;
5288     case Null:
5289       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5290     case AnyNull:
5291       return make( ptr, klass(), offset );
5292     case BotPTR:
5293     case NotNull:
5294       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5295     default: typerr(t);
5296     }
5297   }
5298 
5299   case RawPtr:
5300   case MetadataPtr:
5301   case OopPtr:
5302   case AryPtr:                  // Meet with AryPtr
5303   case InstPtr:                 // Meet with InstPtr
5304     return TypePtr::BOTTOM;
5305 
5306   //
5307   //             A-top         }
5308   //           /   |   \       }  Tops
5309   //       B-top A-any C-top   }
5310   //          | /  |  \ |      }  Any-nulls
5311   //       B-any   |   C-any   }
5312   //          |    |    |
5313   //       B-con A-con C-con   } constants; not comparable across classes
5314   //          |    |    |
5315   //       B-not   |   C-not   }
5316   //          | \  |  / |      }  not-nulls
5317   //       B-bot A-not C-bot   }
5318   //           \   |   /       }  Bottoms
5319   //             A-bot         }
5320   //
5321 
5322   case InstKlassPtr: {  // Meet two KlassPtr types
5323     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5324     int  off     = meet_offset(tkls->offset());
5325     PTR  ptr     = meet_ptr(tkls->ptr());
5326     ciKlass* tkls_klass = tkls->klass();
5327     ciKlass* this_klass  = klass();
5328     bool tkls_xk = tkls->klass_is_exact();
5329     bool this_xk  = klass_is_exact();


5330 
5331     ciKlass* res_klass = NULL;
5332     bool res_xk = false;
5333     switch(meet_instptr(ptr, this_klass, tkls_klass, this_xk, tkls_xk, this->_ptr, tkls->_ptr, res_klass, res_xk)) {


5334       case UNLOADED:
5335         ShouldNotReachHere();
5336       case SUBTYPE:
5337       case NOT_SUBTYPE:
5338       case LCA:
5339       case QUICK: {
5340         assert(res_xk == (ptr == Constant), "");
5341         const Type* res1 = make(ptr, res_klass, off);
5342         return res1;
5343       }
5344       default:
5345         ShouldNotReachHere();
5346     }
5347   } // End of case KlassPtr
5348   case AryKlassPtr: {                // All arrays inherit from Object class
5349     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5350     int offset = meet_offset(tp->offset());
5351     PTR ptr = meet_ptr(tp->ptr());
5352 
5353     switch (ptr) {
5354     case TopPTR:
5355     case AnyNull:                // Fall 'down' to dual of object klass
5356       // For instances when a subclass meets a superclass we fall
5357       // below the centerline when the superclass is exact. We need to
5358       // do the same here.
5359       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
5360         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5361       } else {
5362         // cannot subclass, so the meet has to fall badly below the centerline
5363         ptr = NotNull;
5364         return make(ptr, ciEnv::current()->Object_klass(), offset);
5365       }
5366     case Constant:
5367     case NotNull:
5368     case BotPTR:                // Fall down to object klass
5369       // LCA is object_klass, but if we subclass from the top we can do better
5370       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5371         // If 'this' (InstPtr) is above the centerline and it is Object class
5372         // then we can subclass in the Java class hierarchy.
5373         // For instances when a subclass meets a superclass we fall
5374         // below the centerline when the superclass is exact. We need
5375         // to do the same here.
5376         if (klass()->equals(ciEnv::current()->Object_klass())) {
5377           // that is, tp's array type is a subtype of my klass
5378           return TypeAryKlassPtr::make(ptr,
5379                                        tp->elem(), tp->klass(), offset);
5380         }
5381       }
5382       // The other case cannot happen, since I cannot be a subtype of an array.
5383       // The meet falls down to Object class below centerline.
5384       if( ptr == Constant )
5385          ptr = NotNull;
5386       return make(ptr, ciEnv::current()->Object_klass(), offset);
5387     default: typerr(t);
5388     }
5389   }




















5390 
5391   } // End of switch
5392   return this;                  // Return the double constant
5393 }
5394 
5395 //------------------------------xdual------------------------------------------
5396 // Dual: compute field-by-field dual
5397 const Type    *TypeInstKlassPtr::xdual() const {
5398   return new TypeInstKlassPtr(dual_ptr(), klass(), dual_offset());
5399 }
5400 
5401 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
5402   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
5403 }
5404 
5405 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* klass, int offset) {
5406   if (klass->is_obj_array_klass()) {
5407     // Element is an object array. Recursively call ourself.
5408     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
5409     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass)->cast_to_exactness(false);
5410     return TypeAryKlassPtr::make(ptr, etype, NULL, offset);








5411   } else if (klass->is_type_array_klass()) {
5412     // Element is an typeArray
5413     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
5414     return TypeAryKlassPtr::make(ptr, etype, klass, offset);



5415   } else {
5416     ShouldNotReachHere();
5417     return NULL;
5418   }
5419 }
5420 
5421 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass) {
5422   return TypeAryKlassPtr::make(Constant, klass, 0);







5423 }
5424 
5425 //------------------------------eq---------------------------------------------
5426 // Structural equality check for Type representations
5427 bool TypeAryKlassPtr::eq(const Type *t) const {
5428   const TypeAryKlassPtr *p = t->is_aryklassptr();
5429   return
5430     _elem == p->_elem &&  // Check array



5431     TypeKlassPtr::eq(p);  // Check sub-parts
5432 }
5433 
5434 //------------------------------hash-------------------------------------------
5435 // Type-specific hashing function.
5436 int TypeAryKlassPtr::hash(void) const {
5437   return (intptr_t)_elem + TypeKlassPtr::hash();
5438 }
5439 
5440 //----------------------compute_klass------------------------------------------
5441 // Compute the defining klass for this class
5442 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5443   // Compute _klass based on element type.
5444   ciKlass* k_ary = NULL;
5445   const TypeInstPtr *tinst;
5446   const TypeAryPtr *tary;
5447   const Type* el = elem();
5448   if (el->isa_narrowoop()) {
5449     el = el->make_ptr();
5450   }
5451 
5452   // Get element klass
5453   if ((tinst = el->isa_instptr()) != NULL) {
5454     // Compute array klass from element klass
5455     k_ary = ciObjArrayKlass::make(tinst->klass());






5456   } else if ((tary = el->isa_aryptr()) != NULL) {
5457     // Compute array klass from element klass
5458     ciKlass* k_elem = tary->klass();
5459     // If element type is something like bottom[], k_elem will be null.
5460     if (k_elem != NULL)
5461       k_ary = ciObjArrayKlass::make(k_elem);
5462   } else if ((el->base() == Type::Top) ||
5463              (el->base() == Type::Bottom)) {
5464     // element type of Bottom occurs from meet of basic type
5465     // and object; Top occurs when doing join on Bottom.
5466     // Leave k_ary at NULL.
5467   } else {
5468     // Cannot compute array klass directly from basic type,
5469     // since subtypes of TypeInt all have basic type T_INT.
5470 #ifdef ASSERT
5471     if (verify && el->isa_int()) {
5472       // Check simple cases when verifying klass.
5473       BasicType bt = T_ILLEGAL;
5474       if (el == TypeInt::BYTE) {
5475         bt = T_BYTE;

5500 
5501   // Oops, need to compute _klass and cache it
5502   ciKlass* k_ary = compute_klass();
5503 
5504   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5505     // The _klass field acts as a cache of the underlying
5506     // ciKlass for this array type.  In order to set the field,
5507     // we need to cast away const-ness.
5508     //
5509     // IMPORTANT NOTE: we *never* set the _klass field for the
5510     // type TypeAryPtr::OOPS.  This Type is shared between all
5511     // active compilations.  However, the ciKlass which represents
5512     // this Type is *not* shared between compilations, so caching
5513     // this value would result in fetching a dangling pointer.
5514     //
5515     // Recomputing the underlying ciKlass for each request is
5516     // a bit less efficient than caching, but calls to
5517     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5518     ((TypeAryPtr*)this)->_klass = k_ary;
5519     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5520         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
5521       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5522     }
5523   }
5524   return k_ary;
5525 }
5526 
5527 
5528 //------------------------------add_offset-------------------------------------
5529 // Access internals of klass object
5530 const TypePtr *TypeAryKlassPtr::add_offset(intptr_t offset) const {
5531   return make(_ptr, elem(), klass(), xadd_offset(offset));
5532 }
5533 
5534 const TypeKlassPtr *TypeAryKlassPtr::with_offset(intptr_t offset) const {
5535   return make(_ptr, elem(), klass(), offset);
5536 }
5537 
5538 //------------------------------cast_to_ptr_type-------------------------------
5539 const TypePtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
5540   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
5541   if (ptr == _ptr) return this;
5542   return make(ptr, elem(), _klass, _offset);
5543 }
5544 
5545 bool TypeAryKlassPtr::must_be_exact() const {
5546   if (_elem == Type::BOTTOM) return false;
5547   if (_elem == Type::TOP   ) return false;
5548   const TypeKlassPtr*  tk = _elem->isa_klassptr();
5549   if (!tk)             return true;   // a primitive type, like int
5550   return tk->must_be_exact();
5551 }
5552 
5553 
5554 //-----------------------------cast_to_exactness-------------------------------
5555 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5556   if (must_be_exact()) return this;  // cannot clear xk
5557   ciKlass* k = _klass;
5558   const Type* elem = this->elem();
5559   if (elem->isa_klassptr() && !klass_is_exact) {
5560     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
5561   }
5562   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);







5563 }
5564 
5565 
5566 //-----------------------------as_instance_type--------------------------------
5567 // Corresponding type for an instance of the given class.
5568 // It will be exact if and only if the klass type is exact.
5569 const TypeOopPtr* TypeAryKlassPtr::as_instance_type() const {
5570   ciKlass* k = klass();

5571   bool    xk = klass_is_exact();
5572   const Type* el = elem()->isa_klassptr() ? elem()->is_klassptr()->as_instance_type()->is_oopptr()->cast_to_exactness(false) : elem();
5573   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);






5574 }
5575 
5576 
5577 //------------------------------xmeet------------------------------------------
5578 // Compute the MEET of two types, return a new Type object.
5579 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
5580   // Perform a fast test for common case; meeting the same types together.
5581   if( this == t ) return this;  // Meeting same type-rep?
5582 
5583   // Current "this->_base" is Pointer
5584   switch (t->base()) {          // switch on original type
5585 
5586   case Int:                     // Mixing ints & oops happens when javac
5587   case Long:                    // reuses local variables
5588   case FloatTop:
5589   case FloatCon:
5590   case FloatBot:
5591   case DoubleTop:
5592   case DoubleCon:
5593   case DoubleBot:
5594   case NarrowOop:
5595   case NarrowKlass:
5596   case Bottom:                  // Ye Olde Default
5597     return Type::BOTTOM;
5598   case Top:
5599     return this;
5600 
5601   default:                      // All else is a mistake
5602     typerr(t);
5603 
5604   case AnyPtr: {                // Meeting to AnyPtrs
5605     // Found an AnyPtr type vs self-KlassPtr type
5606     const TypePtr *tp = t->is_ptr();
5607     int offset = meet_offset(tp->offset());
5608     PTR ptr = meet_ptr(tp->ptr());
5609     switch (tp->ptr()) {
5610     case TopPTR:
5611       return this;
5612     case Null:
5613       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5614     case AnyNull:
5615       return make( ptr, _elem, klass(), offset );
5616     case BotPTR:
5617     case NotNull:
5618       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5619     default: typerr(t);
5620     }
5621   }
5622 
5623   case RawPtr:
5624   case MetadataPtr:
5625   case OopPtr:
5626   case AryPtr:                  // Meet with AryPtr
5627   case InstPtr:                 // Meet with InstPtr
5628     return TypePtr::BOTTOM;
5629 
5630   //
5631   //             A-top         }
5632   //           /   |   \       }  Tops
5633   //       B-top A-any C-top   }
5634   //          | /  |  \ |      }  Any-nulls
5635   //       B-any   |   C-any   }
5636   //          |    |    |
5637   //       B-con A-con C-con   } constants; not comparable across classes
5638   //          |    |    |
5639   //       B-not   |   C-not   }
5640   //          | \  |  / |      }  not-nulls
5641   //       B-bot A-not C-bot   }
5642   //           \   |   /       }  Bottoms
5643   //             A-bot         }
5644   //
5645 
5646   case AryKlassPtr: {  // Meet two KlassPtr types
5647     const TypeAryKlassPtr *tap = t->is_aryklassptr();
5648     int off = meet_offset(tap->offset());
5649     const Type* elem = _elem->meet(tap->_elem);
5650 
5651     PTR ptr = meet_ptr(tap->ptr());
5652     ciKlass* res_klass = NULL;
5653     bool res_xk = false;
5654     meet_aryptr(ptr, elem, this->klass(), tap->klass(), this->klass_is_exact(), tap->klass_is_exact(), this->ptr(), tap->ptr(), res_klass, res_xk);






5655     assert(res_xk == (ptr == Constant), "");
5656     return make(ptr, elem, res_klass, off);










5657   } // End of case KlassPtr
5658   case InstKlassPtr: {
5659     const TypeInstKlassPtr *tp = t->is_instklassptr();
5660     int offset = meet_offset(tp->offset());
5661     PTR ptr = meet_ptr(tp->ptr());
5662 
5663     switch (ptr) {
5664     case TopPTR:
5665     case AnyNull:                // Fall 'down' to dual of object klass
5666       // For instances when a subclass meets a superclass we fall
5667       // below the centerline when the superclass is exact. We need to
5668       // do the same here.
5669       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
5670         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
5671       } else {
5672         // cannot subclass, so the meet has to fall badly below the centerline
5673         ptr = NotNull;
5674         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset);
5675       }
5676     case Constant:
5677     case NotNull:
5678     case BotPTR:                // Fall down to object klass
5679       // LCA is object_klass, but if we subclass from the top we can do better
5680       if (above_centerline(tp->ptr())) {
5681         // If 'tp'  is above the centerline and it is Object class
5682         // then we can subclass in the Java class hierarchy.
5683         // For instances when a subclass meets a superclass we fall
5684         // below the centerline when the superclass is exact. We need
5685         // to do the same here.
5686         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
5687           // that is, my array type is a subtype of 'tp' klass
5688           return make(ptr, _elem, _klass, offset);
5689         }
5690       }
5691       // The other case cannot happen, since t cannot be a subtype of an array.
5692       // The meet falls down to Object class below centerline.
5693       if (ptr == Constant)
5694          ptr = NotNull;
5695       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset);
5696     default: typerr(t);
5697     }
5698   }












5699 
5700   } // End of switch
5701   return this;                  // Return the double constant
5702 }
5703 
5704 //------------------------------xdual------------------------------------------
5705 // Dual: compute field-by-field dual
5706 const Type    *TypeAryKlassPtr::xdual() const {
5707   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
5708 }
5709 
5710 //------------------------------get_con----------------------------------------
5711 ciKlass* TypeAryKlassPtr::klass() const {
5712   if (_klass != NULL) {
5713     return _klass;
5714   }
5715   ciKlass* k = NULL;
5716   if (elem()->isa_klassptr()) {
5717     k = elem()->is_klassptr()->klass();
5718     if (k != NULL) {
5719       k = ciObjArrayKlass::make(k);














5720       ((TypeAryKlassPtr*)this)->_klass = k;
5721     }
5722   } else if ((elem()->base() == Type::Top) ||
5723              (elem()->base() == Type::Bottom)) {
5724   } else {
5725     k = ciTypeArrayKlass::make(elem()->basic_type());
5726   }
5727   return k;
5728 }
5729 
5730 //------------------------------dump2------------------------------------------
5731 // Dump Klass Type
5732 #ifndef PRODUCT
5733 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5734   switch( _ptr ) {
5735   case Constant:
5736     st->print("precise ");
5737   case NotNull:
5738     {
5739       st->print("[");




5740       _elem->dump2(d, depth, st);
5741       st->print(": ");
5742     }
5743   case BotPTR:
5744     if( !WizardMode && !Verbose && _ptr != Constant ) break;
5745   case TopPTR:
5746   case AnyNull:
5747     st->print(":%s", ptr_msg[_ptr]);
5748     if( _ptr == Constant ) st->print(":exact");
5749     break;
5750   default:
5751     break;
5752   }
5753 
5754   if( _offset ) {               // Dump offset, if any
5755     if( _offset == OffsetBot )      { st->print("+any"); }
5756     else if( _offset == OffsetTop ) { st->print("+unknown"); }
5757     else                            { st->print("+%d", _offset); }
5758   }
5759 


5760   st->print(" *");
5761 }
5762 #endif
5763 
5764 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
5765   const Type* elem = this->elem();
5766   dims = 1;
5767   while (elem->isa_aryklassptr()) {
5768     elem = elem->is_aryklassptr()->elem();
5769     dims++;
5770   }
5771   return elem;
5772 }
5773 
5774 //=============================================================================
5775 // Convenience common pre-built types.
5776 
5777 //------------------------------make-------------------------------------------
5778 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5779   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();












5780 }
5781 
5782 //------------------------------make-------------------------------------------
5783 const TypeFunc *TypeFunc::make(ciMethod* method) {
5784   Compile* C = Compile::current();
5785   const TypeFunc* tf = C->last_tf(method); // check cache
5786   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5787   const TypeTuple *domain;
5788   if (method->is_static()) {
5789     domain = TypeTuple::make_domain(NULL, method->signature());
5790   } else {
5791     domain = TypeTuple::make_domain(method->holder(), method->signature());













5792   }
5793   const TypeTuple *range  = TypeTuple::make_range(method->signature());
5794   tf = TypeFunc::make(domain, range);
5795   C->set_last_tf(method, tf);  // fill cache
5796   return tf;
5797 }
5798 
5799 //------------------------------meet-------------------------------------------
5800 // Compute the MEET of two types.  It returns a new Type object.
5801 const Type *TypeFunc::xmeet( const Type *t ) const {
5802   // Perform a fast test for common case; meeting the same types together.
5803   if( this == t ) return this;  // Meeting same type-rep?
5804 
5805   // Current "this->_base" is Func
5806   switch (t->base()) {          // switch on original type
5807 
5808   case Bottom:                  // Ye Olde Default
5809     return t;
5810 
5811   default:                      // All else is a mistake
5812     typerr(t);
5813 
5814   case Top:
5815     break;
5816   }
5817   return this;                  // Return the double constant
5818 }
5819 
5820 //------------------------------xdual------------------------------------------
5821 // Dual: compute field-by-field dual
5822 const Type *TypeFunc::xdual() const {
5823   return this;
5824 }
5825 
5826 //------------------------------eq---------------------------------------------
5827 // Structural equality check for Type representations
5828 bool TypeFunc::eq( const Type *t ) const {
5829   const TypeFunc *a = (const TypeFunc*)t;
5830   return _domain == a->_domain &&
5831     _range == a->_range;


5832 }
5833 
5834 //------------------------------hash-------------------------------------------
5835 // Type-specific hashing function.
5836 int TypeFunc::hash(void) const {
5837   return (intptr_t)_domain + (intptr_t)_range;
5838 }
5839 
5840 //------------------------------dump2------------------------------------------
5841 // Dump Function Type
5842 #ifndef PRODUCT
5843 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5844   if( _range->cnt() <= Parms )
5845     st->print("void");
5846   else {
5847     uint i;
5848     for (i = Parms; i < _range->cnt()-1; i++) {
5849       _range->field_at(i)->dump2(d,depth,st);
5850       st->print("/");
5851     }
5852     _range->field_at(i)->dump2(d,depth,st);
5853   }
5854   st->print(" ");
5855   st->print("( ");
5856   if( !depth || d[this] ) {     // Check for recursive dump
5857     st->print("...)");
5858     return;
5859   }
5860   d.Insert((void*)this,(void*)this);    // Stop recursion
5861   if (Parms < _domain->cnt())
5862     _domain->field_at(Parms)->dump2(d,depth-1,st);
5863   for (uint i = Parms+1; i < _domain->cnt(); i++) {
5864     st->print(", ");
5865     _domain->field_at(i)->dump2(d,depth-1,st);
5866   }
5867   st->print(" )");
5868 }
5869 #endif
5870 
5871 //------------------------------singleton--------------------------------------
5872 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5873 // constants (Ldi nodes).  Singletons are integer, float or double constants
5874 // or a single symbol.
5875 bool TypeFunc::singleton(void) const {
5876   return false;                 // Never a singleton
5877 }
5878 
5879 bool TypeFunc::empty(void) const {
5880   return false;                 // Never empty
5881 }
5882 
5883 
5884 BasicType TypeFunc::return_type() const{
5885   if (range()->cnt() == TypeFunc::Parms) {
5886     return T_VOID;
5887   }
5888   return range()->field_at(TypeFunc::Parms)->basic_type();
5889 }

   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_INLINE_TYPE, "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_INLINE_TYPE: {
 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_INLINE_TYPE:
 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_INLINE_TYPE: 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_INLINE_TYPE: 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_INLINE_TYPE] = 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_INLINE_TYPE] = 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_INLINE_TYPE] = 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;

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

1549   // Currently "this->_base" is a TypeInt
1550   switch (t->base()) {          // Switch on original type
1551   case AnyPtr:                  // Mixing with oops happens when javac
1552   case RawPtr:                  // reuses local variables
1553   case OopPtr:
1554   case InstPtr:
1555   case AryPtr:
1556   case MetadataPtr:
1557   case KlassPtr:
1558   case InstKlassPtr:
1559   case AryKlassPtr:
1560   case NarrowOop:
1561   case NarrowKlass:
1562   case Long:
1563   case FloatTop:
1564   case FloatCon:
1565   case FloatBot:
1566   case DoubleTop:
1567   case DoubleCon:
1568   case DoubleBot:
1569   case InlineType:
1570   case Bottom:                  // Ye Olde Default
1571     return Type::BOTTOM;
1572   default:                      // All else is a mistake
1573     typerr(t);
1574   case Top:                     // No change
1575     return this;
1576   case Int:                     // Int vs Int?
1577     break;
1578   }
1579 
1580   // Expand covered set
1581   const TypeInt *r = t->is_int();
1582   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1583 }
1584 
1585 //------------------------------xdual------------------------------------------
1586 // Dual: reverse hi & lo; flip widen
1587 const Type *TypeInt::xdual() const {
1588   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1589   return new TypeInt(_hi,_lo,w);

2037 
2038 bool TypeLong::empty(void) const {
2039   return _lo > _hi;
2040 }
2041 
2042 //=============================================================================
2043 // Convenience common pre-built types.
2044 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2045 const TypeTuple *TypeTuple::IFFALSE;
2046 const TypeTuple *TypeTuple::IFTRUE;
2047 const TypeTuple *TypeTuple::IFNEITHER;
2048 const TypeTuple *TypeTuple::LOOPBODY;
2049 const TypeTuple *TypeTuple::MEMBAR;
2050 const TypeTuple *TypeTuple::STORECONDITIONAL;
2051 const TypeTuple *TypeTuple::START_I2C;
2052 const TypeTuple *TypeTuple::INT_PAIR;
2053 const TypeTuple *TypeTuple::LONG_PAIR;
2054 const TypeTuple *TypeTuple::INT_CC_PAIR;
2055 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2056 
2057 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2058   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
2059     ciField* field = vk->nonstatic_field_at(j);
2060     BasicType bt = field->type()->basic_type();
2061     const Type* ft = Type::get_const_type(field->type());
2062     field_array[pos++] = ft;
2063     if (type2size[bt] == 2) {
2064       field_array[pos++] = Type::HALF;
2065     }
2066   }
2067 }
2068 
2069 //------------------------------make-------------------------------------------
2070 // Make a TypeTuple from the range of a method signature
2071 const TypeTuple *TypeTuple::make_range(ciSignature* sig, bool ret_vt_fields) {
2072   ciType* return_type = sig->return_type();
2073   uint arg_cnt = return_type->size();
2074   if (ret_vt_fields) {
2075     arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2076   }
2077 
2078   const Type **field_array = fields(arg_cnt);
2079   switch (return_type->basic_type()) {
2080   case T_LONG:
2081     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2082     field_array[TypeFunc::Parms+1] = Type::HALF;
2083     break;
2084   case T_DOUBLE:
2085     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2086     field_array[TypeFunc::Parms+1] = Type::HALF;
2087     break;
2088   case T_OBJECT:
2089   case T_ARRAY:
2090   case T_BOOLEAN:
2091   case T_CHAR:
2092   case T_FLOAT:
2093   case T_BYTE:
2094   case T_SHORT:
2095   case T_INT:
2096     field_array[TypeFunc::Parms] = get_const_type(return_type);
2097     break;
2098   case T_INLINE_TYPE:
2099     if (ret_vt_fields) {
2100       uint pos = TypeFunc::Parms;
2101       field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2102       collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2103     } else {
2104       field_array[TypeFunc::Parms] = get_const_type(return_type)->join_speculative(sig->returns_null_free_inline_type() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2105     }
2106     break;
2107   case T_VOID:
2108     break;
2109   default:
2110     ShouldNotReachHere();
2111   }
2112   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2113 }
2114 
2115 // Make a TypeTuple from the domain of a method signature
2116 const TypeTuple *TypeTuple::make_domain(ciMethod* method, bool vt_fields_as_args) {
2117   ciSignature* sig = method->signature();
2118   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2119   if (vt_fields_as_args) {
2120     arg_cnt = 0;
2121     for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2122       arg_cnt += type2size[(*sig_cc)._bt];
2123     }
2124   }
2125 
2126   uint pos = TypeFunc::Parms;
2127   const Type** field_array = fields(arg_cnt);
2128   if (!method->is_static()) {
2129     ciInstanceKlass* recv = method->holder();
2130     if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields()) {
2131       collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2132     } else {
2133       field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2134     }
2135   }
2136 
2137   int i = 0;
2138   while (pos < TypeFunc::Parms + arg_cnt) {
2139     ciType* type = sig->type_at(i);
2140     BasicType bt = type->basic_type();
2141 
2142     switch (bt) {
2143     case T_LONG:
2144       field_array[pos++] = TypeLong::LONG;
2145       field_array[pos++] = Type::HALF;
2146       break;
2147     case T_DOUBLE:
2148       field_array[pos++] = Type::DOUBLE;
2149       field_array[pos++] = Type::HALF;
2150       break;
2151     case T_OBJECT:
2152     case T_ARRAY:
2153     case T_FLOAT:
2154     case T_INT:
2155       field_array[pos++] = get_const_type(type);
2156       break;
2157     case T_BOOLEAN:
2158     case T_CHAR:
2159     case T_BYTE:
2160     case T_SHORT:
2161       field_array[pos++] = TypeInt::INT;
2162       break;
2163     case T_INLINE_TYPE: {
2164       bool is_null_free = sig->is_null_free_at(i);
2165       if (vt_fields_as_args && type->as_inline_klass()->can_be_passed_as_fields() && is_null_free) {
2166         collect_inline_fields(type->as_inline_klass(), field_array, pos);
2167       } else {
2168         field_array[pos++] = get_const_type(type)->join_speculative(is_null_free ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2169       }
2170       break;
2171     }
2172     default:
2173       ShouldNotReachHere();
2174     }
2175     i++;
2176   }
2177   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2178 
2179   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2180 }
2181 
2182 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2183   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2184 }
2185 
2186 //------------------------------fields-----------------------------------------
2187 // Subroutine call type with space allocated for argument types
2188 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2189 const Type **TypeTuple::fields( uint arg_cnt ) {
2190   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2191   flds[TypeFunc::Control  ] = Type::CONTROL;
2192   flds[TypeFunc::I_O      ] = Type::ABIO;
2193   flds[TypeFunc::Memory   ] = Type::MEMORY;
2194   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2195   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2196 
2197   return flds;

2292     if (_fields[i]->empty())  return true;
2293   }
2294   return false;
2295 }
2296 
2297 //=============================================================================
2298 // Convenience common pre-built types.
2299 
2300 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2301   // Certain normalizations keep us sane when comparing types.
2302   // We do not want arrayOop variables to differ only by the wideness
2303   // of their index types.  Pick minimum wideness, since that is the
2304   // forced wideness of small ranges anyway.
2305   if (size->_widen != Type::WidenMin)
2306     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2307   else
2308     return size;
2309 }
2310 
2311 //------------------------------make-------------------------------------------
2312 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2313                              bool not_flat, bool not_null_free) {
2314   if (UseCompressedOops && elem->isa_oopptr()) {
2315     elem = elem->make_narrowoop();
2316   }
2317   size = normalize_array_size(size);
2318   return (TypeAry*)(new TypeAry(elem, size, stable, not_flat, not_null_free))->hashcons();
2319 }
2320 
2321 //------------------------------meet-------------------------------------------
2322 // Compute the MEET of two types.  It returns a new Type object.
2323 const Type *TypeAry::xmeet( const Type *t ) const {
2324   // Perform a fast test for common case; meeting the same types together.
2325   if( this == t ) return this;  // Meeting same type-rep?
2326 
2327   // Current "this->_base" is Ary
2328   switch (t->base()) {          // switch on original type
2329 
2330   case Bottom:                  // Ye Olde Default
2331     return t;
2332 
2333   default:                      // All else is a mistake
2334     typerr(t);
2335 
2336   case Array: {                 // Meeting 2 arrays?
2337     const TypeAry *a = t->is_ary();
2338     return TypeAry::make(_elem->meet_speculative(a->_elem),
2339                          _size->xmeet(a->_size)->is_int(),
2340                          _stable && a->_stable,
2341                          _not_flat && a->_not_flat,
2342                          _not_null_free && a->_not_null_free);
2343   }
2344   case Top:
2345     break;
2346   }
2347   return this;                  // Return the double constant
2348 }
2349 
2350 //------------------------------xdual------------------------------------------
2351 // Dual: compute field-by-field dual
2352 const Type *TypeAry::xdual() const {
2353   const TypeInt* size_dual = _size->dual()->is_int();
2354   size_dual = normalize_array_size(size_dual);
2355   return new TypeAry(_elem->dual(), size_dual, !_stable, !_not_flat, !_not_null_free);
2356 }
2357 
2358 //------------------------------eq---------------------------------------------
2359 // Structural equality check for Type representations
2360 bool TypeAry::eq( const Type *t ) const {
2361   const TypeAry *a = (const TypeAry*)t;
2362   return _elem == a->_elem &&
2363     _stable == a->_stable &&
2364     _size == a->_size &&
2365     _not_flat == a->_not_flat &&
2366     _not_null_free == a->_not_null_free;
2367 
2368 }
2369 
2370 //------------------------------hash-------------------------------------------
2371 // Type-specific hashing function.
2372 int TypeAry::hash(void) const {
2373   return (intptr_t)_elem + (intptr_t)_size + (_stable ? 43 : 0);
2374 }
2375 
2376 /**
2377  * Return same type without a speculative part in the element
2378  */
2379 const Type* TypeAry::remove_speculative() const {
2380   return make(_elem->remove_speculative(), _size, _stable, _not_flat, _not_null_free);
2381 }
2382 
2383 /**
2384  * Return same type with cleaned up speculative part of element
2385  */
2386 const Type* TypeAry::cleanup_speculative() const {
2387   return make(_elem->cleanup_speculative(), _size, _stable, _not_flat, _not_null_free);
2388 }
2389 
2390 /**
2391  * Return same type but with a different inline depth (used for speculation)
2392  *
2393  * @param depth  depth to meet with
2394  */
2395 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2396   if (!UseInlineDepthForSpeculativeTypes) {
2397     return this;
2398   }
2399   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2400 }
2401 
2402 //----------------------interface_vs_oop---------------------------------------
2403 #ifdef ASSERT
2404 bool TypeAry::interface_vs_oop(const Type *t) const {
2405   const TypeAry* t_ary = t->is_ary();
2406   if (t_ary) {
2407     const TypePtr* this_ptr = _elem->make_ptr(); // In case we have narrow_oops
2408     const TypePtr*    t_ptr = t_ary->_elem->make_ptr();
2409     if(this_ptr != NULL && t_ptr != NULL) {
2410       return this_ptr->interface_vs_oop(t_ptr);
2411     }
2412   }
2413   return false;
2414 }
2415 #endif
2416 
2417 //------------------------------dump2------------------------------------------
2418 #ifndef PRODUCT
2419 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2420   if (_stable)  st->print("stable:");
2421   if (Verbose) {
2422     if (_not_flat) st->print("not flat:");
2423     if (_not_null_free) st->print("not null free:");
2424   }
2425   _elem->dump2(d, depth, st);
2426   st->print("[");
2427   _size->dump2(d, depth, st);
2428   st->print("]");
2429 }
2430 #endif
2431 
2432 //------------------------------singleton--------------------------------------
2433 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2434 // constants (Ldi nodes).  Singletons are integer, float or double constants
2435 // or a single symbol.
2436 bool TypeAry::singleton(void) const {
2437   return false;                 // Never a singleton
2438 }
2439 
2440 bool TypeAry::empty(void) const {
2441   return _elem->empty() || _size->empty();
2442 }
2443 
2444 //--------------------------ary_must_be_exact----------------------------------

2446   // This logic looks at the element type of an array, and returns true
2447   // if the element type is either a primitive or a final instance class.
2448   // In such cases, an array built on this ary must have no subclasses.
2449   if (_elem == BOTTOM)      return false;  // general array not exact
2450   if (_elem == TOP   )      return false;  // inverted general array not exact
2451   const TypeOopPtr*  toop = NULL;
2452   if (UseCompressedOops && _elem->isa_narrowoop()) {
2453     toop = _elem->make_ptr()->isa_oopptr();
2454   } else {
2455     toop = _elem->isa_oopptr();
2456   }
2457   if (!toop)                return true;   // a primitive type, like int
2458   ciKlass* tklass = toop->klass();
2459   if (tklass == NULL)       return false;  // unloaded class
2460   if (!tklass->is_loaded()) return false;  // unloaded class
2461   const TypeInstPtr* tinst;
2462   if (_elem->isa_narrowoop())
2463     tinst = _elem->make_ptr()->isa_instptr();
2464   else
2465     tinst = _elem->isa_instptr();
2466   if (tinst) {
2467     if (tklass->as_instance_klass()->is_final()) {
2468       // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
2469       if (tinst->is_inlinetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2470         return false;
2471       }
2472       return true;
2473     }
2474     return false;
2475   }
2476   const TypeAryPtr*  tap;
2477   if (_elem->isa_narrowoop())
2478     tap = _elem->make_ptr()->isa_aryptr();
2479   else
2480     tap = _elem->isa_aryptr();
2481   if (tap)
2482     return tap->ary()->ary_must_be_exact();
2483   return false;
2484 }
2485 
2486 //==============================TypeInlineType=======================================
2487 
2488 const TypeInlineType* TypeInlineType::BOTTOM;
2489 
2490 //------------------------------make-------------------------------------------
2491 const TypeInlineType* TypeInlineType::make(ciInlineKlass* vk, bool larval) {
2492   return (TypeInlineType*)(new TypeInlineType(vk, larval))->hashcons();
2493 }
2494 
2495 //------------------------------meet-------------------------------------------
2496 // Compute the MEET of two types.  It returns a new Type object.
2497 const Type* TypeInlineType::xmeet(const Type* t) const {
2498   // Perform a fast test for common case; meeting the same types together.
2499   if(this == t) return this;  // Meeting same type-rep?
2500 
2501   // Current "this->_base" is InlineType
2502   switch (t->base()) {          // switch on original type
2503 
2504   case Int:
2505   case Long:
2506   case FloatTop:
2507   case FloatCon:
2508   case FloatBot:
2509   case DoubleTop:
2510   case DoubleCon:
2511   case DoubleBot:
2512   case NarrowKlass:
2513   case Bottom:
2514     return Type::BOTTOM;
2515 
2516   case OopPtr:
2517   case MetadataPtr:
2518   case KlassPtr:
2519   case RawPtr:
2520   case AnyPtr:
2521     return TypePtr::BOTTOM;
2522 
2523   case Top:
2524     return this;
2525 
2526   case NarrowOop: {
2527     const Type* res = t->make_ptr()->xmeet(this);
2528     if (res->isa_ptr()) {
2529       return res->make_narrowoop();
2530     }
2531     return res;
2532   }
2533 
2534   case InstKlassPtr:
2535   case AryKlassPtr:
2536   case AryPtr:
2537   case InstPtr: {
2538     return t->xmeet(this);
2539   }
2540 
2541   case InlineType: {
2542     // All inline types inherit from Object
2543     const TypeInlineType* other = t->is_inlinetype();
2544     if (_vk == NULL) {
2545       return this;
2546     } else if (other->_vk == NULL) {
2547       return other;
2548     } else if (_vk == other->_vk) {
2549       if (_larval == other->_larval ||
2550           !_larval) {
2551         return this;
2552       } else {
2553         return t;
2554       }
2555     }
2556     return TypeInstPtr::NOTNULL;
2557   }
2558 
2559   default:                      // All else is a mistake
2560     typerr(t);
2561 
2562   }
2563   return this;
2564 }
2565 
2566 //------------------------------xdual------------------------------------------
2567 const Type* TypeInlineType::xdual() const {
2568   return this;
2569 }
2570 
2571 //------------------------------eq---------------------------------------------
2572 // Structural equality check for Type representations
2573 bool TypeInlineType::eq(const Type* t) const {
2574   const TypeInlineType* vt = t->is_inlinetype();
2575   return (_vk == vt->inline_klass() && _larval == vt->larval());
2576 }
2577 
2578 //------------------------------hash-------------------------------------------
2579 // Type-specific hashing function.
2580 int TypeInlineType::hash(void) const {
2581   return (intptr_t)_vk;
2582 }
2583 
2584 //------------------------------singleton--------------------------------------
2585 // TRUE if Type is a singleton type, FALSE otherwise. Singletons are simple constants.
2586 bool TypeInlineType::singleton(void) const {
2587   return false;
2588 }
2589 
2590 //------------------------------empty------------------------------------------
2591 // TRUE if Type is a type with no values, FALSE otherwise.
2592 bool TypeInlineType::empty(void) const {
2593   return false;
2594 }
2595 
2596 //------------------------------dump2------------------------------------------
2597 #ifndef PRODUCT
2598 void TypeInlineType::dump2(Dict &d, uint depth, outputStream* st) const {
2599   if (_vk == NULL) {
2600     st->print("BOTTOM inlinetype");
2601     return;
2602   }
2603   int count = _vk->nof_declared_nonstatic_fields();
2604   st->print("inlinetype[%d]:{", count);
2605   st->print("%s", count != 0 ? _vk->declared_nonstatic_field_at(0)->type()->name() : "empty");
2606   for (int i = 1; i < count; ++i) {
2607     st->print(", %s", _vk->declared_nonstatic_field_at(i)->type()->name());
2608   }
2609   st->print("}%s", _larval?" : larval":"");
2610 }
2611 #endif
2612 
2613 //==============================TypeVect=======================================
2614 // Convenience common pre-built types.
2615 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2616 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2617 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2618 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2619 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2620 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2621 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2622 
2623 //------------------------------make-------------------------------------------
2624 const TypeVect* TypeVect::make(const Type *elem, uint length) {
2625   BasicType elem_bt = elem->array_element_basic_type();
2626   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2627   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2628   int size = length * type2aelembytes(elem_bt);
2629   switch (Matcher::vector_ideal_reg(size)) {
2630   case Op_VecA:
2631     return (TypeVect*)(new TypeVectA(elem, length))->hashcons();
2632   case Op_VecS:

2765 
2766 //=============================================================================
2767 // Convenience common pre-built types.
2768 const TypePtr *TypePtr::NULL_PTR;
2769 const TypePtr *TypePtr::NOTNULL;
2770 const TypePtr *TypePtr::BOTTOM;
2771 
2772 //------------------------------meet-------------------------------------------
2773 // Meet over the PTR enum
2774 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2775   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2776   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2777   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2778   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2779   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2780   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2781   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2782 };
2783 
2784 //------------------------------make-------------------------------------------
2785 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2786   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2787 }
2788 
2789 //------------------------------cast_to_ptr_type-------------------------------
2790 const Type *TypePtr::cast_to_ptr_type(PTR ptr) const {
2791   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2792   if( ptr == _ptr ) return this;
2793   return make(_base, ptr, _offset, _speculative, _inline_depth);
2794 }
2795 
2796 //------------------------------get_con----------------------------------------
2797 intptr_t TypePtr::get_con() const {
2798   assert( _ptr == Null, "" );
2799   return offset();
2800 }
2801 
2802 //------------------------------meet-------------------------------------------
2803 // Compute the MEET of two types.  It returns a new Type object.
2804 const Type *TypePtr::xmeet(const Type *t) const {
2805   const Type* res = xmeet_helper(t);
2806   if (res->isa_ptr() == NULL) {
2807     return res;
2808   }
2809 
2810   const TypePtr* res_ptr = res->is_ptr();
2811   if (res_ptr->speculative() != NULL) {
2812     // type->speculative() == NULL means that speculation is no better
2813     // than type, i.e. type->speculative() == type. So there are 2
2814     // ways to represent the fact that we have no useful speculative
2815     // data and we should use a single one to be able to test for
2816     // equality between types. Check whether type->speculative() ==
2817     // type and set speculative to NULL if it is the case.
2818     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2819       return res_ptr->remove_speculative();

2841   case NarrowKlass:
2842   case Bottom:                  // Ye Olde Default
2843     return Type::BOTTOM;
2844   case Top:
2845     return this;
2846 
2847   case AnyPtr: {                // Meeting to AnyPtrs
2848     const TypePtr *tp = t->is_ptr();
2849     const TypePtr* speculative = xmeet_speculative(tp);
2850     int depth = meet_inline_depth(tp->inline_depth());
2851     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2852   }
2853   case RawPtr:                  // For these, flip the call around to cut down
2854   case OopPtr:
2855   case InstPtr:                 // on the cases I have to handle.
2856   case AryPtr:
2857   case MetadataPtr:
2858   case KlassPtr:
2859   case InstKlassPtr:
2860   case AryKlassPtr:
2861   case InlineType:
2862     return t->xmeet(this);      // Call in reverse direction
2863   default:                      // All else is a mistake
2864     typerr(t);
2865 
2866   }
2867   return this;
2868 }
2869 
2870 //------------------------------meet_offset------------------------------------
2871 Type::Offset TypePtr::meet_offset(int offset) const {
2872   return _offset.meet(Offset(offset));





2873 }
2874 
2875 //------------------------------dual_offset------------------------------------
2876 Type::Offset TypePtr::dual_offset() const {
2877   return _offset.dual();


2878 }
2879 
2880 //------------------------------xdual------------------------------------------
2881 // Dual: compute field-by-field dual
2882 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2883   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2884 };
2885 const Type *TypePtr::xdual() const {
2886   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2887 }
2888 
2889 //------------------------------xadd_offset------------------------------------
2890 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2891   return _offset.add(offset);











2892 }
2893 
2894 //------------------------------add_offset-------------------------------------
2895 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2896   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2897 }
2898 
2899 //------------------------------eq---------------------------------------------
2900 // Structural equality check for Type representations
2901 bool TypePtr::eq( const Type *t ) const {
2902   const TypePtr *a = (const TypePtr*)t;
2903   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2904 }
2905 
2906 //------------------------------hash-------------------------------------------
2907 // Type-specific hashing function.
2908 int TypePtr::hash(void) const {
2909   return java_add(java_add((jint)_ptr, (jint)offset()), java_add((jint)hash_speculative(), (jint)_inline_depth));
2910 ;
2911 }
2912 
2913 /**
2914  * Return same type without a speculative part
2915  */
2916 const Type* TypePtr::remove_speculative() const {
2917   if (_speculative == NULL) {
2918     return this;
2919   }
2920   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2921   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2922 }
2923 
2924 /**
2925  * Return same type but drop speculative part if we know we won't use
2926  * it
2927  */
2928 const Type* TypePtr::cleanup_speculative() const {
2929   if (speculative() == NULL) {

3149   }
3150   // We already know the speculative type is always null
3151   if (speculative_always_null()) {
3152     return false;
3153   }
3154   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
3155     return false;
3156   }
3157   return true;
3158 }
3159 
3160 //------------------------------dump2------------------------------------------
3161 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3162   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
3163 };
3164 
3165 #ifndef PRODUCT
3166 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3167   if( _ptr == Null ) st->print("NULL");
3168   else st->print("%s *", ptr_msg[_ptr]);
3169   _offset.dump2(st);


3170   dump_inline_depth(st);
3171   dump_speculative(st);
3172 }
3173 
3174 /**
3175  *dump the speculative part of the type
3176  */
3177 void TypePtr::dump_speculative(outputStream *st) const {
3178   if (_speculative != NULL) {
3179     st->print(" (speculative=");
3180     _speculative->dump_on(st);
3181     st->print(")");
3182   }
3183 }
3184 
3185 /**
3186  *dump the inline depth of the type
3187  */
3188 void TypePtr::dump_inline_depth(outputStream *st) const {
3189   if (_inline_depth != InlineDepthBottom) {
3190     if (_inline_depth == InlineDepthTop) {
3191       st->print(" (inline_depth=InlineDepthTop)");
3192     } else {
3193       st->print(" (inline_depth=%d)", _inline_depth);
3194     }
3195   }
3196 }
3197 #endif
3198 
3199 //------------------------------singleton--------------------------------------
3200 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3201 // constants
3202 bool TypePtr::singleton(void) const {
3203   // TopPTR, Null, AnyNull, Constant are all singletons
3204   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3205 }
3206 
3207 bool TypePtr::empty(void) const {
3208   return (_offset == Offset::top) || above_centerline(_ptr);
3209 }
3210 
3211 //=============================================================================
3212 // Convenience common pre-built types.
3213 const TypeRawPtr *TypeRawPtr::BOTTOM;
3214 const TypeRawPtr *TypeRawPtr::NOTNULL;
3215 
3216 //------------------------------make-------------------------------------------
3217 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3218   assert( ptr != Constant, "what is the constant?" );
3219   assert( ptr != Null, "Use TypePtr for NULL" );
3220   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3221 }
3222 
3223 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3224   assert( bits, "Use TypePtr for NULL" );
3225   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3226 }
3227 
3228 //------------------------------cast_to_ptr_type-------------------------------

3332 // Type-specific hashing function.
3333 int TypeRawPtr::hash(void) const {
3334   return (intptr_t)_bits + TypePtr::hash();
3335 }
3336 
3337 //------------------------------dump2------------------------------------------
3338 #ifndef PRODUCT
3339 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3340   if( _ptr == Constant )
3341     st->print(INTPTR_FORMAT, p2i(_bits));
3342   else
3343     st->print("rawptr:%s", ptr_msg[_ptr]);
3344 }
3345 #endif
3346 
3347 //=============================================================================
3348 // Convenience common pre-built type.
3349 const TypeOopPtr *TypeOopPtr::BOTTOM;
3350 
3351 //------------------------------TypeOopPtr-------------------------------------
3352 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset,
3353                        int instance_id, const TypePtr* speculative, int inline_depth)
3354   : TypePtr(t, ptr, offset, speculative, inline_depth),
3355     _const_oop(o), _klass(k),
3356     _klass_is_exact(xk),
3357     _is_ptr_to_narrowoop(false),
3358     _is_ptr_to_narrowklass(false),
3359     _is_ptr_to_boxed_value(false),
3360     _instance_id(instance_id) {
3361   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3362       (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3363     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3364   }
3365 #ifdef _LP64
3366   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3367     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3368       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3369     } else if (klass() == NULL) {
3370       // Array with unknown body type
3371       assert(this->isa_aryptr(), "only arrays without klass");
3372       _is_ptr_to_narrowoop = UseCompressedOops;
3373     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3374       if (klass()->is_obj_array_klass()) {
3375         _is_ptr_to_narrowoop = true;
3376       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3377         // Check if the field of the inline type array element contains oops
3378         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3379         int foffset = field_offset.get() + vk->first_field_offset();
3380         ciField* field = vk->get_field_by_offset(foffset, false);
3381         assert(field != NULL, "missing field");
3382         BasicType bt = field->layout_type();
3383         _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(bt);
3384       }
3385     } else if (klass()->is_instance_klass()) {


3386       if (this->isa_klassptr()) {
3387         // Perm objects don't use compressed references
3388       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3389         // unsafe access
3390         _is_ptr_to_narrowoop = UseCompressedOops;
3391       } else {
3392         assert(this->isa_instptr(), "must be an instance ptr.");

3393         if (klass() == ciEnv::current()->Class_klass() &&
3394             (this->offset() == java_lang_Class::klass_offset() ||
3395              this->offset() == java_lang_Class::array_klass_offset())) {
3396           // Special hidden fields from the Class.
3397           assert(this->isa_instptr(), "must be an instance ptr.");
3398           _is_ptr_to_narrowoop = false;
3399         } else if (klass() == ciEnv::current()->Class_klass() &&
3400                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3401           // Static fields
3402           ciField* field = NULL;
3403           if (const_oop() != NULL) {
3404             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3405             if (k->is_inlinetype() && this->offset() == k->as_inline_klass()->default_value_offset()) {
3406               // Special hidden field that contains the oop of the default inline type
3407               // basic_elem_type = T_INLINE_TYPE;
3408              _is_ptr_to_narrowoop = UseCompressedOops;
3409             } else {
3410               field = k->get_field_by_offset(this->offset(), true);
3411               if (field != NULL) {
3412                 BasicType basic_elem_type = field->layout_type();
3413                 _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3414               } else {
3415                 // unsafe access
3416                 _is_ptr_to_narrowoop = UseCompressedOops;
3417               }
3418             }
3419           }
3420         } else {
3421           // Instance fields which contains a compressed oop references.
3422           ciInstanceKlass* ik = klass()->as_instance_klass();
3423           ciField* field = ik->get_field_by_offset(this->offset(), false);
3424           if (field != NULL) {
3425             BasicType basic_elem_type = field->layout_type();
3426             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3427           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3428             // Compile::find_alias_type() cast exactness on all types to verify
3429             // that it does not affect alias type.
3430             _is_ptr_to_narrowoop = UseCompressedOops;
3431           } else {
3432             // Type for the copy start in LibraryCallKit::inline_native_clone().
3433             _is_ptr_to_narrowoop = UseCompressedOops;
3434           }
3435         }
3436       }
3437     }
3438   }
3439 #endif
3440 }
3441 
3442 //------------------------------make-------------------------------------------
3443 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3444                                    const TypePtr* speculative, int inline_depth) {
3445   assert(ptr != Constant, "no constant generic pointers");
3446   ciKlass*  k = Compile::current()->env()->Object_klass();
3447   bool      xk = false;
3448   ciObject* o = NULL;
3449   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3450 }
3451 
3452 
3453 //------------------------------cast_to_ptr_type-------------------------------
3454 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3455   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3456   if( ptr == _ptr ) return this;
3457   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3458 }
3459 
3460 //-----------------------------cast_to_instance_id----------------------------
3461 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3462   // There are no instances of a general oop.
3463   // Return self unchanged.
3464   return this;
3465 }
3466 
3467 //-----------------------------cast_to_exactness-------------------------------
3468 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3469   // There is no such thing as an exact general oop.
3470   // Return self unchanged.
3471   return this;
3472 }
3473 

3474 //------------------------------as_klass_type----------------------------------
3475 // Return the klass type corresponding to this instance or array type.
3476 // It is the type that is loaded from an object of this type.
3477 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3478   ShouldNotReachHere();
3479   return NULL;
3480 }
3481 
3482 //------------------------------meet-------------------------------------------
3483 // Compute the MEET of two types.  It returns a new Type object.
3484 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3485   // Perform a fast test for common case; meeting the same types together.
3486   if( this == t ) return this;  // Meeting same type-rep?
3487 
3488   // Current "this->_base" is OopPtr
3489   switch (t->base()) {          // switch on original type
3490 
3491   case Int:                     // Mixing ints & oops happens when javac
3492   case Long:                    // reuses local variables
3493   case FloatTop:

3499   case NarrowOop:
3500   case NarrowKlass:
3501   case Bottom:                  // Ye Olde Default
3502     return Type::BOTTOM;
3503   case Top:
3504     return this;
3505 
3506   default:                      // All else is a mistake
3507     typerr(t);
3508 
3509   case RawPtr:
3510   case MetadataPtr:
3511   case KlassPtr:
3512   case InstKlassPtr:
3513   case AryKlassPtr:
3514     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3515 
3516   case AnyPtr: {
3517     // Found an AnyPtr type vs self-OopPtr type
3518     const TypePtr *tp = t->is_ptr();
3519     Offset offset = meet_offset(tp->offset());
3520     PTR ptr = meet_ptr(tp->ptr());
3521     const TypePtr* speculative = xmeet_speculative(tp);
3522     int depth = meet_inline_depth(tp->inline_depth());
3523     switch (tp->ptr()) {
3524     case Null:
3525       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3526       // else fall through:
3527     case TopPTR:
3528     case AnyNull: {
3529       int instance_id = meet_instance_id(InstanceTop);
3530       return make(ptr, offset, instance_id, speculative, depth);
3531     }
3532     case BotPTR:
3533     case NotNull:
3534       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3535     default: typerr(t);
3536     }
3537   }
3538 
3539   case OopPtr: {                 // Meeting to other OopPtrs

3541     int instance_id = meet_instance_id(tp->instance_id());
3542     const TypePtr* speculative = xmeet_speculative(tp);
3543     int depth = meet_inline_depth(tp->inline_depth());
3544     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3545   }
3546 
3547   case InstPtr:                  // For these, flip the call around to cut down
3548   case AryPtr:
3549     return t->xmeet(this);      // Call in reverse direction
3550 
3551   } // End of switch
3552   return this;                  // Return the double constant
3553 }
3554 
3555 
3556 //------------------------------xdual------------------------------------------
3557 // Dual of a pure heap pointer.  No relevant klass or oop information.
3558 const Type *TypeOopPtr::xdual() const {
3559   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3560   assert(const_oop() == NULL,             "no constants here");
3561   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3562 }
3563 
3564 //--------------------------make_from_klass_common-----------------------------
3565 // Computes the element-type given a klass.
3566 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3567   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3568     Compile* C = Compile::current();
3569     Dependencies* deps = C->dependencies();
3570     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3571     // Element is an instance
3572     bool klass_is_exact = false;
3573     if (klass->is_loaded()) {
3574       // Try to set klass_is_exact.
3575       ciInstanceKlass* ik = klass->as_instance_klass();
3576       klass_is_exact = ik->is_final();
3577       if (!klass_is_exact && klass_change
3578           && deps != NULL && UseUniqueSubclasses) {
3579         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3580         if (sub != NULL) {
3581           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3582           klass = ik = sub;
3583           klass_is_exact = sub->is_final();
3584         }
3585       }
3586       if (!klass_is_exact && try_for_exact && deps != NULL &&
3587           !ik->is_interface() && !ik->has_subklass()) {
3588         // Add a dependence; if concrete subclass added we need to recompile
3589         deps->assert_leaf_type(ik);
3590         klass_is_exact = true;
3591       }
3592     }
3593     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, Offset(0));
3594   } else if (klass->is_obj_array_klass()) {
3595     // Element is an object or inline type array. Recursively call ourself.
3596     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact);
3597     bool null_free = klass->as_array_klass()->is_elem_null_free();
3598     if (null_free) {
3599       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3600     }
3601     // Determine null-free/flattened properties
3602     const TypeOopPtr* exact_etype = etype;
3603     if (etype->can_be_inline_type()) {
3604       // Use exact type if element can be an inline type
3605       exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true);
3606     }
3607     bool not_null_free = !exact_etype->can_be_inline_type();
3608     bool not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flatten_array());
3609 
3610     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
3611     bool xk = etype->klass_is_exact() && (!etype->is_inlinetypeptr() || null_free);
3612     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, false, not_flat, not_null_free);
3613     // We used to pass NotNull in here, asserting that the sub-arrays
3614     // are all not-null.  This is not true in generally, as code can
3615     // slam NULLs down in the subarrays.
3616     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, Offset(0));
3617     return arr;
3618   } else if (klass->is_type_array_klass()) {
3619     // Element is an typeArray
3620     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3621     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3622                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3623     // We used to pass NotNull in here, asserting that the array pointer
3624     // is not-null. That was not true in general.
3625     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3626     return arr;
3627   } else if (klass->is_flat_array_klass()) {
3628     ciInlineKlass* vk = klass->as_array_klass()->element_klass()->as_inline_klass();
3629     const TypeAry* arr0 = TypeAry::make(TypeInlineType::make(vk), TypeInt::POS);
3630     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3631     return arr;
3632   } else {
3633     ShouldNotReachHere();
3634     return NULL;
3635   }
3636 }
3637 
3638 //------------------------------make_from_constant-----------------------------
3639 // Make a java pointer from an oop constant
3640 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3641   assert(!o->is_null_object(), "null object not yet handled here.");
3642 
3643   const bool make_constant = require_constant || o->should_be_constant();
3644 
3645   ciKlass* klass = o->klass();
3646   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3647     // Element is an instance or inline type
3648     if (make_constant) {
3649       return TypeInstPtr::make(o);
3650     } else {
3651       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, Offset(0));
3652     }
3653   } else if (klass->is_obj_array_klass()) {
3654     // Element is an object array. Recursively call ourself.
3655     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass());
3656     bool null_free = false;
3657     if (klass->as_array_klass()->is_elem_null_free()) {
3658       null_free = true;
3659       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3660     }
3661     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3662                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ !null_free);
3663     // We used to pass NotNull in here, asserting that the sub-arrays
3664     // are all not-null.  This is not true in generally, as code can
3665     // slam NULLs down in the subarrays.
3666     if (make_constant) {
3667       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3668     } else {
3669       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3670     }
3671   } else if (klass->is_type_array_klass()) {
3672     // Element is an typeArray
3673     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3674     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3675                                         /* stable= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3676     // We used to pass NotNull in here, asserting that the array pointer
3677     // is not-null. That was not true in general.
3678     if (make_constant) {
3679       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3680     } else {
3681       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3682     }
3683   } else if (klass->is_flat_array_klass()) {
3684     ciInlineKlass* vk = klass->as_array_klass()->element_klass()->as_inline_klass();
3685     const TypeAry* arr0 = TypeAry::make(TypeInlineType::make(vk), TypeInt::make(o->as_array()->length()));
3686     // We used to pass NotNull in here, asserting that the sub-arrays
3687     // are all not-null.  This is not true in generally, as code can
3688     // slam NULLs down in the subarrays.
3689     if (make_constant) {
3690       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3691     } else {
3692       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3693     }
3694   }
3695 
3696   fatal("unhandled object type");
3697   return NULL;
3698 }
3699 
3700 //------------------------------get_con----------------------------------------
3701 intptr_t TypeOopPtr::get_con() const {
3702   assert( _ptr == Null || _ptr == Constant, "" );
3703   assert(offset() >= 0, "");
3704 
3705   if (offset() != 0) {
3706     // After being ported to the compiler interface, the compiler no longer
3707     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3708     // to a handle at compile time.  This handle is embedded in the generated
3709     // code and dereferenced at the time the nmethod is made.  Until that time,
3710     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3711     // have access to the addresses!).  This does not seem to currently happen,
3712     // but this assertion here is to help prevent its occurence.
3713     tty->print_cr("Found oop constant with non-zero offset");
3714     ShouldNotReachHere();
3715   }
3716 
3717   return (intptr_t)const_oop()->constant_encoding();
3718 }
3719 
3720 
3721 //-----------------------------filter------------------------------------------
3722 // Do not allow interface-vs.-noninterface joins to collapse to top.
3723 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3724 
3725   const Type* ft = join_helper(kills, include_speculative);

3778     return (one == two) && TypePtr::eq(t);
3779   } else {
3780     return one->equals(two) && TypePtr::eq(t);
3781   }
3782 }
3783 
3784 //------------------------------hash-------------------------------------------
3785 // Type-specific hashing function.
3786 int TypeOopPtr::hash(void) const {
3787   return
3788     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3789              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3790 }
3791 
3792 //------------------------------dump2------------------------------------------
3793 #ifndef PRODUCT
3794 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3795   st->print("oopptr:%s", ptr_msg[_ptr]);
3796   if( _klass_is_exact ) st->print(":exact");
3797   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3798   _offset.dump2(st);





3799   if (_instance_id == InstanceTop)
3800     st->print(",iid=top");
3801   else if (_instance_id != InstanceBot)
3802     st->print(",iid=%d",_instance_id);
3803 
3804   dump_inline_depth(st);
3805   dump_speculative(st);
3806 }
3807 #endif
3808 
3809 //------------------------------singleton--------------------------------------
3810 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3811 // constants
3812 bool TypeOopPtr::singleton(void) const {
3813   // detune optimizer to not generate constant oop + constant offset as a constant!
3814   // TopPTR, Null, AnyNull, Constant are all singletons
3815   return (offset() == 0) && !below_centerline(_ptr);
3816 }
3817 
3818 //------------------------------add_offset-------------------------------------
3819 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3820   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3821 }
3822 
3823 /**
3824  * Return same type without a speculative part
3825  */
3826 const Type* TypeOopPtr::remove_speculative() const {
3827   if (_speculative == NULL) {
3828     return this;
3829   }
3830   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3831   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3832 }
3833 
3834 /**
3835  * Return same type but drop speculative part if we know we won't use

3887  *
3888  * @return  true if type profile is valuable
3889  */
3890 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3891   // no way to improve an already exact type
3892   if (klass_is_exact()) {
3893     return false;
3894   }
3895   return TypePtr::would_improve_type(exact_kls, inline_depth);
3896 }
3897 
3898 //=============================================================================
3899 // Convenience common pre-built types.
3900 const TypeInstPtr *TypeInstPtr::NOTNULL;
3901 const TypeInstPtr *TypeInstPtr::BOTTOM;
3902 const TypeInstPtr *TypeInstPtr::MIRROR;
3903 const TypeInstPtr *TypeInstPtr::MARK;
3904 const TypeInstPtr *TypeInstPtr::KLASS;
3905 
3906 //------------------------------TypeInstPtr-------------------------------------
3907 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset off,
3908                          bool flatten_array, int instance_id, const TypePtr* speculative,
3909                          int inline_depth)
3910   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
3911     _name(k->name()), _flatten_array(flatten_array) {
3912   assert(k != NULL &&
3913          (k->is_loaded() || o == NULL),
3914          "cannot have constants with non-loaded klass");
3915   assert(!klass()->flatten_array() || flatten_array, "Should be flat in array");
3916   assert(!flatten_array || can_be_inline_type(), "Only inline types can be flat in array");
3917 };
3918 
3919 //------------------------------make-------------------------------------------
3920 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3921                                      ciKlass* k,
3922                                      bool xk,
3923                                      ciObject* o,
3924                                      Offset offset,
3925                                      bool flatten_array,
3926                                      int instance_id,
3927                                      const TypePtr* speculative,
3928                                      int inline_depth) {
3929   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3930   // Either const_oop() is NULL or else ptr is Constant
3931   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3932           "constant pointers must have a value supplied" );
3933   // Ptr is never Null
3934   assert( ptr != Null, "NULL pointers are not typed" );
3935 
3936   assert(instance_id <= 0 || xk, "instances are always exactly typed");
3937   if (ptr == Constant) {
3938     // Note:  This case includes meta-object constants, such as methods.
3939     xk = true;
3940   } else if (k->is_loaded()) {
3941     ciInstanceKlass* ik = k->as_instance_klass();
3942     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3943     if (xk && ik->is_interface())  xk = false;  // no exact interface
3944   }
3945 
3946   // Check if this type is known to be flat in arrays
3947   flatten_array = flatten_array || k->flatten_array();
3948 
3949   // Now hash this baby
3950   TypeInstPtr *result =
3951     (TypeInstPtr*)(new TypeInstPtr(ptr, k, xk, o, offset, flatten_array, instance_id, speculative, inline_depth))->hashcons();
3952 
3953   return result;
3954 }
3955 
3956 /**
3957  *  Create constant type for a constant boxed value
3958  */
3959 const Type* TypeInstPtr::get_const_boxed_value() const {
3960   assert(is_ptr_to_boxed_value(), "should be called only for boxed value");
3961   assert((const_oop() != NULL), "should be called only for constant object");
3962   ciConstant constant = const_oop()->as_instance()->field_value_by_offset(offset());
3963   BasicType bt = constant.basic_type();
3964   switch (bt) {
3965     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
3966     case T_INT:      return TypeInt::make(constant.as_int());
3967     case T_CHAR:     return TypeInt::make(constant.as_char());
3968     case T_BYTE:     return TypeInt::make(constant.as_byte());
3969     case T_SHORT:    return TypeInt::make(constant.as_short());
3970     case T_FLOAT:    return TypeF::make(constant.as_float());
3971     case T_DOUBLE:   return TypeD::make(constant.as_double());
3972     case T_LONG:     return TypeLong::make(constant.as_long());
3973     default:         break;
3974   }
3975   fatal("Invalid boxed value type '%s'", type2name(bt));
3976   return NULL;
3977 }
3978 
3979 //------------------------------cast_to_ptr_type-------------------------------
3980 const TypeInstPtr *TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
3981   if( ptr == _ptr ) return this;
3982   // Reconstruct _sig info here since not a problem with later lazy
3983   // construction, _sig will show up on demand.
3984   return make(ptr, klass(), klass_is_exact(), const_oop(), _offset, _flatten_array, _instance_id, _speculative, _inline_depth);
3985 }
3986 
3987 
3988 //-----------------------------cast_to_exactness-------------------------------
3989 const Type *TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
3990   if( klass_is_exact == _klass_is_exact ) return this;
3991   if (!_klass->is_loaded())  return this;
3992   ciInstanceKlass* ik = _klass->as_instance_klass();
3993   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
3994   if( ik->is_interface() )              return this;  // cannot set xk
3995   return make(ptr(), klass(), klass_is_exact, const_oop(), _offset, _flatten_array, _instance_id, _speculative, _inline_depth);
3996 }
3997 
3998 //-----------------------------cast_to_instance_id----------------------------
3999 const TypeOopPtr *TypeInstPtr::cast_to_instance_id(int instance_id) const {
4000   if( instance_id == _instance_id ) return this;
4001   return make(_ptr, klass(), _klass_is_exact, const_oop(), _offset, _flatten_array, instance_id, _speculative, _inline_depth);
4002 }
4003 
4004 //------------------------------xmeet_unloaded---------------------------------
4005 // Compute the MEET of two InstPtrs when at least one is unloaded.
4006 // Assume classes are different since called after check for same name/class-loader
4007 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst) const {
4008     Offset off = meet_offset(tinst->offset());
4009     PTR ptr = meet_ptr(tinst->ptr());
4010     int instance_id = meet_instance_id(tinst->instance_id());
4011     const TypePtr* speculative = xmeet_speculative(tinst);
4012     int depth = meet_inline_depth(tinst->inline_depth());
4013 
4014     const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4015     const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4016     if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4017       //
4018       // Meet unloaded class with java/lang/Object
4019       //
4020       // Meet
4021       //          |                     Unloaded Class
4022       //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4023       //  ===================================================================
4024       //   TOP    | ..........................Unloaded......................|
4025       //  AnyNull |  U-AN    |................Unloaded......................|
4026       // Constant | ... O-NN .................................. |   O-BOT   |
4027       //  NotNull | ... O-NN .................................. |   O-BOT   |
4028       //  BOTTOM  | ........................Object-BOTTOM ..................|
4029       //
4030       assert(loaded->ptr() != TypePtr::Null, "insanity check");
4031       //
4032       if(      loaded->ptr() == TypePtr::TopPTR ) { return unloaded; }
4033       else if (loaded->ptr() == TypePtr::AnyNull) { return TypeInstPtr::make(ptr, unloaded->klass(), false, NULL, off, false, instance_id, speculative, depth); }
4034       else if (loaded->ptr() == TypePtr::BotPTR ) { return TypeInstPtr::BOTTOM; }
4035       else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4036         if (unloaded->ptr() == TypePtr::BotPTR  ) { return TypeInstPtr::BOTTOM;  }
4037         else                                      { return TypeInstPtr::NOTNULL; }
4038       }
4039       else if( unloaded->ptr() == TypePtr::TopPTR )  { return unloaded; }
4040 
4041       return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4042     }
4043 
4044     // Both are unloaded, not the same class, not Object
4045     // Or meet unloaded with a different loaded class, not java/lang/Object
4046     if( ptr != TypePtr::BotPTR ) {
4047       return TypeInstPtr::NOTNULL;
4048     }
4049     return TypeInstPtr::BOTTOM;
4050 }
4051 
4052 
4053 //------------------------------meet-------------------------------------------

4074   case Top:
4075     return this;
4076 
4077   default:                      // All else is a mistake
4078     typerr(t);
4079 
4080   case MetadataPtr:
4081   case KlassPtr:
4082   case InstKlassPtr:
4083   case AryKlassPtr:
4084   case RawPtr: return TypePtr::BOTTOM;
4085 
4086   case AryPtr: {                // All arrays inherit from Object class
4087     // Call in reverse direction to avoid duplication
4088     return t->is_aryptr()->xmeet_helper(this);
4089   }
4090 
4091   case OopPtr: {                // Meeting to OopPtrs
4092     // Found a OopPtr type vs self-InstPtr type
4093     const TypeOopPtr *tp = t->is_oopptr();
4094     Offset offset = meet_offset(tp->offset());
4095     PTR ptr = meet_ptr(tp->ptr());
4096     switch (tp->ptr()) {
4097     case TopPTR:
4098     case AnyNull: {
4099       int instance_id = meet_instance_id(InstanceTop);
4100       const TypePtr* speculative = xmeet_speculative(tp);
4101       int depth = meet_inline_depth(tp->inline_depth());
4102       return make(ptr, klass(), klass_is_exact(),
4103                   (ptr == Constant ? const_oop() : NULL), offset, flatten_array(), instance_id, speculative, depth);
4104     }
4105     case NotNull:
4106     case BotPTR: {
4107       int instance_id = meet_instance_id(tp->instance_id());
4108       const TypePtr* speculative = xmeet_speculative(tp);
4109       int depth = meet_inline_depth(tp->inline_depth());
4110       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4111     }
4112     default: typerr(t);
4113     }
4114   }
4115 
4116   case AnyPtr: {                // Meeting to AnyPtrs
4117     // Found an AnyPtr type vs self-InstPtr type
4118     const TypePtr *tp = t->is_ptr();
4119     Offset offset = meet_offset(tp->offset());
4120     PTR ptr = meet_ptr(tp->ptr());
4121     int instance_id = meet_instance_id(InstanceTop);
4122     const TypePtr* speculative = xmeet_speculative(tp);
4123     int depth = meet_inline_depth(tp->inline_depth());
4124     switch (tp->ptr()) {
4125     case Null:
4126       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4127       // else fall through to AnyNull
4128     case TopPTR:
4129     case AnyNull: {
4130       return make(ptr, klass(), klass_is_exact(),
4131                   (ptr == Constant ? const_oop() : NULL), offset, flatten_array(), instance_id, speculative, depth);
4132     }
4133     case NotNull:
4134     case BotPTR:
4135       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4136     default: typerr(t);
4137     }
4138   }
4139 
4140   /*
4141                  A-top         }
4142                /   |   \       }  Tops
4143            B-top A-any C-top   }
4144               | /  |  \ |      }  Any-nulls
4145            B-any   |   C-any   }
4146               |    |    |
4147            B-con A-con C-con   } constants; not comparable across classes
4148               |    |    |
4149            B-not   |   C-not   }
4150               | \  |  / |      }  not-nulls
4151            B-bot A-not C-bot   }
4152                \   |   /       }  Bottoms
4153                  A-bot         }
4154   */
4155 
4156   case InstPtr: {                // Meeting 2 Oops?
4157     // Found an InstPtr sub-type vs self-InstPtr type
4158     const TypeInstPtr *tinst = t->is_instptr();
4159     Offset off = meet_offset(tinst->offset());
4160     PTR ptr = meet_ptr(tinst->ptr());
4161     int instance_id = meet_instance_id(tinst->instance_id());
4162     const TypePtr* speculative = xmeet_speculative(tinst);
4163     int depth = meet_inline_depth(tinst->inline_depth());
4164     ciKlass* tinst_klass = tinst->klass();
4165     ciKlass* this_klass  = klass();
4166     bool tinst_xk = tinst->klass_is_exact();
4167     bool this_xk  = this->klass_is_exact();
4168     bool tinst_flatten_array = tinst->flatten_array();
4169     bool this_flatten_array  = this->flatten_array();
4170 
4171     ciKlass* res_klass = NULL;
4172     bool res_xk = false;
4173     bool res_flatten_array = false;
4174     const Type* res;
4175     MeetResult kind = meet_instptr(ptr, this_klass, tinst_klass, this_xk, tinst_xk, this->_ptr, tinst->_ptr,
4176                                    this_flatten_array, tinst_flatten_array,
4177                                    res_klass, res_xk, res_flatten_array);
4178     if (kind == UNLOADED) {
4179       // One of these classes has not been loaded
4180       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst);
4181 #ifndef PRODUCT
4182       if (PrintOpto && Verbose) {
4183         tty->print("meet of unloaded classes resulted in: ");
4184         unloaded_meet->dump();
4185         tty->cr();
4186         tty->print("  this == ");
4187         dump();
4188         tty->cr();
4189         tty->print(" tinst == ");
4190         tinst->dump();
4191         tty->cr();
4192       }
4193 #endif
4194       res = unloaded_meet;
4195     } else {
4196       if (kind == NOT_SUBTYPE && instance_id > 0) {
4197         instance_id = InstanceBot;
4198       } else if (kind == LCA) {
4199         instance_id = InstanceBot;
4200       }
4201       ciObject* o = NULL;             // Assume not constant when done
4202       ciObject* this_oop = const_oop();
4203       ciObject* tinst_oop = tinst->const_oop();
4204       if (ptr == Constant) {
4205         if (this_oop != NULL && tinst_oop != NULL &&
4206             this_oop->equals(tinst_oop))
4207           o = this_oop;
4208         else if (above_centerline(_ptr)) {
4209           assert(!tinst_klass->is_interface(), "");
4210           o = tinst_oop;
4211         } else if (above_centerline(tinst->_ptr)) {
4212           assert(!this_klass->is_interface(), "");
4213           o = this_oop;
4214         } else
4215           ptr = NotNull;
4216       }
4217       res = make(ptr, res_klass, res_xk, o, off, res_flatten_array, instance_id, speculative, depth);
4218     }
4219 
4220     return res;
4221 
4222   } // End of case InstPtr
4223 
4224   case InlineType: {
4225     const TypeInlineType* tv = t->is_inlinetype();
4226     if (above_centerline(ptr())) {
4227       if (tv->inline_klass()->is_subtype_of(_klass)) {
4228         return t;
4229       } else {
4230         return TypeInstPtr::NOTNULL;
4231       }
4232     } else {
4233       PTR ptr = this->_ptr;
4234       if (ptr == Constant) {
4235         ptr = NotNull;
4236       }
4237       if (tv->inline_klass()->is_subtype_of(_klass)) {
4238         return make(ptr, _klass, false, NULL, Offset(0), _flatten_array, InstanceBot, _speculative);
4239       } else {
4240         return make(ptr, ciEnv::current()->Object_klass());
4241       }
4242     }
4243   }
4244 
4245   } // End of switch
4246   return this;                  // Return the double constant
4247 }
4248 
4249 TypePtr::MeetResult TypePtr::meet_instptr(PTR &ptr, ciKlass* this_klass, ciKlass* tinst_klass, bool this_xk, bool tinst_xk,
4250                                           PTR this_ptr, PTR tinst_ptr, bool this_flatten_array, bool tinst_flatten_array,
4251                                           ciKlass*&res_klass, bool &res_xk, bool& res_flatten_array) {
4252 
4253   bool this_flatten_array_orig = this_flatten_array;
4254   bool tinst_flatten_array_orig = tinst_flatten_array;
4255 
4256   // Check for easy case; klasses are equal (and perhaps not loaded!)
4257   // If we have constants, then we created oops so classes are loaded
4258   // and we can handle the constants further down.  This case handles
4259   // both-not-loaded or both-loaded classes
4260   if (ptr != Constant && this_klass->equals(tinst_klass) && this_xk == tinst_xk && this_flatten_array == tinst_flatten_array) {
4261     res_klass = this_klass;
4262     res_xk = this_xk;
4263     res_flatten_array = this_flatten_array;
4264     return QUICK;
4265   }
4266 
4267   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4268   if (!tinst_klass->is_loaded() || !this_klass->is_loaded()) {
4269     return UNLOADED;
4270   }
4271 
4272   // Handle mixing oops and interfaces first.
4273   if (this_klass->is_interface() && !(tinst_klass->is_interface() ||
4274                                       tinst_klass == ciEnv::current()->Object_klass())) {
4275     ciKlass *tmp = tinst_klass; // Swap interface around
4276     tinst_klass = this_klass;
4277     this_klass = tmp;
4278     bool tmp2 = tinst_xk;
4279     tinst_xk = this_xk;
4280     this_xk = tmp2;
4281     tmp2 = tinst_flatten_array;
4282     tinst_flatten_array = this_flatten_array;
4283     this_flatten_array = tmp2;
4284   }
4285   if (tinst_klass->is_interface() &&
4286       !(this_klass->is_interface() ||
4287         // Treat java/lang/Object as an honorary interface,
4288         // because we need a bottom for the interface hierarchy.
4289         this_klass == ciEnv::current()->Object_klass())) {
4290     // Oop meets interface!
4291 
4292     // See if the oop subtypes (implements) interface.
4293     if (this_klass->is_subtype_of(tinst_klass)) {
4294       // Oop indeed subtypes.  Now keep oop or interface depending
4295       // on whether we are both above the centerline or either is
4296       // below the centerline.  If we are on the centerline
4297       // (e.g., Constant vs. AnyNull interface), use the constant.
4298       res_klass  = below_centerline(ptr) ? tinst_klass : this_klass;
4299       // If we are keeping this_klass, keep its exactness too.
4300       res_xk = below_centerline(ptr) ? tinst_xk    : this_xk;
4301       res_flatten_array = below_centerline(ptr) ? tinst_flatten_array    : this_flatten_array;
4302       return SUBTYPE;
4303     } else {                  // Does not implement, fall to Object
4304       // Oop does not implement interface, so mixing falls to Object
4305       // just like the verifier does (if both are above the
4306       // centerline fall to interface)
4307       res_klass = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
4308       res_xk = above_centerline(ptr) ? tinst_xk : false;
4309       res_flatten_array = above_centerline(ptr) ? tinst_flatten_array : false;
4310       // Watch out for Constant vs. AnyNull interface.
4311       if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
4312       return NOT_SUBTYPE;
4313     }
4314   }
4315 
4316   // Either oop vs oop or interface vs interface or interface vs Object
4317 
4318   // !!! Here's how the symmetry requirement breaks down into invariants:
4319   // If we split one up & one down AND they subtype, take the down man.
4320   // If we split one up & one down AND they do NOT subtype, "fall hard".
4321   // If both are up and they subtype, take the subtype class.
4322   // If both are up and they do NOT subtype, "fall hard".
4323   // If both are down and they subtype, take the supertype class.
4324   // If both are down and they do NOT subtype, "fall hard".
4325   // Constants treated as down.
4326 
4327   // Now, reorder the above list; observe that both-down+subtype is also
4328   // "fall hard"; "fall hard" becomes the default case:
4329   // If we split one up & one down AND they subtype, take the down man.
4330   // If both are up and they subtype, take the subtype class.
4331 
4332   // If both are down and they subtype, "fall hard".
4333   // If both are down and they do NOT subtype, "fall hard".
4334   // If both are up and they do NOT subtype, "fall hard".
4335   // If we split one up & one down AND they do NOT subtype, "fall hard".
4336 
4337   // If a proper subtype is exact, and we return it, we return it exactly.
4338   // If a proper supertype is exact, there can be no subtyping relationship!
4339   // If both types are equal to the subtype, exactness is and-ed below the
4340   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4341 
4342   // Check for subtyping:
4343   ciKlass *subtype = NULL;
4344   bool subtype_exact = false;
4345   bool flat_array = false;
4346   if (tinst_klass->equals(this_klass)) {
4347     subtype = this_klass;
4348     subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
4349     flat_array = below_centerline(ptr) ? (this_flatten_array && tinst_flatten_array) : (this_flatten_array || tinst_flatten_array);
4350   } else if (!tinst_xk && this_klass->is_subtype_of(tinst_klass) && (!tinst_flatten_array || this_flatten_array)) {
4351     subtype = this_klass;     // Pick subtyping class
4352     subtype_exact = this_xk;
4353     flat_array = this_flatten_array;
4354   } else if (!this_xk && tinst_klass->is_subtype_of(this_klass) && (!this_flatten_array || tinst_flatten_array)) {
4355     subtype = tinst_klass;    // Pick subtyping class
4356     subtype_exact = tinst_xk;
4357     flat_array = tinst_flatten_array;
4358   }
4359 
4360   if (subtype) {
4361     if (above_centerline(ptr)) { // both are up?
4362       this_klass = tinst_klass = subtype;
4363       this_xk = tinst_xk = subtype_exact;
4364       this_flatten_array = tinst_flatten_array = flat_array;
4365     } else if (above_centerline(this_ptr) && !above_centerline(tinst_ptr)) {
4366       this_klass = tinst_klass; // tinst is down; keep down man
4367       this_xk = tinst_xk;
4368       this_flatten_array = tinst_flatten_array;
4369     } else if (above_centerline(tinst_ptr) && !above_centerline(this_ptr)) {
4370       tinst_klass = this_klass; // this is down; keep down man
4371       tinst_xk = this_xk;
4372       tinst_flatten_array = this_flatten_array;
4373     } else {
4374       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4375       this_flatten_array = flat_array;
4376     }
4377   }
4378 
4379   // Check for classes now being equal
4380   if (tinst_klass->equals(this_klass)) {
4381     // If the klasses are equal, the constants may still differ.  Fall to
4382     // NotNull if they do (neither constant is NULL; that is a special case
4383     // handled elsewhere).
4384     res_klass = this_klass;
4385     res_xk = this_xk;
4386     res_flatten_array = this_flatten_array;
4387     return SUBTYPE;
4388   } // Else classes are not equal
4389 
4390   // Since klasses are different, we require a LCA in the Java
4391   // class hierarchy - which means we have to fall to at least NotNull.
4392   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4393     ptr = NotNull;
4394   }
4395 
4396   // Now we find the LCA of Java classes
4397   ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4398 
4399   res_klass = k;
4400   res_xk = false;
4401   res_flatten_array = this_flatten_array_orig && tinst_flatten_array_orig;
4402 
4403   return LCA;
4404 }
4405 
4406 
4407 //------------------------java_mirror_type--------------------------------------
4408 ciType* TypeInstPtr::java_mirror_type(bool* is_val_mirror) const {
4409   // must be a singleton type
4410   if( const_oop() == NULL )  return NULL;
4411 
4412   // must be of type java.lang.Class
4413   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4414   return const_oop()->as_instance()->java_mirror_type(is_val_mirror);

4415 }
4416 
4417 
4418 //------------------------------xdual------------------------------------------
4419 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4420 // inheritance mechanism.
4421 const Type *TypeInstPtr::xdual() const {
4422   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), flatten_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4423 }
4424 
4425 //------------------------------eq---------------------------------------------
4426 // Structural equality check for Type representations
4427 bool TypeInstPtr::eq( const Type *t ) const {
4428   const TypeInstPtr *p = t->is_instptr();
4429   return
4430     klass()->equals(p->klass()) &&
4431     flatten_array() == p->flatten_array() &&
4432     TypeOopPtr::eq(p);          // Check sub-type stuff
4433 }
4434 
4435 //------------------------------hash-------------------------------------------
4436 // Type-specific hashing function.
4437 int TypeInstPtr::hash(void) const {
4438   int hash = java_add(java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()), (jint)flatten_array());
4439   return hash;
4440 }
4441 
4442 //------------------------------dump2------------------------------------------
4443 // Dump oop Type
4444 #ifndef PRODUCT
4445 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4446   // Print the name of the klass.
4447   klass()->print_name_on(st);
4448 
4449   switch( _ptr ) {
4450   case Constant:
4451     if (WizardMode || Verbose) {
4452       ResourceMark rm;
4453       stringStream ss;
4454 
4455       st->print(" ");
4456       const_oop()->print_oop(&ss);
4457       // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4458       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4459       char* buf = ss.as_string(/* c_heap= */false);
4460       StringUtils::replace_no_expand(buf, "\n", "");
4461       st->print_raw(buf);
4462     }
4463   case BotPTR:
4464     if (!WizardMode && !Verbose) {
4465       if( _klass_is_exact ) st->print(":exact");
4466       break;
4467     }
4468   case TopPTR:
4469   case AnyNull:
4470   case NotNull:
4471     st->print(":%s", ptr_msg[_ptr]);
4472     if( _klass_is_exact ) st->print(":exact");
4473     break;
4474   default:
4475     break;
4476   }
4477 
4478   _offset.dump2(st);




4479 
4480   st->print(" *");
4481 
4482   if (flatten_array() && !klass()->is_inlinetype()) {
4483     st->print(" (flatten array)");
4484   }
4485 
4486   if (_instance_id == InstanceTop)
4487     st->print(",iid=top");
4488   else if (_instance_id != InstanceBot)
4489     st->print(",iid=%d",_instance_id);
4490 
4491   dump_inline_depth(st);
4492   dump_speculative(st);
4493 }
4494 #endif
4495 
4496 //------------------------------add_offset-------------------------------------
4497 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4498   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), flatten_array(),
4499               _instance_id, add_offset_speculative(offset), _inline_depth);
4500 }
4501 
4502 const Type *TypeInstPtr::remove_speculative() const {
4503   if (_speculative == NULL) {
4504     return this;
4505   }
4506   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4507   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(),
4508               _instance_id, NULL, _inline_depth);
4509 }
4510 
4511 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4512   if (!UseInlineDepthForSpeculativeTypes) {
4513     return this;
4514   }
4515   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(), _instance_id, _speculative, depth);
4516 }
4517 
4518 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4519   assert(is_known_instance(), "should be known");
4520   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(), instance_id, _speculative, _inline_depth);
4521 }
4522 
4523 const TypeInstPtr *TypeInstPtr::cast_to_flatten_array() const {
4524   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4525 }
4526 
4527 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4528   bool xk = klass_is_exact();
4529   ciInstanceKlass* ik = klass()->as_instance_klass();
4530   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final() && !ik->is_interface()) {
4531     Compile* C = Compile::current();
4532     Dependencies* deps = C->dependencies();
4533     deps->assert_leaf_type(ik);
4534     xk = true;
4535   }
4536   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), Offset(0), flatten_array());
4537 }
4538 
4539 //=============================================================================
4540 // Convenience common pre-built types.
4541 const TypeAryPtr *TypeAryPtr::RANGE;
4542 const TypeAryPtr *TypeAryPtr::OOPS;
4543 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4544 const TypeAryPtr *TypeAryPtr::BYTES;
4545 const TypeAryPtr *TypeAryPtr::SHORTS;
4546 const TypeAryPtr *TypeAryPtr::CHARS;
4547 const TypeAryPtr *TypeAryPtr::INTS;
4548 const TypeAryPtr *TypeAryPtr::LONGS;
4549 const TypeAryPtr *TypeAryPtr::FLOATS;
4550 const TypeAryPtr *TypeAryPtr::DOUBLES;
4551 const TypeAryPtr *TypeAryPtr::INLINES;
4552 
4553 //------------------------------make-------------------------------------------
4554 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4555                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4556   assert(!(k == NULL && ary->_elem->isa_int()),
4557          "integral arrays must be pre-equipped with a class");
4558   if (!xk)  xk = ary->ary_must_be_exact();
4559   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4560   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4561 }
4562 
4563 //------------------------------make-------------------------------------------
4564 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4565                                    int instance_id, const TypePtr* speculative, int inline_depth,
4566                                    bool is_autobox_cache) {
4567   assert(!(k == NULL && ary->_elem->isa_int()),
4568          "integral arrays must be pre-equipped with a class");
4569   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4570   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4571   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4572   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4573 }
4574 
4575 //------------------------------cast_to_ptr_type-------------------------------
4576 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4577   if( ptr == _ptr ) return this;
4578   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4579 }
4580 
4581 
4582 //-----------------------------cast_to_exactness-------------------------------
4583 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4584   if( klass_is_exact == _klass_is_exact ) return this;
4585   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4586 
4587   const TypeAry* new_ary = _ary;
4588   if (klass() != NULL && klass()->is_obj_array_klass() && klass_is_exact) {
4589     // An object array can't be flat or null-free if the klass is exact
4590     new_ary = TypeAry::make(elem(), size(), is_stable(), /* not_flat= */ true, /* not_null_free= */ true);
4591   }
4592   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4593 }
4594 
4595 //-----------------------------cast_to_instance_id----------------------------
4596 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4597   if( instance_id == _instance_id ) return this;
4598   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4599 }
4600 
4601 
4602 //-----------------------------max_array_length-------------------------------
4603 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4604 jint TypeAryPtr::max_array_length(BasicType etype) {
4605   if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4606     if (etype == T_NARROWOOP) {
4607       etype = T_OBJECT;
4608     } else if (etype == T_ILLEGAL) { // bottom[]
4609       etype = T_BYTE; // will produce conservatively high value
4610     } else {
4611       fatal("not an element type: %s", type2name(etype));
4612     }
4613   }
4614   return arrayOopDesc::max_array_length(etype);
4615 }
4616 
4617 //-----------------------------narrow_size_type-------------------------------
4618 // Narrow the given size type to the index range for the given array base type.

4634   if (hi > max_hi) {
4635     hi = max_hi;
4636     if (size->is_con()) {
4637       lo = hi;
4638     }
4639     chg = true;
4640   }
4641   // Negative length arrays will produce weird intermediate dead fast-path code
4642   if (lo > hi)
4643     return TypeInt::ZERO;
4644   if (!chg)
4645     return size;
4646   return TypeInt::make(lo, hi, Type::WidenMin);
4647 }
4648 
4649 //-------------------------------cast_to_size----------------------------------
4650 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4651   assert(new_size != NULL, "");
4652   new_size = narrow_size_type(new_size);
4653   if (new_size == size())  return this;
4654   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_not_flat(), is_not_null_free());
4655   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4656 }
4657 
4658 //-------------------------------cast_to_not_flat------------------------------
4659 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
4660   if (not_flat == is_not_flat()) {
4661     return this;
4662   }
4663   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_flat, is_not_null_free());
4664   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4665 }
4666 
4667 //-------------------------------cast_to_not_null_free-------------------------
4668 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
4669   if (not_null_free == is_not_null_free()) {
4670     return this;
4671   }
4672   // Not null free implies not flat
4673   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), not_null_free ? true : is_not_flat(), not_null_free);
4674   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4675 }
4676 
4677 //---------------------------------update_properties---------------------------
4678 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
4679   if ((from->is_flat()          && is_not_flat()) ||
4680       (from->is_not_flat()      && is_flat()) ||
4681       (from->is_null_free()     && is_not_null_free()) ||
4682       (from->is_not_null_free() && is_null_free())) {
4683     return NULL; // Inconsistent properties
4684   } else if (from->is_not_null_free()) {
4685     return cast_to_not_null_free(); // Implies not flat
4686   } else if (from->is_not_flat()) {
4687     return cast_to_not_flat();
4688   }
4689   return this;
4690 }
4691 
4692 //------------------------------cast_to_stable---------------------------------
4693 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4694   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4695     return this;
4696 
4697   const Type* elem = this->elem();
4698   const TypePtr* elem_ptr = elem->make_ptr();
4699 
4700   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4701     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4702     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4703   }
4704 
4705   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_not_flat(), is_not_null_free());
4706 
4707   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4708 }
4709 
4710 //-----------------------------stable_dimension--------------------------------
4711 int TypeAryPtr::stable_dimension() const {
4712   if (!is_stable())  return 0;
4713   int dim = 1;
4714   const TypePtr* elem_ptr = elem()->make_ptr();
4715   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4716     dim += elem_ptr->is_aryptr()->stable_dimension();
4717   return dim;
4718 }
4719 
4720 //----------------------cast_to_autobox_cache-----------------------------------
4721 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4722   if (is_autobox_cache())  return this;
4723   const TypeOopPtr* etype = elem()->make_oopptr();
4724   if (etype == NULL)  return this;
4725   // The pointers in the autobox arrays are always non-null.
4726   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4727   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_not_flat(), is_not_null_free());
4728   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4729 }
4730 
4731 //------------------------------eq---------------------------------------------
4732 // Structural equality check for Type representations
4733 bool TypeAryPtr::eq( const Type *t ) const {
4734   const TypeAryPtr *p = t->is_aryptr();
4735   return
4736     _ary == p->_ary &&  // Check array
4737     TypeOopPtr::eq(p) &&// Check sub-parts
4738     _field_offset == p->_field_offset;
4739 }
4740 
4741 //------------------------------hash-------------------------------------------
4742 // Type-specific hashing function.
4743 int TypeAryPtr::hash(void) const {
4744   return (intptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
4745 }
4746 
4747 //------------------------------meet-------------------------------------------
4748 // Compute the MEET of two types.  It returns a new Type object.
4749 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4750   // Perform a fast test for common case; meeting the same types together.
4751   if( this == t ) return this;  // Meeting same type-rep?
4752   // Current "this->_base" is Pointer
4753   switch (t->base()) {          // switch on original type
4754 
4755   // Mixing ints & oops happens when javac reuses local variables
4756   case Int:
4757   case Long:
4758   case FloatTop:
4759   case FloatCon:
4760   case FloatBot:
4761   case DoubleTop:
4762   case DoubleCon:
4763   case DoubleBot:
4764   case NarrowOop:
4765   case NarrowKlass:
4766   case Bottom:                  // Ye Olde Default
4767     return Type::BOTTOM;
4768   case Top:
4769     return this;
4770 
4771   default:                      // All else is a mistake
4772     typerr(t);
4773 
4774   case OopPtr: {                // Meeting to OopPtrs
4775     // Found a OopPtr type vs self-AryPtr type
4776     const TypeOopPtr *tp = t->is_oopptr();
4777     Offset offset = meet_offset(tp->offset());
4778     PTR ptr = meet_ptr(tp->ptr());
4779     int depth = meet_inline_depth(tp->inline_depth());
4780     const TypePtr* speculative = xmeet_speculative(tp);
4781     switch (tp->ptr()) {
4782     case TopPTR:
4783     case AnyNull: {
4784       int instance_id = meet_instance_id(InstanceTop);
4785       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4786                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4787     }
4788     case BotPTR:
4789     case NotNull: {
4790       int instance_id = meet_instance_id(tp->instance_id());
4791       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4792     }
4793     default: ShouldNotReachHere();
4794     }
4795   }
4796 
4797   case AnyPtr: {                // Meeting two AnyPtrs
4798     // Found an AnyPtr type vs self-AryPtr type
4799     const TypePtr *tp = t->is_ptr();
4800     Offset offset = meet_offset(tp->offset());
4801     PTR ptr = meet_ptr(tp->ptr());
4802     const TypePtr* speculative = xmeet_speculative(tp);
4803     int depth = meet_inline_depth(tp->inline_depth());
4804     switch (tp->ptr()) {
4805     case TopPTR:
4806       return this;
4807     case BotPTR:
4808     case NotNull:
4809       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4810     case Null:
4811       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4812       // else fall through to AnyNull
4813     case AnyNull: {
4814       int instance_id = meet_instance_id(InstanceTop);
4815       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4816                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4817     }
4818     default: ShouldNotReachHere();
4819     }
4820   }
4821 
4822   case MetadataPtr:
4823   case KlassPtr:
4824   case InstKlassPtr:
4825   case AryKlassPtr:
4826   case RawPtr: return TypePtr::BOTTOM;
4827 
4828   case AryPtr: {                // Meeting 2 references?
4829     const TypeAryPtr *tap = t->is_aryptr();
4830     Offset off = meet_offset(tap->offset());
4831     Offset field_off = meet_field_offset(tap->field_offset());
4832     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4833     PTR ptr = meet_ptr(tap->ptr());
4834     int instance_id = meet_instance_id(tap->instance_id());
4835     const TypePtr* speculative = xmeet_speculative(tap);
4836     int depth = meet_inline_depth(tap->inline_depth());
4837 
4838     ciKlass* res_klass = NULL;
4839     bool res_xk = false;
4840     bool res_not_flat = false;
4841     bool res_not_null_free = false;
4842     const Type* res_elem = NULL;
4843     if (meet_aryptr(ptr, _ary->_elem, tap->_ary->_elem, this->klass(), tap->klass(),
4844                     this->klass_is_exact(), tap->klass_is_exact(), this->ptr(), tap->ptr(),
4845                     this->is_not_flat(), tap->is_not_flat(),
4846                     this->is_not_null_free(), tap->is_not_null_free(),
4847                     res_elem, res_klass, res_xk, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
4848       instance_id = InstanceBot;
4849     } else if (klass() != NULL && tap->klass() != NULL && klass()->is_flat_array_klass() != tap->klass()->is_flat_array_klass()) {
4850       // Meeting flattened inline type array with non-flattened array. Adjust (field) offset accordingly.
4851       if (tary->_elem->isa_inlinetype()) {
4852         // Result is flattened
4853         off = Offset(is_flat() ? offset() : tap->offset());
4854         field_off = is_flat() ? field_offset() : tap->field_offset();
4855       } else if (tary->_elem->make_oopptr() != NULL && tary->_elem->make_oopptr()->isa_instptr() && below_centerline(ptr)) {
4856         // Result is non-flattened
4857         off = Offset(flattened_offset()).meet(Offset(tap->flattened_offset()));
4858         field_off = Offset::bottom;
4859       }
4860     }
4861 
4862     ciObject* o = NULL;             // Assume not constant when done
4863     ciObject* this_oop = const_oop();
4864     ciObject* tap_oop = tap->const_oop();
4865     if (ptr == Constant) {
4866       if (this_oop != NULL && tap_oop != NULL &&
4867           this_oop->equals(tap_oop)) {
4868         o = tap_oop;
4869       } else if (above_centerline(_ptr)) {
4870         o = tap_oop;
4871       } else if (above_centerline(tap->_ptr)) {
4872         o = this_oop;
4873       } else {
4874         ptr = NotNull;
4875       }
4876     }
4877     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);
4878   }
4879 
4880   // All arrays inherit from Object class
4881   case InstPtr: {
4882     const TypeInstPtr *tp = t->is_instptr();
4883     Offset offset = meet_offset(tp->offset());
4884     PTR ptr = meet_ptr(tp->ptr());
4885     int instance_id = meet_instance_id(tp->instance_id());
4886     const TypePtr* speculative = xmeet_speculative(tp);
4887     int depth = meet_inline_depth(tp->inline_depth());
4888     switch (ptr) {
4889     case TopPTR:
4890     case AnyNull:                // Fall 'down' to dual of object klass
4891       // For instances when a subclass meets a superclass we fall
4892       // below the centerline when the superclass is exact. We need to
4893       // do the same here.
4894       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact() && !tp->flatten_array()) {
4895         return make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4896       } else {
4897         // cannot subclass, so the meet has to fall badly below the centerline
4898         ptr = NotNull;
4899         instance_id = InstanceBot;
4900         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
4901       }
4902     case Constant:
4903     case NotNull:
4904     case BotPTR:                // Fall down to object klass
4905       // LCA is object_klass, but if we subclass from the top we can do better
4906       if (above_centerline(tp->ptr())) {
4907         // If 'tp'  is above the centerline and it is Object class
4908         // then we can subclass in the Java class hierarchy.
4909         // For instances when a subclass meets a superclass we fall
4910         // below the centerline when the superclass is exact. We need
4911         // to do the same here.
4912         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact() && !tp->flatten_array()) {
4913           // that is, my array type is a subtype of 'tp' klass
4914           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4915                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
4916         }
4917       }
4918       // The other case cannot happen, since t cannot be a subtype of an array.
4919       // The meet falls down to Object class below centerline.
4920       if (ptr == Constant) {
4921          ptr = NotNull;
4922       }
4923       if (instance_id > 0) {
4924         instance_id = InstanceBot;
4925       }
4926       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, false, instance_id, speculative, depth);
4927     default: typerr(t);
4928     }
4929   }
4930 
4931   case InlineType: {
4932     const TypeInlineType* tv = t->is_inlinetype();
4933     if (above_centerline(ptr())) {
4934       return TypeInstPtr::NOTNULL;
4935     } else {
4936       PTR ptr = this->_ptr;
4937       if (ptr == Constant) {
4938         ptr = NotNull;
4939       }
4940       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass());
4941     }
4942   }
4943   }
4944   return this;                  // Lint noise
4945 }
4946 
4947 
4948 TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type* this_elem, const Type* tap_elem,
4949                                          ciKlass* this_klass, ciKlass* tap_klass,
4950                                          bool this_xk, bool tap_xk, PTR this_ptr, PTR tap_ptr,
4951                                          bool this_not_flat, bool tap_not_flat,
4952                                          bool this_not_null_free, bool tap_not_null_free,
4953                                          const Type*& res_elem, ciKlass*& res_klass,
4954                                          bool& res_xk, bool& res_not_flat, bool& res_not_null_free) {
4955   res_klass = NULL;
4956   MeetResult result = SUBTYPE;
4957   res_elem = this_elem->meet(tap_elem);
4958   res_not_flat = this_not_flat && tap_not_flat;
4959   res_not_null_free = this_not_null_free && tap_not_null_free;
4960 
4961   if (res_elem->isa_int()) {
4962     // Integral array element types have irrelevant lattice relations.
4963     // It is the klass that determines array layout, not the element type.
4964     if (this_klass == NULL) {
4965       res_klass = tap_klass;
4966     } else if (tap_klass == NULL || tap_klass == this_klass) {
4967       res_klass = this_klass;
4968     } else {
4969       // Something like byte[int+] meets char[int+].
4970       // This must fall to bottom, not (int[-128..65535])[int+].
4971       // instance_id = InstanceBot;
4972       res_elem = Type::BOTTOM;
4973       result = NOT_SUBTYPE;
4974     }
4975   } else // Non integral arrays.
4976     // Must fall to bottom if exact klasses in upper lattice
4977     // are not equal or super klass is exact.
4978     if ((above_centerline(ptr) || ptr == Constant) && this_klass != tap_klass &&
4979         // meet with top[] and bottom[] are processed further down:
4980         tap_klass != NULL  && this_klass != NULL   &&
4981         // both are exact and not equal:
4982         ((tap_xk && this_xk) ||
4983          // 'tap'  is exact and super or unrelated:
4984          (tap_xk && !tap_klass->is_subtype_of(this_klass)) ||
4985          // 'this' is exact and super or unrelated:
4986          (this_xk && !this_klass->is_subtype_of(tap_klass)))) {
4987       if (above_centerline(ptr) || (res_elem->make_ptr() && above_centerline(res_elem->make_ptr()->_ptr)) ||
4988           res_elem->isa_inlinetype()) {
4989         res_elem = Type::BOTTOM;
4990       }
4991       ptr = NotNull;
4992       res_xk = false;
4993       return NOT_SUBTYPE;
4994     }
4995 
4996   res_xk = false;
4997   switch (tap_ptr) {
4998     case AnyNull:
4999     case TopPTR:
5000       // Compute new klass on demand, do not use tap->_klass
5001       if (below_centerline(this_ptr)) {
5002         res_xk = this_xk;
5003         if (this_elem->isa_inlinetype()) {
5004           res_elem = this_elem;
5005         }
5006       } else {
5007         res_xk = (tap_xk || this_xk);
5008       }
5009       break;
5010     case Constant: {
5011       if (this_ptr == Constant) {
5012         res_xk = true;
5013       } else if(above_centerline(this_ptr)) {
5014         res_xk = true;
5015       } else {
5016         // Only precise for identical arrays
5017         res_xk = this_xk && (this_klass == tap_klass);
5018       }
5019       break;
5020     }
5021     case NotNull:
5022     case BotPTR:
5023       // Compute new klass on demand, do not use tap->_klass
5024       if (above_centerline(this_ptr)) {
5025         res_xk = tap_xk;
5026         if (tap_elem->isa_inlinetype()) {
5027           res_elem = tap_elem;
5028         }
5029       } else {
5030         res_xk = (tap_xk && this_xk) &&
5031           (this_klass == tap_klass); // Only precise for identical arrays
5032       }
5033       break;
5034     default:  {
5035       ShouldNotReachHere();
5036       return result;
5037     }
5038   }
5039 
5040   return result;
5041 }
5042 
5043 
5044 //------------------------------xdual------------------------------------------
5045 // Dual: compute field-by-field dual
5046 const Type *TypeAryPtr::xdual() const {
5047   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());
5048 }
5049 
5050 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5051   return _field_offset.meet(offset);
5052 }
5053 
5054 //------------------------------dual_offset------------------------------------
5055 Type::Offset TypeAryPtr::dual_field_offset() const {
5056   return _field_offset.dual();
5057 }
5058 
5059 //----------------------interface_vs_oop---------------------------------------
5060 #ifdef ASSERT
5061 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
5062   const TypeAryPtr* t_aryptr = t->isa_aryptr();
5063   if (t_aryptr) {
5064     return _ary->interface_vs_oop(t_aryptr->_ary);
5065   }
5066   return false;
5067 }
5068 #endif
5069 
5070 //------------------------------dump2------------------------------------------
5071 #ifndef PRODUCT
5072 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5073   _ary->dump2(d,depth,st);
5074   switch( _ptr ) {
5075   case Constant:
5076     const_oop()->print(st);
5077     break;
5078   case BotPTR:
5079     if (!WizardMode && !Verbose) {
5080       if( _klass_is_exact ) st->print(":exact");
5081       break;
5082     }
5083   case TopPTR:
5084   case AnyNull:
5085   case NotNull:
5086     st->print(":%s", ptr_msg[_ptr]);
5087     if( _klass_is_exact ) st->print(":exact");
5088     break;
5089   default:
5090     break;
5091   }
5092 
5093   if (is_flat()) {
5094     st->print("(");
5095     _field_offset.dump2(st);
5096     st->print(")");
5097   }
5098   if (offset() != 0) {
5099     int header_size = objArrayOopDesc::header_size() * wordSize;
5100     if( _offset == Offset::top )       st->print("+undefined");
5101     else if( _offset == Offset::bottom )  st->print("+any");
5102     else if( offset() < header_size ) st->print("+%d", offset());
5103     else {
5104       BasicType basic_elem_type = elem()->basic_type();
5105       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5106       int elem_size = type2aelembytes(basic_elem_type);
5107       st->print("[%d]", (offset() - array_base)/elem_size);
5108     }
5109   }
5110   st->print(" *");
5111   if (_instance_id == InstanceTop)
5112     st->print(",iid=top");
5113   else if (_instance_id != InstanceBot)
5114     st->print(",iid=%d",_instance_id);
5115 
5116   dump_inline_depth(st);
5117   dump_speculative(st);
5118 }
5119 #endif
5120 
5121 bool TypeAryPtr::empty(void) const {
5122   if (_ary->empty())       return true;
5123   return TypeOopPtr::empty();
5124 }
5125 
5126 //------------------------------add_offset-------------------------------------
5127 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
5128   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);
5129 }
5130 
5131 const Type *TypeAryPtr::remove_speculative() const {
5132   if (_speculative == NULL) {
5133     return this;
5134   }
5135   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5136   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);
5137 }
5138 
5139 const Type* TypeAryPtr::cleanup_speculative() const {
5140   if (speculative() == NULL) {
5141     return this;
5142   }
5143   // Keep speculative part if it contains information about flat-/nullability
5144   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5145   if (spec_aryptr != NULL && (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5146     return this;
5147   }
5148   return TypeOopPtr::cleanup_speculative();
5149 }
5150 
5151 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
5152   if (!UseInlineDepthForSpeculativeTypes) {
5153     return this;
5154   }
5155   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5156 }
5157 
5158 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5159   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);
5160 }
5161 
5162 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5163   int adj = 0;
5164   if (offset != Type::OffsetBot && offset != Type::OffsetTop) {
5165     const Type* elemtype = elem();
5166     if (elemtype->isa_inlinetype()) {
5167       if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5168         adj = _offset.get();
5169         offset += _offset.get();
5170       }
5171       uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5172       if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5173         offset += _field_offset.get();
5174         if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5175           offset += header;
5176         }
5177       }
5178       if (offset >= (intptr_t)header || offset < 0) {
5179         // Try to get the field of the inline type array element we are pointing to
5180         ciKlass* arytype_klass = klass();
5181         ciFlatArrayKlass* vak = arytype_klass->as_flat_array_klass();
5182         ciInlineKlass* vk = vak->element_klass()->as_inline_klass();
5183         int shift = vak->log2_element_size();
5184         int mask = (1 << shift) - 1;
5185         intptr_t field_offset = ((offset - header) & mask);
5186         ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
5187         if (field == NULL) {
5188           // This may happen with nested AddP(base, AddP(base, base, offset), longcon(16))
5189           return add_offset(offset);
5190         } else {
5191           return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5192         }
5193       }
5194     }
5195   }
5196   return add_offset(offset - adj);
5197 }
5198 
5199 // Return offset incremented by field_offset for flattened inline type arrays
5200 const int TypeAryPtr::flattened_offset() const {
5201   int offset = _offset.get();
5202   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5203       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5204     offset += _field_offset.get();
5205   }
5206   return offset;
5207 }
5208 
5209 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
5210   assert(is_known_instance(), "should be known");
5211   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5212 }
5213 
5214 //=============================================================================
5215 
5216 
5217 //------------------------------hash-------------------------------------------
5218 // Type-specific hashing function.
5219 int TypeNarrowPtr::hash(void) const {
5220   return _ptrtype->hash() + 7;
5221 }
5222 
5223 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5224   return _ptrtype->singleton();
5225 }
5226 
5227 bool TypeNarrowPtr::empty(void) const {
5228   return _ptrtype->empty();
5229 }
5230 
5231 intptr_t TypeNarrowPtr::get_con() const {
5232   return _ptrtype->get_con();
5233 }
5234 
5235 bool TypeNarrowPtr::eq( const Type *t ) const {
5236   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5287 
5288   case Int:                     // Mixing ints & oops happens when javac
5289   case Long:                    // reuses local variables
5290   case FloatTop:
5291   case FloatCon:
5292   case FloatBot:
5293   case DoubleTop:
5294   case DoubleCon:
5295   case DoubleBot:
5296   case AnyPtr:
5297   case RawPtr:
5298   case OopPtr:
5299   case InstPtr:
5300   case AryPtr:
5301   case MetadataPtr:
5302   case KlassPtr:
5303   case InstKlassPtr:
5304   case AryKlassPtr:
5305   case NarrowOop:
5306   case NarrowKlass:

5307   case Bottom:                  // Ye Olde Default
5308     return Type::BOTTOM;
5309   case Top:
5310     return this;
5311 
5312   case InlineType:
5313     return t->xmeet(this);
5314 
5315   default:                      // All else is a mistake
5316     typerr(t);
5317 
5318   } // End of switch
5319 
5320   return this;
5321 }
5322 
5323 #ifndef PRODUCT
5324 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5325   _ptrtype->dump2(d, depth, st);
5326 }
5327 #endif
5328 
5329 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5330 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5331 
5332 
5333 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5334   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();

5373     return (one == two) && TypePtr::eq(t);
5374   } else {
5375     return one->equals(two) && TypePtr::eq(t);
5376   }
5377 }
5378 
5379 //------------------------------hash-------------------------------------------
5380 // Type-specific hashing function.
5381 int TypeMetadataPtr::hash(void) const {
5382   return
5383     (metadata() ? metadata()->hash() : 0) +
5384     TypePtr::hash();
5385 }
5386 
5387 //------------------------------singleton--------------------------------------
5388 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5389 // constants
5390 bool TypeMetadataPtr::singleton(void) const {
5391   // detune optimizer to not generate constant metadata + constant offset as a constant!
5392   // TopPTR, Null, AnyNull, Constant are all singletons
5393   return (offset() == 0) && !below_centerline(_ptr);
5394 }
5395 
5396 //------------------------------add_offset-------------------------------------
5397 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
5398   return make( _ptr, _metadata, xadd_offset(offset));
5399 }
5400 
5401 //-----------------------------filter------------------------------------------
5402 // Do not allow interface-vs.-noninterface joins to collapse to top.
5403 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5404   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5405   if (ft == NULL || ft->empty())
5406     return Type::TOP;           // Canonical empty value
5407   return ft;
5408 }
5409 
5410  //------------------------------get_con----------------------------------------
5411 intptr_t TypeMetadataPtr::get_con() const {
5412   assert( _ptr == Null || _ptr == Constant, "" );
5413   assert(offset() >= 0, "");
5414 
5415   if (offset() != 0) {
5416     // After being ported to the compiler interface, the compiler no longer
5417     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5418     // to a handle at compile time.  This handle is embedded in the generated
5419     // code and dereferenced at the time the nmethod is made.  Until that time,
5420     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5421     // have access to the addresses!).  This does not seem to currently happen,
5422     // but this assertion here is to help prevent its occurence.
5423     tty->print_cr("Found oop constant with non-zero offset");
5424     ShouldNotReachHere();
5425   }
5426 
5427   return (intptr_t)metadata()->constant_encoding();
5428 }
5429 
5430 //------------------------------cast_to_ptr_type-------------------------------
5431 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5432   if( ptr == _ptr ) return this;
5433   return make(ptr, metadata(), _offset);
5434 }
5435 

5446   case Long:                    // reuses local variables
5447   case FloatTop:
5448   case FloatCon:
5449   case FloatBot:
5450   case DoubleTop:
5451   case DoubleCon:
5452   case DoubleBot:
5453   case NarrowOop:
5454   case NarrowKlass:
5455   case Bottom:                  // Ye Olde Default
5456     return Type::BOTTOM;
5457   case Top:
5458     return this;
5459 
5460   default:                      // All else is a mistake
5461     typerr(t);
5462 
5463   case AnyPtr: {
5464     // Found an AnyPtr type vs self-OopPtr type
5465     const TypePtr *tp = t->is_ptr();
5466     Offset offset = meet_offset(tp->offset());
5467     PTR ptr = meet_ptr(tp->ptr());
5468     switch (tp->ptr()) {
5469     case Null:
5470       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5471       // else fall through:
5472     case TopPTR:
5473     case AnyNull: {
5474       return make(ptr, _metadata, offset);
5475     }
5476     case BotPTR:
5477     case NotNull:
5478       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5479     default: typerr(t);
5480     }
5481   }
5482 
5483   case RawPtr:
5484   case KlassPtr:
5485   case InstKlassPtr:
5486   case AryKlassPtr:
5487   case OopPtr:
5488   case InstPtr:
5489   case AryPtr:
5490     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5491 
5492   case MetadataPtr: {
5493     const TypeMetadataPtr *tp = t->is_metadataptr();
5494     Offset offset = meet_offset(tp->offset());
5495     PTR tptr = tp->ptr();
5496     PTR ptr = meet_ptr(tptr);
5497     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5498     if (tptr == TopPTR || _ptr == TopPTR ||
5499         metadata()->equals(tp->metadata())) {
5500       return make(ptr, md, offset);
5501     }
5502     // metadata is different
5503     if( ptr == Constant ) {  // Cannot be equal constants, so...
5504       if( tptr == Constant && _ptr != Constant)  return t;
5505       if( _ptr == Constant && tptr != Constant)  return this;
5506       ptr = NotNull;            // Fall down in lattice
5507     }
5508     return make(ptr, NULL, offset);
5509     break;
5510   }
5511   } // End of switch
5512   return this;                  // Return the double constant
5513 }
5514 
5515 
5516 //------------------------------xdual------------------------------------------
5517 // Dual of a pure metadata pointer.
5518 const Type *TypeMetadataPtr::xdual() const {
5519   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5520 }
5521 
5522 //------------------------------dump2------------------------------------------
5523 #ifndef PRODUCT
5524 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5525   st->print("metadataptr:%s", ptr_msg[_ptr]);
5526   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5527   switch (offset()) {
5528   case OffsetTop: st->print("+top"); break;
5529   case OffsetBot: st->print("+any"); break;
5530   case         0: break;
5531   default:        st->print("+%d",offset()); break;
5532   }
5533 }
5534 #endif
5535 
5536 
5537 //=============================================================================
5538 // Convenience common pre-built type.
5539 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5540 
5541 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5542   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5543 }
5544 
5545 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5546   return make(Constant, m, Offset(0));
5547 }
5548 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5549   return make(Constant, m, Offset(0));
5550 }
5551 
5552 //------------------------------make-------------------------------------------
5553 // Create a meta data constant
5554 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5555   assert(m == NULL || !m->is_klass(), "wrong type");
5556   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5557 }
5558 
5559 
5560 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5561   const Type* elem = _ary->_elem;
5562   bool xk = klass_is_exact();
5563   if (elem->make_oopptr() != NULL) {
5564     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5565     if (elem->is_klassptr()->klass_is_exact()) {
5566       xk = true;
5567     }
5568   }
5569   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
5570 }
5571 
5572 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass) {
5573   if (klass->is_instance_klass()) {
5574     return TypeInstKlassPtr::make(klass);
5575   }
5576   return TypeAryKlassPtr::make(klass);
5577 }
5578 
5579 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset) {
5580   if (klass->is_instance_klass()) {
5581     return TypeInstKlassPtr::make(ptr, klass, offset);
5582   }
5583   return TypeAryKlassPtr::make(klass, ptr, offset);
5584 }
5585 

5586 //------------------------------TypeKlassPtr-----------------------------------
5587 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, Offset offset)
5588   : TypePtr(t, ptr, offset), _klass(klass) {
5589 }
5590 
5591 //------------------------------eq---------------------------------------------
5592 // Structural equality check for Type representations
5593 bool TypeKlassPtr::eq(const Type *t) const {
5594   const TypeKlassPtr *p = t->is_klassptr();
5595   return
5596     TypePtr::eq(p);
5597 }
5598 
5599 //------------------------------hash-------------------------------------------
5600 // Type-specific hashing function.
5601 int TypeKlassPtr::hash(void) const {
5602   return TypePtr::hash();
5603 }
5604 
5605 //------------------------------singleton--------------------------------------
5606 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5607 // constants
5608 bool TypeKlassPtr::singleton(void) const {
5609   // detune optimizer to not generate constant klass + constant offset as a constant!
5610   // TopPTR, Null, AnyNull, Constant are all singletons
5611   return (offset() == 0) && !below_centerline(_ptr);
5612 }
5613 
5614 // Do not allow interface-vs.-noninterface joins to collapse to top.
5615 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5616   // logic here mirrors the one from TypeOopPtr::filter. See comments
5617   // there.
5618   const Type* ft = join_helper(kills, include_speculative);
5619   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5620   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5621 
5622   if (ft->empty()) {
5623     if (!empty() && ktkp != NULL && ktkp->is_loaded() && ktkp->klass()->is_interface())
5624       return kills;             // Uplift to interface
5625 
5626     return Type::TOP;           // Canonical empty value
5627   }
5628 
5629   // Interface klass type could be exact in opposite to interface type,
5630   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5631   if (ftkp != NULL && ktkp != NULL &&
5632       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5633       !ftkp->klass_is_exact() && // Keep exact interface klass
5634       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5635     return ktkp->cast_to_ptr_type(ftkp->ptr());
5636   }
5637 
5638   return ft;
5639 }
5640 
5641 //------------------------------get_con----------------------------------------
5642 intptr_t TypeKlassPtr::get_con() const {
5643   assert( _ptr == Null || _ptr == Constant, "" );
5644   assert( offset() >= 0, "" );
5645 
5646   if (offset() != 0) {
5647     // After being ported to the compiler interface, the compiler no longer
5648     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5649     // to a handle at compile time.  This handle is embedded in the generated
5650     // code and dereferenced at the time the nmethod is made.  Until that time,
5651     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5652     // have access to the addresses!).  This does not seem to currently happen,
5653     // but this assertion here is to help prevent its occurence.
5654     tty->print_cr("Found oop constant with non-zero offset");
5655     ShouldNotReachHere();
5656   }
5657 
5658   return (intptr_t)klass()->constant_encoding();
5659 }
5660 
5661 //------------------------------dump2------------------------------------------
5662 // Dump Klass Type
5663 #ifndef PRODUCT
5664 void TypeInstKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5665   switch(_ptr) {
5666   case Constant:
5667     st->print("precise ");
5668   case NotNull:
5669     {
5670       const char *name = klass()->name()->as_utf8();
5671       if (name) {
5672         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5673       } else {
5674         ShouldNotReachHere();
5675       }
5676     }
5677   case BotPTR:
5678     if (!WizardMode && !Verbose && _ptr != Constant) break;
5679   case TopPTR:
5680   case AnyNull:
5681     st->print(":%s", ptr_msg[_ptr]);
5682     if (_ptr == Constant) st->print(":exact");
5683     break;
5684   default:
5685     break;
5686   }
5687   if (Verbose) {
5688     if (_flatten_array) st->print(":flatten array");



5689   }
5690   _offset.dump2(st);
5691   st->print(" *");
5692 }
5693 #endif
5694 
5695 //=============================================================================
5696 // Convenience common pre-built types.
5697 
5698 // Not-null object klass or below
5699 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5700 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5701 
5702 bool TypeInstKlassPtr::eq(const Type *t) const {
5703   const TypeKlassPtr *p = t->is_klassptr();
5704   return
5705     klass()->equals(p->klass()) &&
5706     flatten_array() == p->flatten_array() &&
5707     TypeKlassPtr::eq(p);
5708 }
5709 
5710 int TypeInstKlassPtr::hash(void) const {
5711   return java_add(java_add((jint)klass()->hash(), TypeKlassPtr::hash()), (jint)flatten_array());
5712 }
5713 
5714 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, bool flatten_array) {
5715   flatten_array = flatten_array || k->flatten_array();
5716 
5717   TypeInstKlassPtr *r =
5718     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, offset, flatten_array))->hashcons();
5719 
5720   return r;
5721 }
5722 
5723 //------------------------------add_offset-------------------------------------
5724 // Access internals of klass object
5725 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5726   return make(_ptr, klass(), xadd_offset(offset), flatten_array());
5727 }
5728 
5729 const TypeKlassPtr *TypeInstKlassPtr::with_offset(intptr_t offset) const {
5730   return make(_ptr, klass(), Offset(offset), flatten_array());
5731 }
5732 
5733 //------------------------------cast_to_ptr_type-------------------------------
5734 const TypePtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5735   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5736   if( ptr == _ptr ) return this;
5737   return make(ptr, _klass, _offset, flatten_array());
5738 }
5739 
5740 
5741 bool TypeInstKlassPtr::must_be_exact() const {
5742   if (!_klass->is_loaded())  return false;
5743   ciInstanceKlass* ik = _klass->as_instance_klass();
5744   if (ik->is_final())  return true;  // cannot clear xk
5745   return false;
5746 }
5747 
5748 //-----------------------------cast_to_exactness-------------------------------
5749 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5750   if (klass_is_exact == (_ptr == Constant)) return this;
5751   if (must_be_exact()) return this;
5752   ciKlass* k = klass();
5753   return make(klass_is_exact ? Constant : NotNull, k, _offset, flatten_array());
5754 }
5755 
5756 
5757 //-----------------------------as_instance_type--------------------------------
5758 // Corresponding type for an instance of the given class.
5759 // It will be NotNull, and exact if and only if the klass type is exact.
5760 const TypeOopPtr* TypeInstKlassPtr::as_instance_type() const {
5761   ciKlass* k = klass();
5762   bool    xk = klass_is_exact();
5763   return TypeInstPtr::make(TypePtr::BotPTR, k, xk, NULL, Offset(0), flatten_array() && !klass()->is_inlinetype());
5764 }
5765 
5766 //------------------------------xmeet------------------------------------------
5767 // Compute the MEET of two types, return a new Type object.
5768 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5769   // Perform a fast test for common case; meeting the same types together.
5770   if( this == t ) return this;  // Meeting same type-rep?
5771 
5772   // Current "this->_base" is Pointer
5773   switch (t->base()) {          // switch on original type
5774 
5775   case Int:                     // Mixing ints & oops happens when javac
5776   case Long:                    // reuses local variables
5777   case FloatTop:
5778   case FloatCon:
5779   case FloatBot:
5780   case DoubleTop:
5781   case DoubleCon:
5782   case DoubleBot:
5783   case NarrowOop:
5784   case NarrowKlass:
5785   case Bottom:                  // Ye Olde Default
5786     return Type::BOTTOM;
5787   case Top:
5788     return this;
5789 
5790   default:                      // All else is a mistake
5791     typerr(t);
5792 
5793   case AnyPtr: {                // Meeting to AnyPtrs
5794     // Found an AnyPtr type vs self-KlassPtr type
5795     const TypePtr *tp = t->is_ptr();
5796     Offset offset = meet_offset(tp->offset());
5797     PTR ptr = meet_ptr(tp->ptr());
5798     switch (tp->ptr()) {
5799     case TopPTR:
5800       return this;
5801     case Null:
5802       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5803     case AnyNull:
5804       return make(ptr, klass(), offset, flatten_array());
5805     case BotPTR:
5806     case NotNull:
5807       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5808     default: typerr(t);
5809     }
5810   }
5811 
5812   case RawPtr:
5813   case MetadataPtr:
5814   case OopPtr:
5815   case AryPtr:                  // Meet with AryPtr
5816   case InstPtr:                 // Meet with InstPtr
5817       return TypePtr::BOTTOM;
5818 
5819   //
5820   //             A-top         }
5821   //           /   |   \       }  Tops
5822   //       B-top A-any C-top   }
5823   //          | /  |  \ |      }  Any-nulls
5824   //       B-any   |   C-any   }
5825   //          |    |    |
5826   //       B-con A-con C-con   } constants; not comparable across classes
5827   //          |    |    |
5828   //       B-not   |   C-not   }
5829   //          | \  |  / |      }  not-nulls
5830   //       B-bot A-not C-bot   }
5831   //           \   |   /       }  Bottoms
5832   //             A-bot         }
5833   //
5834 
5835   case InstKlassPtr: {  // Meet two KlassPtr types
5836     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5837     Offset  off     = meet_offset(tkls->offset());
5838     PTR  ptr     = meet_ptr(tkls->ptr());
5839     ciKlass* tkls_klass = tkls->klass();
5840     ciKlass* this_klass  = klass();
5841     bool tkls_xk = tkls->klass_is_exact();
5842     bool this_xk  = klass_is_exact();
5843     bool tkls_flatten_array = tkls->flatten_array();
5844     bool this_flatten_array  = this->flatten_array();
5845 
5846     ciKlass* res_klass = NULL;
5847     bool res_xk = false;
5848     bool res_flatten_array = false;
5849     switch(meet_instptr(ptr, this_klass, tkls_klass, this_xk, tkls_xk, this->_ptr, tkls->_ptr,
5850                         this_flatten_array, tkls_flatten_array, res_klass, res_xk, res_flatten_array)) {
5851       case UNLOADED:
5852         ShouldNotReachHere();
5853       case SUBTYPE:
5854       case NOT_SUBTYPE:
5855       case LCA:
5856       case QUICK: {
5857         assert(res_xk == (ptr == Constant), "");
5858         const Type* res1 = make(ptr, res_klass, off, res_flatten_array);
5859         return res1;
5860       }
5861       default:
5862         ShouldNotReachHere();
5863     }
5864   } // End of case KlassPtr
5865   case AryKlassPtr: {                // All arrays inherit from Object class
5866     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5867     Offset offset = meet_offset(tp->offset());
5868     PTR ptr = meet_ptr(tp->ptr());
5869 
5870     switch (ptr) {
5871     case TopPTR:
5872     case AnyNull:                // Fall 'down' to dual of object klass
5873       // For instances when a subclass meets a superclass we fall
5874       // below the centerline when the superclass is exact. We need to
5875       // do the same here.
5876       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
5877         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->null_free());
5878       } else {
5879         // cannot subclass, so the meet has to fall badly below the centerline
5880         ptr = NotNull;
5881         return make(ptr, ciEnv::current()->Object_klass(), offset, false);
5882       }
5883     case Constant:
5884     case NotNull:
5885     case BotPTR:                // Fall down to object klass
5886       // LCA is object_klass, but if we subclass from the top we can do better
5887       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5888         // If 'this' (InstPtr) is above the centerline and it is Object class
5889         // then we can subclass in the Java class hierarchy.
5890         // For instances when a subclass meets a superclass we fall
5891         // below the centerline when the superclass is exact. We need
5892         // to do the same here.
5893         if (klass()->equals(ciEnv::current()->Object_klass())) {
5894           // that is, tp's array type is a subtype of my klass
5895           return TypeAryKlassPtr::make(ptr,
5896                                        tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->null_free());
5897         }
5898       }
5899       // The other case cannot happen, since I cannot be a subtype of an array.
5900       // The meet falls down to Object class below centerline.
5901       if( ptr == Constant )
5902          ptr = NotNull;
5903       return make(ptr, ciEnv::current()->Object_klass(), offset, false);
5904     default: typerr(t);
5905     }
5906   }
5907   case InlineType: {
5908     const TypeInlineType* tv = t->is_inlinetype();
5909     if (above_centerline(ptr())) {
5910       if (tv->inline_klass()->is_subtype_of(_klass)) {
5911         return t;
5912       } else {
5913         return TypeInstPtr::NOTNULL;
5914       }
5915     } else {
5916       PTR ptr = this->_ptr;
5917       if (ptr == Constant) {
5918         ptr = NotNull;
5919       }
5920       if (tv->inline_klass()->is_subtype_of(_klass)) {
5921         return make(ptr, _klass, Offset(0), _flatten_array);
5922       } else {
5923         return make(ptr, ciEnv::current()->Object_klass(), Offset(0));
5924       }
5925     }
5926   }
5927 
5928   } // End of switch
5929   return this;                  // Return the double constant
5930 }
5931 
5932 //------------------------------xdual------------------------------------------
5933 // Dual: compute field-by-field dual
5934 const Type    *TypeInstKlassPtr::xdual() const {
5935   return new TypeInstKlassPtr(dual_ptr(), klass(), dual_offset(), flatten_array());
5936 }
5937 
5938 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
5939   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, null_free))->hashcons();
5940 }
5941 
5942 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
5943   if (klass->is_obj_array_klass()) {
5944     // Element is an object array. Recursively call ourself.
5945     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
5946     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass)->cast_to_exactness(false);
5947 
5948     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5949     if (etype->klass_is_exact() && etype->isa_instklassptr() && etype->is_instklassptr()->klass()->is_inlinetype() && !null_free) {
5950       etype = TypeInstKlassPtr::make(NotNull, etype->is_instklassptr()->klass(), Offset(etype->is_instklassptr()->offset()), etype->is_instklassptr()->flatten_array());
5951     }
5952 
5953     const TypeAryKlassPtr* res = TypeAryKlassPtr::make(ptr, etype, NULL, offset, not_flat, not_null_free, null_free);
5954     assert(res->klass() == klass, "");
5955     return res;
5956   } else if (klass->is_type_array_klass()) {
5957     // Element is an typeArray
5958     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
5959     return TypeAryKlassPtr::make(ptr, etype, klass, offset, not_flat, not_null_free, null_free);
5960   } else if (klass->is_flat_array_klass()) {
5961     ciInlineKlass* vk = klass->as_array_klass()->element_klass()->as_inline_klass();
5962     return TypeAryKlassPtr::make(ptr, TypeInlineType::make(vk), klass, offset, not_flat, not_null_free, null_free);
5963   } else {
5964     ShouldNotReachHere();
5965     return NULL;
5966   }
5967 }
5968 
5969 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* k, PTR ptr, Offset offset) {
5970   bool null_free = k->as_array_klass()->is_elem_null_free();
5971   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));
5972 
5973   bool not_flat = !UseFlatArray || not_null_free || (k->as_array_klass()->element_klass() != NULL &&
5974                                                      k->as_array_klass()->element_klass()->is_inlinetype() &&
5975                                                      !k->as_array_klass()->element_klass()->flatten_array());
5976 
5977   return TypeAryKlassPtr::make(ptr, k, offset, not_flat, not_null_free, null_free);
5978 }
5979 
5980 //------------------------------eq---------------------------------------------
5981 // Structural equality check for Type representations
5982 bool TypeAryKlassPtr::eq(const Type *t) const {
5983   const TypeAryKlassPtr *p = t->is_aryklassptr();
5984   return
5985     _elem == p->_elem &&  // Check array
5986     _not_flat == p->_not_flat &&
5987     _not_null_free == p->_not_null_free &&
5988     _null_free == p->_null_free &&
5989     TypeKlassPtr::eq(p);  // Check sub-parts
5990 }
5991 
5992 //------------------------------hash-------------------------------------------
5993 // Type-specific hashing function.
5994 int TypeAryKlassPtr::hash(void) const {
5995   return (intptr_t)_elem + TypeKlassPtr::hash();
5996 }
5997 
5998 //----------------------compute_klass------------------------------------------
5999 // Compute the defining klass for this class
6000 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
6001   // Compute _klass based on element type.
6002   ciKlass* k_ary = NULL;

6003   const TypeAryPtr *tary;
6004   const Type* el = elem();
6005   if (el->isa_narrowoop()) {
6006     el = el->make_ptr();
6007   }
6008 
6009   // Get element klass
6010   if (el->isa_instptr()) {
6011     // Compute object array klass from element klass
6012     bool null_free = el->is_inlinetypeptr() && el->isa_instptr()->ptr() != TypePtr::TopPTR && !el->isa_instptr()->maybe_null();
6013     k_ary = ciArrayKlass::make(el->is_oopptr()->klass(), null_free);
6014   } else if (el->isa_inlinetype()) {
6015     // If element type is TypeInlineType::BOTTOM, inline_klass() will be null.
6016     if (el->inline_klass() != NULL) {
6017       k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6018     }
6019   } else if ((tary = el->isa_aryptr()) != NULL) {
6020     // Compute array klass from element klass
6021     ciKlass* k_elem = tary->klass();
6022     // If element type is something like bottom[], k_elem will be null.
6023     if (k_elem != NULL)
6024       k_ary = ciObjArrayKlass::make(k_elem);
6025   } else if ((el->base() == Type::Top) ||
6026              (el->base() == Type::Bottom)) {
6027     // element type of Bottom occurs from meet of basic type
6028     // and object; Top occurs when doing join on Bottom.
6029     // Leave k_ary at NULL.
6030   } else {
6031     // Cannot compute array klass directly from basic type,
6032     // since subtypes of TypeInt all have basic type T_INT.
6033 #ifdef ASSERT
6034     if (verify && el->isa_int()) {
6035       // Check simple cases when verifying klass.
6036       BasicType bt = T_ILLEGAL;
6037       if (el == TypeInt::BYTE) {
6038         bt = T_BYTE;

6063 
6064   // Oops, need to compute _klass and cache it
6065   ciKlass* k_ary = compute_klass();
6066 
6067   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6068     // The _klass field acts as a cache of the underlying
6069     // ciKlass for this array type.  In order to set the field,
6070     // we need to cast away const-ness.
6071     //
6072     // IMPORTANT NOTE: we *never* set the _klass field for the
6073     // type TypeAryPtr::OOPS.  This Type is shared between all
6074     // active compilations.  However, the ciKlass which represents
6075     // this Type is *not* shared between compilations, so caching
6076     // this value would result in fetching a dangling pointer.
6077     //
6078     // Recomputing the underlying ciKlass for each request is
6079     // a bit less efficient than caching, but calls to
6080     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6081     ((TypeAryPtr*)this)->_klass = k_ary;
6082     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
6083         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) {
6084       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
6085     }
6086   }
6087   return k_ary;
6088 }
6089 
6090 
6091 //------------------------------add_offset-------------------------------------
6092 // Access internals of klass object
6093 const TypePtr *TypeAryKlassPtr::add_offset(intptr_t offset) const {
6094   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6095 }
6096 
6097 const TypeKlassPtr *TypeAryKlassPtr::with_offset(intptr_t offset) const {
6098   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6099 }
6100 
6101 //------------------------------cast_to_ptr_type-------------------------------
6102 const TypePtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6103   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6104   if (ptr == _ptr) return this;
6105   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6106 }
6107 
6108 bool TypeAryKlassPtr::must_be_exact() const {
6109   if (_elem == Type::BOTTOM) return false;
6110   if (_elem == Type::TOP   ) return false;
6111   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6112   if (!tk)             return true;   // a primitive type, like int
6113   return tk->must_be_exact();
6114 }
6115 
6116 
6117 //-----------------------------cast_to_exactness-------------------------------
6118 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6119   if (must_be_exact() && !klass_is_exact) return this;  // cannot clear xk
6120   ciKlass* k = _klass;
6121   const Type* elem = this->elem();
6122   if (elem->isa_klassptr() && !klass_is_exact) {
6123     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6124   }
6125   bool not_flat = is_not_flat();
6126   bool not_null_free = is_not_null_free();
6127   if (klass() != NULL && klass()->is_obj_array_klass() && klass_is_exact) {
6128     // An object array can't be flat or null-free if the klass is exact
6129     not_flat = true;
6130     not_null_free = true;
6131   }
6132   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6133 }
6134 
6135 
6136 //-----------------------------as_instance_type--------------------------------
6137 // Corresponding type for an instance of the given class.
6138 // It will be exact if and only if the klass type is exact.
6139 const TypeOopPtr* TypeAryKlassPtr::as_instance_type() const {
6140   ciKlass* k = klass();
6141   assert(k != NULL, "klass should not be NULL");
6142   bool    xk = klass_is_exact();
6143   const Type* el = elem()->isa_klassptr() ? elem()->is_klassptr()->as_instance_type()->is_oopptr()->cast_to_exactness(false) : elem();
6144   bool null_free = _null_free;
6145   if (null_free && el->isa_ptr()) {
6146     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6147   }
6148   bool not_flat = is_not_flat();
6149   bool not_null_free = is_not_null_free();
6150   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, not_flat, not_null_free), k, xk, Offset(0));
6151 }
6152 
6153 
6154 //------------------------------xmeet------------------------------------------
6155 // Compute the MEET of two types, return a new Type object.
6156 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6157   // Perform a fast test for common case; meeting the same types together.
6158   if( this == t ) return this;  // Meeting same type-rep?
6159 
6160   // Current "this->_base" is Pointer
6161   switch (t->base()) {          // switch on original type
6162 
6163   case Int:                     // Mixing ints & oops happens when javac
6164   case Long:                    // reuses local variables
6165   case FloatTop:
6166   case FloatCon:
6167   case FloatBot:
6168   case DoubleTop:
6169   case DoubleCon:
6170   case DoubleBot:
6171   case NarrowOop:
6172   case NarrowKlass:
6173   case Bottom:                  // Ye Olde Default
6174     return Type::BOTTOM;
6175   case Top:
6176     return this;
6177 
6178   default:                      // All else is a mistake
6179     typerr(t);
6180 
6181   case AnyPtr: {                // Meeting to AnyPtrs
6182     // Found an AnyPtr type vs self-KlassPtr type
6183     const TypePtr *tp = t->is_ptr();
6184     Offset offset = meet_offset(tp->offset());
6185     PTR ptr = meet_ptr(tp->ptr());
6186     switch (tp->ptr()) {
6187     case TopPTR:
6188       return this;
6189     case Null:
6190       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6191     case AnyNull:
6192       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), _null_free);
6193     case BotPTR:
6194     case NotNull:
6195       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6196     default: typerr(t);
6197     }
6198   }
6199 
6200   case RawPtr:
6201   case MetadataPtr:
6202   case OopPtr:
6203   case AryPtr:                  // Meet with AryPtr
6204   case InstPtr:                 // Meet with InstPtr
6205     return TypePtr::BOTTOM;
6206 
6207   //
6208   //             A-top         }
6209   //           /   |   \       }  Tops
6210   //       B-top A-any C-top   }
6211   //          | /  |  \ |      }  Any-nulls
6212   //       B-any   |   C-any   }
6213   //          |    |    |
6214   //       B-con A-con C-con   } constants; not comparable across classes
6215   //          |    |    |
6216   //       B-not   |   C-not   }
6217   //          | \  |  / |      }  not-nulls
6218   //       B-bot A-not C-bot   }
6219   //           \   |   /       }  Bottoms
6220   //             A-bot         }
6221   //
6222 
6223   case AryKlassPtr: {  // Meet two KlassPtr types
6224     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6225     Offset off = meet_offset(tap->offset());
6226     const Type* res_elem = NULL;

6227     PTR ptr = meet_ptr(tap->ptr());
6228     ciKlass* res_klass = NULL;
6229     bool res_xk = false;
6230     bool res_not_flat = false;
6231     bool res_not_null_free = false;
6232     MeetResult res = meet_aryptr(ptr, _elem, tap->_elem, this->klass(), tap->klass(),
6233                                  this->klass_is_exact(), tap->klass_is_exact(),
6234                                  this->ptr(), tap->ptr(), this->is_not_flat(), tap->is_not_flat(),
6235                                  this->is_not_null_free(), tap->is_not_null_free(),
6236                                  res_elem, res_klass, res_xk, res_not_flat, res_not_null_free);
6237     assert(res_xk == (ptr == Constant), "");
6238     bool null_free = meet_null_free(tap->_null_free);
6239     if (res == NOT_SUBTYPE) {
6240       null_free = false;
6241     } else if (res == SUBTYPE) {
6242       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6243         null_free = _null_free;
6244       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6245         null_free = tap->_null_free;
6246       }
6247     }
6248     return make(ptr, res_elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
6249   } // End of case KlassPtr
6250   case InstKlassPtr: {
6251     const TypeInstKlassPtr *tp = t->is_instklassptr();
6252     Offset offset = meet_offset(tp->offset());
6253     PTR ptr = meet_ptr(tp->ptr());
6254 
6255     switch (ptr) {
6256     case TopPTR:
6257     case AnyNull:                // Fall 'down' to dual of object klass
6258       // For instances when a subclass meets a superclass we fall
6259       // below the centerline when the superclass is exact. We need to
6260       // do the same here.
6261       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6262         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), _null_free);
6263       } else {
6264         // cannot subclass, so the meet has to fall badly below the centerline
6265         ptr = NotNull;
6266         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset, false);
6267       }
6268     case Constant:
6269     case NotNull:
6270     case BotPTR:                // Fall down to object klass
6271       // LCA is object_klass, but if we subclass from the top we can do better
6272       if (above_centerline(tp->ptr())) {
6273         // If 'tp'  is above the centerline and it is Object class
6274         // then we can subclass in the Java class hierarchy.
6275         // For instances when a subclass meets a superclass we fall
6276         // below the centerline when the superclass is exact. We need
6277         // to do the same here.
6278         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6279           // that is, my array type is a subtype of 'tp' klass
6280           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), _null_free);
6281         }
6282       }
6283       // The other case cannot happen, since t cannot be a subtype of an array.
6284       // The meet falls down to Object class below centerline.
6285       if (ptr == Constant)
6286          ptr = NotNull;
6287       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset, false);
6288     default: typerr(t);
6289     }
6290   }
6291   case InlineType: {
6292     const TypeInlineType* tv = t->is_inlinetype();
6293     if (above_centerline(ptr())) {
6294       return TypeInstKlassPtr::BOTTOM;
6295     } else {
6296       PTR ptr = this->_ptr;
6297       if (ptr == Constant) {
6298         ptr = NotNull;
6299       }
6300       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), Offset(0));
6301     }
6302   }
6303 
6304   } // End of switch
6305   return this;                  // Return the double constant
6306 }
6307 
6308 //------------------------------xdual------------------------------------------
6309 // Dual: compute field-by-field dual
6310 const Type    *TypeAryKlassPtr::xdual() const {
6311   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
6312 }
6313 
6314 //------------------------------get_con----------------------------------------
6315 ciKlass* TypeAryKlassPtr::klass() const {
6316     if (_klass != NULL) {
6317     return _klass;
6318   }
6319   ciKlass* k = NULL;
6320   const Type* el = elem();
6321   if (el->isa_instklassptr()) {
6322     // Compute object array klass from element klass
6323     bool null_free = el->is_instklassptr()->klass()->is_inlinetype() && el->isa_instklassptr()->ptr() != TypePtr::TopPTR && (_null_free != 0);
6324     k = ciArrayKlass::make(el->is_klassptr()->klass(), null_free);
6325     ((TypeAryKlassPtr*)this)->_klass = k;
6326   } else if (el->isa_inlinetype()) {
6327     // If element type is TypeInlineType::BOTTOM, inline_klass() will be null.
6328     if (el->inline_klass() != NULL) {
6329       k = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6330       ((TypeAryKlassPtr*)this)->_klass = k;
6331     }
6332   } else if (el->isa_aryklassptr() != NULL) {
6333     // Compute array klass from element klass
6334     ciKlass* k_elem = el->is_aryklassptr()->klass();
6335     // If element type is something like bottom[], k_elem will be null.
6336     if (k_elem != NULL) {
6337       k = ciObjArrayKlass::make(k_elem);
6338       ((TypeAryKlassPtr*)this)->_klass = k;
6339     }
6340   } else if ((elem()->base() == Type::Top) ||
6341              (elem()->base() == Type::Bottom)) {
6342   } else {
6343     k = ciTypeArrayKlass::make(elem()->basic_type());
6344   }
6345   return k;
6346 }
6347 
6348 //------------------------------dump2------------------------------------------
6349 // Dump Klass Type
6350 #ifndef PRODUCT
6351 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6352   switch( _ptr ) {
6353   case Constant:
6354     st->print("precise ");
6355   case NotNull:
6356     {
6357       st->print("[");
6358       if (_elem->isa_inlinetype()) {
6359         const char *name = _elem->is_inlinetype()->inline_klass()->name()->as_utf8();
6360         st->print("precise %s: " INTPTR_FORMAT " ", name, p2i(klass()));
6361       }
6362       _elem->dump2(d, depth, st);
6363       st->print(": ");
6364     }
6365   case BotPTR:
6366     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6367   case TopPTR:
6368   case AnyNull:
6369     st->print(":%s", ptr_msg[_ptr]);
6370     if( _ptr == Constant ) st->print(":exact");
6371     break;
6372   default:
6373     break;
6374   }
6375   if (Verbose) {
6376     if (_not_flat) st->print(":not flat");
6377     if (_not_null_free) st->print(":not null free");
6378     if (_null_free != 0) st->print(":null free(%d)", _null_free);

6379   }
6380 
6381   _offset.dump2(st);
6382 
6383   st->print(" *");
6384 }
6385 #endif
6386 
6387 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6388   const Type* elem = this->elem();
6389   dims = 1;
6390   while (elem->isa_aryklassptr()) {
6391     elem = elem->is_aryklassptr()->elem();
6392     dims++;
6393   }
6394   return elem;
6395 }
6396 
6397 //=============================================================================
6398 // Convenience common pre-built types.
6399 
6400 //------------------------------make-------------------------------------------
6401 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
6402                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
6403   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
6404 }
6405 
6406 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
6407   return make(domain, domain, range, range);
6408 }
6409 
6410 //------------------------------osr_domain-----------------------------
6411 const TypeTuple* osr_domain() {
6412   const Type **fields = TypeTuple::fields(2);
6413   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
6414   return TypeTuple::make(TypeFunc::Parms+1, fields);
6415 }
6416 
6417 //------------------------------make-------------------------------------------
6418 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
6419   Compile* C = Compile::current();
6420   const TypeFunc* tf = NULL;
6421   if (!is_osr_compilation) {
6422     tf = C->last_tf(method); // check cache
6423     if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
6424   }
6425   // Inline types are not passed/returned by reference, instead each field of
6426   // the inline type is passed/returned as an argument. We maintain two views of
6427   // the argument/return list here: one based on the signature (with an inline
6428   // type argument/return as a single slot), one based on the actual calling
6429   // convention (with an inline type argument/return as a list of its fields).
6430   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
6431   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, false);
6432   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, true) : domain_sig;
6433   ciSignature* sig = method->signature();
6434   bool has_scalar_ret = sig->returns_null_free_inline_type() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
6435   const TypeTuple* range_sig = TypeTuple::make_range(sig, false);
6436   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, true) : range_sig;
6437   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
6438   if (!is_osr_compilation) {
6439     C->set_last_tf(method, tf);  // fill cache
6440   }



6441   return tf;
6442 }
6443 
6444 //------------------------------meet-------------------------------------------
6445 // Compute the MEET of two types.  It returns a new Type object.
6446 const Type *TypeFunc::xmeet( const Type *t ) const {
6447   // Perform a fast test for common case; meeting the same types together.
6448   if( this == t ) return this;  // Meeting same type-rep?
6449 
6450   // Current "this->_base" is Func
6451   switch (t->base()) {          // switch on original type
6452 
6453   case Bottom:                  // Ye Olde Default
6454     return t;
6455 
6456   default:                      // All else is a mistake
6457     typerr(t);
6458 
6459   case Top:
6460     break;
6461   }
6462   return this;                  // Return the double constant
6463 }
6464 
6465 //------------------------------xdual------------------------------------------
6466 // Dual: compute field-by-field dual
6467 const Type *TypeFunc::xdual() const {
6468   return this;
6469 }
6470 
6471 //------------------------------eq---------------------------------------------
6472 // Structural equality check for Type representations
6473 bool TypeFunc::eq( const Type *t ) const {
6474   const TypeFunc *a = (const TypeFunc*)t;
6475   return _domain_sig == a->_domain_sig &&
6476     _domain_cc == a->_domain_cc &&
6477     _range_sig == a->_range_sig &&
6478     _range_cc == a->_range_cc;
6479 }
6480 
6481 //------------------------------hash-------------------------------------------
6482 // Type-specific hashing function.
6483 int TypeFunc::hash(void) const {
6484   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
6485 }
6486 
6487 //------------------------------dump2------------------------------------------
6488 // Dump Function Type
6489 #ifndef PRODUCT
6490 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6491   if( _range_sig->cnt() <= Parms )
6492     st->print("void");
6493   else {
6494     uint i;
6495     for (i = Parms; i < _range_sig->cnt()-1; i++) {
6496       _range_sig->field_at(i)->dump2(d,depth,st);
6497       st->print("/");
6498     }
6499     _range_sig->field_at(i)->dump2(d,depth,st);
6500   }
6501   st->print(" ");
6502   st->print("( ");
6503   if( !depth || d[this] ) {     // Check for recursive dump
6504     st->print("...)");
6505     return;
6506   }
6507   d.Insert((void*)this,(void*)this);    // Stop recursion
6508   if (Parms < _domain_sig->cnt())
6509     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
6510   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
6511     st->print(", ");
6512     _domain_sig->field_at(i)->dump2(d,depth-1,st);
6513   }
6514   st->print(" )");
6515 }
6516 #endif
6517 
6518 //------------------------------singleton--------------------------------------
6519 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6520 // constants (Ldi nodes).  Singletons are integer, float or double constants
6521 // or a single symbol.
6522 bool TypeFunc::singleton(void) const {
6523   return false;                 // Never a singleton
6524 }
6525 
6526 bool TypeFunc::empty(void) const {
6527   return false;                 // Never empty
6528 }
6529 
6530 
6531 BasicType TypeFunc::return_type() const{
6532   if (range_sig()->cnt() == TypeFunc::Parms) {
6533     return T_VOID;
6534   }
6535   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
6536 }
< prev index next >