< prev index next >

src/hotspot/share/opto/type.cpp

Print this page

   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"



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














































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

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

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










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

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

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

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

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


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

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

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

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

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

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



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

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

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

1499   // Currently "this->_base" is a TypeInt
1500   switch (t->base()) {          // Switch on original type
1501   case AnyPtr:                  // Mixing with oops happens when javac
1502   case RawPtr:                  // reuses local variables
1503   case OopPtr:
1504   case InstPtr:
1505   case AryPtr:
1506   case MetadataPtr:
1507   case KlassPtr:
1508   case InstKlassPtr:
1509   case AryKlassPtr:
1510   case NarrowOop:
1511   case NarrowKlass:
1512   case Long:
1513   case FloatTop:
1514   case FloatCon:
1515   case FloatBot:
1516   case DoubleTop:
1517   case DoubleCon:
1518   case DoubleBot:

1519   case Bottom:                  // Ye Olde Default
1520     return Type::BOTTOM;
1521   default:                      // All else is a mistake
1522     typerr(t);
1523   case Top:                     // No change
1524     return this;
1525   case Int:                     // Int vs Int?
1526     break;
1527   }
1528 
1529   // Expand covered set
1530   const TypeInt *r = t->is_int();
1531   return make( MIN2(_lo,r->_lo), MAX2(_hi,r->_hi), MAX2(_widen,r->_widen) );
1532 }
1533 
1534 //------------------------------xdual------------------------------------------
1535 // Dual: reverse hi & lo; flip widen
1536 const Type *TypeInt::xdual() const {
1537   int w = normalize_int_widen(_hi,_lo, WidenMax-_widen);
1538   return new TypeInt(_hi,_lo,w);

1986 
1987 bool TypeLong::empty(void) const {
1988   return _lo > _hi;
1989 }
1990 
1991 //=============================================================================
1992 // Convenience common pre-built types.
1993 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
1994 const TypeTuple *TypeTuple::IFFALSE;
1995 const TypeTuple *TypeTuple::IFTRUE;
1996 const TypeTuple *TypeTuple::IFNEITHER;
1997 const TypeTuple *TypeTuple::LOOPBODY;
1998 const TypeTuple *TypeTuple::MEMBAR;
1999 const TypeTuple *TypeTuple::STORECONDITIONAL;
2000 const TypeTuple *TypeTuple::START_I2C;
2001 const TypeTuple *TypeTuple::INT_PAIR;
2002 const TypeTuple *TypeTuple::LONG_PAIR;
2003 const TypeTuple *TypeTuple::INT_CC_PAIR;
2004 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2005 












2006 //------------------------------make-------------------------------------------
2007 // Make a TypeTuple from the range of a method signature
2008 const TypeTuple *TypeTuple::make_range(ciSignature* sig) {
2009   ciType* return_type = sig->return_type();
2010   uint arg_cnt = return_type->size();








2011   const Type **field_array = fields(arg_cnt);
2012   switch (return_type->basic_type()) {
2013   case T_LONG:
2014     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2015     field_array[TypeFunc::Parms+1] = Type::HALF;
2016     break;
2017   case T_DOUBLE:
2018     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2019     field_array[TypeFunc::Parms+1] = Type::HALF;
2020     break;
2021   case T_OBJECT:
2022   case T_ARRAY:
2023   case T_BOOLEAN:
2024   case T_CHAR:
2025   case T_FLOAT:
2026   case T_BYTE:
2027   case T_SHORT:
2028   case T_INT:
2029     field_array[TypeFunc::Parms] = get_const_type(return_type);
2030     break;













2031   case T_VOID:
2032     break;
2033   default:
2034     ShouldNotReachHere();
2035   }
2036   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2037 }
2038 
2039 // Make a TypeTuple from the domain of a method signature
2040 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig) {
2041   uint arg_cnt = sig->size();








2042 
2043   uint pos = TypeFunc::Parms;
2044   const Type **field_array;
2045   if (recv != NULL) {
2046     arg_cnt++;
2047     field_array = fields(arg_cnt);
2048     // Use get_const_type here because it respects UseUniqueSubclasses:
2049     field_array[pos++] = get_const_type(recv)->join_speculative(TypePtr::NOTNULL);
2050   } else {
2051     field_array = fields(arg_cnt);
2052   }
2053 
2054   int i = 0;
2055   while (pos < TypeFunc::Parms + arg_cnt) {
2056     ciType* type = sig->type_at(i);

2057 
2058     switch (type->basic_type()) {
2059     case T_LONG:
2060       field_array[pos++] = TypeLong::LONG;
2061       field_array[pos++] = Type::HALF;
2062       break;
2063     case T_DOUBLE:
2064       field_array[pos++] = Type::DOUBLE;
2065       field_array[pos++] = Type::HALF;
2066       break;
2067     case T_OBJECT:
2068     case T_ARRAY:
2069     case T_FLOAT:
2070     case T_INT:
2071       field_array[pos++] = get_const_type(type);
2072       break;
2073     case T_BOOLEAN:
2074     case T_CHAR:
2075     case T_BYTE:
2076     case T_SHORT:
2077       field_array[pos++] = TypeInt::INT;
2078       break;












2079     default:
2080       ShouldNotReachHere();
2081     }
2082     i++;
2083   }

2084 
2085   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2086 }
2087 
2088 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2089   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2090 }
2091 
2092 //------------------------------fields-----------------------------------------
2093 // Subroutine call type with space allocated for argument types
2094 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2095 const Type **TypeTuple::fields( uint arg_cnt ) {
2096   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2097   flds[TypeFunc::Control  ] = Type::CONTROL;
2098   flds[TypeFunc::I_O      ] = Type::ABIO;
2099   flds[TypeFunc::Memory   ] = Type::MEMORY;
2100   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2101   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2102 
2103   return flds;

2198     if (_fields[i]->empty())  return true;
2199   }
2200   return false;
2201 }
2202 
2203 //=============================================================================
2204 // Convenience common pre-built types.
2205 
2206 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2207   // Certain normalizations keep us sane when comparing types.
2208   // We do not want arrayOop variables to differ only by the wideness
2209   // of their index types.  Pick minimum wideness, since that is the
2210   // forced wideness of small ranges anyway.
2211   if (size->_widen != Type::WidenMin)
2212     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2213   else
2214     return size;
2215 }
2216 
2217 //------------------------------make-------------------------------------------
2218 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {

2219   if (UseCompressedOops && elem->isa_oopptr()) {
2220     elem = elem->make_narrowoop();
2221   }
2222   size = normalize_array_size(size);
2223   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2224 }
2225 
2226 //------------------------------meet-------------------------------------------
2227 // Compute the MEET of two types.  It returns a new Type object.
2228 const Type *TypeAry::xmeet( const Type *t ) const {
2229   // Perform a fast test for common case; meeting the same types together.
2230   if( this == t ) return this;  // Meeting same type-rep?
2231 
2232   // Current "this->_base" is Ary
2233   switch (t->base()) {          // switch on original type
2234 
2235   case Bottom:                  // Ye Olde Default
2236     return t;
2237 
2238   default:                      // All else is a mistake
2239     typerr(t);
2240 
2241   case Array: {                 // Meeting 2 arrays?
2242     const TypeAry *a = t->is_ary();
2243     return TypeAry::make(_elem->meet_speculative(a->_elem),
2244                          _size->xmeet(a->_size)->is_int(),
2245                          _stable && a->_stable);


2246   }
2247   case Top:
2248     break;
2249   }
2250   return this;                  // Return the double constant
2251 }
2252 
2253 //------------------------------xdual------------------------------------------
2254 // Dual: compute field-by-field dual
2255 const Type *TypeAry::xdual() const {
2256   const TypeInt* size_dual = _size->dual()->is_int();
2257   size_dual = normalize_array_size(size_dual);
2258   return new TypeAry(_elem->dual(), size_dual, !_stable);
2259 }
2260 
2261 //------------------------------eq---------------------------------------------
2262 // Structural equality check for Type representations
2263 bool TypeAry::eq( const Type *t ) const {
2264   const TypeAry *a = (const TypeAry*)t;
2265   return _elem == a->_elem &&
2266     _stable == a->_stable &&
2267     _size == a->_size;



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




2321   _elem->dump2(d, depth, st);
2322   st->print("[");
2323   _size->dump2(d, depth, st);
2324   st->print("]");
2325 }
2326 #endif
2327 
2328 //------------------------------singleton--------------------------------------
2329 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2330 // constants (Ldi nodes).  Singletons are integer, float or double constants
2331 // or a single symbol.
2332 bool TypeAry::singleton(void) const {
2333   return false;                 // Never a singleton
2334 }
2335 
2336 bool TypeAry::empty(void) const {
2337   return _elem->empty() || _size->empty();
2338 }
2339 
2340 //--------------------------ary_must_be_exact----------------------------------

2342   // This logic looks at the element type of an array, and returns true
2343   // if the element type is either a primitive or a final instance class.
2344   // In such cases, an array built on this ary must have no subclasses.
2345   if (_elem == BOTTOM)      return false;  // general array not exact
2346   if (_elem == TOP   )      return false;  // inverted general array not exact
2347   const TypeOopPtr*  toop = NULL;
2348   if (UseCompressedOops && _elem->isa_narrowoop()) {
2349     toop = _elem->make_ptr()->isa_oopptr();
2350   } else {
2351     toop = _elem->isa_oopptr();
2352   }
2353   if (!toop)                return true;   // a primitive type, like int
2354   ciKlass* tklass = toop->klass();
2355   if (tklass == NULL)       return false;  // unloaded class
2356   if (!tklass->is_loaded()) return false;  // unloaded class
2357   const TypeInstPtr* tinst;
2358   if (_elem->isa_narrowoop())
2359     tinst = _elem->make_ptr()->isa_instptr();
2360   else
2361     tinst = _elem->isa_instptr();
2362   if (tinst)
2363     return tklass->as_instance_klass()->is_final();








2364   const TypeAryPtr*  tap;
2365   if (_elem->isa_narrowoop())
2366     tap = _elem->make_ptr()->isa_aryptr();
2367   else
2368     tap = _elem->isa_aryptr();
2369   if (tap)
2370     return tap->ary()->ary_must_be_exact();
2371   return false;
2372 }
2373 































































































































2374 //==============================TypeVect=======================================
2375 // Convenience common pre-built types.
2376 const TypeVect *TypeVect::VECTA = NULL; // vector length agnostic
2377 const TypeVect *TypeVect::VECTS = NULL; //  32-bit vectors
2378 const TypeVect *TypeVect::VECTD = NULL; //  64-bit vectors
2379 const TypeVect *TypeVect::VECTX = NULL; // 128-bit vectors
2380 const TypeVect *TypeVect::VECTY = NULL; // 256-bit vectors
2381 const TypeVect *TypeVect::VECTZ = NULL; // 512-bit vectors
2382 const TypeVect *TypeVect::VECTMASK = NULL; // predicate/mask vector
2383 
2384 //------------------------------make-------------------------------------------
2385 const TypeVect* TypeVect::make(const Type *elem, uint length, bool is_mask) {
2386   if (is_mask) {
2387     return makemask(elem, length);
2388   }
2389   BasicType elem_bt = elem->array_element_basic_type();
2390   assert(is_java_primitive(elem_bt), "only primitive types in vector");
2391   assert(Matcher::vector_size_supported(elem_bt, length), "length in range");
2392   int size = length * type2aelembytes(elem_bt);
2393   switch (Matcher::vector_ideal_reg(size)) {

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

2615   case NarrowKlass:
2616   case Bottom:                  // Ye Olde Default
2617     return Type::BOTTOM;
2618   case Top:
2619     return this;
2620 
2621   case AnyPtr: {                // Meeting to AnyPtrs
2622     const TypePtr *tp = t->is_ptr();
2623     const TypePtr* speculative = xmeet_speculative(tp);
2624     int depth = meet_inline_depth(tp->inline_depth());
2625     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2626   }
2627   case RawPtr:                  // For these, flip the call around to cut down
2628   case OopPtr:
2629   case InstPtr:                 // on the cases I have to handle.
2630   case AryPtr:
2631   case MetadataPtr:
2632   case KlassPtr:
2633   case InstKlassPtr:
2634   case AryKlassPtr:

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

2940   }
2941   // We already know the speculative type is always null
2942   if (speculative_always_null()) {
2943     return false;
2944   }
2945   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
2946     return false;
2947   }
2948   return true;
2949 }
2950 
2951 //------------------------------dump2------------------------------------------
2952 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2953   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
2954 };
2955 
2956 #ifndef PRODUCT
2957 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2958   if( _ptr == Null ) st->print("NULL");
2959   else st->print("%s *", ptr_msg[_ptr]);
2960   if( _offset == OffsetTop ) st->print("+top");
2961   else if( _offset == OffsetBot ) st->print("+bot");
2962   else if( _offset ) st->print("+%d", _offset);
2963   dump_inline_depth(st);
2964   dump_speculative(st);
2965 }
2966 
2967 /**
2968  *dump the speculative part of the type
2969  */
2970 void TypePtr::dump_speculative(outputStream *st) const {
2971   if (_speculative != NULL) {
2972     st->print(" (speculative=");
2973     _speculative->dump_on(st);
2974     st->print(")");
2975   }
2976 }
2977 
2978 /**
2979  *dump the inline depth of the type
2980  */
2981 void TypePtr::dump_inline_depth(outputStream *st) const {
2982   if (_inline_depth != InlineDepthBottom) {
2983     if (_inline_depth == InlineDepthTop) {
2984       st->print(" (inline_depth=InlineDepthTop)");
2985     } else {
2986       st->print(" (inline_depth=%d)", _inline_depth);
2987     }
2988   }
2989 }
2990 #endif
2991 
2992 //------------------------------singleton--------------------------------------
2993 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2994 // constants
2995 bool TypePtr::singleton(void) const {
2996   // TopPTR, Null, AnyNull, Constant are all singletons
2997   return (_offset != OffsetBot) && !below_centerline(_ptr);
2998 }
2999 
3000 bool TypePtr::empty(void) const {
3001   return (_offset == OffsetTop) || above_centerline(_ptr);
3002 }
3003 
3004 //=============================================================================
3005 // Convenience common pre-built types.
3006 const TypeRawPtr *TypeRawPtr::BOTTOM;
3007 const TypeRawPtr *TypeRawPtr::NOTNULL;
3008 
3009 //------------------------------make-------------------------------------------
3010 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3011   assert( ptr != Constant, "what is the constant?" );
3012   assert( ptr != Null, "Use TypePtr for NULL" );
3013   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3014 }
3015 
3016 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3017   assert( bits, "Use TypePtr for NULL" );
3018   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3019 }
3020 
3021 //------------------------------cast_to_ptr_type-------------------------------

3125 // Type-specific hashing function.
3126 int TypeRawPtr::hash(void) const {
3127   return (intptr_t)_bits + TypePtr::hash();
3128 }
3129 
3130 //------------------------------dump2------------------------------------------
3131 #ifndef PRODUCT
3132 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3133   if( _ptr == Constant )
3134     st->print(INTPTR_FORMAT, p2i(_bits));
3135   else
3136     st->print("rawptr:%s", ptr_msg[_ptr]);
3137 }
3138 #endif
3139 
3140 //=============================================================================
3141 // Convenience common pre-built type.
3142 const TypeOopPtr *TypeOopPtr::BOTTOM;
3143 
3144 //------------------------------TypeOopPtr-------------------------------------
3145 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset,
3146                        int instance_id, const TypePtr* speculative, int inline_depth)
3147   : TypePtr(t, ptr, offset, speculative, inline_depth),
3148     _const_oop(o), _klass(k),
3149     _klass_is_exact(xk),
3150     _is_ptr_to_narrowoop(false),
3151     _is_ptr_to_narrowklass(false),
3152     _is_ptr_to_boxed_value(false),
3153     _instance_id(instance_id) {
3154   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3155       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
3156     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3157   }
3158 #ifdef _LP64
3159   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3160     if (_offset == oopDesc::klass_offset_in_bytes()) {
3161       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3162     } else if (klass() == NULL) {
3163       // Array with unknown body type
3164       assert(this->isa_aryptr(), "only arrays without klass");
3165       _is_ptr_to_narrowoop = UseCompressedOops;
3166     } else if (this->isa_aryptr()) {
3167       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3168                              _offset != arrayOopDesc::length_offset_in_bytes());









3169     } else if (klass()->is_instance_klass()) {
3170       ciInstanceKlass* ik = klass()->as_instance_klass();
3171       ciField* field = NULL;
3172       if (this->isa_klassptr()) {
3173         // Perm objects don't use compressed references
3174       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3175         // unsafe access
3176         _is_ptr_to_narrowoop = UseCompressedOops;
3177       } else {
3178         assert(this->isa_instptr(), "must be an instance ptr.");
3179 
3180         if (klass() == ciEnv::current()->Class_klass() &&
3181             (_offset == java_lang_Class::klass_offset() ||
3182              _offset == java_lang_Class::array_klass_offset())) {
3183           // Special hidden fields from the Class.
3184           assert(this->isa_instptr(), "must be an instance ptr.");
3185           _is_ptr_to_narrowoop = false;
3186         } else if (klass() == ciEnv::current()->Class_klass() &&
3187                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3188           // Static fields
3189           ciField* field = NULL;
3190           if (const_oop() != NULL) {
3191             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3192             field = k->get_field_by_offset(_offset, true);
3193           }
3194           if (field != NULL) {
3195             BasicType basic_elem_type = field->layout_type();
3196             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3197           } else {
3198             // unsafe access
3199             _is_ptr_to_narrowoop = UseCompressedOops;






3200           }
3201         } else {
3202           // Instance fields which contains a compressed oop references.
3203           field = ik->get_field_by_offset(_offset, false);

3204           if (field != NULL) {
3205             BasicType basic_elem_type = field->layout_type();
3206             _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(basic_elem_type);
3207           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3208             // Compile::find_alias_type() cast exactness on all types to verify
3209             // that it does not affect alias type.
3210             _is_ptr_to_narrowoop = UseCompressedOops;
3211           } else {
3212             // Type for the copy start in LibraryCallKit::inline_native_clone().
3213             _is_ptr_to_narrowoop = UseCompressedOops;
3214           }
3215         }
3216       }
3217     }
3218   }
3219 #endif
3220 }
3221 
3222 //------------------------------make-------------------------------------------
3223 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3224                                      const TypePtr* speculative, int inline_depth) {
3225   assert(ptr != Constant, "no constant generic pointers");
3226   ciKlass*  k = Compile::current()->env()->Object_klass();
3227   bool      xk = false;
3228   ciObject* o = NULL;
3229   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3230 }
3231 
3232 
3233 //------------------------------cast_to_ptr_type-------------------------------
3234 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3235   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3236   if( ptr == _ptr ) return this;
3237   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3238 }
3239 
3240 //-----------------------------cast_to_instance_id----------------------------
3241 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3242   // There are no instances of a general oop.
3243   // Return self unchanged.
3244   return this;
3245 }
3246 
3247 //-----------------------------cast_to_exactness-------------------------------
3248 const Type *TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3249   // There is no such thing as an exact general oop.
3250   // Return self unchanged.
3251   return this;
3252 }
3253 
3254 
3255 //------------------------------as_klass_type----------------------------------
3256 // Return the klass type corresponding to this instance or array type.
3257 // It is the type that is loaded from an object of this type.
3258 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3259   ShouldNotReachHere();
3260   return NULL;
3261 }
3262 
3263 //------------------------------meet-------------------------------------------
3264 // Compute the MEET of two types.  It returns a new Type object.
3265 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3266   // Perform a fast test for common case; meeting the same types together.
3267   if( this == t ) return this;  // Meeting same type-rep?
3268 
3269   // Current "this->_base" is OopPtr
3270   switch (t->base()) {          // switch on original type
3271 
3272   case Int:                     // Mixing ints & oops happens when javac
3273   case Long:                    // reuses local variables
3274   case FloatTop:

3280   case NarrowOop:
3281   case NarrowKlass:
3282   case Bottom:                  // Ye Olde Default
3283     return Type::BOTTOM;
3284   case Top:
3285     return this;
3286 
3287   default:                      // All else is a mistake
3288     typerr(t);
3289 
3290   case RawPtr:
3291   case MetadataPtr:
3292   case KlassPtr:
3293   case InstKlassPtr:
3294   case AryKlassPtr:
3295     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3296 
3297   case AnyPtr: {
3298     // Found an AnyPtr type vs self-OopPtr type
3299     const TypePtr *tp = t->is_ptr();
3300     int offset = meet_offset(tp->offset());
3301     PTR ptr = meet_ptr(tp->ptr());
3302     const TypePtr* speculative = xmeet_speculative(tp);
3303     int depth = meet_inline_depth(tp->inline_depth());
3304     switch (tp->ptr()) {
3305     case Null:
3306       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3307       // else fall through:
3308     case TopPTR:
3309     case AnyNull: {
3310       int instance_id = meet_instance_id(InstanceTop);
3311       return make(ptr, offset, instance_id, speculative, depth);
3312     }
3313     case BotPTR:
3314     case NotNull:
3315       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3316     default: typerr(t);
3317     }
3318   }
3319 
3320   case OopPtr: {                 // Meeting to other OopPtrs

3322     int instance_id = meet_instance_id(tp->instance_id());
3323     const TypePtr* speculative = xmeet_speculative(tp);
3324     int depth = meet_inline_depth(tp->inline_depth());
3325     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3326   }
3327 
3328   case InstPtr:                  // For these, flip the call around to cut down
3329   case AryPtr:
3330     return t->xmeet(this);      // Call in reverse direction
3331 
3332   } // End of switch
3333   return this;                  // Return the double constant
3334 }
3335 
3336 
3337 //------------------------------xdual------------------------------------------
3338 // Dual of a pure heap pointer.  No relevant klass or oop information.
3339 const Type *TypeOopPtr::xdual() const {
3340   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3341   assert(const_oop() == NULL,             "no constants here");
3342   return new TypeOopPtr(_base, dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3343 }
3344 
3345 //--------------------------make_from_klass_common-----------------------------
3346 // Computes the element-type given a klass.
3347 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact) {
3348   if (klass->is_instance_klass()) {
3349     Compile* C = Compile::current();
3350     Dependencies* deps = C->dependencies();
3351     assert((deps != NULL) == (C->method() != NULL && C->method()->code_size() > 0), "sanity");
3352     // Element is an instance
3353     bool klass_is_exact = false;
3354     if (klass->is_loaded()) {
3355       // Try to set klass_is_exact.
3356       ciInstanceKlass* ik = klass->as_instance_klass();
3357       klass_is_exact = ik->is_final();
3358       if (!klass_is_exact && klass_change
3359           && deps != NULL && UseUniqueSubclasses) {
3360         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3361         if (sub != NULL) {
3362           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3363           klass = ik = sub;
3364           klass_is_exact = sub->is_final();
3365         }
3366       }
3367       if (!klass_is_exact && try_for_exact && deps != NULL &&
3368           !ik->is_interface() && !ik->has_subklass()) {
3369         // Add a dependence; if concrete subclass added we need to recompile
3370         deps->assert_leaf_type(ik);
3371         klass_is_exact = true;
3372       }
3373     }
3374     return TypeInstPtr::make(TypePtr::BotPTR, klass, klass_is_exact, NULL, 0);
3375   } else if (klass->is_obj_array_klass()) {
3376     // Element is an object array. Recursively call ourself.
3377     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(klass->as_obj_array_klass()->element_klass(), false, try_for_exact);
3378     bool xk = etype->klass_is_exact();
3379     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);














3380     // We used to pass NotNull in here, asserting that the sub-arrays
3381     // are all not-null.  This is not true in generally, as code can
3382     // slam NULLs down in the subarrays.
3383     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, xk, 0);
3384     return arr;
3385   } else if (klass->is_type_array_klass()) {
3386     // Element is an typeArray
3387     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3388     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

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





3392     return arr;
3393   } else {
3394     ShouldNotReachHere();
3395     return NULL;
3396   }
3397 }
3398 
3399 //------------------------------make_from_constant-----------------------------
3400 // Make a java pointer from an oop constant
3401 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3402   assert(!o->is_null_object(), "null object not yet handled here.");
3403 
3404   const bool make_constant = require_constant || o->should_be_constant();
3405 
3406   ciKlass* klass = o->klass();
3407   if (klass->is_instance_klass()) {
3408     // Element is an instance
3409     if (make_constant) {
3410       return TypeInstPtr::make(o);
3411     } else {
3412       return TypeInstPtr::make(TypePtr::NotNull, klass, true, NULL, 0);
3413     }
3414   } else if (klass->is_obj_array_klass()) {
3415     // Element is an object array. Recursively call ourself.
3416     const TypeOopPtr *etype =
3417       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass());
3418     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));





3419     // We used to pass NotNull in here, asserting that the sub-arrays
3420     // are all not-null.  This is not true in generally, as code can
3421     // slam NULLs down in the subarrays.
3422     if (make_constant) {
3423       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3424     } else {
3425       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3426     }
3427   } else if (klass->is_type_array_klass()) {
3428     // Element is an typeArray
3429     const Type* etype =
3430       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3431     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3432     // We used to pass NotNull in here, asserting that the array pointer
3433     // is not-null. That was not true in general.
3434     if (make_constant) {
3435       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);











3436     } else {
3437       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3438     }
3439   }
3440 
3441   fatal("unhandled object type");
3442   return NULL;
3443 }
3444 
3445 //------------------------------get_con----------------------------------------
3446 intptr_t TypeOopPtr::get_con() const {
3447   assert( _ptr == Null || _ptr == Constant, "" );
3448   assert( _offset >= 0, "" );
3449 
3450   if (_offset != 0) {
3451     // After being ported to the compiler interface, the compiler no longer
3452     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3453     // to a handle at compile time.  This handle is embedded in the generated
3454     // code and dereferenced at the time the nmethod is made.  Until that time,
3455     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3456     // have access to the addresses!).  This does not seem to currently happen,
3457     // but this assertion here is to help prevent its occurence.
3458     tty->print_cr("Found oop constant with non-zero offset");
3459     ShouldNotReachHere();
3460   }
3461 
3462   return (intptr_t)const_oop()->constant_encoding();
3463 }
3464 
3465 
3466 //-----------------------------filter------------------------------------------
3467 // Do not allow interface-vs.-noninterface joins to collapse to top.
3468 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3469 
3470   const Type* ft = join_helper(kills, include_speculative);

3523     return (one == two) && TypePtr::eq(t);
3524   } else {
3525     return one->equals(two) && TypePtr::eq(t);
3526   }
3527 }
3528 
3529 //------------------------------hash-------------------------------------------
3530 // Type-specific hashing function.
3531 int TypeOopPtr::hash(void) const {
3532   return
3533     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3534              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3535 }
3536 
3537 //------------------------------dump2------------------------------------------
3538 #ifndef PRODUCT
3539 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3540   st->print("oopptr:%s", ptr_msg[_ptr]);
3541   if( _klass_is_exact ) st->print(":exact");
3542   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3543   switch( _offset ) {
3544   case OffsetTop: st->print("+top"); break;
3545   case OffsetBot: st->print("+any"); break;
3546   case         0: break;
3547   default:        st->print("+%d",_offset); break;
3548   }
3549   if (_instance_id == InstanceTop)
3550     st->print(",iid=top");
3551   else if (_instance_id != InstanceBot)
3552     st->print(",iid=%d",_instance_id);
3553 
3554   dump_inline_depth(st);
3555   dump_speculative(st);
3556 }
3557 #endif
3558 
3559 //------------------------------singleton--------------------------------------
3560 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3561 // constants
3562 bool TypeOopPtr::singleton(void) const {
3563   // detune optimizer to not generate constant oop + constant offset as a constant!
3564   // TopPTR, Null, AnyNull, Constant are all singletons
3565   return (_offset == 0) && !below_centerline(_ptr);
3566 }
3567 
3568 //------------------------------add_offset-------------------------------------
3569 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3570   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3571 }
3572 
3573 /**
3574  * Return same type without a speculative part
3575  */
3576 const Type* TypeOopPtr::remove_speculative() const {
3577   if (_speculative == NULL) {
3578     return this;
3579   }
3580   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3581   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3582 }
3583 
3584 /**
3585  * Return same type but drop speculative part if we know we won't use

3637  *
3638  * @return  true if type profile is valuable
3639  */
3640 bool TypeOopPtr::would_improve_type(ciKlass* exact_kls, int inline_depth) const {
3641   // no way to improve an already exact type
3642   if (klass_is_exact()) {
3643     return false;
3644   }
3645   return TypePtr::would_improve_type(exact_kls, inline_depth);
3646 }
3647 
3648 //=============================================================================
3649 // Convenience common pre-built types.
3650 const TypeInstPtr *TypeInstPtr::NOTNULL;
3651 const TypeInstPtr *TypeInstPtr::BOTTOM;
3652 const TypeInstPtr *TypeInstPtr::MIRROR;
3653 const TypeInstPtr *TypeInstPtr::MARK;
3654 const TypeInstPtr *TypeInstPtr::KLASS;
3655 
3656 //------------------------------TypeInstPtr-------------------------------------
3657 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int off,
3658                          int instance_id, const TypePtr* speculative, int inline_depth)
3659   : TypeOopPtr(InstPtr, ptr, k, xk, o, off, instance_id, speculative, inline_depth),
3660     _name(k->name()) {
3661    assert(k != NULL &&
3662           (k->is_loaded() || o == NULL),
3663           "cannot have constants with non-loaded klass");



3664 };
3665 
3666 //------------------------------make-------------------------------------------
3667 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3668                                      ciKlass* k,
3669                                      bool xk,
3670                                      ciObject* o,
3671                                      int offset,

3672                                      int instance_id,
3673                                      const TypePtr* speculative,
3674                                      int inline_depth) {
3675   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3676   // Either const_oop() is NULL or else ptr is Constant
3677   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3678           "constant pointers must have a value supplied" );
3679   // Ptr is never Null
3680   assert( ptr != Null, "NULL pointers are not typed" );
3681 
3682   assert(instance_id <= 0 || xk, "instances are always exactly typed");
3683   if (ptr == Constant) {
3684     // Note:  This case includes meta-object constants, such as methods.
3685     xk = true;
3686   } else if (k->is_loaded()) {
3687     ciInstanceKlass* ik = k->as_instance_klass();
3688     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3689     if (xk && ik->is_interface())  xk = false;  // no exact interface
3690   }
3691 



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

3817   case Top:
3818     return this;
3819 
3820   default:                      // All else is a mistake
3821     typerr(t);
3822 
3823   case MetadataPtr:
3824   case KlassPtr:
3825   case InstKlassPtr:
3826   case AryKlassPtr:
3827   case RawPtr: return TypePtr::BOTTOM;
3828 
3829   case AryPtr: {                // All arrays inherit from Object class
3830     // Call in reverse direction to avoid duplication
3831     return t->is_aryptr()->xmeet_helper(this);
3832   }
3833 
3834   case OopPtr: {                // Meeting to OopPtrs
3835     // Found a OopPtr type vs self-InstPtr type
3836     const TypeOopPtr *tp = t->is_oopptr();
3837     int offset = meet_offset(tp->offset());
3838     PTR ptr = meet_ptr(tp->ptr());
3839     switch (tp->ptr()) {
3840     case TopPTR:
3841     case AnyNull: {
3842       int instance_id = meet_instance_id(InstanceTop);
3843       const TypePtr* speculative = xmeet_speculative(tp);
3844       int depth = meet_inline_depth(tp->inline_depth());
3845       return make(ptr, klass(), klass_is_exact(),
3846                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3847     }
3848     case NotNull:
3849     case BotPTR: {
3850       int instance_id = meet_instance_id(tp->instance_id());
3851       const TypePtr* speculative = xmeet_speculative(tp);
3852       int depth = meet_inline_depth(tp->inline_depth());
3853       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
3854     }
3855     default: typerr(t);
3856     }
3857   }
3858 
3859   case AnyPtr: {                // Meeting to AnyPtrs
3860     // Found an AnyPtr type vs self-InstPtr type
3861     const TypePtr *tp = t->is_ptr();
3862     int offset = meet_offset(tp->offset());
3863     PTR ptr = meet_ptr(tp->ptr());
3864     int instance_id = meet_instance_id(InstanceTop);
3865     const TypePtr* speculative = xmeet_speculative(tp);
3866     int depth = meet_inline_depth(tp->inline_depth());
3867     switch (tp->ptr()) {
3868     case Null:
3869       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3870       // else fall through to AnyNull
3871     case TopPTR:
3872     case AnyNull: {
3873       return make(ptr, klass(), klass_is_exact(),
3874                   (ptr == Constant ? const_oop() : NULL), offset, instance_id, speculative, depth);
3875     }
3876     case NotNull:
3877     case BotPTR:
3878       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
3879     default: typerr(t);
3880     }
3881   }
3882 
3883   /*
3884                  A-top         }
3885                /   |   \       }  Tops
3886            B-top A-any C-top   }
3887               | /  |  \ |      }  Any-nulls
3888            B-any   |   C-any   }
3889               |    |    |
3890            B-con A-con C-con   } constants; not comparable across classes
3891               |    |    |
3892            B-not   |   C-not   }
3893               | \  |  / |      }  not-nulls
3894            B-bot A-not C-bot   }
3895                \   |   /       }  Bottoms
3896                  A-bot         }
3897   */
3898 
3899   case InstPtr: {                // Meeting 2 Oops?
3900     // Found an InstPtr sub-type vs self-InstPtr type
3901     const TypeInstPtr *tinst = t->is_instptr();
3902     int off = meet_offset(tinst->offset());
3903     PTR ptr = meet_ptr(tinst->ptr());
3904     int instance_id = meet_instance_id(tinst->instance_id());
3905     const TypePtr* speculative = xmeet_speculative(tinst);
3906     int depth = meet_inline_depth(tinst->inline_depth());
3907     ciKlass* tinst_klass = tinst->klass();
3908     ciKlass* this_klass  = klass();
3909     bool tinst_xk = tinst->klass_is_exact();
3910     bool this_xk  = klass_is_exact();


3911 
3912     ciKlass* res_klass = NULL;
3913     bool res_xk = false;

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


3916     if (kind == UNLOADED) {
3917       // One of these classes has not been loaded
3918       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst);
3919 #ifndef PRODUCT
3920       if (PrintOpto && Verbose) {
3921         tty->print("meet of unloaded classes resulted in: ");
3922         unloaded_meet->dump();
3923         tty->cr();
3924         tty->print("  this == ");
3925         dump();
3926         tty->cr();
3927         tty->print(" tinst == ");
3928         tinst->dump();
3929         tty->cr();
3930       }
3931 #endif
3932       res = unloaded_meet;
3933     } else {
3934       if (kind == NOT_SUBTYPE && instance_id > 0) {
3935         instance_id = InstanceBot;
3936       } else if (kind == LCA) {
3937         instance_id = InstanceBot;
3938       }
3939       ciObject* o = NULL;             // Assume not constant when done
3940       ciObject* this_oop = const_oop();
3941       ciObject* tinst_oop = tinst->const_oop();
3942       if (ptr == Constant) {
3943         if (this_oop != NULL && tinst_oop != NULL &&
3944             this_oop->equals(tinst_oop))
3945           o = this_oop;
3946         else if (above_centerline(_ptr)) {
3947           assert(!tinst_klass->is_interface(), "");
3948           o = tinst_oop;
3949         } else if (above_centerline(tinst->_ptr)) {
3950           assert(!this_klass->is_interface(), "");
3951           o = this_oop;
3952         } else
3953           ptr = NotNull;
3954       }
3955       res = make(ptr, res_klass, res_xk, o, off, instance_id, speculative, depth);
3956     }
3957 
3958     return res;
3959 
3960   } // End of case InstPtr
3961 





















3962   } // End of switch
3963   return this;                  // Return the double constant
3964 }
3965 
3966 TypePtr::MeetResult TypePtr::meet_instptr(PTR &ptr, ciKlass* this_klass, ciKlass* tinst_klass, bool this_xk, bool tinst_xk,
3967                                           PTR this_ptr,
3968                                           PTR tinst_ptr, ciKlass*&res_klass, bool &res_xk) {



3969 
3970   // Check for easy case; klasses are equal (and perhaps not loaded!)
3971   // If we have constants, then we created oops so classes are loaded
3972   // and we can handle the constants further down.  This case handles
3973   // both-not-loaded or both-loaded classes
3974   if (ptr != Constant && this_klass->equals(tinst_klass) && this_xk == tinst_xk) {
3975     res_klass = this_klass;
3976     res_xk = this_xk;

3977     return QUICK;
3978   }
3979 
3980   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
3981   if (!tinst_klass->is_loaded() || !this_klass->is_loaded()) {
3982     return UNLOADED;
3983   }
3984 
3985   // Handle mixing oops and interfaces first.
3986   if (this_klass->is_interface() && !(tinst_klass->is_interface() ||
3987                                       tinst_klass == ciEnv::current()->Object_klass())) {
3988     ciKlass *tmp = tinst_klass; // Swap interface around
3989     tinst_klass = this_klass;
3990     this_klass = tmp;
3991     bool tmp2 = tinst_xk;
3992     tinst_xk = this_xk;
3993     this_xk = tmp2;



3994   }
3995   if (tinst_klass->is_interface() &&
3996       !(this_klass->is_interface() ||
3997         // Treat java/lang/Object as an honorary interface,
3998         // because we need a bottom for the interface hierarchy.
3999         this_klass == ciEnv::current()->Object_klass())) {
4000     // Oop meets interface!
4001 
4002     // See if the oop subtypes (implements) interface.
4003     if (this_klass->is_subtype_of(tinst_klass)) {
4004       // Oop indeed subtypes.  Now keep oop or interface depending
4005       // on whether we are both above the centerline or either is
4006       // below the centerline.  If we are on the centerline
4007       // (e.g., Constant vs. AnyNull interface), use the constant.
4008       res_klass  = below_centerline(ptr) ? tinst_klass : this_klass;
4009       // If we are keeping this_klass, keep its exactness too.
4010       res_xk = below_centerline(ptr) ? tinst_xk    : this_xk;

4011       return SUBTYPE;
4012     } else {                  // Does not implement, fall to Object
4013       // Oop does not implement interface, so mixing falls to Object
4014       // just like the verifier does (if both are above the
4015       // centerline fall to interface)
4016       res_klass = above_centerline(ptr) ? tinst_klass : ciEnv::current()->Object_klass();
4017       res_xk = above_centerline(ptr) ? tinst_xk : false;

4018       // Watch out for Constant vs. AnyNull interface.
4019       if (ptr == Constant)  ptr = NotNull;   // forget it was a constant
4020       return NOT_SUBTYPE;
4021     }
4022   }
4023 
4024   // Either oop vs oop or interface vs interface or interface vs Object
4025 
4026   // !!! Here's how the symmetry requirement breaks down into invariants:
4027   // If we split one up & one down AND they subtype, take the down man.
4028   // If we split one up & one down AND they do NOT subtype, "fall hard".
4029   // If both are up and they subtype, take the subtype class.
4030   // If both are up and they do NOT subtype, "fall hard".
4031   // If both are down and they subtype, take the supertype class.
4032   // If both are down and they do NOT subtype, "fall hard".
4033   // Constants treated as down.
4034 
4035   // Now, reorder the above list; observe that both-down+subtype is also
4036   // "fall hard"; "fall hard" becomes the default case:
4037   // If we split one up & one down AND they subtype, take the down man.
4038   // If both are up and they subtype, take the subtype class.
4039 
4040   // If both are down and they subtype, "fall hard".
4041   // If both are down and they do NOT subtype, "fall hard".
4042   // If both are up and they do NOT subtype, "fall hard".
4043   // If we split one up & one down AND they do NOT subtype, "fall hard".
4044 
4045   // If a proper subtype is exact, and we return it, we return it exactly.
4046   // If a proper supertype is exact, there can be no subtyping relationship!
4047   // If both types are equal to the subtype, exactness is and-ed below the
4048   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4049 
4050   // Check for subtyping:
4051   ciKlass *subtype = NULL;
4052   bool subtype_exact = false;

4053   if (tinst_klass->equals(this_klass)) {
4054     subtype = this_klass;
4055     subtype_exact = below_centerline(ptr) ? (this_xk && tinst_xk) : (this_xk || tinst_xk);
4056   } else if (!tinst_xk && this_klass->is_subtype_of(tinst_klass)) {

4057     subtype = this_klass;     // Pick subtyping class
4058     subtype_exact = this_xk;
4059   } else if (!this_xk && tinst_klass->is_subtype_of(this_klass)) {

4060     subtype = tinst_klass;    // Pick subtyping class
4061     subtype_exact = tinst_xk;

4062   }
4063 
4064   if (subtype) {
4065     if (above_centerline(ptr)) { // both are up?
4066       this_klass = tinst_klass = subtype;
4067       this_xk = tinst_xk = subtype_exact;

4068     } else if (above_centerline(this_ptr) && !above_centerline(tinst_ptr)) {
4069       this_klass = tinst_klass; // tinst is down; keep down man
4070       this_xk = tinst_xk;

4071     } else if (above_centerline(tinst_ptr) && !above_centerline(this_ptr)) {
4072       tinst_klass = this_klass; // this is down; keep down man
4073       tinst_xk = this_xk;

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

4076     }
4077   }
4078 
4079   // Check for classes now being equal
4080   if (tinst_klass->equals(this_klass)) {
4081     // If the klasses are equal, the constants may still differ.  Fall to
4082     // NotNull if they do (neither constant is NULL; that is a special case
4083     // handled elsewhere).
4084     res_klass = this_klass;
4085     res_xk = this_xk;

4086     return SUBTYPE;
4087   } // Else classes are not equal
4088 
4089   // Since klasses are different, we require a LCA in the Java
4090   // class hierarchy - which means we have to fall to at least NotNull.
4091   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4092     ptr = NotNull;
4093   }
4094 
4095   // Now we find the LCA of Java classes
4096   ciKlass* k = this_klass->least_common_ancestor(tinst_klass);
4097 
4098   res_klass = k;
4099   res_xk = false;

4100 
4101   return LCA;
4102 }
4103 
4104 
4105 //------------------------java_mirror_type--------------------------------------
4106 ciType* TypeInstPtr::java_mirror_type() const {
4107   // must be a singleton type
4108   if( const_oop() == NULL )  return NULL;
4109 
4110   // must be of type java.lang.Class
4111   if( klass() != ciEnv::current()->Class_klass() )  return NULL;
4112 
4113   return const_oop()->as_instance()->java_mirror_type();
4114 }
4115 
4116 
4117 //------------------------------xdual------------------------------------------
4118 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4119 // inheritance mechanism.
4120 const Type *TypeInstPtr::xdual() const {
4121   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4122 }
4123 
4124 //------------------------------eq---------------------------------------------
4125 // Structural equality check for Type representations
4126 bool TypeInstPtr::eq( const Type *t ) const {
4127   const TypeInstPtr *p = t->is_instptr();
4128   return
4129     klass()->equals(p->klass()) &&

4130     TypeOopPtr::eq(p);          // Check sub-type stuff
4131 }
4132 
4133 //------------------------------hash-------------------------------------------
4134 // Type-specific hashing function.
4135 int TypeInstPtr::hash(void) const {
4136   int hash = java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash());
4137   return hash;
4138 }
4139 
4140 //------------------------------dump2------------------------------------------
4141 // Dump oop Type
4142 #ifndef PRODUCT
4143 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4144   // Print the name of the klass.
4145   klass()->print_name_on(st);
4146 
4147   switch( _ptr ) {
4148   case Constant:
4149     if (WizardMode || Verbose) {
4150       ResourceMark rm;
4151       stringStream ss;
4152 
4153       st->print(" ");
4154       const_oop()->print_oop(&ss);
4155       // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4156       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4157       char* buf = ss.as_string(/* c_heap= */false);
4158       StringUtils::replace_no_expand(buf, "\n", "");
4159       st->print_raw(buf);
4160     }
4161   case BotPTR:
4162     if (!WizardMode && !Verbose) {
4163       if( _klass_is_exact ) st->print(":exact");
4164       break;
4165     }
4166   case TopPTR:
4167   case AnyNull:
4168   case NotNull:
4169     st->print(":%s", ptr_msg[_ptr]);
4170     if( _klass_is_exact ) st->print(":exact");
4171     break;
4172   default:
4173     break;
4174   }
4175 
4176   if( _offset ) {               // Dump offset, if any
4177     if( _offset == OffsetBot )      st->print("+any");
4178     else if( _offset == OffsetTop ) st->print("+unknown");
4179     else st->print("+%d", _offset);
4180   }
4181 
4182   st->print(" *");





4183   if (_instance_id == InstanceTop)
4184     st->print(",iid=top");
4185   else if (_instance_id != InstanceBot)
4186     st->print(",iid=%d",_instance_id);
4187 
4188   dump_inline_depth(st);
4189   dump_speculative(st);
4190 }
4191 #endif
4192 
4193 //------------------------------add_offset-------------------------------------
4194 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4195   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset),
4196               _instance_id, add_offset_speculative(offset), _inline_depth);
4197 }
4198 
4199 const Type *TypeInstPtr::remove_speculative() const {
4200   if (_speculative == NULL) {
4201     return this;
4202   }
4203   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4204   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset,
4205               _instance_id, NULL, _inline_depth);
4206 }
4207 
4208 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4209   if (!UseInlineDepthForSpeculativeTypes) {
4210     return this;
4211   }
4212   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4213 }
4214 
4215 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4216   assert(is_known_instance(), "should be known");
4217   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);




4218 }
4219 
4220 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4221   bool xk = klass_is_exact();
4222   ciInstanceKlass* ik = klass()->as_instance_klass();
4223   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final() && !ik->is_interface()) {
4224     Compile* C = Compile::current();
4225     Dependencies* deps = C->dependencies();
4226     deps->assert_leaf_type(ik);
4227     xk = true;
4228   }
4229   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), 0);
4230 }
4231 
4232 //=============================================================================
4233 // Convenience common pre-built types.
4234 const TypeAryPtr *TypeAryPtr::RANGE;
4235 const TypeAryPtr *TypeAryPtr::OOPS;
4236 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4237 const TypeAryPtr *TypeAryPtr::BYTES;
4238 const TypeAryPtr *TypeAryPtr::SHORTS;
4239 const TypeAryPtr *TypeAryPtr::CHARS;
4240 const TypeAryPtr *TypeAryPtr::INTS;
4241 const TypeAryPtr *TypeAryPtr::LONGS;
4242 const TypeAryPtr *TypeAryPtr::FLOATS;
4243 const TypeAryPtr *TypeAryPtr::DOUBLES;

4244 
4245 //------------------------------make-------------------------------------------
4246 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4247                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4248   assert(!(k == NULL && ary->_elem->isa_int()),
4249          "integral arrays must be pre-equipped with a class");
4250   if (!xk)  xk = ary->ary_must_be_exact();
4251   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4252   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4253 }
4254 
4255 //------------------------------make-------------------------------------------
4256 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4257                                    int instance_id, const TypePtr* speculative, int inline_depth,
4258                                    bool is_autobox_cache) {
4259   assert(!(k == NULL && ary->_elem->isa_int()),
4260          "integral arrays must be pre-equipped with a class");
4261   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4262   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4263   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4264   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4265 }
4266 
4267 //------------------------------cast_to_ptr_type-------------------------------
4268 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4269   if( ptr == _ptr ) return this;
4270   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4271 }
4272 
4273 
4274 //-----------------------------cast_to_exactness-------------------------------
4275 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4276   if( klass_is_exact == _klass_is_exact ) return this;
4277   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4278   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);






4279 }
4280 
4281 //-----------------------------cast_to_instance_id----------------------------
4282 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4283   if( instance_id == _instance_id ) return this;
4284   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4285 }
4286 
4287 
4288 //-----------------------------max_array_length-------------------------------
4289 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4290 jint TypeAryPtr::max_array_length(BasicType etype) {
4291   if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4292     if (etype == T_NARROWOOP) {
4293       etype = T_OBJECT;
4294     } else if (etype == T_ILLEGAL) { // bottom[]
4295       etype = T_BYTE; // will produce conservatively high value
4296     } else {
4297       fatal("not an element type: %s", type2name(etype));
4298     }
4299   }
4300   return arrayOopDesc::max_array_length(etype);
4301 }
4302 
4303 //-----------------------------narrow_size_type-------------------------------
4304 // Narrow the given size type to the index range for the given array base type.

4320   if (hi > max_hi) {
4321     hi = max_hi;
4322     if (size->is_con()) {
4323       lo = hi;
4324     }
4325     chg = true;
4326   }
4327   // Negative length arrays will produce weird intermediate dead fast-path code
4328   if (lo > hi)
4329     return TypeInt::ZERO;
4330   if (!chg)
4331     return size;
4332   return TypeInt::make(lo, hi, Type::WidenMin);
4333 }
4334 
4335 //-------------------------------cast_to_size----------------------------------
4336 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4337   assert(new_size != NULL, "");
4338   new_size = narrow_size_type(new_size);
4339   if (new_size == size())  return this;
4340   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4341   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);


































4342 }
4343 
4344 //------------------------------cast_to_stable---------------------------------
4345 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4346   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4347     return this;
4348 
4349   const Type* elem = this->elem();
4350   const TypePtr* elem_ptr = elem->make_ptr();
4351 
4352   if (stable_dimension > 1 && elem_ptr != NULL && elem_ptr->isa_aryptr()) {
4353     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4354     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4355   }
4356 
4357   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4358 
4359   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4360 }
4361 
4362 //-----------------------------stable_dimension--------------------------------
4363 int TypeAryPtr::stable_dimension() const {
4364   if (!is_stable())  return 0;
4365   int dim = 1;
4366   const TypePtr* elem_ptr = elem()->make_ptr();
4367   if (elem_ptr != NULL && elem_ptr->isa_aryptr())
4368     dim += elem_ptr->is_aryptr()->stable_dimension();
4369   return dim;
4370 }
4371 
4372 //----------------------cast_to_autobox_cache-----------------------------------
4373 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4374   if (is_autobox_cache())  return this;
4375   const TypeOopPtr* etype = elem()->make_oopptr();
4376   if (etype == NULL)  return this;
4377   // The pointers in the autobox arrays are always non-null.
4378   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4379   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4380   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);




4381 }
4382 
4383 //------------------------------eq---------------------------------------------
4384 // Structural equality check for Type representations
4385 bool TypeAryPtr::eq( const Type *t ) const {
4386   const TypeAryPtr *p = t->is_aryptr();
4387   return
4388     _ary == p->_ary &&  // Check array
4389     TypeOopPtr::eq(p);  // Check sub-parts

4390 }
4391 
4392 //------------------------------hash-------------------------------------------
4393 // Type-specific hashing function.
4394 int TypeAryPtr::hash(void) const {
4395   return (intptr_t)_ary + TypeOopPtr::hash();
4396 }
4397 
4398 //------------------------------meet-------------------------------------------
4399 // Compute the MEET of two types.  It returns a new Type object.
4400 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4401   // Perform a fast test for common case; meeting the same types together.
4402   if( this == t ) return this;  // Meeting same type-rep?
4403   // Current "this->_base" is Pointer
4404   switch (t->base()) {          // switch on original type
4405 
4406   // Mixing ints & oops happens when javac reuses local variables
4407   case Int:
4408   case Long:
4409   case FloatTop:
4410   case FloatCon:
4411   case FloatBot:
4412   case DoubleTop:
4413   case DoubleCon:
4414   case DoubleBot:
4415   case NarrowOop:
4416   case NarrowKlass:
4417   case Bottom:                  // Ye Olde Default
4418     return Type::BOTTOM;
4419   case Top:
4420     return this;
4421 
4422   default:                      // All else is a mistake
4423     typerr(t);
4424 
4425   case OopPtr: {                // Meeting to OopPtrs
4426     // Found a OopPtr type vs self-AryPtr type
4427     const TypeOopPtr *tp = t->is_oopptr();
4428     int offset = meet_offset(tp->offset());
4429     PTR ptr = meet_ptr(tp->ptr());
4430     int depth = meet_inline_depth(tp->inline_depth());
4431     const TypePtr* speculative = xmeet_speculative(tp);
4432     switch (tp->ptr()) {
4433     case TopPTR:
4434     case AnyNull: {
4435       int instance_id = meet_instance_id(InstanceTop);
4436       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4437                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4438     }
4439     case BotPTR:
4440     case NotNull: {
4441       int instance_id = meet_instance_id(tp->instance_id());
4442       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4443     }
4444     default: ShouldNotReachHere();
4445     }
4446   }
4447 
4448   case AnyPtr: {                // Meeting two AnyPtrs
4449     // Found an AnyPtr type vs self-AryPtr type
4450     const TypePtr *tp = t->is_ptr();
4451     int offset = meet_offset(tp->offset());
4452     PTR ptr = meet_ptr(tp->ptr());
4453     const TypePtr* speculative = xmeet_speculative(tp);
4454     int depth = meet_inline_depth(tp->inline_depth());
4455     switch (tp->ptr()) {
4456     case TopPTR:
4457       return this;
4458     case BotPTR:
4459     case NotNull:
4460       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4461     case Null:
4462       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4463       // else fall through to AnyNull
4464     case AnyNull: {
4465       int instance_id = meet_instance_id(InstanceTop);
4466       return make(ptr, (ptr == Constant ? const_oop() : NULL),
4467                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4468     }
4469     default: ShouldNotReachHere();
4470     }
4471   }
4472 
4473   case MetadataPtr:
4474   case KlassPtr:
4475   case InstKlassPtr:
4476   case AryKlassPtr:
4477   case RawPtr: return TypePtr::BOTTOM;
4478 
4479   case AryPtr: {                // Meeting 2 references?
4480     const TypeAryPtr *tap = t->is_aryptr();
4481     int off = meet_offset(tap->offset());

4482     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4483     PTR ptr = meet_ptr(tap->ptr());
4484     int instance_id = meet_instance_id(tap->instance_id());
4485     const TypePtr* speculative = xmeet_speculative(tap);
4486     int depth = meet_inline_depth(tap->inline_depth());
4487 
4488     ciKlass* res_klass = NULL;
4489     bool res_xk = false;
4490     const Type* elem = tary->_elem;
4491     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) {






4492       instance_id = InstanceBot;











4493     }
4494 
4495     ciObject* o = NULL;             // Assume not constant when done
4496     ciObject* this_oop = const_oop();
4497     ciObject* tap_oop = tap->const_oop();
4498     if (ptr == Constant) {
4499       if (this_oop != NULL && tap_oop != NULL &&
4500           this_oop->equals(tap_oop)) {
4501         o = tap_oop;
4502       } else if (above_centerline(_ptr)) {
4503         o = tap_oop;
4504       } else if (above_centerline(tap->_ptr)) {
4505         o = this_oop;
4506       } else {
4507         ptr = NotNull;
4508       }
4509     }
4510     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4511   }
4512 
4513   // All arrays inherit from Object class
4514   case InstPtr: {
4515     const TypeInstPtr *tp = t->is_instptr();
4516     int offset = meet_offset(tp->offset());
4517     PTR ptr = meet_ptr(tp->ptr());
4518     int instance_id = meet_instance_id(tp->instance_id());
4519     const TypePtr* speculative = xmeet_speculative(tp);
4520     int depth = meet_inline_depth(tp->inline_depth());
4521     switch (ptr) {
4522     case TopPTR:
4523     case AnyNull:                // Fall 'down' to dual of object klass
4524       // For instances when a subclass meets a superclass we fall
4525       // below the centerline when the superclass is exact. We need to
4526       // do the same here.
4527       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4528         return make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4529       } else {
4530         // cannot subclass, so the meet has to fall badly below the centerline
4531         ptr = NotNull;
4532         instance_id = InstanceBot;
4533         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL,offset, instance_id, speculative, depth);
4534       }
4535     case Constant:
4536     case NotNull:
4537     case BotPTR:                // Fall down to object klass
4538       // LCA is object_klass, but if we subclass from the top we can do better
4539       if (above_centerline(tp->ptr())) {
4540         // If 'tp'  is above the centerline and it is Object class
4541         // then we can subclass in the Java class hierarchy.
4542         // For instances when a subclass meets a superclass we fall
4543         // below the centerline when the superclass is exact. We need
4544         // to do the same here.
4545         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
4546           // that is, my array type is a subtype of 'tp' klass
4547           return make(ptr, (ptr == Constant ? const_oop() : NULL),
4548                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4549         }
4550       }
4551       // The other case cannot happen, since t cannot be a subtype of an array.
4552       // The meet falls down to Object class below centerline.
4553       if (ptr == Constant) {
4554          ptr = NotNull;
4555       }
4556       if (instance_id > 0) {
4557         instance_id = InstanceBot;
4558       }
4559       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), false, NULL, offset, instance_id, speculative, depth);
4560     default: typerr(t);
4561     }
4562   }













4563   }
4564   return this;                  // Lint noise
4565 }
4566 
4567 
4568 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) {






4569   res_klass = NULL;
4570   MeetResult result = SUBTYPE;
4571   if (elem->isa_int()) {




4572     // Integral array element types have irrelevant lattice relations.
4573     // It is the klass that determines array layout, not the element type.
4574     if (this_klass == NULL)
4575       res_klass = tap_klass;
4576     else if (tap_klass == NULL || tap_klass == this_klass) {
4577       res_klass = this_klass;
4578     } else {
4579       // Something like byte[int+] meets char[int+].
4580       // This must fall to bottom, not (int[-128..65535])[int+].
4581       // instance_id = InstanceBot;
4582       elem = Type::BOTTOM;
4583       result = NOT_SUBTYPE;
4584     }
4585   } else // Non integral arrays.
4586     // Must fall to bottom if exact klasses in upper lattice
4587     // are not equal or super klass is exact.
4588     if ((above_centerline(ptr) || ptr == Constant) && this_klass != tap_klass &&
4589         // meet with top[] and bottom[] are processed further down:
4590         tap_klass != NULL  && this_klass != NULL   &&
4591         // both are exact and not equal:
4592         ((tap_xk && this_xk) ||
4593          // 'tap'  is exact and super or unrelated:
4594          (tap_xk && !tap_klass->is_subtype_of(this_klass)) ||
4595          // 'this' is exact and super or unrelated:
4596          (this_xk && !this_klass->is_subtype_of(tap_klass)))) {
4597       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
4598         elem = Type::BOTTOM;

4599       }
4600       ptr = NotNull;
4601       res_xk = false;
4602       return NOT_SUBTYPE;
4603     }
4604 
4605   res_xk = false;
4606   switch (tap_ptr) {
4607     case AnyNull:
4608     case TopPTR:
4609       // Compute new klass on demand, do not use tap->_klass
4610       if (below_centerline(this_ptr)) {
4611         res_xk = this_xk;



4612       } else {
4613         res_xk = (tap_xk || this_xk);
4614       }
4615       return result;
4616     case Constant: {
4617       if (this_ptr == Constant) {
4618           res_xk = true;
4619       } else if(above_centerline(this_ptr)) {
4620         res_xk = true;
4621       } else {
4622         // Only precise for identical arrays
4623         res_xk = this_xk && (this_klass == tap_klass);
4624       }
4625       return result;
4626     }
4627     case NotNull:
4628     case BotPTR:
4629       // Compute new klass on demand, do not use tap->_klass
4630       if (above_centerline(this_ptr)) {
4631         res_xk = tap_xk;



4632       } else {
4633         res_xk = (tap_xk && this_xk) &&
4634           (this_klass == tap_klass); // Only precise for identical arrays
4635       }
4636       return result;
4637     default:  {
4638       ShouldNotReachHere();
4639       return result;
4640     }
4641   }

4642   return result;
4643 }
4644 
4645 
4646 //------------------------------xdual------------------------------------------
4647 // Dual: compute field-by-field dual
4648 const Type *TypeAryPtr::xdual() const {
4649   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());









4650 }
4651 
4652 //----------------------interface_vs_oop---------------------------------------
4653 #ifdef ASSERT
4654 bool TypeAryPtr::interface_vs_oop(const Type *t) const {
4655   const TypeAryPtr* t_aryptr = t->isa_aryptr();
4656   if (t_aryptr) {
4657     return _ary->interface_vs_oop(t_aryptr->_ary);
4658   }
4659   return false;
4660 }
4661 #endif
4662 
4663 //------------------------------dump2------------------------------------------
4664 #ifndef PRODUCT
4665 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4666   _ary->dump2(d,depth,st);
4667   switch( _ptr ) {
4668   case Constant:
4669     const_oop()->print(st);
4670     break;
4671   case BotPTR:
4672     if (!WizardMode && !Verbose) {
4673       if( _klass_is_exact ) st->print(":exact");
4674       break;
4675     }
4676   case TopPTR:
4677   case AnyNull:
4678   case NotNull:
4679     st->print(":%s", ptr_msg[_ptr]);
4680     if( _klass_is_exact ) st->print(":exact");
4681     break;
4682   default:
4683     break;
4684   }
4685 
4686   if( _offset != 0 ) {





4687     int header_size = objArrayOopDesc::header_size() * wordSize;
4688     if( _offset == OffsetTop )       st->print("+undefined");
4689     else if( _offset == OffsetBot )  st->print("+any");
4690     else if( _offset < header_size ) st->print("+%d", _offset);
4691     else {
4692       BasicType basic_elem_type = elem()->basic_type();
4693       int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
4694       int elem_size = type2aelembytes(basic_elem_type);
4695       st->print("[%d]", (_offset - array_base)/elem_size);
4696     }
4697   }
4698   st->print(" *");
4699   if (_instance_id == InstanceTop)
4700     st->print(",iid=top");
4701   else if (_instance_id != InstanceBot)
4702     st->print(",iid=%d",_instance_id);
4703 
4704   dump_inline_depth(st);
4705   dump_speculative(st);
4706 }
4707 #endif
4708 
4709 bool TypeAryPtr::empty(void) const {
4710   if (_ary->empty())       return true;
4711   return TypeOopPtr::empty();
4712 }
4713 
4714 //------------------------------add_offset-------------------------------------
4715 const TypePtr *TypeAryPtr::add_offset(intptr_t offset) const {
4716   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4717 }
4718 
4719 const Type *TypeAryPtr::remove_speculative() const {
4720   if (_speculative == NULL) {
4721     return this;
4722   }
4723   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4724   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, NULL, _inline_depth);












4725 }
4726 
4727 const TypePtr *TypeAryPtr::with_inline_depth(int depth) const {
4728   if (!UseInlineDepthForSpeculativeTypes) {
4729     return this;
4730   }
4731   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);
















































4732 }
4733 
4734 const TypePtr *TypeAryPtr::with_instance_id(int instance_id) const {
4735   assert(is_known_instance(), "should be known");
4736   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4737 }
4738 
4739 //=============================================================================
4740 

4741 //------------------------------hash-------------------------------------------
4742 // Type-specific hashing function.
4743 int TypeNarrowPtr::hash(void) const {
4744   return _ptrtype->hash() + 7;
4745 }
4746 
4747 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
4748   return _ptrtype->singleton();
4749 }
4750 
4751 bool TypeNarrowPtr::empty(void) const {
4752   return _ptrtype->empty();
4753 }
4754 
4755 intptr_t TypeNarrowPtr::get_con() const {
4756   return _ptrtype->get_con();
4757 }
4758 
4759 bool TypeNarrowPtr::eq( const Type *t ) const {
4760   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

4811 
4812   case Int:                     // Mixing ints & oops happens when javac
4813   case Long:                    // reuses local variables
4814   case FloatTop:
4815   case FloatCon:
4816   case FloatBot:
4817   case DoubleTop:
4818   case DoubleCon:
4819   case DoubleBot:
4820   case AnyPtr:
4821   case RawPtr:
4822   case OopPtr:
4823   case InstPtr:
4824   case AryPtr:
4825   case MetadataPtr:
4826   case KlassPtr:
4827   case InstKlassPtr:
4828   case AryKlassPtr:
4829   case NarrowOop:
4830   case NarrowKlass:
4831 
4832   case Bottom:                  // Ye Olde Default
4833     return Type::BOTTOM;
4834   case Top:
4835     return this;
4836 



4837   default:                      // All else is a mistake
4838     typerr(t);
4839 
4840   } // End of switch
4841 
4842   return this;
4843 }
4844 
4845 #ifndef PRODUCT
4846 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
4847   _ptrtype->dump2(d, depth, st);
4848 }
4849 #endif
4850 
4851 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
4852 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
4853 
4854 
4855 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
4856   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();

4895     return (one == two) && TypePtr::eq(t);
4896   } else {
4897     return one->equals(two) && TypePtr::eq(t);
4898   }
4899 }
4900 
4901 //------------------------------hash-------------------------------------------
4902 // Type-specific hashing function.
4903 int TypeMetadataPtr::hash(void) const {
4904   return
4905     (metadata() ? metadata()->hash() : 0) +
4906     TypePtr::hash();
4907 }
4908 
4909 //------------------------------singleton--------------------------------------
4910 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4911 // constants
4912 bool TypeMetadataPtr::singleton(void) const {
4913   // detune optimizer to not generate constant metadata + constant offset as a constant!
4914   // TopPTR, Null, AnyNull, Constant are all singletons
4915   return (_offset == 0) && !below_centerline(_ptr);
4916 }
4917 
4918 //------------------------------add_offset-------------------------------------
4919 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
4920   return make( _ptr, _metadata, xadd_offset(offset));
4921 }
4922 
4923 //-----------------------------filter------------------------------------------
4924 // Do not allow interface-vs.-noninterface joins to collapse to top.
4925 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
4926   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
4927   if (ft == NULL || ft->empty())
4928     return Type::TOP;           // Canonical empty value
4929   return ft;
4930 }
4931 
4932  //------------------------------get_con----------------------------------------
4933 intptr_t TypeMetadataPtr::get_con() const {
4934   assert( _ptr == Null || _ptr == Constant, "" );
4935   assert( _offset >= 0, "" );
4936 
4937   if (_offset != 0) {
4938     // After being ported to the compiler interface, the compiler no longer
4939     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4940     // to a handle at compile time.  This handle is embedded in the generated
4941     // code and dereferenced at the time the nmethod is made.  Until that time,
4942     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4943     // have access to the addresses!).  This does not seem to currently happen,
4944     // but this assertion here is to help prevent its occurence.
4945     tty->print_cr("Found oop constant with non-zero offset");
4946     ShouldNotReachHere();
4947   }
4948 
4949   return (intptr_t)metadata()->constant_encoding();
4950 }
4951 
4952 //------------------------------cast_to_ptr_type-------------------------------
4953 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
4954   if( ptr == _ptr ) return this;
4955   return make(ptr, metadata(), _offset);
4956 }
4957 

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

5232     TypeKlassPtr::eq(p);
5233 }
5234 
5235 int TypeInstKlassPtr::hash(void) const {
5236   return java_add((jint)klass()->hash(), TypeKlassPtr::hash());
5237 }
5238 
5239 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, int offset) {


5240   TypeInstKlassPtr *r =
5241     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, offset))->hashcons();
5242 
5243   return r;
5244 }
5245 
5246 //------------------------------add_offset-------------------------------------
5247 // Access internals of klass object
5248 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5249   return make( _ptr, klass(), xadd_offset(offset) );
5250 }
5251 
5252 const TypeKlassPtr *TypeInstKlassPtr::with_offset(intptr_t offset) const {
5253   return make(_ptr, klass(), offset);
5254 }
5255 
5256 //------------------------------cast_to_ptr_type-------------------------------
5257 const TypePtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5258   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5259   if( ptr == _ptr ) return this;
5260   return make(ptr, _klass, _offset);
5261 }
5262 
5263 
5264 bool TypeInstKlassPtr::must_be_exact() const {
5265   if (!_klass->is_loaded())  return false;
5266   ciInstanceKlass* ik = _klass->as_instance_klass();
5267   if (ik->is_final())  return true;  // cannot clear xk
5268   return false;
5269 }
5270 
5271 //-----------------------------cast_to_exactness-------------------------------
5272 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5273   if (klass_is_exact == (_ptr == Constant)) return this;
5274   if (must_be_exact()) return this;
5275   ciKlass* k = klass();
5276   return make(klass_is_exact ? Constant : NotNull, k, _offset);
5277 }
5278 
5279 
5280 //-----------------------------as_instance_type--------------------------------
5281 // Corresponding type for an instance of the given class.
5282 // It will be NotNull, and exact if and only if the klass type is exact.
5283 const TypeOopPtr* TypeInstKlassPtr::as_instance_type() const {
5284   ciKlass* k = klass();
5285   bool    xk = klass_is_exact();
5286   return TypeInstPtr::make(TypePtr::BotPTR, k, xk, NULL, 0);
5287 }
5288 
5289 //------------------------------xmeet------------------------------------------
5290 // Compute the MEET of two types, return a new Type object.
5291 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5292   // Perform a fast test for common case; meeting the same types together.
5293   if( this == t ) return this;  // Meeting same type-rep?
5294 
5295   // Current "this->_base" is Pointer
5296   switch (t->base()) {          // switch on original type
5297 
5298   case Int:                     // Mixing ints & oops happens when javac
5299   case Long:                    // reuses local variables
5300   case FloatTop:
5301   case FloatCon:
5302   case FloatBot:
5303   case DoubleTop:
5304   case DoubleCon:
5305   case DoubleBot:
5306   case NarrowOop:
5307   case NarrowKlass:
5308   case Bottom:                  // Ye Olde Default
5309     return Type::BOTTOM;
5310   case Top:
5311     return this;
5312 
5313   default:                      // All else is a mistake
5314     typerr(t);
5315 
5316   case AnyPtr: {                // Meeting to AnyPtrs
5317     // Found an AnyPtr type vs self-KlassPtr type
5318     const TypePtr *tp = t->is_ptr();
5319     int offset = meet_offset(tp->offset());
5320     PTR ptr = meet_ptr(tp->ptr());
5321     switch (tp->ptr()) {
5322     case TopPTR:
5323       return this;
5324     case Null:
5325       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5326     case AnyNull:
5327       return make( ptr, klass(), offset );
5328     case BotPTR:
5329     case NotNull:
5330       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5331     default: typerr(t);
5332     }
5333   }
5334 
5335   case RawPtr:
5336   case MetadataPtr:
5337   case OopPtr:
5338   case AryPtr:                  // Meet with AryPtr
5339   case InstPtr:                 // Meet with InstPtr
5340     return TypePtr::BOTTOM;
5341 
5342   //
5343   //             A-top         }
5344   //           /   |   \       }  Tops
5345   //       B-top A-any C-top   }
5346   //          | /  |  \ |      }  Any-nulls
5347   //       B-any   |   C-any   }
5348   //          |    |    |
5349   //       B-con A-con C-con   } constants; not comparable across classes
5350   //          |    |    |
5351   //       B-not   |   C-not   }
5352   //          | \  |  / |      }  not-nulls
5353   //       B-bot A-not C-bot   }
5354   //           \   |   /       }  Bottoms
5355   //             A-bot         }
5356   //
5357 
5358   case InstKlassPtr: {  // Meet two KlassPtr types
5359     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5360     int  off     = meet_offset(tkls->offset());
5361     PTR  ptr     = meet_ptr(tkls->ptr());
5362     ciKlass* tkls_klass = tkls->klass();
5363     ciKlass* this_klass  = klass();
5364     bool tkls_xk = tkls->klass_is_exact();
5365     bool this_xk  = klass_is_exact();


5366 
5367     ciKlass* res_klass = NULL;
5368     bool res_xk = false;
5369     switch(meet_instptr(ptr, this_klass, tkls_klass, this_xk, tkls_xk, this->_ptr, tkls->_ptr, res_klass, res_xk)) {


5370       case UNLOADED:
5371         ShouldNotReachHere();
5372       case SUBTYPE:
5373       case NOT_SUBTYPE:
5374       case LCA:
5375       case QUICK: {
5376         assert(res_xk == (ptr == Constant), "");
5377         const Type* res1 = make(ptr, res_klass, off);
5378         return res1;
5379       }
5380       default:
5381         ShouldNotReachHere();
5382     }
5383   } // End of case KlassPtr
5384   case AryKlassPtr: {                // All arrays inherit from Object class
5385     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5386     int offset = meet_offset(tp->offset());
5387     PTR ptr = meet_ptr(tp->ptr());
5388 
5389     switch (ptr) {
5390     case TopPTR:
5391     case AnyNull:                // Fall 'down' to dual of object klass
5392       // For instances when a subclass meets a superclass we fall
5393       // below the centerline when the superclass is exact. We need to
5394       // do the same here.
5395       if (klass()->equals(ciEnv::current()->Object_klass()) && !klass_is_exact()) {
5396         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5397       } else {
5398         // cannot subclass, so the meet has to fall badly below the centerline
5399         ptr = NotNull;
5400         return make(ptr, ciEnv::current()->Object_klass(), offset);
5401       }
5402     case Constant:
5403     case NotNull:
5404     case BotPTR:                // Fall down to object klass
5405       // LCA is object_klass, but if we subclass from the top we can do better
5406       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5407         // If 'this' (InstPtr) is above the centerline and it is Object class
5408         // then we can subclass in the Java class hierarchy.
5409         // For instances when a subclass meets a superclass we fall
5410         // below the centerline when the superclass is exact. We need
5411         // to do the same here.
5412         if (klass()->equals(ciEnv::current()->Object_klass())) {
5413           // that is, tp's array type is a subtype of my klass
5414           return TypeAryKlassPtr::make(ptr,
5415                                        tp->elem(), tp->klass(), offset);
5416         }
5417       }
5418       // The other case cannot happen, since I cannot be a subtype of an array.
5419       // The meet falls down to Object class below centerline.
5420       if( ptr == Constant )
5421          ptr = NotNull;
5422       return make(ptr, ciEnv::current()->Object_klass(), offset);
5423     default: typerr(t);
5424     }
5425   }




















5426 
5427   } // End of switch
5428   return this;                  // Return the double constant
5429 }
5430 
5431 //------------------------------xdual------------------------------------------
5432 // Dual: compute field-by-field dual
5433 const Type    *TypeInstKlassPtr::xdual() const {
5434   return new TypeInstKlassPtr(dual_ptr(), klass(), dual_offset());
5435 }
5436 
5437 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
5438   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
5439 }
5440 
5441 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* klass, int offset) {
5442   if (klass->is_obj_array_klass()) {
5443     // Element is an object array. Recursively call ourself.
5444     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
5445     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass)->cast_to_exactness(false);
5446     return TypeAryKlassPtr::make(ptr, etype, NULL, offset);








5447   } else if (klass->is_type_array_klass()) {
5448     // Element is an typeArray
5449     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
5450     return TypeAryKlassPtr::make(ptr, etype, klass, offset);



5451   } else {
5452     ShouldNotReachHere();
5453     return NULL;
5454   }
5455 }
5456 
5457 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass) {
5458   return TypeAryKlassPtr::make(Constant, klass, 0);







5459 }
5460 
5461 //------------------------------eq---------------------------------------------
5462 // Structural equality check for Type representations
5463 bool TypeAryKlassPtr::eq(const Type *t) const {
5464   const TypeAryKlassPtr *p = t->is_aryklassptr();
5465   return
5466     _elem == p->_elem &&  // Check array



5467     TypeKlassPtr::eq(p);  // Check sub-parts
5468 }
5469 
5470 //------------------------------hash-------------------------------------------
5471 // Type-specific hashing function.
5472 int TypeAryKlassPtr::hash(void) const {
5473   return (intptr_t)_elem + TypeKlassPtr::hash();
5474 }
5475 
5476 //----------------------compute_klass------------------------------------------
5477 // Compute the defining klass for this class
5478 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
5479   // Compute _klass based on element type.
5480   ciKlass* k_ary = NULL;
5481   const TypeInstPtr *tinst;
5482   const TypeAryPtr *tary;
5483   const Type* el = elem();
5484   if (el->isa_narrowoop()) {
5485     el = el->make_ptr();
5486   }
5487 
5488   // Get element klass
5489   if ((tinst = el->isa_instptr()) != NULL) {
5490     // Compute array klass from element klass
5491     k_ary = ciObjArrayKlass::make(tinst->klass());






5492   } else if ((tary = el->isa_aryptr()) != NULL) {
5493     // Compute array klass from element klass
5494     ciKlass* k_elem = tary->klass();
5495     // If element type is something like bottom[], k_elem will be null.
5496     if (k_elem != NULL)
5497       k_ary = ciObjArrayKlass::make(k_elem);
5498   } else if ((el->base() == Type::Top) ||
5499              (el->base() == Type::Bottom)) {
5500     // element type of Bottom occurs from meet of basic type
5501     // and object; Top occurs when doing join on Bottom.
5502     // Leave k_ary at NULL.
5503   } else {
5504     // Cannot compute array klass directly from basic type,
5505     // since subtypes of TypeInt all have basic type T_INT.
5506 #ifdef ASSERT
5507     if (verify && el->isa_int()) {
5508       // Check simple cases when verifying klass.
5509       BasicType bt = T_ILLEGAL;
5510       if (el == TypeInt::BYTE) {
5511         bt = T_BYTE;

5536 
5537   // Oops, need to compute _klass and cache it
5538   ciKlass* k_ary = compute_klass();
5539 
5540   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
5541     // The _klass field acts as a cache of the underlying
5542     // ciKlass for this array type.  In order to set the field,
5543     // we need to cast away const-ness.
5544     //
5545     // IMPORTANT NOTE: we *never* set the _klass field for the
5546     // type TypeAryPtr::OOPS.  This Type is shared between all
5547     // active compilations.  However, the ciKlass which represents
5548     // this Type is *not* shared between compilations, so caching
5549     // this value would result in fetching a dangling pointer.
5550     //
5551     // Recomputing the underlying ciKlass for each request is
5552     // a bit less efficient than caching, but calls to
5553     // TypeAryPtr::OOPS->klass() are not common enough to matter.
5554     ((TypeAryPtr*)this)->_klass = k_ary;
5555     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
5556         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes()) {
5557       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
5558     }
5559   }
5560   return k_ary;
5561 }
5562 
5563 
5564 //------------------------------add_offset-------------------------------------
5565 // Access internals of klass object
5566 const TypePtr *TypeAryKlassPtr::add_offset(intptr_t offset) const {
5567   return make(_ptr, elem(), klass(), xadd_offset(offset));
5568 }
5569 
5570 const TypeKlassPtr *TypeAryKlassPtr::with_offset(intptr_t offset) const {
5571   return make(_ptr, elem(), klass(), offset);
5572 }
5573 
5574 //------------------------------cast_to_ptr_type-------------------------------
5575 const TypePtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
5576   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
5577   if (ptr == _ptr) return this;
5578   return make(ptr, elem(), _klass, _offset);
5579 }
5580 
5581 bool TypeAryKlassPtr::must_be_exact() const {
5582   if (_elem == Type::BOTTOM) return false;
5583   if (_elem == Type::TOP   ) return false;
5584   const TypeKlassPtr*  tk = _elem->isa_klassptr();
5585   if (!tk)             return true;   // a primitive type, like int
5586   return tk->must_be_exact();
5587 }
5588 
5589 
5590 //-----------------------------cast_to_exactness-------------------------------
5591 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5592   if (must_be_exact()) return this;  // cannot clear xk
5593   ciKlass* k = _klass;
5594   const Type* elem = this->elem();
5595   if (elem->isa_klassptr() && !klass_is_exact) {
5596     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
5597   }
5598   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);







5599 }
5600 
5601 
5602 //-----------------------------as_instance_type--------------------------------
5603 // Corresponding type for an instance of the given class.
5604 // It will be exact if and only if the klass type is exact.
5605 const TypeOopPtr* TypeAryKlassPtr::as_instance_type() const {
5606   ciKlass* k = klass();

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






5610 }
5611 
5612 
5613 //------------------------------xmeet------------------------------------------
5614 // Compute the MEET of two types, return a new Type object.
5615 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
5616   // Perform a fast test for common case; meeting the same types together.
5617   if( this == t ) return this;  // Meeting same type-rep?
5618 
5619   // Current "this->_base" is Pointer
5620   switch (t->base()) {          // switch on original type
5621 
5622   case Int:                     // Mixing ints & oops happens when javac
5623   case Long:                    // reuses local variables
5624   case FloatTop:
5625   case FloatCon:
5626   case FloatBot:
5627   case DoubleTop:
5628   case DoubleCon:
5629   case DoubleBot:
5630   case NarrowOop:
5631   case NarrowKlass:
5632   case Bottom:                  // Ye Olde Default
5633     return Type::BOTTOM;
5634   case Top:
5635     return this;
5636 
5637   default:                      // All else is a mistake
5638     typerr(t);
5639 
5640   case AnyPtr: {                // Meeting to AnyPtrs
5641     // Found an AnyPtr type vs self-KlassPtr type
5642     const TypePtr *tp = t->is_ptr();
5643     int offset = meet_offset(tp->offset());
5644     PTR ptr = meet_ptr(tp->ptr());
5645     switch (tp->ptr()) {
5646     case TopPTR:
5647       return this;
5648     case Null:
5649       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5650     case AnyNull:
5651       return make( ptr, _elem, klass(), offset );
5652     case BotPTR:
5653     case NotNull:
5654       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5655     default: typerr(t);
5656     }
5657   }
5658 
5659   case RawPtr:
5660   case MetadataPtr:
5661   case OopPtr:
5662   case AryPtr:                  // Meet with AryPtr
5663   case InstPtr:                 // Meet with InstPtr
5664     return TypePtr::BOTTOM;
5665 
5666   //
5667   //             A-top         }
5668   //           /   |   \       }  Tops
5669   //       B-top A-any C-top   }
5670   //          | /  |  \ |      }  Any-nulls
5671   //       B-any   |   C-any   }
5672   //          |    |    |
5673   //       B-con A-con C-con   } constants; not comparable across classes
5674   //          |    |    |
5675   //       B-not   |   C-not   }
5676   //          | \  |  / |      }  not-nulls
5677   //       B-bot A-not C-bot   }
5678   //           \   |   /       }  Bottoms
5679   //             A-bot         }
5680   //
5681 
5682   case AryKlassPtr: {  // Meet two KlassPtr types
5683     const TypeAryKlassPtr *tap = t->is_aryklassptr();
5684     int off = meet_offset(tap->offset());
5685     const Type* elem = _elem->meet(tap->_elem);
5686 
5687     PTR ptr = meet_ptr(tap->ptr());
5688     ciKlass* res_klass = NULL;
5689     bool res_xk = false;
5690     meet_aryptr(ptr, elem, this->klass(), tap->klass(), this->klass_is_exact(), tap->klass_is_exact(), this->ptr(), tap->ptr(), res_klass, res_xk);






5691     assert(res_xk == (ptr == Constant), "");
5692     return make(ptr, elem, res_klass, off);










5693   } // End of case KlassPtr
5694   case InstKlassPtr: {
5695     const TypeInstKlassPtr *tp = t->is_instklassptr();
5696     int offset = meet_offset(tp->offset());
5697     PTR ptr = meet_ptr(tp->ptr());
5698 
5699     switch (ptr) {
5700     case TopPTR:
5701     case AnyNull:                // Fall 'down' to dual of object klass
5702       // For instances when a subclass meets a superclass we fall
5703       // below the centerline when the superclass is exact. We need to
5704       // do the same here.
5705       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
5706         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
5707       } else {
5708         // cannot subclass, so the meet has to fall badly below the centerline
5709         ptr = NotNull;
5710         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset);
5711       }
5712     case Constant:
5713     case NotNull:
5714     case BotPTR:                // Fall down to object klass
5715       // LCA is object_klass, but if we subclass from the top we can do better
5716       if (above_centerline(tp->ptr())) {
5717         // If 'tp'  is above the centerline and it is Object class
5718         // then we can subclass in the Java class hierarchy.
5719         // For instances when a subclass meets a superclass we fall
5720         // below the centerline when the superclass is exact. We need
5721         // to do the same here.
5722         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
5723           // that is, my array type is a subtype of 'tp' klass
5724           return make(ptr, _elem, _klass, offset);
5725         }
5726       }
5727       // The other case cannot happen, since t cannot be a subtype of an array.
5728       // The meet falls down to Object class below centerline.
5729       if (ptr == Constant)
5730          ptr = NotNull;
5731       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset);
5732     default: typerr(t);
5733     }
5734   }












5735 
5736   } // End of switch
5737   return this;                  // Return the double constant
5738 }
5739 
5740 //------------------------------xdual------------------------------------------
5741 // Dual: compute field-by-field dual
5742 const Type    *TypeAryKlassPtr::xdual() const {
5743   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
5744 }
5745 
5746 //------------------------------get_con----------------------------------------
5747 ciKlass* TypeAryKlassPtr::klass() const {
5748   if (_klass != NULL) {
5749     return _klass;
5750   }
5751   ciKlass* k = NULL;
5752   if (elem()->isa_klassptr()) {
5753     k = elem()->is_klassptr()->klass();
5754     if (k != NULL) {
5755       k = ciObjArrayKlass::make(k);














5756       ((TypeAryKlassPtr*)this)->_klass = k;
5757     }
5758   } else if ((elem()->base() == Type::Top) ||
5759              (elem()->base() == Type::Bottom)) {
5760   } else {
5761     k = ciTypeArrayKlass::make(elem()->basic_type());
5762   }
5763   return k;
5764 }
5765 
5766 //------------------------------dump2------------------------------------------
5767 // Dump Klass Type
5768 #ifndef PRODUCT
5769 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5770   switch( _ptr ) {
5771   case Constant:
5772     st->print("precise ");
5773   case NotNull:
5774     {
5775       st->print("[");




5776       _elem->dump2(d, depth, st);
5777       st->print(": ");
5778     }
5779   case BotPTR:
5780     if( !WizardMode && !Verbose && _ptr != Constant ) break;
5781   case TopPTR:
5782   case AnyNull:
5783     st->print(":%s", ptr_msg[_ptr]);
5784     if( _ptr == Constant ) st->print(":exact");
5785     break;
5786   default:
5787     break;
5788   }
5789 
5790   if( _offset ) {               // Dump offset, if any
5791     if( _offset == OffsetBot )      { st->print("+any"); }
5792     else if( _offset == OffsetTop ) { st->print("+unknown"); }
5793     else                            { st->print("+%d", _offset); }
5794   }
5795 


5796   st->print(" *");
5797 }
5798 #endif
5799 
5800 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
5801   const Type* elem = this->elem();
5802   dims = 1;
5803   while (elem->isa_aryklassptr()) {
5804     elem = elem->is_aryklassptr()->elem();
5805     dims++;
5806   }
5807   return elem;
5808 }
5809 
5810 //=============================================================================
5811 // Convenience common pre-built types.
5812 
5813 //------------------------------make-------------------------------------------
5814 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
5815   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();












5816 }
5817 
5818 //------------------------------make-------------------------------------------
5819 const TypeFunc *TypeFunc::make(ciMethod* method) {
5820   Compile* C = Compile::current();
5821   const TypeFunc* tf = C->last_tf(method); // check cache
5822   if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
5823   const TypeTuple *domain;
5824   if (method->is_static()) {
5825     domain = TypeTuple::make_domain(NULL, method->signature());
5826   } else {
5827     domain = TypeTuple::make_domain(method->holder(), method->signature());













5828   }
5829   const TypeTuple *range  = TypeTuple::make_range(method->signature());
5830   tf = TypeFunc::make(domain, range);
5831   C->set_last_tf(method, tf);  // fill cache
5832   return tf;
5833 }
5834 
5835 //------------------------------meet-------------------------------------------
5836 // Compute the MEET of two types.  It returns a new Type object.
5837 const Type *TypeFunc::xmeet( const Type *t ) const {
5838   // Perform a fast test for common case; meeting the same types together.
5839   if( this == t ) return this;  // Meeting same type-rep?
5840 
5841   // Current "this->_base" is Func
5842   switch (t->base()) {          // switch on original type
5843 
5844   case Bottom:                  // Ye Olde Default
5845     return t;
5846 
5847   default:                      // All else is a mistake
5848     typerr(t);
5849 
5850   case Top:
5851     break;
5852   }
5853   return this;                  // Return the double constant
5854 }
5855 
5856 //------------------------------xdual------------------------------------------
5857 // Dual: compute field-by-field dual
5858 const Type *TypeFunc::xdual() const {
5859   return this;
5860 }
5861 
5862 //------------------------------eq---------------------------------------------
5863 // Structural equality check for Type representations
5864 bool TypeFunc::eq( const Type *t ) const {
5865   const TypeFunc *a = (const TypeFunc*)t;
5866   return _domain == a->_domain &&
5867     _range == a->_range;


5868 }
5869 
5870 //------------------------------hash-------------------------------------------
5871 // Type-specific hashing function.
5872 int TypeFunc::hash(void) const {
5873   return (intptr_t)_domain + (intptr_t)_range;
5874 }
5875 
5876 //------------------------------dump2------------------------------------------
5877 // Dump Function Type
5878 #ifndef PRODUCT
5879 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
5880   if( _range->cnt() <= Parms )
5881     st->print("void");
5882   else {
5883     uint i;
5884     for (i = Parms; i < _range->cnt()-1; i++) {
5885       _range->field_at(i)->dump2(d,depth,st);
5886       st->print("/");
5887     }
5888     _range->field_at(i)->dump2(d,depth,st);
5889   }
5890   st->print(" ");
5891   st->print("( ");
5892   if( !depth || d[this] ) {     // Check for recursive dump
5893     st->print("...)");
5894     return;
5895   }
5896   d.Insert((void*)this,(void*)this);    // Stop recursion
5897   if (Parms < _domain->cnt())
5898     _domain->field_at(Parms)->dump2(d,depth-1,st);
5899   for (uint i = Parms+1; i < _domain->cnt(); i++) {
5900     st->print(", ");
5901     _domain->field_at(i)->dump2(d,depth-1,st);
5902   }
5903   st->print(" )");
5904 }
5905 #endif
5906 
5907 //------------------------------singleton--------------------------------------
5908 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5909 // constants (Ldi nodes).  Singletons are integer, float or double constants
5910 // or a single symbol.
5911 bool TypeFunc::singleton(void) const {
5912   return false;                 // Never a singleton
5913 }
5914 
5915 bool TypeFunc::empty(void) const {
5916   return false;                 // Never empty
5917 }
5918 
5919 
5920 BasicType TypeFunc::return_type() const{
5921   if (range()->cnt() == TypeFunc::Parms) {
5922     return T_VOID;
5923   }
5924   return range()->field_at(TypeFunc::Parms)->basic_type();
5925 }

   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciFlatArrayKlass.hpp"
  27 #include "ci/ciField.hpp"
  28 #include "ci/ciInlineKlass.hpp"
  29 #include "ci/ciMethodData.hpp"
  30 #include "ci/ciTypeFlow.hpp"
  31 #include "classfile/javaClasses.hpp"
  32 #include "classfile/symbolTable.hpp"
  33 #include "compiler/compileLog.hpp"
  34 #include "libadt/dict.hpp"
  35 #include "memory/oopFactory.hpp"
  36 #include "memory/resourceArea.hpp"
  37 #include "oops/instanceKlass.hpp"
  38 #include "oops/instanceMirrorKlass.hpp"
  39 #include "oops/objArrayKlass.hpp"
  40 #include "oops/typeArrayKlass.hpp"
  41 #include "opto/matcher.hpp"
  42 #include "opto/node.hpp"
  43 #include "opto/opcodes.hpp"
  44 #include "opto/type.hpp"
  45 #include "utilities/powerOfTwo.hpp"
  46 #include "utilities/stringUtils.hpp"
  47 
  48 // Portions of code courtesy of Clifford Click
  49 
  50 // Optimization - Graph Style
  51 
  52 // Dictionary of types shared among compilations.
  53 Dict* Type::_shared_type_dict = NULL;
  54 const Type::Offset Type::Offset::top(Type::OffsetTop);
  55 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
  56 
  57 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
  58   // Either is 'TOP' offset?  Return the other offset!
  59   int offset = other._offset;
  60   if (_offset == OffsetTop) return Offset(offset);
  61   if (offset == OffsetTop) return Offset(_offset);
  62   // If either is different, return 'BOTTOM' offset
  63   if (_offset != offset) return bottom;
  64   return Offset(_offset);
  65 }
  66 
  67 const Type::Offset Type::Offset::dual() const {
  68   if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
  69   if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
  70   return Offset(_offset);               // Map everything else into self
  71 }
  72 
  73 const Type::Offset Type::Offset::add(intptr_t offset) const {
  74   // Adding to 'TOP' offset?  Return 'TOP'!
  75   if (_offset == OffsetTop || offset == OffsetTop) return top;
  76   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  77   if (_offset == OffsetBot || offset == OffsetBot) return bottom;
  78   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  79   offset += (intptr_t)_offset;
  80   if (offset != (int)offset || offset == OffsetTop) return bottom;
  81 
  82   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  83   // It is possible to construct a negative offset during PhaseCCP
  84 
  85   return Offset((int)offset);        // Sum valid offsets
  86 }
  87 
  88 void Type::Offset::dump2(outputStream *st) const {
  89   if (_offset == 0) {
  90     return;
  91   } else if (_offset == OffsetTop) {
  92     st->print("+top");
  93   }
  94   else if (_offset == OffsetBot) {
  95     st->print("+bot");
  96   } else if (_offset) {
  97     st->print("+%d", _offset);
  98   }
  99 }
 100 
 101 // Array which maps compiler types to Basic Types
 102 const Type::TypeInfo Type::_type_info[Type::lastype] = {
 103   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
 104   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
 105   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
 106   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
 107   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
 108   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
 109   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
 110   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
 111   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
 112   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
 113 
 114 #if defined(PPC64)
 115   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 116   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 117   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 118   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 119   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 120   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 121   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 122 #elif defined(S390)
 123   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 124   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 125   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 126   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD
 127   { Bad,             T_ILLEGAL,    "vectorx:",      false, 0,                    relocInfo::none          },  // VectorX
 128   { Bad,             T_ILLEGAL,    "vectory:",      false, 0,                    relocInfo::none          },  // VectorY
 129   { Bad,             T_ILLEGAL,    "vectorz:",      false, 0,                    relocInfo::none          },  // VectorZ
 130 #else // all other
 131   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 132   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 133   { Bad,             T_ILLEGAL,    "vectors:",      false, Op_VecS,              relocInfo::none          },  // VectorS
 134   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_VecD,              relocInfo::none          },  // VectorD
 135   { Bad,             T_ILLEGAL,    "vectorx:",      false, Op_VecX,              relocInfo::none          },  // VectorX
 136   { Bad,             T_ILLEGAL,    "vectory:",      false, Op_VecY,              relocInfo::none          },  // VectorY
 137   { Bad,             T_ILLEGAL,    "vectorz:",      false, Op_VecZ,              relocInfo::none          },  // VectorZ
 138 #endif
 139   { Bad,             T_PRIMITIVE_OBJECT, "inline:",      false, Node::NotAMachineReg, relocInfo::none          },  // InlineType
 140   { Bad,             T_ADDRESS,    "anyptr:",       false, Op_RegP,              relocInfo::none          },  // AnyPtr
 141   { Bad,             T_ADDRESS,    "rawptr:",       false, Op_RegP,              relocInfo::none          },  // RawPtr
 142   { Bad,             T_OBJECT,     "oop:",          true,  Op_RegP,              relocInfo::oop_type      },  // OopPtr
 143   { Bad,             T_OBJECT,     "inst:",         true,  Op_RegP,              relocInfo::oop_type      },  // InstPtr
 144   { Bad,             T_OBJECT,     "ary:",          true,  Op_RegP,              relocInfo::oop_type      },  // AryPtr
 145   { Bad,             T_METADATA,   "metadata:",     false, Op_RegP,              relocInfo::metadata_type },  // MetadataPtr
 146   { Bad,             T_METADATA,   "klass:",        false, Op_RegP,              relocInfo::metadata_type },  // KlassPtr
 147   { Bad,             T_METADATA,   "instklass:",    false, Op_RegP,              relocInfo::metadata_type },  // InstKlassPtr
 148   { Bad,             T_METADATA,   "aryklass:",     false, Op_RegP,              relocInfo::metadata_type },  // AryKlassPtr
 149   { Bad,             T_OBJECT,     "func",          false, 0,                    relocInfo::none          },  // Function
 150   { Abio,            T_ILLEGAL,    "abIO",          false, 0,                    relocInfo::none          },  // Abio
 151   { Return_Address,  T_ADDRESS,    "return_address",false, Op_RegP,              relocInfo::none          },  // Return_Address
 152   { Memory,          T_ILLEGAL,    "memory",        false, 0,                    relocInfo::none          },  // Memory
 153   { FloatBot,        T_FLOAT,      "float_top",     false, Op_RegF,              relocInfo::none          },  // FloatTop
 154   { FloatCon,        T_FLOAT,      "ftcon:",        false, Op_RegF,              relocInfo::none          },  // FloatCon
 155   { FloatTop,        T_FLOAT,      "float",         false, Op_RegF,              relocInfo::none          },  // FloatBot
 156   { DoubleBot,       T_DOUBLE,     "double_top",    false, Op_RegD,              relocInfo::none          },  // DoubleTop
 157   { DoubleCon,       T_DOUBLE,     "dblcon:",       false, Op_RegD,              relocInfo::none          },  // DoubleCon
 158   { DoubleTop,       T_DOUBLE,     "double",        false, Op_RegD,              relocInfo::none          },  // DoubleBot
 159   { Top,             T_ILLEGAL,    "bottom",        false, 0,                    relocInfo::none          }   // Bottom

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

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

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

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

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

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

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

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

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

2889   case NarrowKlass:
2890   case Bottom:                  // Ye Olde Default
2891     return Type::BOTTOM;
2892   case Top:
2893     return this;
2894 
2895   case AnyPtr: {                // Meeting to AnyPtrs
2896     const TypePtr *tp = t->is_ptr();
2897     const TypePtr* speculative = xmeet_speculative(tp);
2898     int depth = meet_inline_depth(tp->inline_depth());
2899     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2900   }
2901   case RawPtr:                  // For these, flip the call around to cut down
2902   case OopPtr:
2903   case InstPtr:                 // on the cases I have to handle.
2904   case AryPtr:
2905   case MetadataPtr:
2906   case KlassPtr:
2907   case InstKlassPtr:
2908   case AryKlassPtr:
2909   case InlineType:
2910     return t->xmeet(this);      // Call in reverse direction
2911   default:                      // All else is a mistake
2912     typerr(t);
2913 
2914   }
2915   return this;
2916 }
2917 
2918 //------------------------------meet_offset------------------------------------
2919 Type::Offset TypePtr::meet_offset(int offset) const {
2920   return _offset.meet(Offset(offset));





2921 }
2922 
2923 //------------------------------dual_offset------------------------------------
2924 Type::Offset TypePtr::dual_offset() const {
2925   return _offset.dual();


2926 }
2927 
2928 //------------------------------xdual------------------------------------------
2929 // Dual: compute field-by-field dual
2930 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2931   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2932 };
2933 const Type *TypePtr::xdual() const {
2934   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2935 }
2936 
2937 //------------------------------xadd_offset------------------------------------
2938 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2939   return _offset.add(offset);











2940 }
2941 
2942 //------------------------------add_offset-------------------------------------
2943 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2944   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2945 }
2946 
2947 //------------------------------eq---------------------------------------------
2948 // Structural equality check for Type representations
2949 bool TypePtr::eq( const Type *t ) const {
2950   const TypePtr *a = (const TypePtr*)t;
2951   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2952 }
2953 
2954 //------------------------------hash-------------------------------------------
2955 // Type-specific hashing function.
2956 int TypePtr::hash(void) const {
2957   return java_add(java_add((jint)_ptr, (jint)offset()), java_add((jint)hash_speculative(), (jint)_inline_depth));
2958 ;
2959 }
2960 
2961 /**
2962  * Return same type without a speculative part
2963  */
2964 const Type* TypePtr::remove_speculative() const {
2965   if (_speculative == NULL) {
2966     return this;
2967   }
2968   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2969   return make(AnyPtr, _ptr, _offset, NULL, _inline_depth);
2970 }
2971 
2972 /**
2973  * Return same type but drop speculative part if we know we won't use
2974  * it
2975  */
2976 const Type* TypePtr::cleanup_speculative() const {
2977   if (speculative() == NULL) {

3197   }
3198   // We already know the speculative type is always null
3199   if (speculative_always_null()) {
3200     return false;
3201   }
3202   if (ptr_kind == ProfileAlwaysNull && speculative() != NULL && speculative()->isa_oopptr()) {
3203     return false;
3204   }
3205   return true;
3206 }
3207 
3208 //------------------------------dump2------------------------------------------
3209 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3210   "TopPTR","AnyNull","Constant","NULL","NotNull","BotPTR"
3211 };
3212 
3213 #ifndef PRODUCT
3214 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3215   if( _ptr == Null ) st->print("NULL");
3216   else st->print("%s *", ptr_msg[_ptr]);
3217   _offset.dump2(st);


3218   dump_inline_depth(st);
3219   dump_speculative(st);
3220 }
3221 
3222 /**
3223  *dump the speculative part of the type
3224  */
3225 void TypePtr::dump_speculative(outputStream *st) const {
3226   if (_speculative != NULL) {
3227     st->print(" (speculative=");
3228     _speculative->dump_on(st);
3229     st->print(")");
3230   }
3231 }
3232 
3233 /**
3234  *dump the inline depth of the type
3235  */
3236 void TypePtr::dump_inline_depth(outputStream *st) const {
3237   if (_inline_depth != InlineDepthBottom) {
3238     if (_inline_depth == InlineDepthTop) {
3239       st->print(" (inline_depth=InlineDepthTop)");
3240     } else {
3241       st->print(" (inline_depth=%d)", _inline_depth);
3242     }
3243   }
3244 }
3245 #endif
3246 
3247 //------------------------------singleton--------------------------------------
3248 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3249 // constants
3250 bool TypePtr::singleton(void) const {
3251   // TopPTR, Null, AnyNull, Constant are all singletons
3252   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3253 }
3254 
3255 bool TypePtr::empty(void) const {
3256   return (_offset == Offset::top) || above_centerline(_ptr);
3257 }
3258 
3259 //=============================================================================
3260 // Convenience common pre-built types.
3261 const TypeRawPtr *TypeRawPtr::BOTTOM;
3262 const TypeRawPtr *TypeRawPtr::NOTNULL;
3263 
3264 //------------------------------make-------------------------------------------
3265 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3266   assert( ptr != Constant, "what is the constant?" );
3267   assert( ptr != Null, "Use TypePtr for NULL" );
3268   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3269 }
3270 
3271 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3272   assert( bits, "Use TypePtr for NULL" );
3273   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3274 }
3275 
3276 //------------------------------cast_to_ptr_type-------------------------------

3380 // Type-specific hashing function.
3381 int TypeRawPtr::hash(void) const {
3382   return (intptr_t)_bits + TypePtr::hash();
3383 }
3384 
3385 //------------------------------dump2------------------------------------------
3386 #ifndef PRODUCT
3387 void TypeRawPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3388   if( _ptr == Constant )
3389     st->print(INTPTR_FORMAT, p2i(_bits));
3390   else
3391     st->print("rawptr:%s", ptr_msg[_ptr]);
3392 }
3393 #endif
3394 
3395 //=============================================================================
3396 // Convenience common pre-built type.
3397 const TypeOopPtr *TypeOopPtr::BOTTOM;
3398 
3399 //------------------------------TypeOopPtr-------------------------------------
3400 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset,
3401                        int instance_id, const TypePtr* speculative, int inline_depth)
3402   : TypePtr(t, ptr, offset, speculative, inline_depth),
3403     _const_oop(o), _klass(k),
3404     _klass_is_exact(xk),
3405     _is_ptr_to_narrowoop(false),
3406     _is_ptr_to_narrowklass(false),
3407     _is_ptr_to_boxed_value(false),
3408     _instance_id(instance_id) {
3409   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3410       (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3411     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3412   }
3413 #ifdef _LP64
3414   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3415     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3416       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3417     } else if (klass() == NULL) {
3418       // Array with unknown body type
3419       assert(this->isa_aryptr(), "only arrays without klass");
3420       _is_ptr_to_narrowoop = UseCompressedOops;
3421     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3422       if (klass()->is_obj_array_klass()) {
3423         _is_ptr_to_narrowoop = true;
3424       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3425         // Check if the field of the inline type array element contains oops
3426         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3427         int foffset = field_offset.get() + vk->first_field_offset();
3428         ciField* field = vk->get_field_by_offset(foffset, false);
3429         assert(field != NULL, "missing field");
3430         BasicType bt = field->layout_type();
3431         _is_ptr_to_narrowoop = UseCompressedOops && is_reference_type(bt);
3432       }
3433     } else if (klass()->is_instance_klass()) {


3434       if (this->isa_klassptr()) {
3435         // Perm objects don't use compressed references
3436       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3437         // unsafe access
3438         _is_ptr_to_narrowoop = UseCompressedOops;
3439       } else {
3440         assert(this->isa_instptr(), "must be an instance ptr.");

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

3522 //------------------------------as_klass_type----------------------------------
3523 // Return the klass type corresponding to this instance or array type.
3524 // It is the type that is loaded from an object of this type.
3525 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3526   ShouldNotReachHere();
3527   return NULL;
3528 }
3529 
3530 //------------------------------meet-------------------------------------------
3531 // Compute the MEET of two types.  It returns a new Type object.
3532 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3533   // Perform a fast test for common case; meeting the same types together.
3534   if( this == t ) return this;  // Meeting same type-rep?
3535 
3536   // Current "this->_base" is OopPtr
3537   switch (t->base()) {          // switch on original type
3538 
3539   case Int:                     // Mixing ints & oops happens when javac
3540   case Long:                    // reuses local variables
3541   case FloatTop:

3547   case NarrowOop:
3548   case NarrowKlass:
3549   case Bottom:                  // Ye Olde Default
3550     return Type::BOTTOM;
3551   case Top:
3552     return this;
3553 
3554   default:                      // All else is a mistake
3555     typerr(t);
3556 
3557   case RawPtr:
3558   case MetadataPtr:
3559   case KlassPtr:
3560   case InstKlassPtr:
3561   case AryKlassPtr:
3562     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3563 
3564   case AnyPtr: {
3565     // Found an AnyPtr type vs self-OopPtr type
3566     const TypePtr *tp = t->is_ptr();
3567     Offset offset = meet_offset(tp->offset());
3568     PTR ptr = meet_ptr(tp->ptr());
3569     const TypePtr* speculative = xmeet_speculative(tp);
3570     int depth = meet_inline_depth(tp->inline_depth());
3571     switch (tp->ptr()) {
3572     case Null:
3573       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3574       // else fall through:
3575     case TopPTR:
3576     case AnyNull: {
3577       int instance_id = meet_instance_id(InstanceTop);
3578       return make(ptr, offset, instance_id, speculative, depth);
3579     }
3580     case BotPTR:
3581     case NotNull:
3582       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3583     default: typerr(t);
3584     }
3585   }
3586 
3587   case OopPtr: {                 // Meeting to other OopPtrs

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

3826     return (one == two) && TypePtr::eq(t);
3827   } else {
3828     return one->equals(two) && TypePtr::eq(t);
3829   }
3830 }
3831 
3832 //------------------------------hash-------------------------------------------
3833 // Type-specific hashing function.
3834 int TypeOopPtr::hash(void) const {
3835   return
3836     java_add(java_add((jint)(const_oop() ? const_oop()->hash() : 0), (jint)_klass_is_exact),
3837              java_add((jint)_instance_id, (jint)TypePtr::hash()));
3838 }
3839 
3840 //------------------------------dump2------------------------------------------
3841 #ifndef PRODUCT
3842 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3843   st->print("oopptr:%s", ptr_msg[_ptr]);
3844   if( _klass_is_exact ) st->print(":exact");
3845   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3846   _offset.dump2(st);





3847   if (_instance_id == InstanceTop)
3848     st->print(",iid=top");
3849   else if (_instance_id != InstanceBot)
3850     st->print(",iid=%d",_instance_id);
3851 
3852   dump_inline_depth(st);
3853   dump_speculative(st);
3854 }
3855 #endif
3856 
3857 //------------------------------singleton--------------------------------------
3858 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3859 // constants
3860 bool TypeOopPtr::singleton(void) const {
3861   // detune optimizer to not generate constant oop + constant offset as a constant!
3862   // TopPTR, Null, AnyNull, Constant are all singletons
3863   return (offset() == 0) && !below_centerline(_ptr);
3864 }
3865 
3866 //------------------------------add_offset-------------------------------------
3867 const TypePtr *TypeOopPtr::add_offset(intptr_t offset) const {
3868   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3869 }
3870 
3871 /**
3872  * Return same type without a speculative part
3873  */
3874 const Type* TypeOopPtr::remove_speculative() const {
3875   if (_speculative == NULL) {
3876     return this;
3877   }
3878   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3879   return make(_ptr, _offset, _instance_id, NULL, _inline_depth);
3880 }
3881 
3882 /**
3883  * Return same type but drop speculative part if we know we won't use

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

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

4463 }
4464 
4465 
4466 //------------------------------xdual------------------------------------------
4467 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4468 // inheritance mechanism.
4469 const Type *TypeInstPtr::xdual() const {
4470   return new TypeInstPtr(dual_ptr(), klass(), klass_is_exact(), const_oop(), dual_offset(), flatten_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4471 }
4472 
4473 //------------------------------eq---------------------------------------------
4474 // Structural equality check for Type representations
4475 bool TypeInstPtr::eq( const Type *t ) const {
4476   const TypeInstPtr *p = t->is_instptr();
4477   return
4478     klass()->equals(p->klass()) &&
4479     flatten_array() == p->flatten_array() &&
4480     TypeOopPtr::eq(p);          // Check sub-type stuff
4481 }
4482 
4483 //------------------------------hash-------------------------------------------
4484 // Type-specific hashing function.
4485 int TypeInstPtr::hash(void) const {
4486   int hash = java_add(java_add((jint)klass()->hash(), (jint)TypeOopPtr::hash()), (jint)flatten_array());
4487   return hash;
4488 }
4489 
4490 //------------------------------dump2------------------------------------------
4491 // Dump oop Type
4492 #ifndef PRODUCT
4493 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {
4494   // Print the name of the klass.
4495   klass()->print_name_on(st);
4496 
4497   switch( _ptr ) {
4498   case Constant:
4499     if (WizardMode || Verbose) {
4500       ResourceMark rm;
4501       stringStream ss;
4502 
4503       st->print(" ");
4504       const_oop()->print_oop(&ss);
4505       // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4506       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4507       char* buf = ss.as_string(/* c_heap= */false);
4508       StringUtils::replace_no_expand(buf, "\n", "");
4509       st->print_raw(buf);
4510     }
4511   case BotPTR:
4512     if (!WizardMode && !Verbose) {
4513       if( _klass_is_exact ) st->print(":exact");
4514       break;
4515     }
4516   case TopPTR:
4517   case AnyNull:
4518   case NotNull:
4519     st->print(":%s", ptr_msg[_ptr]);
4520     if( _klass_is_exact ) st->print(":exact");
4521     break;
4522   default:
4523     break;
4524   }
4525 
4526   _offset.dump2(st);




4527 
4528   st->print(" *");
4529 
4530   if (flatten_array() && !klass()->is_inlinetype()) {
4531     st->print(" (flatten array)");
4532   }
4533 
4534   if (_instance_id == InstanceTop)
4535     st->print(",iid=top");
4536   else if (_instance_id != InstanceBot)
4537     st->print(",iid=%d",_instance_id);
4538 
4539   dump_inline_depth(st);
4540   dump_speculative(st);
4541 }
4542 #endif
4543 
4544 //------------------------------add_offset-------------------------------------
4545 const TypePtr *TypeInstPtr::add_offset(intptr_t offset) const {
4546   return make(_ptr, klass(), klass_is_exact(), const_oop(), xadd_offset(offset), flatten_array(),
4547               _instance_id, add_offset_speculative(offset), _inline_depth);
4548 }
4549 
4550 const Type *TypeInstPtr::remove_speculative() const {
4551   if (_speculative == NULL) {
4552     return this;
4553   }
4554   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4555   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(),
4556               _instance_id, NULL, _inline_depth);
4557 }
4558 
4559 const TypePtr *TypeInstPtr::with_inline_depth(int depth) const {
4560   if (!UseInlineDepthForSpeculativeTypes) {
4561     return this;
4562   }
4563   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(), _instance_id, _speculative, depth);
4564 }
4565 
4566 const TypePtr *TypeInstPtr::with_instance_id(int instance_id) const {
4567   assert(is_known_instance(), "should be known");
4568   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, flatten_array(), instance_id, _speculative, _inline_depth);
4569 }
4570 
4571 const TypeInstPtr *TypeInstPtr::cast_to_flatten_array() const {
4572   return make(_ptr, klass(), klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4573 }
4574 
4575 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4576   bool xk = klass_is_exact();
4577   ciInstanceKlass* ik = klass()->as_instance_klass();
4578   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final() && !ik->is_interface()) {
4579     Compile* C = Compile::current();
4580     Dependencies* deps = C->dependencies();
4581     deps->assert_leaf_type(ik);
4582     xk = true;
4583   }
4584   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), Offset(0), flatten_array());
4585 }
4586 
4587 //=============================================================================
4588 // Convenience common pre-built types.
4589 const TypeAryPtr *TypeAryPtr::RANGE;
4590 const TypeAryPtr *TypeAryPtr::OOPS;
4591 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4592 const TypeAryPtr *TypeAryPtr::BYTES;
4593 const TypeAryPtr *TypeAryPtr::SHORTS;
4594 const TypeAryPtr *TypeAryPtr::CHARS;
4595 const TypeAryPtr *TypeAryPtr::INTS;
4596 const TypeAryPtr *TypeAryPtr::LONGS;
4597 const TypeAryPtr *TypeAryPtr::FLOATS;
4598 const TypeAryPtr *TypeAryPtr::DOUBLES;
4599 const TypeAryPtr *TypeAryPtr::INLINES;
4600 
4601 //------------------------------make-------------------------------------------
4602 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4603                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4604   assert(!(k == NULL && ary->_elem->isa_int()),
4605          "integral arrays must be pre-equipped with a class");
4606   if (!xk)  xk = ary->ary_must_be_exact();
4607   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4608   return (TypeAryPtr*)(new TypeAryPtr(ptr, NULL, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4609 }
4610 
4611 //------------------------------make-------------------------------------------
4612 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4613                                    int instance_id, const TypePtr* speculative, int inline_depth,
4614                                    bool is_autobox_cache) {
4615   assert(!(k == NULL && ary->_elem->isa_int()),
4616          "integral arrays must be pre-equipped with a class");
4617   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4618   if (!xk)  xk = (o != NULL) || ary->ary_must_be_exact();
4619   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4620   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4621 }
4622 
4623 //------------------------------cast_to_ptr_type-------------------------------
4624 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4625   if( ptr == _ptr ) return this;
4626   return make(ptr, const_oop(), _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4627 }
4628 
4629 
4630 //-----------------------------cast_to_exactness-------------------------------
4631 const Type *TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4632   if( klass_is_exact == _klass_is_exact ) return this;
4633   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4634 
4635   const TypeAry* new_ary = _ary;
4636   if (klass() != NULL && klass()->is_obj_array_klass() && klass_is_exact) {
4637     // An object array can't be flat or null-free if the klass is exact
4638     new_ary = TypeAry::make(elem(), size(), is_stable(), /* not_flat= */ true, /* not_null_free= */ true);
4639   }
4640   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4641 }
4642 
4643 //-----------------------------cast_to_instance_id----------------------------
4644 const TypeOopPtr *TypeAryPtr::cast_to_instance_id(int instance_id) const {
4645   if( instance_id == _instance_id ) return this;
4646   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4647 }
4648 
4649 
4650 //-----------------------------max_array_length-------------------------------
4651 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4652 jint TypeAryPtr::max_array_length(BasicType etype) {
4653   if (!is_java_primitive(etype) && !is_reference_type(etype)) {
4654     if (etype == T_NARROWOOP) {
4655       etype = T_OBJECT;
4656     } else if (etype == T_ILLEGAL) { // bottom[]
4657       etype = T_BYTE; // will produce conservatively high value
4658     } else {
4659       fatal("not an element type: %s", type2name(etype));
4660     }
4661   }
4662   return arrayOopDesc::max_array_length(etype);
4663 }
4664 
4665 //-----------------------------narrow_size_type-------------------------------
4666 // Narrow the given size type to the index range for the given array base type.

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

5336 
5337   case Int:                     // Mixing ints & oops happens when javac
5338   case Long:                    // reuses local variables
5339   case FloatTop:
5340   case FloatCon:
5341   case FloatBot:
5342   case DoubleTop:
5343   case DoubleCon:
5344   case DoubleBot:
5345   case AnyPtr:
5346   case RawPtr:
5347   case OopPtr:
5348   case InstPtr:
5349   case AryPtr:
5350   case MetadataPtr:
5351   case KlassPtr:
5352   case InstKlassPtr:
5353   case AryKlassPtr:
5354   case NarrowOop:
5355   case NarrowKlass:

5356   case Bottom:                  // Ye Olde Default
5357     return Type::BOTTOM;
5358   case Top:
5359     return this;
5360 
5361   case InlineType:
5362     return t->xmeet(this);
5363 
5364   default:                      // All else is a mistake
5365     typerr(t);
5366 
5367   } // End of switch
5368 
5369   return this;
5370 }
5371 
5372 #ifndef PRODUCT
5373 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5374   _ptrtype->dump2(d, depth, st);
5375 }
5376 #endif
5377 
5378 const TypeNarrowOop *TypeNarrowOop::BOTTOM;
5379 const TypeNarrowOop *TypeNarrowOop::NULL_PTR;
5380 
5381 
5382 const TypeNarrowOop* TypeNarrowOop::make(const TypePtr* type) {
5383   return (const TypeNarrowOop*)(new TypeNarrowOop(type))->hashcons();

5422     return (one == two) && TypePtr::eq(t);
5423   } else {
5424     return one->equals(two) && TypePtr::eq(t);
5425   }
5426 }
5427 
5428 //------------------------------hash-------------------------------------------
5429 // Type-specific hashing function.
5430 int TypeMetadataPtr::hash(void) const {
5431   return
5432     (metadata() ? metadata()->hash() : 0) +
5433     TypePtr::hash();
5434 }
5435 
5436 //------------------------------singleton--------------------------------------
5437 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5438 // constants
5439 bool TypeMetadataPtr::singleton(void) const {
5440   // detune optimizer to not generate constant metadata + constant offset as a constant!
5441   // TopPTR, Null, AnyNull, Constant are all singletons
5442   return (offset() == 0) && !below_centerline(_ptr);
5443 }
5444 
5445 //------------------------------add_offset-------------------------------------
5446 const TypePtr *TypeMetadataPtr::add_offset( intptr_t offset ) const {
5447   return make( _ptr, _metadata, xadd_offset(offset));
5448 }
5449 
5450 //-----------------------------filter------------------------------------------
5451 // Do not allow interface-vs.-noninterface joins to collapse to top.
5452 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5453   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5454   if (ft == NULL || ft->empty())
5455     return Type::TOP;           // Canonical empty value
5456   return ft;
5457 }
5458 
5459  //------------------------------get_con----------------------------------------
5460 intptr_t TypeMetadataPtr::get_con() const {
5461   assert( _ptr == Null || _ptr == Constant, "" );
5462   assert(offset() >= 0, "");
5463 
5464   if (offset() != 0) {
5465     // After being ported to the compiler interface, the compiler no longer
5466     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5467     // to a handle at compile time.  This handle is embedded in the generated
5468     // code and dereferenced at the time the nmethod is made.  Until that time,
5469     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5470     // have access to the addresses!).  This does not seem to currently happen,
5471     // but this assertion here is to help prevent its occurence.
5472     tty->print_cr("Found oop constant with non-zero offset");
5473     ShouldNotReachHere();
5474   }
5475 
5476   return (intptr_t)metadata()->constant_encoding();
5477 }
5478 
5479 //------------------------------cast_to_ptr_type-------------------------------
5480 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5481   if( ptr == _ptr ) return this;
5482   return make(ptr, metadata(), _offset);
5483 }
5484 

5495   case Long:                    // reuses local variables
5496   case FloatTop:
5497   case FloatCon:
5498   case FloatBot:
5499   case DoubleTop:
5500   case DoubleCon:
5501   case DoubleBot:
5502   case NarrowOop:
5503   case NarrowKlass:
5504   case Bottom:                  // Ye Olde Default
5505     return Type::BOTTOM;
5506   case Top:
5507     return this;
5508 
5509   default:                      // All else is a mistake
5510     typerr(t);
5511 
5512   case AnyPtr: {
5513     // Found an AnyPtr type vs self-OopPtr type
5514     const TypePtr *tp = t->is_ptr();
5515     Offset offset = meet_offset(tp->offset());
5516     PTR ptr = meet_ptr(tp->ptr());
5517     switch (tp->ptr()) {
5518     case Null:
5519       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5520       // else fall through:
5521     case TopPTR:
5522     case AnyNull: {
5523       return make(ptr, _metadata, offset);
5524     }
5525     case BotPTR:
5526     case NotNull:
5527       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5528     default: typerr(t);
5529     }
5530   }
5531 
5532   case RawPtr:
5533   case KlassPtr:
5534   case InstKlassPtr:
5535   case AryKlassPtr:
5536   case OopPtr:
5537   case InstPtr:
5538   case AryPtr:
5539     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5540 
5541   case MetadataPtr: {
5542     const TypeMetadataPtr *tp = t->is_metadataptr();
5543     Offset offset = meet_offset(tp->offset());
5544     PTR tptr = tp->ptr();
5545     PTR ptr = meet_ptr(tptr);
5546     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5547     if (tptr == TopPTR || _ptr == TopPTR ||
5548         metadata()->equals(tp->metadata())) {
5549       return make(ptr, md, offset);
5550     }
5551     // metadata is different
5552     if( ptr == Constant ) {  // Cannot be equal constants, so...
5553       if( tptr == Constant && _ptr != Constant)  return t;
5554       if( _ptr == Constant && tptr != Constant)  return this;
5555       ptr = NotNull;            // Fall down in lattice
5556     }
5557     return make(ptr, NULL, offset);
5558     break;
5559   }
5560   } // End of switch
5561   return this;                  // Return the double constant
5562 }
5563 
5564 
5565 //------------------------------xdual------------------------------------------
5566 // Dual of a pure metadata pointer.
5567 const Type *TypeMetadataPtr::xdual() const {
5568   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5569 }
5570 
5571 //------------------------------dump2------------------------------------------
5572 #ifndef PRODUCT
5573 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5574   st->print("metadataptr:%s", ptr_msg[_ptr]);
5575   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5576   switch (offset()) {
5577   case OffsetTop: st->print("+top"); break;
5578   case OffsetBot: st->print("+any"); break;
5579   case         0: break;
5580   default:        st->print("+%d",offset()); break;
5581   }
5582 }
5583 #endif
5584 
5585 
5586 //=============================================================================
5587 // Convenience common pre-built type.
5588 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5589 
5590 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5591   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5592 }
5593 
5594 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5595   return make(Constant, m, Offset(0));
5596 }
5597 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5598   return make(Constant, m, Offset(0));
5599 }
5600 
5601 //------------------------------make-------------------------------------------
5602 // Create a meta data constant
5603 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5604   assert(m == NULL || !m->is_klass(), "wrong type");
5605   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5606 }
5607 
5608 
5609 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5610   const Type* elem = _ary->_elem;
5611   bool xk = klass_is_exact();
5612   if (elem->make_oopptr() != NULL) {
5613     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5614     if (elem->is_klassptr()->klass_is_exact()) {
5615       xk = true;
5616     }
5617   }
5618   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
5619 }
5620 
5621 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass) {
5622   if (klass->is_instance_klass()) {
5623     return TypeInstKlassPtr::make(klass);
5624   }
5625   return TypeAryKlassPtr::make(klass);
5626 }
5627 
5628 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset) {
5629   if (klass->is_instance_klass()) {
5630     return TypeInstKlassPtr::make(ptr, klass, offset);
5631   }
5632   return TypeAryKlassPtr::make(klass, ptr, offset);
5633 }
5634 

5635 //------------------------------TypeKlassPtr-----------------------------------
5636 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, Offset offset)
5637   : TypePtr(t, ptr, offset), _klass(klass) {
5638 }
5639 
5640 //------------------------------eq---------------------------------------------
5641 // Structural equality check for Type representations
5642 bool TypeKlassPtr::eq(const Type *t) const {
5643   const TypeKlassPtr *p = t->is_klassptr();
5644   return
5645     TypePtr::eq(p);
5646 }
5647 
5648 //------------------------------hash-------------------------------------------
5649 // Type-specific hashing function.
5650 int TypeKlassPtr::hash(void) const {
5651   return TypePtr::hash();
5652 }
5653 
5654 //------------------------------singleton--------------------------------------
5655 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5656 // constants
5657 bool TypeKlassPtr::singleton(void) const {
5658   // detune optimizer to not generate constant klass + constant offset as a constant!
5659   // TopPTR, Null, AnyNull, Constant are all singletons
5660   return (offset() == 0) && !below_centerline(_ptr);
5661 }
5662 
5663 // Do not allow interface-vs.-noninterface joins to collapse to top.
5664 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5665   // logic here mirrors the one from TypeOopPtr::filter. See comments
5666   // there.
5667   const Type* ft = join_helper(kills, include_speculative);
5668   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5669   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5670 
5671   if (ft->empty()) {
5672     if (!empty() && ktkp != NULL && ktkp->is_loaded() && ktkp->klass()->is_interface())
5673       return kills;             // Uplift to interface
5674 
5675     return Type::TOP;           // Canonical empty value
5676   }
5677 
5678   // Interface klass type could be exact in opposite to interface type,
5679   // return it here instead of incorrect Constant ptr J/L/Object (6894807).
5680   if (ftkp != NULL && ktkp != NULL &&
5681       ftkp->is_loaded() &&  ftkp->klass()->is_interface() &&
5682       !ftkp->klass_is_exact() && // Keep exact interface klass
5683       ktkp->is_loaded() && !ktkp->klass()->is_interface()) {
5684     return ktkp->cast_to_ptr_type(ftkp->ptr());
5685   }
5686 
5687   return ft;
5688 }
5689 
5690 //------------------------------get_con----------------------------------------
5691 intptr_t TypeKlassPtr::get_con() const {
5692   assert( _ptr == Null || _ptr == Constant, "" );
5693   assert( offset() >= 0, "" );
5694 
5695   if (offset() != 0) {
5696     // After being ported to the compiler interface, the compiler no longer
5697     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5698     // to a handle at compile time.  This handle is embedded in the generated
5699     // code and dereferenced at the time the nmethod is made.  Until that time,
5700     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5701     // have access to the addresses!).  This does not seem to currently happen,
5702     // but this assertion here is to help prevent its occurence.
5703     tty->print_cr("Found oop constant with non-zero offset");
5704     ShouldNotReachHere();
5705   }
5706 
5707   return (intptr_t)klass()->constant_encoding();
5708 }
5709 
5710 //------------------------------dump2------------------------------------------
5711 // Dump Klass Type
5712 #ifndef PRODUCT
5713 void TypeInstKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {
5714   switch(_ptr) {
5715   case Constant:
5716     st->print("precise ");
5717   case NotNull:
5718     {
5719       const char *name = klass()->name()->as_utf8();
5720       if (name) {
5721         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5722       } else {
5723         ShouldNotReachHere();
5724       }
5725     }
5726   case BotPTR:
5727     if (!WizardMode && !Verbose && _ptr != Constant) break;
5728   case TopPTR:
5729   case AnyNull:
5730     st->print(":%s", ptr_msg[_ptr]);
5731     if (_ptr == Constant) st->print(":exact");
5732     break;
5733   default:
5734     break;
5735   }
5736   if (Verbose) {
5737     if (_flatten_array) st->print(":flatten array");



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

6052   const TypeAryPtr *tary;
6053   const Type* el = elem();
6054   if (el->isa_narrowoop()) {
6055     el = el->make_ptr();
6056   }
6057 
6058   // Get element klass
6059   if (el->isa_instptr()) {
6060     // Compute object array klass from element klass
6061     bool null_free = el->is_inlinetypeptr() && el->isa_instptr()->ptr() != TypePtr::TopPTR && !el->isa_instptr()->maybe_null();
6062     k_ary = ciArrayKlass::make(el->is_oopptr()->klass(), null_free);
6063   } else if (el->isa_inlinetype()) {
6064     // If element type is TypeInlineType::BOTTOM, inline_klass() will be null.
6065     if (el->inline_klass() != NULL) {
6066       k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6067     }
6068   } else if ((tary = el->isa_aryptr()) != NULL) {
6069     // Compute array klass from element klass
6070     ciKlass* k_elem = tary->klass();
6071     // If element type is something like bottom[], k_elem will be null.
6072     if (k_elem != NULL)
6073       k_ary = ciObjArrayKlass::make(k_elem);
6074   } else if ((el->base() == Type::Top) ||
6075              (el->base() == Type::Bottom)) {
6076     // element type of Bottom occurs from meet of basic type
6077     // and object; Top occurs when doing join on Bottom.
6078     // Leave k_ary at NULL.
6079   } else {
6080     // Cannot compute array klass directly from basic type,
6081     // since subtypes of TypeInt all have basic type T_INT.
6082 #ifdef ASSERT
6083     if (verify && el->isa_int()) {
6084       // Check simple cases when verifying klass.
6085       BasicType bt = T_ILLEGAL;
6086       if (el == TypeInt::BYTE) {
6087         bt = T_BYTE;

6112 
6113   // Oops, need to compute _klass and cache it
6114   ciKlass* k_ary = compute_klass();
6115 
6116   if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
6117     // The _klass field acts as a cache of the underlying
6118     // ciKlass for this array type.  In order to set the field,
6119     // we need to cast away const-ness.
6120     //
6121     // IMPORTANT NOTE: we *never* set the _klass field for the
6122     // type TypeAryPtr::OOPS.  This Type is shared between all
6123     // active compilations.  However, the ciKlass which represents
6124     // this Type is *not* shared between compilations, so caching
6125     // this value would result in fetching a dangling pointer.
6126     //
6127     // Recomputing the underlying ciKlass for each request is
6128     // a bit less efficient than caching, but calls to
6129     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6130     ((TypeAryPtr*)this)->_klass = k_ary;
6131     if (UseCompressedOops && k_ary != NULL && k_ary->is_obj_array_klass() &&
6132         offset() != 0 && offset() != arrayOopDesc::length_offset_in_bytes()) {
6133       ((TypeAryPtr*)this)->_is_ptr_to_narrowoop = true;
6134     }
6135   }
6136   return k_ary;
6137 }
6138 
6139 
6140 //------------------------------add_offset-------------------------------------
6141 // Access internals of klass object
6142 const TypePtr *TypeAryKlassPtr::add_offset(intptr_t offset) const {
6143   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6144 }
6145 
6146 const TypeKlassPtr *TypeAryKlassPtr::with_offset(intptr_t offset) const {
6147   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6148 }
6149 
6150 //------------------------------cast_to_ptr_type-------------------------------
6151 const TypePtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6152   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6153   if (ptr == _ptr) return this;
6154   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6155 }
6156 
6157 bool TypeAryKlassPtr::must_be_exact() const {
6158   if (_elem == Type::BOTTOM) return false;
6159   if (_elem == Type::TOP   ) return false;
6160   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6161   if (!tk)             return true;   // a primitive type, like int
6162   return tk->must_be_exact();
6163 }
6164 
6165 
6166 //-----------------------------cast_to_exactness-------------------------------
6167 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6168   if (must_be_exact() && !klass_is_exact) return this;  // cannot clear xk
6169   ciKlass* k = _klass;
6170   const Type* elem = this->elem();
6171   if (elem->isa_klassptr() && !klass_is_exact) {
6172     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6173   }
6174   bool not_flat = is_not_flat();
6175   bool not_null_free = is_not_null_free();
6176   if (klass() != NULL && klass()->is_obj_array_klass() && klass_is_exact) {
6177     // An object array can't be flat or null-free if the klass is exact
6178     not_flat = true;
6179     not_null_free = true;
6180   }
6181   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6182 }
6183 
6184 
6185 //-----------------------------as_instance_type--------------------------------
6186 // Corresponding type for an instance of the given class.
6187 // It will be exact if and only if the klass type is exact.
6188 const TypeOopPtr* TypeAryKlassPtr::as_instance_type() const {
6189   ciKlass* k = klass();
6190   assert(k != NULL, "klass should not be NULL");
6191   bool    xk = klass_is_exact();
6192   const Type* el = elem()->isa_klassptr() ? elem()->is_klassptr()->as_instance_type()->is_oopptr()->cast_to_exactness(false) : elem();
6193   bool null_free = _null_free;
6194   if (null_free && el->isa_ptr()) {
6195     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6196   }
6197   bool not_flat = is_not_flat();
6198   bool not_null_free = is_not_null_free();
6199   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, not_flat, not_null_free), k, xk, Offset(0));
6200 }
6201 
6202 
6203 //------------------------------xmeet------------------------------------------
6204 // Compute the MEET of two types, return a new Type object.
6205 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6206   // Perform a fast test for common case; meeting the same types together.
6207   if( this == t ) return this;  // Meeting same type-rep?
6208 
6209   // Current "this->_base" is Pointer
6210   switch (t->base()) {          // switch on original type
6211 
6212   case Int:                     // Mixing ints & oops happens when javac
6213   case Long:                    // reuses local variables
6214   case FloatTop:
6215   case FloatCon:
6216   case FloatBot:
6217   case DoubleTop:
6218   case DoubleCon:
6219   case DoubleBot:
6220   case NarrowOop:
6221   case NarrowKlass:
6222   case Bottom:                  // Ye Olde Default
6223     return Type::BOTTOM;
6224   case Top:
6225     return this;
6226 
6227   default:                      // All else is a mistake
6228     typerr(t);
6229 
6230   case AnyPtr: {                // Meeting to AnyPtrs
6231     // Found an AnyPtr type vs self-KlassPtr type
6232     const TypePtr *tp = t->is_ptr();
6233     Offset offset = meet_offset(tp->offset());
6234     PTR ptr = meet_ptr(tp->ptr());
6235     switch (tp->ptr()) {
6236     case TopPTR:
6237       return this;
6238     case Null:
6239       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6240     case AnyNull:
6241       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), _null_free);
6242     case BotPTR:
6243     case NotNull:
6244       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6245     default: typerr(t);
6246     }
6247   }
6248 
6249   case RawPtr:
6250   case MetadataPtr:
6251   case OopPtr:
6252   case AryPtr:                  // Meet with AryPtr
6253   case InstPtr:                 // Meet with InstPtr
6254     return TypePtr::BOTTOM;
6255 
6256   //
6257   //             A-top         }
6258   //           /   |   \       }  Tops
6259   //       B-top A-any C-top   }
6260   //          | /  |  \ |      }  Any-nulls
6261   //       B-any   |   C-any   }
6262   //          |    |    |
6263   //       B-con A-con C-con   } constants; not comparable across classes
6264   //          |    |    |
6265   //       B-not   |   C-not   }
6266   //          | \  |  / |      }  not-nulls
6267   //       B-bot A-not C-bot   }
6268   //           \   |   /       }  Bottoms
6269   //             A-bot         }
6270   //
6271 
6272   case AryKlassPtr: {  // Meet two KlassPtr types
6273     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6274     Offset off = meet_offset(tap->offset());
6275     const Type* res_elem = NULL;

6276     PTR ptr = meet_ptr(tap->ptr());
6277     ciKlass* res_klass = NULL;
6278     bool res_xk = false;
6279     bool res_not_flat = false;
6280     bool res_not_null_free = false;
6281     MeetResult res = meet_aryptr(ptr, _elem, tap->_elem, this->klass(), tap->klass(),
6282                                  this->klass_is_exact(), tap->klass_is_exact(),
6283                                  this->ptr(), tap->ptr(), this->is_not_flat(), tap->is_not_flat(),
6284                                  this->is_not_null_free(), tap->is_not_null_free(),
6285                                  res_elem, res_klass, res_xk, res_not_flat, res_not_null_free);
6286     assert(res_xk == (ptr == Constant), "");
6287     bool null_free = meet_null_free(tap->_null_free);
6288     if (res == NOT_SUBTYPE) {
6289       null_free = false;
6290     } else if (res == SUBTYPE) {
6291       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6292         null_free = _null_free;
6293       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6294         null_free = tap->_null_free;
6295       }
6296     }
6297     return make(ptr, res_elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
6298   } // End of case KlassPtr
6299   case InstKlassPtr: {
6300     const TypeInstKlassPtr *tp = t->is_instklassptr();
6301     Offset offset = meet_offset(tp->offset());
6302     PTR ptr = meet_ptr(tp->ptr());
6303 
6304     switch (ptr) {
6305     case TopPTR:
6306     case AnyNull:                // Fall 'down' to dual of object klass
6307       // For instances when a subclass meets a superclass we fall
6308       // below the centerline when the superclass is exact. We need to
6309       // do the same here.
6310       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6311         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), _null_free);
6312       } else {
6313         // cannot subclass, so the meet has to fall badly below the centerline
6314         ptr = NotNull;
6315         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset, false);
6316       }
6317     case Constant:
6318     case NotNull:
6319     case BotPTR:                // Fall down to object klass
6320       // LCA is object_klass, but if we subclass from the top we can do better
6321       if (above_centerline(tp->ptr())) {
6322         // If 'tp'  is above the centerline and it is Object class
6323         // then we can subclass in the Java class hierarchy.
6324         // For instances when a subclass meets a superclass we fall
6325         // below the centerline when the superclass is exact. We need
6326         // to do the same here.
6327         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && !tp->klass_is_exact()) {
6328           // that is, my array type is a subtype of 'tp' klass
6329           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), _null_free);
6330         }
6331       }
6332       // The other case cannot happen, since t cannot be a subtype of an array.
6333       // The meet falls down to Object class below centerline.
6334       if (ptr == Constant)
6335          ptr = NotNull;
6336       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), offset, false);
6337     default: typerr(t);
6338     }
6339   }
6340   case InlineType: {
6341     const TypeInlineType* tv = t->is_inlinetype();
6342     if (above_centerline(ptr())) {
6343       return TypeInstKlassPtr::BOTTOM;
6344     } else {
6345       PTR ptr = this->_ptr;
6346       if (ptr == Constant) {
6347         ptr = NotNull;
6348       }
6349       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), Offset(0));
6350     }
6351   }
6352 
6353   } // End of switch
6354   return this;                  // Return the double constant
6355 }
6356 
6357 //------------------------------xdual------------------------------------------
6358 // Dual: compute field-by-field dual
6359 const Type    *TypeAryKlassPtr::xdual() const {
6360   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
6361 }
6362 
6363 //------------------------------get_con----------------------------------------
6364 ciKlass* TypeAryKlassPtr::klass() const {
6365     if (_klass != NULL) {
6366     return _klass;
6367   }
6368   ciKlass* k = NULL;
6369   const Type* el = elem();
6370   if (el->isa_instklassptr()) {
6371     // Compute object array klass from element klass
6372     bool null_free = el->is_instklassptr()->klass()->is_inlinetype() && el->isa_instklassptr()->ptr() != TypePtr::TopPTR && (_null_free != 0);
6373     k = ciArrayKlass::make(el->is_klassptr()->klass(), null_free);
6374     ((TypeAryKlassPtr*)this)->_klass = k;
6375   } else if (el->isa_inlinetype()) {
6376     // If element type is TypeInlineType::BOTTOM, inline_klass() will be null.
6377     if (el->inline_klass() != NULL) {
6378       k = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6379       ((TypeAryKlassPtr*)this)->_klass = k;
6380     }
6381   } else if (el->isa_aryklassptr() != NULL) {
6382     // Compute array klass from element klass
6383     ciKlass* k_elem = el->is_aryklassptr()->klass();
6384     // If element type is something like bottom[], k_elem will be null.
6385     if (k_elem != NULL) {
6386       k = ciObjArrayKlass::make(k_elem);
6387       ((TypeAryKlassPtr*)this)->_klass = k;
6388     }
6389   } else if ((elem()->base() == Type::Top) ||
6390              (elem()->base() == Type::Bottom)) {
6391   } else {
6392     k = ciTypeArrayKlass::make(elem()->basic_type());
6393   }
6394   return k;
6395 }
6396 
6397 //------------------------------dump2------------------------------------------
6398 // Dump Klass Type
6399 #ifndef PRODUCT
6400 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6401   switch( _ptr ) {
6402   case Constant:
6403     st->print("precise ");
6404   case NotNull:
6405     {
6406       st->print("[");
6407       if (_elem->isa_inlinetype()) {
6408         const char *name = _elem->is_inlinetype()->inline_klass()->name()->as_utf8();
6409         st->print("precise %s: " INTPTR_FORMAT " ", name, p2i(klass()));
6410       }
6411       _elem->dump2(d, depth, st);
6412       st->print(": ");
6413     }
6414   case BotPTR:
6415     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6416   case TopPTR:
6417   case AnyNull:
6418     st->print(":%s", ptr_msg[_ptr]);
6419     if( _ptr == Constant ) st->print(":exact");
6420     break;
6421   default:
6422     break;
6423   }
6424   if (Verbose) {
6425     if (_not_flat) st->print(":not flat");
6426     if (_not_null_free) st->print(":not null free");
6427     if (_null_free != 0) st->print(":null free(%d)", _null_free);

6428   }
6429 
6430   _offset.dump2(st);
6431 
6432   st->print(" *");
6433 }
6434 #endif
6435 
6436 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6437   const Type* elem = this->elem();
6438   dims = 1;
6439   while (elem->isa_aryklassptr()) {
6440     elem = elem->is_aryklassptr()->elem();
6441     dims++;
6442   }
6443   return elem;
6444 }
6445 
6446 //=============================================================================
6447 // Convenience common pre-built types.
6448 
6449 //------------------------------make-------------------------------------------
6450 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
6451                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
6452   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
6453 }
6454 
6455 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
6456   return make(domain, domain, range, range);
6457 }
6458 
6459 //------------------------------osr_domain-----------------------------
6460 const TypeTuple* osr_domain() {
6461   const Type **fields = TypeTuple::fields(2);
6462   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
6463   return TypeTuple::make(TypeFunc::Parms+1, fields);
6464 }
6465 
6466 //------------------------------make-------------------------------------------
6467 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
6468   Compile* C = Compile::current();
6469   const TypeFunc* tf = NULL;
6470   if (!is_osr_compilation) {
6471     tf = C->last_tf(method); // check cache
6472     if (tf != NULL)  return tf;  // The hit rate here is almost 50%.
6473   }
6474   // Inline types are not passed/returned by reference, instead each field of
6475   // the inline type is passed/returned as an argument. We maintain two views of
6476   // the argument/return list here: one based on the signature (with an inline
6477   // type argument/return as a single slot), one based on the actual calling
6478   // convention (with an inline type argument/return as a list of its fields).
6479   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
6480   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, false);
6481   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, true) : domain_sig;
6482   ciSignature* sig = method->signature();
6483   bool has_scalar_ret = sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
6484   const TypeTuple* range_sig = TypeTuple::make_range(sig, false);
6485   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, true) : range_sig;
6486   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
6487   if (!is_osr_compilation) {
6488     C->set_last_tf(method, tf);  // fill cache
6489   }



6490   return tf;
6491 }
6492 
6493 //------------------------------meet-------------------------------------------
6494 // Compute the MEET of two types.  It returns a new Type object.
6495 const Type *TypeFunc::xmeet( const Type *t ) const {
6496   // Perform a fast test for common case; meeting the same types together.
6497   if( this == t ) return this;  // Meeting same type-rep?
6498 
6499   // Current "this->_base" is Func
6500   switch (t->base()) {          // switch on original type
6501 
6502   case Bottom:                  // Ye Olde Default
6503     return t;
6504 
6505   default:                      // All else is a mistake
6506     typerr(t);
6507 
6508   case Top:
6509     break;
6510   }
6511   return this;                  // Return the double constant
6512 }
6513 
6514 //------------------------------xdual------------------------------------------
6515 // Dual: compute field-by-field dual
6516 const Type *TypeFunc::xdual() const {
6517   return this;
6518 }
6519 
6520 //------------------------------eq---------------------------------------------
6521 // Structural equality check for Type representations
6522 bool TypeFunc::eq( const Type *t ) const {
6523   const TypeFunc *a = (const TypeFunc*)t;
6524   return _domain_sig == a->_domain_sig &&
6525     _domain_cc == a->_domain_cc &&
6526     _range_sig == a->_range_sig &&
6527     _range_cc == a->_range_cc;
6528 }
6529 
6530 //------------------------------hash-------------------------------------------
6531 // Type-specific hashing function.
6532 int TypeFunc::hash(void) const {
6533   return (intptr_t)_domain_sig + (intptr_t)_domain_cc + (intptr_t)_range_sig + (intptr_t)_range_cc;
6534 }
6535 
6536 //------------------------------dump2------------------------------------------
6537 // Dump Function Type
6538 #ifndef PRODUCT
6539 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6540   if( _range_sig->cnt() <= Parms )
6541     st->print("void");
6542   else {
6543     uint i;
6544     for (i = Parms; i < _range_sig->cnt()-1; i++) {
6545       _range_sig->field_at(i)->dump2(d,depth,st);
6546       st->print("/");
6547     }
6548     _range_sig->field_at(i)->dump2(d,depth,st);
6549   }
6550   st->print(" ");
6551   st->print("( ");
6552   if( !depth || d[this] ) {     // Check for recursive dump
6553     st->print("...)");
6554     return;
6555   }
6556   d.Insert((void*)this,(void*)this);    // Stop recursion
6557   if (Parms < _domain_sig->cnt())
6558     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
6559   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
6560     st->print(", ");
6561     _domain_sig->field_at(i)->dump2(d,depth-1,st);
6562   }
6563   st->print(" )");
6564 }
6565 #endif
6566 
6567 //------------------------------singleton--------------------------------------
6568 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6569 // constants (Ldi nodes).  Singletons are integer, float or double constants
6570 // or a single symbol.
6571 bool TypeFunc::singleton(void) const {
6572   return false;                 // Never a singleton
6573 }
6574 
6575 bool TypeFunc::empty(void) const {
6576   return false;                 // Never empty
6577 }
6578 
6579 
6580 BasicType TypeFunc::return_type() const{
6581   if (range_sig()->cnt() == TypeFunc::Parms) {
6582     return T_VOID;
6583   }
6584   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
6585 }
< prev index next >