< 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/checkedCast.hpp"
  43 #include "utilities/powerOfTwo.hpp"
  44 #include "utilities/stringUtils.hpp"
  45 
  46 // Portions of code courtesy of Clifford Click
  47 
  48 // Optimization - Graph Style
  49 
  50 // Dictionary of types shared among compilations.
  51 Dict* Type::_shared_type_dict = nullptr;













































  52 
  53 // Array which maps compiler types to Basic Types
  54 const Type::TypeInfo Type::_type_info[Type::lastype] = {
  55   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
  56   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
  57   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
  58   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
  59   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
  60   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
  61   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
  62   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
  63   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
  64   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
  65   { Bad,             T_ARRAY,      "interfaces:",   false, Node::NotAMachineReg, relocInfo::none          },  // Interfaces
  66 
  67 #if defined(PPC64)
  68   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
  69   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
  70   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
  71   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD

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



 226   default:
 227     // make sure we did not mix up the cases:
 228     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 229     assert(type != ciTypeFlow::StateVector::top_type(), "");
 230     assert(type != ciTypeFlow::StateVector::null_type(), "");
 231     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 232     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 233     assert(!type->is_return_address(), "");
 234 
 235     return Type::get_const_type(type);
 236   }
 237 }
 238 
 239 
 240 //-----------------------make_from_constant------------------------------------
 241 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 242                                      int stable_dimension, bool is_narrow_oop,
 243                                      bool is_autobox_cache) {
 244   switch (constant.basic_type()) {
 245     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());

 512   const Type **ffalse =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 513   ffalse[0] = Type::CONTROL;
 514   ffalse[1] = Type::TOP;
 515   TypeTuple::IFFALSE = TypeTuple::make( 2, ffalse );
 516 
 517   const Type **fneither =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 518   fneither[0] = Type::TOP;
 519   fneither[1] = Type::TOP;
 520   TypeTuple::IFNEITHER = TypeTuple::make( 2, fneither );
 521 
 522   const Type **ftrue =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 523   ftrue[0] = Type::TOP;
 524   ftrue[1] = Type::CONTROL;
 525   TypeTuple::IFTRUE = TypeTuple::make( 2, ftrue );
 526 
 527   const Type **floop =(const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 528   floop[0] = Type::CONTROL;
 529   floop[1] = TypeInt::INT;
 530   TypeTuple::LOOPBODY = TypeTuple::make( 2, floop );
 531 
 532   TypePtr::NULL_PTR= TypePtr::make(AnyPtr, TypePtr::Null, 0);
 533   TypePtr::NOTNULL = TypePtr::make(AnyPtr, TypePtr::NotNull, OffsetBot);
 534   TypePtr::BOTTOM  = TypePtr::make(AnyPtr, TypePtr::BotPTR, OffsetBot);
 535 
 536   TypeRawPtr::BOTTOM = TypeRawPtr::make( TypePtr::BotPTR );
 537   TypeRawPtr::NOTNULL= TypeRawPtr::make( TypePtr::NotNull );
 538 
 539   const Type **fmembar = TypeTuple::fields(0);
 540   TypeTuple::MEMBAR = TypeTuple::make(TypeFunc::Parms+0, fmembar);
 541 
 542   const Type **fsc = (const Type**)shared_type_arena->AmallocWords(2*sizeof(Type*));
 543   fsc[0] = TypeInt::CC;
 544   fsc[1] = Type::MEMORY;
 545   TypeTuple::STORECONDITIONAL = TypeTuple::make(2, fsc);
 546 
 547   TypeInstPtr::NOTNULL = TypeInstPtr::make(TypePtr::NotNull, current->env()->Object_klass());
 548   TypeInstPtr::BOTTOM  = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass());
 549   TypeInstPtr::MIRROR  = TypeInstPtr::make(TypePtr::NotNull, current->env()->Class_klass());
 550   TypeInstPtr::MARK    = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 551                                            false, 0, oopDesc::mark_offset_in_bytes());
 552   TypeInstPtr::KLASS   = TypeInstPtr::make(TypePtr::BotPTR,  current->env()->Object_klass(),
 553                                            false, 0, oopDesc::klass_offset_in_bytes());
 554   TypeOopPtr::BOTTOM  = TypeOopPtr::make(TypePtr::BotPTR, OffsetBot, TypeOopPtr::InstanceBot);
 555 
 556   TypeMetadataPtr::BOTTOM = TypeMetadataPtr::make(TypePtr::BotPTR, nullptr, OffsetBot);
 557 
 558   TypeNarrowOop::NULL_PTR = TypeNarrowOop::make( TypePtr::NULL_PTR );
 559   TypeNarrowOop::BOTTOM   = TypeNarrowOop::make( TypeInstPtr::BOTTOM );
 560 
 561   TypeNarrowKlass::NULL_PTR = TypeNarrowKlass::make( TypePtr::NULL_PTR );
 562 
 563   mreg2type[Op_Node] = Type::BOTTOM;
 564   mreg2type[Op_Set ] = 0;
 565   mreg2type[Op_RegN] = TypeNarrowOop::BOTTOM;
 566   mreg2type[Op_RegI] = TypeInt::INT;
 567   mreg2type[Op_RegP] = TypePtr::BOTTOM;
 568   mreg2type[Op_RegF] = Type::FLOAT;
 569   mreg2type[Op_RegD] = Type::DOUBLE;
 570   mreg2type[Op_RegL] = TypeLong::LONG;
 571   mreg2type[Op_RegFlags] = TypeInt::CC;
 572 
 573   GrowableArray<ciInstanceKlass*> array_interfaces;
 574   array_interfaces.push(current->env()->Cloneable_klass());
 575   array_interfaces.push(current->env()->Serializable_klass());
 576   TypeAryPtr::_array_interfaces = TypeInterfaces::make(&array_interfaces);
 577   TypeAryKlassPtr::_array_interfaces = TypeAryPtr::_array_interfaces;
 578 
 579   TypeAryPtr::RANGE   = TypeAryPtr::make( TypePtr::BotPTR, TypeAry::make(Type::BOTTOM,TypeInt::POS), nullptr /* current->env()->Object_klass() */, false, arrayOopDesc::length_offset_in_bytes());
 580 
 581   TypeAryPtr::NARROWOOPS = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeNarrowOop::BOTTOM, TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
 582 
 583 #ifdef _LP64
 584   if (UseCompressedOops) {
 585     assert(TypeAryPtr::NARROWOOPS->is_ptr_to_narrowoop(), "array of narrow oops must be ptr to narrow oop");
 586     TypeAryPtr::OOPS  = TypeAryPtr::NARROWOOPS;
 587   } else
 588 #endif
 589   {
 590     // There is no shared klass for Object[].  See note in TypeAryPtr::klass().
 591     TypeAryPtr::OOPS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInstPtr::BOTTOM,TypeInt::POS), nullptr /*ciArrayKlass::make(o)*/,  false,  Type::OffsetBot);
 592   }
 593   TypeAryPtr::BYTES   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::BYTE      ,TypeInt::POS), ciTypeArrayKlass::make(T_BYTE),   true,  Type::OffsetBot);
 594   TypeAryPtr::SHORTS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::SHORT     ,TypeInt::POS), ciTypeArrayKlass::make(T_SHORT),  true,  Type::OffsetBot);
 595   TypeAryPtr::CHARS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::CHAR      ,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR),   true,  Type::OffsetBot);
 596   TypeAryPtr::INTS    = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeInt::INT       ,TypeInt::POS), ciTypeArrayKlass::make(T_INT),    true,  Type::OffsetBot);
 597   TypeAryPtr::LONGS   = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(TypeLong::LONG     ,TypeInt::POS), ciTypeArrayKlass::make(T_LONG),   true,  Type::OffsetBot);
 598   TypeAryPtr::FLOATS  = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::FLOAT        ,TypeInt::POS), ciTypeArrayKlass::make(T_FLOAT),  true,  Type::OffsetBot);
 599   TypeAryPtr::DOUBLES = TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(Type::DOUBLE       ,TypeInt::POS), ciTypeArrayKlass::make(T_DOUBLE), true,  Type::OffsetBot);

 600 
 601   // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
 602   TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
 603   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;

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

 654   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 655   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 656   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 657 
 658   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 659   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 660   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 661   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 662   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 663   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 664   _zero_type[T_INT]         = TypeInt::ZERO;
 665   _zero_type[T_LONG]        = TypeLong::ZERO;
 666   _zero_type[T_FLOAT]       = TypeF::ZERO;
 667   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 668   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 669   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop

 670   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 671   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 672 
 673   // get_zero_type() should not happen for T_CONFLICT
 674   _zero_type[T_CONFLICT]= nullptr;
 675 
 676   TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(TypeInt::BOOL, MaxVectorSize))->hashcons();
 677   mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
 678 
 679   if (Matcher::supports_scalable_vector()) {
 680     TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
 681   }
 682 
 683   // Vector predefined types, it needs initialized _const_basic_type[].
 684   if (Matcher::vector_size_supported(T_BYTE,4)) {
 685     TypeVect::VECTS = TypeVect::make(T_BYTE,4);
 686   }
 687   if (Matcher::vector_size_supported(T_FLOAT,2)) {
 688     TypeVect::VECTD = TypeVect::make(T_FLOAT,2);
 689   }

2106 
2107 bool TypeLong::empty(void) const {
2108   return _lo > _hi;
2109 }
2110 
2111 //=============================================================================
2112 // Convenience common pre-built types.
2113 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2114 const TypeTuple *TypeTuple::IFFALSE;
2115 const TypeTuple *TypeTuple::IFTRUE;
2116 const TypeTuple *TypeTuple::IFNEITHER;
2117 const TypeTuple *TypeTuple::LOOPBODY;
2118 const TypeTuple *TypeTuple::MEMBAR;
2119 const TypeTuple *TypeTuple::STORECONDITIONAL;
2120 const TypeTuple *TypeTuple::START_I2C;
2121 const TypeTuple *TypeTuple::INT_PAIR;
2122 const TypeTuple *TypeTuple::LONG_PAIR;
2123 const TypeTuple *TypeTuple::INT_CC_PAIR;
2124 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2125 













2126 //------------------------------make-------------------------------------------
2127 // Make a TypeTuple from the range of a method signature
2128 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
2129   ciType* return_type = sig->return_type();
2130   uint arg_cnt = return_type->size();







2131   const Type **field_array = fields(arg_cnt);
2132   switch (return_type->basic_type()) {
2133   case T_LONG:
2134     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2135     field_array[TypeFunc::Parms+1] = Type::HALF;
2136     break;
2137   case T_DOUBLE:
2138     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2139     field_array[TypeFunc::Parms+1] = Type::HALF;
2140     break;
2141   case T_OBJECT:













2142   case T_ARRAY:
2143   case T_BOOLEAN:
2144   case T_CHAR:
2145   case T_FLOAT:
2146   case T_BYTE:
2147   case T_SHORT:
2148   case T_INT:
2149     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2150     break;
2151   case T_VOID:
2152     break;
2153   default:
2154     ShouldNotReachHere();
2155   }
2156   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2157 }
2158 
2159 // Make a TypeTuple from the domain of a method signature
2160 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2161   uint arg_cnt = sig->size();








2162 
2163   uint pos = TypeFunc::Parms;
2164   const Type **field_array;
2165   if (recv != nullptr) {
2166     arg_cnt++;
2167     field_array = fields(arg_cnt);
2168     // Use get_const_type here because it respects UseUniqueSubclasses:
2169     field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2170   } else {
2171     field_array = fields(arg_cnt);
2172   }
2173 
2174   int i = 0;
2175   while (pos < TypeFunc::Parms + arg_cnt) {
2176     ciType* type = sig->type_at(i);

2177 
2178     switch (type->basic_type()) {
2179     case T_LONG:
2180       field_array[pos++] = TypeLong::LONG;
2181       field_array[pos++] = Type::HALF;
2182       break;
2183     case T_DOUBLE:
2184       field_array[pos++] = Type::DOUBLE;
2185       field_array[pos++] = Type::HALF;
2186       break;
2187     case T_OBJECT:










2188     case T_ARRAY:
2189     case T_FLOAT:
2190     case T_INT:
2191       field_array[pos++] = get_const_type(type, interface_handling);
2192       break;
2193     case T_BOOLEAN:
2194     case T_CHAR:
2195     case T_BYTE:
2196     case T_SHORT:
2197       field_array[pos++] = TypeInt::INT;
2198       break;
2199     default:
2200       ShouldNotReachHere();
2201     }
2202     i++;
2203   }

2204 
2205   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2206 }
2207 
2208 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2209   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2210 }
2211 
2212 //------------------------------fields-----------------------------------------
2213 // Subroutine call type with space allocated for argument types
2214 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2215 const Type **TypeTuple::fields( uint arg_cnt ) {
2216   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2217   flds[TypeFunc::Control  ] = Type::CONTROL;
2218   flds[TypeFunc::I_O      ] = Type::ABIO;
2219   flds[TypeFunc::Memory   ] = Type::MEMORY;
2220   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2221   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2222 
2223   return flds;

2318     if (_fields[i]->empty())  return true;
2319   }
2320   return false;
2321 }
2322 
2323 //=============================================================================
2324 // Convenience common pre-built types.
2325 
2326 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2327   // Certain normalizations keep us sane when comparing types.
2328   // We do not want arrayOop variables to differ only by the wideness
2329   // of their index types.  Pick minimum wideness, since that is the
2330   // forced wideness of small ranges anyway.
2331   if (size->_widen != Type::WidenMin)
2332     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2333   else
2334     return size;
2335 }
2336 
2337 //------------------------------make-------------------------------------------
2338 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {

2339   if (UseCompressedOops && elem->isa_oopptr()) {
2340     elem = elem->make_narrowoop();
2341   }
2342   size = normalize_array_size(size);
2343   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2344 }
2345 
2346 //------------------------------meet-------------------------------------------
2347 // Compute the MEET of two types.  It returns a new Type object.
2348 const Type *TypeAry::xmeet( const Type *t ) const {
2349   // Perform a fast test for common case; meeting the same types together.
2350   if( this == t ) return this;  // Meeting same type-rep?
2351 
2352   // Current "this->_base" is Ary
2353   switch (t->base()) {          // switch on original type
2354 
2355   case Bottom:                  // Ye Olde Default
2356     return t;
2357 
2358   default:                      // All else is a mistake
2359     typerr(t);
2360 
2361   case Array: {                 // Meeting 2 arrays?
2362     const TypeAry *a = t->is_ary();
2363     return TypeAry::make(_elem->meet_speculative(a->_elem),
2364                          _size->xmeet(a->_size)->is_int(),
2365                          _stable && a->_stable);



2366   }
2367   case Top:
2368     break;
2369   }
2370   return this;                  // Return the double constant
2371 }
2372 
2373 //------------------------------xdual------------------------------------------
2374 // Dual: compute field-by-field dual
2375 const Type *TypeAry::xdual() const {
2376   const TypeInt* size_dual = _size->dual()->is_int();
2377   size_dual = normalize_array_size(size_dual);
2378   return new TypeAry(_elem->dual(), size_dual, !_stable);
2379 }
2380 
2381 //------------------------------eq---------------------------------------------
2382 // Structural equality check for Type representations
2383 bool TypeAry::eq( const Type *t ) const {
2384   const TypeAry *a = (const TypeAry*)t;
2385   return _elem == a->_elem &&
2386     _stable == a->_stable &&
2387     _size == a->_size;




2388 }
2389 
2390 //------------------------------hash-------------------------------------------
2391 // Type-specific hashing function.
2392 uint TypeAry::hash(void) const {
2393   return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);

2394 }
2395 
2396 /**
2397  * Return same type without a speculative part in the element
2398  */
2399 const TypeAry* TypeAry::remove_speculative() const {
2400   return make(_elem->remove_speculative(), _size, _stable);
2401 }
2402 
2403 /**
2404  * Return same type with cleaned up speculative part of element
2405  */
2406 const Type* TypeAry::cleanup_speculative() const {
2407   return make(_elem->cleanup_speculative(), _size, _stable);
2408 }
2409 
2410 /**
2411  * Return same type but with a different inline depth (used for speculation)
2412  *
2413  * @param depth  depth to meet with
2414  */
2415 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2416   if (!UseInlineDepthForSpeculativeTypes) {
2417     return this;
2418   }
2419   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2420 }
2421 
2422 //------------------------------dump2------------------------------------------
2423 #ifndef PRODUCT
2424 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2425   if (_stable)  st->print("stable:");





2426   _elem->dump2(d, depth, st);
2427   st->print("[");
2428   _size->dump2(d, depth, st);
2429   st->print("]");
2430 }
2431 #endif
2432 
2433 //------------------------------singleton--------------------------------------
2434 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2435 // constants (Ldi nodes).  Singletons are integer, float or double constants
2436 // or a single symbol.
2437 bool TypeAry::singleton(void) const {
2438   return false;                 // Never a singleton
2439 }
2440 
2441 bool TypeAry::empty(void) const {
2442   return _elem->empty() || _size->empty();
2443 }
2444 
2445 //--------------------------ary_must_be_exact----------------------------------
2446 bool TypeAry::ary_must_be_exact() const {
2447   // This logic looks at the element type of an array, and returns true
2448   // if the element type is either a primitive or a final instance class.
2449   // In such cases, an array built on this ary must have no subclasses.
2450   if (_elem == BOTTOM)      return false;  // general array not exact
2451   if (_elem == TOP   )      return false;  // inverted general array not exact
2452   const TypeOopPtr*  toop = nullptr;
2453   if (UseCompressedOops && _elem->isa_narrowoop()) {
2454     toop = _elem->make_ptr()->isa_oopptr();
2455   } else {
2456     toop = _elem->isa_oopptr();
2457   }
2458   if (!toop)                return true;   // a primitive type, like int
2459   if (!toop->is_loaded())   return false;  // unloaded class
2460   const TypeInstPtr* tinst;
2461   if (_elem->isa_narrowoop())
2462     tinst = _elem->make_ptr()->isa_instptr();
2463   else
2464     tinst = _elem->isa_instptr();
2465   if (tinst)
2466     return tinst->instance_klass()->is_final();








2467   const TypeAryPtr*  tap;
2468   if (_elem->isa_narrowoop())
2469     tap = _elem->make_ptr()->isa_aryptr();
2470   else
2471     tap = _elem->isa_aryptr();
2472   if (tap)
2473     return tap->ary()->ary_must_be_exact();
2474   return false;
2475 }
2476 
2477 //==============================TypeVect=======================================
2478 // Convenience common pre-built types.
2479 const TypeVect *TypeVect::VECTA = nullptr; // vector length agnostic
2480 const TypeVect *TypeVect::VECTS = nullptr; //  32-bit vectors
2481 const TypeVect *TypeVect::VECTD = nullptr; //  64-bit vectors
2482 const TypeVect *TypeVect::VECTX = nullptr; // 128-bit vectors
2483 const TypeVect *TypeVect::VECTY = nullptr; // 256-bit vectors
2484 const TypeVect *TypeVect::VECTZ = nullptr; // 512-bit vectors
2485 const TypeVect *TypeVect::VECTMASK = nullptr; // predicate/mask vector
2486 

2642 
2643 //=============================================================================
2644 // Convenience common pre-built types.
2645 const TypePtr *TypePtr::NULL_PTR;
2646 const TypePtr *TypePtr::NOTNULL;
2647 const TypePtr *TypePtr::BOTTOM;
2648 
2649 //------------------------------meet-------------------------------------------
2650 // Meet over the PTR enum
2651 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2652   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2653   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2654   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2655   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2656   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2657   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2658   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2659 };
2660 
2661 //------------------------------make-------------------------------------------
2662 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2663   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2664 }
2665 
2666 //------------------------------cast_to_ptr_type-------------------------------
2667 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2668   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2669   if( ptr == _ptr ) return this;
2670   return make(_base, ptr, _offset, _speculative, _inline_depth);
2671 }
2672 
2673 //------------------------------get_con----------------------------------------
2674 intptr_t TypePtr::get_con() const {
2675   assert( _ptr == Null, "" );
2676   return _offset;
2677 }
2678 
2679 //------------------------------meet-------------------------------------------
2680 // Compute the MEET of two types.  It returns a new Type object.
2681 const Type *TypePtr::xmeet(const Type *t) const {
2682   const Type* res = xmeet_helper(t);
2683   if (res->isa_ptr() == nullptr) {
2684     return res;
2685   }
2686 
2687   const TypePtr* res_ptr = res->is_ptr();
2688   if (res_ptr->speculative() != nullptr) {
2689     // type->speculative() is null means that speculation is no better
2690     // than type, i.e. type->speculative() == type. So there are 2
2691     // ways to represent the fact that we have no useful speculative
2692     // data and we should use a single one to be able to test for
2693     // equality between types. Check whether type->speculative() ==
2694     // type and set speculative to null if it is the case.
2695     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2696       return res_ptr->remove_speculative();

2727     int depth = meet_inline_depth(tp->inline_depth());
2728     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2729   }
2730   case RawPtr:                  // For these, flip the call around to cut down
2731   case OopPtr:
2732   case InstPtr:                 // on the cases I have to handle.
2733   case AryPtr:
2734   case MetadataPtr:
2735   case KlassPtr:
2736   case InstKlassPtr:
2737   case AryKlassPtr:
2738     return t->xmeet(this);      // Call in reverse direction
2739   default:                      // All else is a mistake
2740     typerr(t);
2741 
2742   }
2743   return this;
2744 }
2745 
2746 //------------------------------meet_offset------------------------------------
2747 int TypePtr::meet_offset( int offset ) const {
2748   // Either is 'TOP' offset?  Return the other offset!
2749   if( _offset == OffsetTop ) return offset;
2750   if( offset == OffsetTop ) return _offset;
2751   // If either is different, return 'BOTTOM' offset
2752   if( _offset != offset ) return OffsetBot;
2753   return _offset;
2754 }
2755 
2756 //------------------------------dual_offset------------------------------------
2757 int TypePtr::dual_offset( ) const {
2758   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2759   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2760   return _offset;               // Map everything else into self
2761 }
2762 
2763 //------------------------------xdual------------------------------------------
2764 // Dual: compute field-by-field dual
2765 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2766   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2767 };
2768 const Type *TypePtr::xdual() const {
2769   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2770 }
2771 
2772 //------------------------------xadd_offset------------------------------------
2773 int TypePtr::xadd_offset( intptr_t offset ) const {
2774   // Adding to 'TOP' offset?  Return 'TOP'!
2775   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2776   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2777   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2778   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2779   offset += (intptr_t)_offset;
2780   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2781 
2782   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2783   // It is possible to construct a negative offset during PhaseCCP
2784 
2785   return (int)offset;        // Sum valid offsets
2786 }
2787 
2788 //------------------------------add_offset-------------------------------------
2789 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2790   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2791 }
2792 
2793 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2794   return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2795 }
2796 
2797 //------------------------------eq---------------------------------------------
2798 // Structural equality check for Type representations
2799 bool TypePtr::eq( const Type *t ) const {
2800   const TypePtr *a = (const TypePtr*)t;
2801   return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2802 }
2803 
2804 //------------------------------hash-------------------------------------------
2805 // Type-specific hashing function.
2806 uint TypePtr::hash(void) const {
2807   return (uint)_ptr + (uint)_offset + (uint)hash_speculative() + (uint)_inline_depth;
2808 }
2809 
2810 /**
2811  * Return same type without a speculative part
2812  */
2813 const TypePtr* TypePtr::remove_speculative() const {
2814   if (_speculative == nullptr) {
2815     return this;
2816   }
2817   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2818   return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2819 }
2820 
2821 /**
2822  * Return same type but drop speculative part if we know we won't use
2823  * it
2824  */
2825 const Type* TypePtr::cleanup_speculative() const {
2826   if (speculative() == nullptr) {
2827     return this;

3053   }
3054   // We already know the speculative type is always null
3055   if (speculative_always_null()) {
3056     return false;
3057   }
3058   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3059     return false;
3060   }
3061   return true;
3062 }
3063 
3064 //------------------------------dump2------------------------------------------
3065 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3066   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3067 };
3068 
3069 #ifndef PRODUCT
3070 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3071   if( _ptr == Null ) st->print("null");
3072   else st->print("%s *", ptr_msg[_ptr]);
3073   if( _offset == OffsetTop ) st->print("+top");
3074   else if( _offset == OffsetBot ) st->print("+bot");
3075   else if( _offset ) st->print("+%d", _offset);
3076   dump_inline_depth(st);
3077   dump_speculative(st);
3078 }
3079 
3080 /**
3081  *dump the speculative part of the type
3082  */
3083 void TypePtr::dump_speculative(outputStream *st) const {
3084   if (_speculative != nullptr) {
3085     st->print(" (speculative=");
3086     _speculative->dump_on(st);
3087     st->print(")");
3088   }
3089 }
3090 
3091 /**
3092  *dump the inline depth of the type
3093  */
3094 void TypePtr::dump_inline_depth(outputStream *st) const {
3095   if (_inline_depth != InlineDepthBottom) {
3096     if (_inline_depth == InlineDepthTop) {
3097       st->print(" (inline_depth=InlineDepthTop)");
3098     } else {
3099       st->print(" (inline_depth=%d)", _inline_depth);
3100     }
3101   }
3102 }
3103 #endif
3104 
3105 //------------------------------singleton--------------------------------------
3106 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3107 // constants
3108 bool TypePtr::singleton(void) const {
3109   // TopPTR, Null, AnyNull, Constant are all singletons
3110   return (_offset != OffsetBot) && !below_centerline(_ptr);
3111 }
3112 
3113 bool TypePtr::empty(void) const {
3114   return (_offset == OffsetTop) || above_centerline(_ptr);
3115 }
3116 
3117 //=============================================================================
3118 // Convenience common pre-built types.
3119 const TypeRawPtr *TypeRawPtr::BOTTOM;
3120 const TypeRawPtr *TypeRawPtr::NOTNULL;
3121 
3122 //------------------------------make-------------------------------------------
3123 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3124   assert( ptr != Constant, "what is the constant?" );
3125   assert( ptr != Null, "Use TypePtr for null" );
3126   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3127 }
3128 
3129 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3130   assert( bits, "Use TypePtr for null" );
3131   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3132 }
3133 
3134 //------------------------------cast_to_ptr_type-------------------------------

3486 void TypeInterfaces::verify_is_loaded() const {
3487   for (int i = 0; i < _list.length(); i++) {
3488     ciKlass* interface = _list.at(i);
3489     assert(interface->is_loaded(), "Interface not loaded");
3490   }
3491 }
3492 #endif
3493 
3494 // Can't be implemented because there's no way to know if the type is above or below the center line.
3495 const Type* TypeInterfaces::xmeet(const Type* t) const {
3496   ShouldNotReachHere();
3497   return Type::xmeet(t);
3498 }
3499 
3500 bool TypeInterfaces::singleton(void) const {
3501   ShouldNotReachHere();
3502   return Type::singleton();
3503 }
3504 
3505 //------------------------------TypeOopPtr-------------------------------------
3506 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3507                        int instance_id, const TypePtr* speculative, int inline_depth)
3508   : TypePtr(t, ptr, offset, speculative, inline_depth),
3509     _const_oop(o), _klass(k),
3510     _interfaces(interfaces),
3511     _klass_is_exact(xk),
3512     _is_ptr_to_narrowoop(false),
3513     _is_ptr_to_narrowklass(false),
3514     _is_ptr_to_boxed_value(false),
3515     _instance_id(instance_id) {
3516 #ifdef ASSERT
3517   if (klass() != nullptr && klass()->is_loaded()) {
3518     interfaces->verify_is_loaded();
3519   }
3520 #endif
3521   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3522       (offset > 0) && xk && (k != 0) && k->is_instance_klass()) {
3523     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3524   }
3525 #ifdef _LP64
3526   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3527     if (_offset == oopDesc::klass_offset_in_bytes()) {
3528       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3529     } else if (klass() == nullptr) {
3530       // Array with unknown body type
3531       assert(this->isa_aryptr(), "only arrays without klass");
3532       _is_ptr_to_narrowoop = UseCompressedOops;
3533     } else if (this->isa_aryptr()) {
3534       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3535                              _offset != arrayOopDesc::length_offset_in_bytes());









3536     } else if (klass()->is_instance_klass()) {
3537       ciInstanceKlass* ik = klass()->as_instance_klass();
3538       if (this->isa_klassptr()) {
3539         // Perm objects don't use compressed references
3540       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3541         // unsafe access
3542         _is_ptr_to_narrowoop = UseCompressedOops;
3543       } else {
3544         assert(this->isa_instptr(), "must be an instance ptr.");
3545 
3546         if (klass() == ciEnv::current()->Class_klass() &&
3547             (_offset == java_lang_Class::klass_offset() ||
3548              _offset == java_lang_Class::array_klass_offset())) {
3549           // Special hidden fields from the Class.
3550           assert(this->isa_instptr(), "must be an instance ptr.");
3551           _is_ptr_to_narrowoop = false;
3552         } else if (klass() == ciEnv::current()->Class_klass() &&
3553                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3554           // Static fields
3555           ciField* field = nullptr;
3556           if (const_oop() != nullptr) {
3557             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3558             field = k->get_field_by_offset(_offset, true);
3559           }
3560           if (field != nullptr) {
3561             BasicType basic_elem_type = field->layout_type();
3562             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3563           } else {
3564             // unsafe access
3565             _is_ptr_to_narrowoop = UseCompressedOops;






3566           }
3567         } else {
3568           // Instance fields which contains a compressed oop references.
3569           ciField* field = ik->get_field_by_offset(_offset, false);

3570           if (field != nullptr) {
3571             BasicType basic_elem_type = field->layout_type();
3572             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3573           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3574             // Compile::find_alias_type() cast exactness on all types to verify
3575             // that it does not affect alias type.
3576             _is_ptr_to_narrowoop = UseCompressedOops;
3577           } else {
3578             // Type for the copy start in LibraryCallKit::inline_native_clone().
3579             _is_ptr_to_narrowoop = UseCompressedOops;
3580           }
3581         }
3582       }
3583     }
3584   }
3585 #endif
3586 }
3587 
3588 //------------------------------make-------------------------------------------
3589 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3590                                      const TypePtr* speculative, int inline_depth) {
3591   assert(ptr != Constant, "no constant generic pointers");
3592   ciKlass*  k = Compile::current()->env()->Object_klass();
3593   bool      xk = false;
3594   ciObject* o = nullptr;
3595   const TypeInterfaces* interfaces = TypeInterfaces::make();
3596   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3597 }
3598 
3599 
3600 //------------------------------cast_to_ptr_type-------------------------------
3601 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3602   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3603   if( ptr == _ptr ) return this;
3604   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3605 }
3606 
3607 //-----------------------------cast_to_instance_id----------------------------
3608 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3609   // There are no instances of a general oop.
3610   // Return self unchanged.
3611   return this;
3612 }
3613 
3614 //-----------------------------cast_to_exactness-------------------------------
3615 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3616   // There is no such thing as an exact general oop.
3617   // Return self unchanged.
3618   return this;
3619 }
3620 
3621 
3622 //------------------------------as_klass_type----------------------------------
3623 // Return the klass type corresponding to this instance or array type.
3624 // It is the type that is loaded from an object of this type.
3625 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3626   ShouldNotReachHere();
3627   return nullptr;
3628 }
3629 
3630 //------------------------------meet-------------------------------------------
3631 // Compute the MEET of two types.  It returns a new Type object.
3632 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3633   // Perform a fast test for common case; meeting the same types together.
3634   if( this == t ) return this;  // Meeting same type-rep?
3635 
3636   // Current "this->_base" is OopPtr
3637   switch (t->base()) {          // switch on original type
3638 
3639   case Int:                     // Mixing ints & oops happens when javac
3640   case Long:                    // reuses local variables
3641   case FloatTop:

3647   case NarrowOop:
3648   case NarrowKlass:
3649   case Bottom:                  // Ye Olde Default
3650     return Type::BOTTOM;
3651   case Top:
3652     return this;
3653 
3654   default:                      // All else is a mistake
3655     typerr(t);
3656 
3657   case RawPtr:
3658   case MetadataPtr:
3659   case KlassPtr:
3660   case InstKlassPtr:
3661   case AryKlassPtr:
3662     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3663 
3664   case AnyPtr: {
3665     // Found an AnyPtr type vs self-OopPtr type
3666     const TypePtr *tp = t->is_ptr();
3667     int offset = meet_offset(tp->offset());
3668     PTR ptr = meet_ptr(tp->ptr());
3669     const TypePtr* speculative = xmeet_speculative(tp);
3670     int depth = meet_inline_depth(tp->inline_depth());
3671     switch (tp->ptr()) {
3672     case Null:
3673       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3674       // else fall through:
3675     case TopPTR:
3676     case AnyNull: {
3677       int instance_id = meet_instance_id(InstanceTop);
3678       return make(ptr, offset, instance_id, speculative, depth);
3679     }
3680     case BotPTR:
3681     case NotNull:
3682       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3683     default: typerr(t);
3684     }
3685   }
3686 
3687   case OopPtr: {                 // Meeting to other OopPtrs

3689     int instance_id = meet_instance_id(tp->instance_id());
3690     const TypePtr* speculative = xmeet_speculative(tp);
3691     int depth = meet_inline_depth(tp->inline_depth());
3692     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3693   }
3694 
3695   case InstPtr:                  // For these, flip the call around to cut down
3696   case AryPtr:
3697     return t->xmeet(this);      // Call in reverse direction
3698 
3699   } // End of switch
3700   return this;                  // Return the double constant
3701 }
3702 
3703 
3704 //------------------------------xdual------------------------------------------
3705 // Dual of a pure heap pointer.  No relevant klass or oop information.
3706 const Type *TypeOopPtr::xdual() const {
3707   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3708   assert(const_oop() == nullptr,             "no constants here");
3709   return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3710 }
3711 
3712 //--------------------------make_from_klass_common-----------------------------
3713 // Computes the element-type given a klass.
3714 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3715   if (klass->is_instance_klass()) {
3716     Compile* C = Compile::current();
3717     Dependencies* deps = C->dependencies();
3718     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3719     // Element is an instance
3720     bool klass_is_exact = false;
3721     if (klass->is_loaded()) {
3722       // Try to set klass_is_exact.
3723       ciInstanceKlass* ik = klass->as_instance_klass();
3724       klass_is_exact = ik->is_final();
3725       if (!klass_is_exact && klass_change
3726           && deps != nullptr && UseUniqueSubclasses) {
3727         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3728         if (sub != nullptr) {
3729           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3730           klass = ik = sub;
3731           klass_is_exact = sub->is_final();
3732         }
3733       }
3734       if (!klass_is_exact && try_for_exact && deps != nullptr &&
3735           !ik->is_interface() && !ik->has_subklass()) {
3736         // Add a dependence; if concrete subclass added we need to recompile
3737         deps->assert_leaf_type(ik);
3738         klass_is_exact = true;
3739       }
3740     }
3741     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3742     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3743   } else if (klass->is_obj_array_klass()) {
3744     // Element is an object array. Recursively call ourself.
3745     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3746     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3747     bool xk = etype->klass_is_exact();
3748     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);













3749     // We used to pass NotNull in here, asserting that the sub-arrays
3750     // are all not-null.  This is not true in generally, as code can
3751     // slam nulls down in the subarrays.
3752     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3753     return arr;
3754   } else if (klass->is_type_array_klass()) {
3755     // Element is an typeArray
3756     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3757     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

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






3761     return arr;
3762   } else {
3763     ShouldNotReachHere();
3764     return nullptr;
3765   }
3766 }
3767 
3768 //------------------------------make_from_constant-----------------------------
3769 // Make a java pointer from an oop constant
3770 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3771   assert(!o->is_null_object(), "null object not yet handled here.");
3772 
3773   const bool make_constant = require_constant || o->should_be_constant();
3774 
3775   ciKlass* klass = o->klass();
3776   if (klass->is_instance_klass()) {
3777     // Element is an instance
3778     if (make_constant) {
3779       return TypeInstPtr::make(o);
3780     } else {
3781       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3782     }
3783   } else if (klass->is_obj_array_klass()) {
3784     // Element is an object array. Recursively call ourself.
3785     const TypeOopPtr *etype =
3786       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3787     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));





3788     // We used to pass NotNull in here, asserting that the sub-arrays
3789     // are all not-null.  This is not true in generally, as code can
3790     // slam nulls down in the subarrays.
3791     if (make_constant) {
3792       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3793     } else {
3794       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3795     }
3796   } else if (klass->is_type_array_klass()) {
3797     // Element is an typeArray
3798     const Type* etype =
3799       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3800     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3801     // We used to pass NotNull in here, asserting that the array pointer
3802     // is not-null. That was not true in general.
3803     if (make_constant) {
3804       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3805     } else {
3806       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);












3807     }
3808   }
3809 
3810   fatal("unhandled object type");
3811   return nullptr;
3812 }
3813 
3814 //------------------------------get_con----------------------------------------
3815 intptr_t TypeOopPtr::get_con() const {
3816   assert( _ptr == Null || _ptr == Constant, "" );
3817   assert( _offset >= 0, "" );
3818 
3819   if (_offset != 0) {
3820     // After being ported to the compiler interface, the compiler no longer
3821     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3822     // to a handle at compile time.  This handle is embedded in the generated
3823     // code and dereferenced at the time the nmethod is made.  Until that time,
3824     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3825     // have access to the addresses!).  This does not seem to currently happen,
3826     // but this assertion here is to help prevent its occurrence.
3827     tty->print_cr("Found oop constant with non-zero offset");
3828     ShouldNotReachHere();
3829   }
3830 
3831   return (intptr_t)const_oop()->constant_encoding();
3832 }
3833 
3834 
3835 //-----------------------------filter------------------------------------------
3836 // Do not allow interface-vs.-noninterface joins to collapse to top.
3837 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3838 
3839   const Type* ft = join_helper(kills, include_speculative);

3860   } else {
3861     return one->equals(two) && TypePtr::eq(t);
3862   }
3863 }
3864 
3865 //------------------------------hash-------------------------------------------
3866 // Type-specific hashing function.
3867 uint TypeOopPtr::hash(void) const {
3868   return
3869     (uint)(const_oop() ? const_oop()->hash() : 0) +
3870     (uint)_klass_is_exact +
3871     (uint)_instance_id + TypePtr::hash();
3872 }
3873 
3874 //------------------------------dump2------------------------------------------
3875 #ifndef PRODUCT
3876 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3877   st->print("oopptr:%s", ptr_msg[_ptr]);
3878   if( _klass_is_exact ) st->print(":exact");
3879   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3880   switch( _offset ) {
3881   case OffsetTop: st->print("+top"); break;
3882   case OffsetBot: st->print("+any"); break;
3883   case         0: break;
3884   default:        st->print("+%d",_offset); break;
3885   }
3886   if (_instance_id == InstanceTop)
3887     st->print(",iid=top");
3888   else if (_instance_id != InstanceBot)
3889     st->print(",iid=%d",_instance_id);
3890 
3891   dump_inline_depth(st);
3892   dump_speculative(st);
3893 }
3894 #endif
3895 
3896 //------------------------------singleton--------------------------------------
3897 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3898 // constants
3899 bool TypeOopPtr::singleton(void) const {
3900   // detune optimizer to not generate constant oop + constant offset as a constant!
3901   // TopPTR, Null, AnyNull, Constant are all singletons
3902   return (_offset == 0) && !below_centerline(_ptr);
3903 }
3904 
3905 //------------------------------add_offset-------------------------------------
3906 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3907   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3908 }
3909 
3910 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3911   return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3912 }
3913 
3914 /**
3915  * Return same type without a speculative part
3916  */
3917 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3918   if (_speculative == nullptr) {
3919     return this;
3920   }
3921   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3922   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
3923 }
3924 
3925 /**
3926  * Return same type but drop speculative part if we know we won't use
3927  * it
3928  */
3929 const Type* TypeOopPtr::cleanup_speculative() const {
3930   // If the klass is exact and the ptr is not null then there's
3931   // nothing that the speculative type can help us with

4004 const TypeInstPtr *TypeInstPtr::BOTTOM;
4005 const TypeInstPtr *TypeInstPtr::MIRROR;
4006 const TypeInstPtr *TypeInstPtr::MARK;
4007 const TypeInstPtr *TypeInstPtr::KLASS;
4008 
4009 // Is there a single ciKlass* that can represent that type?
4010 ciKlass* TypeInstPtr::exact_klass_helper() const {
4011   if (_interfaces->empty()) {
4012     return _klass;
4013   }
4014   if (_klass != ciEnv::current()->Object_klass()) {
4015     if (_interfaces->eq(_klass->as_instance_klass())) {
4016       return _klass;
4017     }
4018     return nullptr;
4019   }
4020   return _interfaces->exact_klass();
4021 }
4022 
4023 //------------------------------TypeInstPtr-------------------------------------
4024 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
4025                          int instance_id, const TypePtr* speculative, int inline_depth)
4026   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {

4027   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4028   assert(k != nullptr &&
4029          (k->is_loaded() || o == nullptr),
4030          "cannot have constants with non-loaded klass");


4031 };
4032 
4033 //------------------------------make-------------------------------------------
4034 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4035                                      ciKlass* k,
4036                                      const TypeInterfaces* interfaces,
4037                                      bool xk,
4038                                      ciObject* o,
4039                                      int offset,

4040                                      int instance_id,
4041                                      const TypePtr* speculative,
4042                                      int inline_depth) {
4043   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4044   // Either const_oop() is null or else ptr is Constant
4045   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4046           "constant pointers must have a value supplied" );
4047   // Ptr is never Null
4048   assert( ptr != Null, "null pointers are not typed" );
4049 
4050   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4051   if (ptr == Constant) {
4052     // Note:  This case includes meta-object constants, such as methods.
4053     xk = true;
4054   } else if (k->is_loaded()) {
4055     ciInstanceKlass* ik = k->as_instance_klass();
4056     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4057     assert(!ik->is_interface(), "no interface here");
4058     if (xk && ik->is_interface())  xk = false;  // no exact interface
4059   }
4060 



4061   // Now hash this baby
4062   TypeInstPtr *result =
4063     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4064 
4065   return result;
4066 }
4067 
4068 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4069   if (k->is_instance_klass()) {
4070     if (k->is_loaded()) {
4071       if (k->is_interface() && interface_handling == ignore_interfaces) {
4072         assert(interface, "no interface expected");
4073         k = ciEnv::current()->Object_klass();
4074         const TypeInterfaces* interfaces = TypeInterfaces::make();
4075         return interfaces;
4076       }
4077       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4078       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4079       if (k->is_interface()) {
4080         assert(interface, "no interface expected");
4081         k = ciEnv::current()->Object_klass();
4082       } else {
4083         assert(klass, "no instance klass expected");

4109   switch (bt) {
4110     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4111     case T_INT:      return TypeInt::make(constant.as_int());
4112     case T_CHAR:     return TypeInt::make(constant.as_char());
4113     case T_BYTE:     return TypeInt::make(constant.as_byte());
4114     case T_SHORT:    return TypeInt::make(constant.as_short());
4115     case T_FLOAT:    return TypeF::make(constant.as_float());
4116     case T_DOUBLE:   return TypeD::make(constant.as_double());
4117     case T_LONG:     return TypeLong::make(constant.as_long());
4118     default:         break;
4119   }
4120   fatal("Invalid boxed value type '%s'", type2name(bt));
4121   return nullptr;
4122 }
4123 
4124 //------------------------------cast_to_ptr_type-------------------------------
4125 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4126   if( ptr == _ptr ) return this;
4127   // Reconstruct _sig info here since not a problem with later lazy
4128   // construction, _sig will show up on demand.
4129   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4130 }
4131 
4132 
4133 //-----------------------------cast_to_exactness-------------------------------
4134 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4135   if( klass_is_exact == _klass_is_exact ) return this;
4136   if (!_klass->is_loaded())  return this;
4137   ciInstanceKlass* ik = _klass->as_instance_klass();
4138   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4139   assert(!ik->is_interface(), "no interface here");
4140   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
4141 }
4142 
4143 //-----------------------------cast_to_instance_id----------------------------
4144 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4145   if( instance_id == _instance_id ) return this;
4146   return make(_ptr, klass(),  _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4147 }
4148 
4149 //------------------------------xmeet_unloaded---------------------------------
4150 // Compute the MEET of two InstPtrs when at least one is unloaded.
4151 // Assume classes are different since called after check for same name/class-loader
4152 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4153   int off = meet_offset(tinst->offset());
4154   PTR ptr = meet_ptr(tinst->ptr());
4155   int instance_id = meet_instance_id(tinst->instance_id());
4156   const TypePtr* speculative = xmeet_speculative(tinst);
4157   int depth = meet_inline_depth(tinst->inline_depth());
4158 
4159   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4160   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4161   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4162     //
4163     // Meet unloaded class with java/lang/Object
4164     //
4165     // Meet
4166     //          |                     Unloaded Class
4167     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4168     //  ===================================================================
4169     //   TOP    | ..........................Unloaded......................|
4170     //  AnyNull |  U-AN    |................Unloaded......................|
4171     // Constant | ... O-NN .................................. |   O-BOT   |
4172     //  NotNull | ... O-NN .................................. |   O-BOT   |
4173     //  BOTTOM  | ........................Object-BOTTOM ..................|
4174     //
4175     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4176     //
4177     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded; }
4178     else if (loaded->ptr() == TypePtr::AnyNull)  { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }
4179     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM; }
4180     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4181       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM;  }
4182       else                                       { return TypeInstPtr::NOTNULL; }
4183     }
4184     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded; }
4185 
4186     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4187   }
4188 
4189   // Both are unloaded, not the same class, not Object
4190   // Or meet unloaded with a different loaded class, not java/lang/Object
4191   if (ptr != TypePtr::BotPTR) {
4192     return TypeInstPtr::NOTNULL;
4193   }
4194   return TypeInstPtr::BOTTOM;
4195 }
4196 
4197 
4198 //------------------------------meet-------------------------------------------

4219   case Top:
4220     return this;
4221 
4222   default:                      // All else is a mistake
4223     typerr(t);
4224 
4225   case MetadataPtr:
4226   case KlassPtr:
4227   case InstKlassPtr:
4228   case AryKlassPtr:
4229   case RawPtr: return TypePtr::BOTTOM;
4230 
4231   case AryPtr: {                // All arrays inherit from Object class
4232     // Call in reverse direction to avoid duplication
4233     return t->is_aryptr()->xmeet_helper(this);
4234   }
4235 
4236   case OopPtr: {                // Meeting to OopPtrs
4237     // Found a OopPtr type vs self-InstPtr type
4238     const TypeOopPtr *tp = t->is_oopptr();
4239     int offset = meet_offset(tp->offset());
4240     PTR ptr = meet_ptr(tp->ptr());
4241     switch (tp->ptr()) {
4242     case TopPTR:
4243     case AnyNull: {
4244       int instance_id = meet_instance_id(InstanceTop);
4245       const TypePtr* speculative = xmeet_speculative(tp);
4246       int depth = meet_inline_depth(tp->inline_depth());
4247       return make(ptr, klass(), _interfaces, klass_is_exact(),
4248                   (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4249     }
4250     case NotNull:
4251     case BotPTR: {
4252       int instance_id = meet_instance_id(tp->instance_id());
4253       const TypePtr* speculative = xmeet_speculative(tp);
4254       int depth = meet_inline_depth(tp->inline_depth());
4255       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4256     }
4257     default: typerr(t);
4258     }
4259   }
4260 
4261   case AnyPtr: {                // Meeting to AnyPtrs
4262     // Found an AnyPtr type vs self-InstPtr type
4263     const TypePtr *tp = t->is_ptr();
4264     int offset = meet_offset(tp->offset());
4265     PTR ptr = meet_ptr(tp->ptr());
4266     int instance_id = meet_instance_id(InstanceTop);
4267     const TypePtr* speculative = xmeet_speculative(tp);
4268     int depth = meet_inline_depth(tp->inline_depth());
4269     switch (tp->ptr()) {
4270     case Null:
4271       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4272       // else fall through to AnyNull
4273     case TopPTR:
4274     case AnyNull: {
4275       return make(ptr, klass(), _interfaces, klass_is_exact(),
4276                   (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4277     }
4278     case NotNull:
4279     case BotPTR:
4280       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4281     default: typerr(t);
4282     }
4283   }
4284 
4285   /*
4286                  A-top         }
4287                /   |   \       }  Tops
4288            B-top A-any C-top   }
4289               | /  |  \ |      }  Any-nulls
4290            B-any   |   C-any   }
4291               |    |    |
4292            B-con A-con C-con   } constants; not comparable across classes
4293               |    |    |
4294            B-not   |   C-not   }
4295               | \  |  / |      }  not-nulls
4296            B-bot A-not C-bot   }
4297                \   |   /       }  Bottoms
4298                  A-bot         }
4299   */
4300 
4301   case InstPtr: {                // Meeting 2 Oops?
4302     // Found an InstPtr sub-type vs self-InstPtr type
4303     const TypeInstPtr *tinst = t->is_instptr();
4304     int off = meet_offset(tinst->offset());
4305     PTR ptr = meet_ptr(tinst->ptr());
4306     int instance_id = meet_instance_id(tinst->instance_id());
4307     const TypePtr* speculative = xmeet_speculative(tinst);
4308     int depth = meet_inline_depth(tinst->inline_depth());
4309     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4310 
4311     ciKlass* tinst_klass = tinst->klass();
4312     ciKlass* this_klass  = klass();
4313 
4314     ciKlass* res_klass = nullptr;
4315     bool res_xk = false;

4316     const Type* res;
4317     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4318 
4319     if (kind == UNLOADED) {
4320       // One of these classes has not been loaded
4321       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4322 #ifndef PRODUCT
4323       if (PrintOpto && Verbose) {
4324         tty->print("meet of unloaded classes resulted in: ");
4325         unloaded_meet->dump();
4326         tty->cr();
4327         tty->print("  this == ");
4328         dump();
4329         tty->cr();
4330         tty->print(" tinst == ");
4331         tinst->dump();
4332         tty->cr();
4333       }
4334 #endif
4335       res = unloaded_meet;
4336     } else {
4337       if (kind == NOT_SUBTYPE && instance_id > 0) {
4338         instance_id = InstanceBot;
4339       } else if (kind == LCA) {
4340         instance_id = InstanceBot;
4341       }
4342       ciObject* o = nullptr;             // Assume not constant when done
4343       ciObject* this_oop = const_oop();
4344       ciObject* tinst_oop = tinst->const_oop();
4345       if (ptr == Constant) {
4346         if (this_oop != nullptr && tinst_oop != nullptr &&
4347             this_oop->equals(tinst_oop))
4348           o = this_oop;
4349         else if (above_centerline(_ptr)) {
4350           assert(!tinst_klass->is_interface(), "");
4351           o = tinst_oop;
4352         } else if (above_centerline(tinst->_ptr)) {
4353           assert(!this_klass->is_interface(), "");
4354           o = this_oop;
4355         } else
4356           ptr = NotNull;
4357       }
4358       res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4359     }
4360 
4361     return res;
4362 
4363   } // End of case InstPtr
4364 
4365   } // End of switch
4366   return this;                  // Return the double constant
4367 }
4368 
4369 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4370                                                             ciKlass*& res_klass, bool& res_xk) {
4371   ciKlass* this_klass = this_type->klass();
4372   ciKlass* other_klass = other_type->klass();




4373   bool this_xk = this_type->klass_is_exact();
4374   bool other_xk = other_type->klass_is_exact();
4375   PTR this_ptr = this_type->ptr();
4376   PTR other_ptr = other_type->ptr();
4377   const TypeInterfaces* this_interfaces = this_type->interfaces();
4378   const TypeInterfaces* other_interfaces = other_type->interfaces();
4379   // Check for easy case; klasses are equal (and perhaps not loaded!)
4380   // If we have constants, then we created oops so classes are loaded
4381   // and we can handle the constants further down.  This case handles
4382   // both-not-loaded or both-loaded classes
4383   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4384     res_klass = this_klass;
4385     res_xk = this_xk;

4386     return QUICK;
4387   }
4388 
4389   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4390   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4391     return UNLOADED;
4392   }
4393 
4394   // !!! Here's how the symmetry requirement breaks down into invariants:
4395   // If we split one up & one down AND they subtype, take the down man.
4396   // If we split one up & one down AND they do NOT subtype, "fall hard".
4397   // If both are up and they subtype, take the subtype class.
4398   // If both are up and they do NOT subtype, "fall hard".
4399   // If both are down and they subtype, take the supertype class.
4400   // If both are down and they do NOT subtype, "fall hard".
4401   // Constants treated as down.
4402 
4403   // Now, reorder the above list; observe that both-down+subtype is also
4404   // "fall hard"; "fall hard" becomes the default case:
4405   // If we split one up & one down AND they subtype, take the down man.
4406   // If both are up and they subtype, take the subtype class.
4407 
4408   // If both are down and they subtype, "fall hard".
4409   // If both are down and they do NOT subtype, "fall hard".
4410   // If both are up and they do NOT subtype, "fall hard".
4411   // If we split one up & one down AND they do NOT subtype, "fall hard".
4412 
4413   // If a proper subtype is exact, and we return it, we return it exactly.
4414   // If a proper supertype is exact, there can be no subtyping relationship!
4415   // If both types are equal to the subtype, exactness is and-ed below the
4416   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4417 
4418   // Check for subtyping:
4419   const T* subtype = nullptr;
4420   bool subtype_exact = false;

4421   if (this_type->is_same_java_type_as(other_type)) {
4422     subtype = this_type;
4423     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4424   } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {

4425     subtype = this_type;     // Pick subtyping class
4426     subtype_exact = this_xk;
4427   } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {

4428     subtype = other_type;    // Pick subtyping class
4429     subtype_exact = other_xk;

4430   }
4431 
4432   if (subtype) {
4433     if (above_centerline(ptr)) { // both are up?
4434       this_type = other_type = subtype;
4435       this_xk = other_xk = subtype_exact;

4436     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4437       this_type = other_type; // tinst is down; keep down man
4438       this_xk = other_xk;

4439     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4440       other_type = this_type; // this is down; keep down man
4441       other_xk = this_xk;

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

4444     }
4445   }
4446 
4447   // Check for classes now being equal
4448   if (this_type->is_same_java_type_as(other_type)) {
4449     // If the klasses are equal, the constants may still differ.  Fall to
4450     // NotNull if they do (neither constant is null; that is a special case
4451     // handled elsewhere).
4452     res_klass = this_type->klass();
4453     res_xk = this_xk;

4454     return SUBTYPE;
4455   } // Else classes are not equal
4456 
4457   // Since klasses are different, we require a LCA in the Java
4458   // class hierarchy - which means we have to fall to at least NotNull.
4459   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4460     ptr = NotNull;
4461   }
4462 
4463   interfaces = this_interfaces->intersection_with(other_interfaces);
4464 
4465   // Now we find the LCA of Java classes
4466   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4467 
4468   res_klass = k;
4469   res_xk = false;

4470 
4471   return LCA;
4472 }
4473 
4474 //------------------------java_mirror_type--------------------------------------
4475 ciType* TypeInstPtr::java_mirror_type() const {
4476   // must be a singleton type
4477   if( const_oop() == nullptr )  return nullptr;
4478 
4479   // must be of type java.lang.Class
4480   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;
4481 
4482   return const_oop()->as_instance()->java_mirror_type();
4483 }
4484 
4485 
4486 //------------------------------xdual------------------------------------------
4487 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4488 // inheritance mechanism.
4489 const Type *TypeInstPtr::xdual() const {
4490   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4491 }
4492 
4493 //------------------------------eq---------------------------------------------
4494 // Structural equality check for Type representations
4495 bool TypeInstPtr::eq( const Type *t ) const {
4496   const TypeInstPtr *p = t->is_instptr();
4497   return
4498     klass()->equals(p->klass()) &&

4499     _interfaces->eq(p->_interfaces) &&
4500     TypeOopPtr::eq(p);          // Check sub-type stuff
4501 }
4502 
4503 //------------------------------hash-------------------------------------------
4504 // Type-specific hashing function.
4505 uint TypeInstPtr::hash(void) const {
4506   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4507 }
4508 
4509 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4510   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4511 }
4512 
4513 
4514 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4515   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4516 }
4517 
4518 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4519   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4520 }
4521 
4522 
4523 //------------------------------dump2------------------------------------------
4524 // Dump oop Type
4525 #ifndef PRODUCT
4526 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {

4540       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4541       char* buf = ss.as_string(/* c_heap= */false);
4542       StringUtils::replace_no_expand(buf, "\n", "");
4543       st->print_raw(buf);
4544     }
4545   case BotPTR:
4546     if (!WizardMode && !Verbose) {
4547       if( _klass_is_exact ) st->print(":exact");
4548       break;
4549     }
4550   case TopPTR:
4551   case AnyNull:
4552   case NotNull:
4553     st->print(":%s", ptr_msg[_ptr]);
4554     if( _klass_is_exact ) st->print(":exact");
4555     break;
4556   default:
4557     break;
4558   }
4559 
4560   if( _offset ) {               // Dump offset, if any
4561     if( _offset == OffsetBot )      st->print("+any");
4562     else if( _offset == OffsetTop ) st->print("+unknown");
4563     else st->print("+%d", _offset);
4564   }
4565 
4566   st->print(" *");





4567   if (_instance_id == InstanceTop)
4568     st->print(",iid=top");
4569   else if (_instance_id != InstanceBot)
4570     st->print(",iid=%d",_instance_id);
4571 
4572   dump_inline_depth(st);
4573   dump_speculative(st);
4574 }
4575 #endif
4576 
4577 //------------------------------add_offset-------------------------------------
4578 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4579   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4580               _instance_id, add_offset_speculative(offset), _inline_depth);
4581 }
4582 
4583 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4584   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4585               _instance_id, with_offset_speculative(offset), _inline_depth);
4586 }
4587 
4588 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4589   if (_speculative == nullptr) {
4590     return this;
4591   }
4592   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4593   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4594               _instance_id, nullptr, _inline_depth);
4595 }
4596 
4597 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4598   if (!UseInlineDepthForSpeculativeTypes) {
4599     return this;
4600   }
4601   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4602 }
4603 
4604 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4605   assert(is_known_instance(), "should be known");
4606   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);




4607 }
4608 
4609 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4610   bool xk = klass_is_exact();
4611   ciInstanceKlass* ik = klass()->as_instance_klass();
4612   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4613     if (_interfaces->eq(ik)) {
4614       Compile* C = Compile::current();
4615       Dependencies* deps = C->dependencies();
4616       deps->assert_leaf_type(ik);
4617       xk = true;
4618     }
4619   }
4620   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4621 }
4622 
4623 template <class T1, class T2> bool TypePtr::is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk) {
4624   static_assert(std::is_base_of<T2, T1>::value, "");
4625 
4626   if (!this_one->is_instance_type(other)) {
4627     return false;
4628   }
4629 
4630   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4631     return true;
4632   }
4633 
4634   return this_one->klass()->is_subtype_of(other->klass()) &&
4635          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4636 }
4637 
4638 
4639 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4640   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);

4645   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4646     return true;
4647   }
4648 
4649   if (this_one->is_instance_type(other)) {
4650     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4651   }
4652 
4653   int dummy;
4654   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4655   if (this_top_or_bottom) {
4656     return false;
4657   }
4658 
4659   const T1* other_ary = this_one->is_array_type(other);
4660   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4661   const TypePtr* this_elem = this_one->elem()->make_ptr();
4662   if (other_elem != nullptr && this_elem != nullptr) {
4663     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4664   }
4665 
4666   if (other_elem == nullptr && this_elem == nullptr) {
4667     return this_one->_klass->is_subtype_of(other->_klass);
4668   }
4669 
4670   return false;
4671 }
4672 
4673 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4674   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4675 }
4676 
4677 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4678   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4679 }
4680 
4681 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4682   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4683 }
4684 
4685 //=============================================================================
4686 // Convenience common pre-built types.
4687 const TypeAryPtr *TypeAryPtr::RANGE;
4688 const TypeAryPtr *TypeAryPtr::OOPS;
4689 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4690 const TypeAryPtr *TypeAryPtr::BYTES;
4691 const TypeAryPtr *TypeAryPtr::SHORTS;
4692 const TypeAryPtr *TypeAryPtr::CHARS;
4693 const TypeAryPtr *TypeAryPtr::INTS;
4694 const TypeAryPtr *TypeAryPtr::LONGS;
4695 const TypeAryPtr *TypeAryPtr::FLOATS;
4696 const TypeAryPtr *TypeAryPtr::DOUBLES;

4697 
4698 //------------------------------make-------------------------------------------
4699 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4700                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4701   assert(!(k == nullptr && ary->_elem->isa_int()),
4702          "integral arrays must be pre-equipped with a class");
4703   if (!xk)  xk = ary->ary_must_be_exact();
4704   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4705   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4706       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4707     k = nullptr;
4708   }
4709   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();



4710 }
4711 
4712 //------------------------------make-------------------------------------------
4713 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4714                                    int instance_id, const TypePtr* speculative, int inline_depth,
4715                                    bool is_autobox_cache) {
4716   assert(!(k == nullptr && ary->_elem->isa_int()),
4717          "integral arrays must be pre-equipped with a class");
4718   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4719   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
4720   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4721   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4722       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4723     k = nullptr;
4724   }
4725   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();



4726 }
4727 
4728 //------------------------------cast_to_ptr_type-------------------------------
4729 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4730   if( ptr == _ptr ) return this;
4731   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4732 }
4733 
4734 
4735 //-----------------------------cast_to_exactness-------------------------------
4736 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4737   if( klass_is_exact == _klass_is_exact ) return this;
4738   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4739   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4740 }
4741 
4742 //-----------------------------cast_to_instance_id----------------------------
4743 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4744   if( instance_id == _instance_id ) return this;
4745   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4746 }
4747 
4748 
4749 //-----------------------------max_array_length-------------------------------
4750 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4751 jint TypeAryPtr::max_array_length(BasicType etype) {
4752   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4753     if (etype == T_NARROWOOP) {
4754       etype = T_OBJECT;
4755     } else if (etype == T_ILLEGAL) { // bottom[]
4756       etype = T_BYTE; // will produce conservatively high value
4757     } else {
4758       fatal("not an element type: %s", type2name(etype));
4759     }
4760   }
4761   return arrayOopDesc::max_array_length(etype);
4762 }
4763 
4764 //-----------------------------narrow_size_type-------------------------------
4765 // Narrow the given size type to the index range for the given array base type.

4781   if (hi > max_hi) {
4782     hi = max_hi;
4783     if (size->is_con()) {
4784       lo = hi;
4785     }
4786     chg = true;
4787   }
4788   // Negative length arrays will produce weird intermediate dead fast-path code
4789   if (lo > hi)
4790     return TypeInt::ZERO;
4791   if (!chg)
4792     return size;
4793   return TypeInt::make(lo, hi, Type::WidenMin);
4794 }
4795 
4796 //-------------------------------cast_to_size----------------------------------
4797 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4798   assert(new_size != nullptr, "");
4799   new_size = narrow_size_type(new_size);
4800   if (new_size == size())  return this;
4801   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4802   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);




























































4803 }
4804 
4805 //------------------------------cast_to_stable---------------------------------
4806 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4807   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4808     return this;
4809 
4810   const Type* elem = this->elem();
4811   const TypePtr* elem_ptr = elem->make_ptr();
4812 
4813   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4814     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4815     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4816   }
4817 
4818   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4819 
4820   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4821 }
4822 
4823 //-----------------------------stable_dimension--------------------------------
4824 int TypeAryPtr::stable_dimension() const {
4825   if (!is_stable())  return 0;
4826   int dim = 1;
4827   const TypePtr* elem_ptr = elem()->make_ptr();
4828   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4829     dim += elem_ptr->is_aryptr()->stable_dimension();
4830   return dim;
4831 }
4832 
4833 //----------------------cast_to_autobox_cache-----------------------------------
4834 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4835   if (is_autobox_cache())  return this;
4836   const TypeOopPtr* etype = elem()->make_oopptr();
4837   if (etype == nullptr)  return this;
4838   // The pointers in the autobox arrays are always non-null.
4839   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4840   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4841   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4842 }
4843 
4844 //------------------------------eq---------------------------------------------
4845 // Structural equality check for Type representations
4846 bool TypeAryPtr::eq( const Type *t ) const {
4847   const TypeAryPtr *p = t->is_aryptr();
4848   return
4849     _ary == p->_ary &&  // Check array
4850     TypeOopPtr::eq(p);  // Check sub-parts

4851 }
4852 
4853 //------------------------------hash-------------------------------------------
4854 // Type-specific hashing function.
4855 uint TypeAryPtr::hash(void) const {
4856   return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4857 }
4858 
4859 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4860   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4861 }
4862 
4863 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4864   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4865 }
4866 
4867 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4868   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4869 }
4870 //------------------------------meet-------------------------------------------
4871 // Compute the MEET of two types.  It returns a new Type object.
4872 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4873   // Perform a fast test for common case; meeting the same types together.
4874   if( this == t ) return this;  // Meeting same type-rep?
4875   // Current "this->_base" is Pointer
4876   switch (t->base()) {          // switch on original type

4880   case Long:
4881   case FloatTop:
4882   case FloatCon:
4883   case FloatBot:
4884   case DoubleTop:
4885   case DoubleCon:
4886   case DoubleBot:
4887   case NarrowOop:
4888   case NarrowKlass:
4889   case Bottom:                  // Ye Olde Default
4890     return Type::BOTTOM;
4891   case Top:
4892     return this;
4893 
4894   default:                      // All else is a mistake
4895     typerr(t);
4896 
4897   case OopPtr: {                // Meeting to OopPtrs
4898     // Found a OopPtr type vs self-AryPtr type
4899     const TypeOopPtr *tp = t->is_oopptr();
4900     int offset = meet_offset(tp->offset());
4901     PTR ptr = meet_ptr(tp->ptr());
4902     int depth = meet_inline_depth(tp->inline_depth());
4903     const TypePtr* speculative = xmeet_speculative(tp);
4904     switch (tp->ptr()) {
4905     case TopPTR:
4906     case AnyNull: {
4907       int instance_id = meet_instance_id(InstanceTop);
4908       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4909                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4910     }
4911     case BotPTR:
4912     case NotNull: {
4913       int instance_id = meet_instance_id(tp->instance_id());
4914       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4915     }
4916     default: ShouldNotReachHere();
4917     }
4918   }
4919 
4920   case AnyPtr: {                // Meeting two AnyPtrs
4921     // Found an AnyPtr type vs self-AryPtr type
4922     const TypePtr *tp = t->is_ptr();
4923     int offset = meet_offset(tp->offset());
4924     PTR ptr = meet_ptr(tp->ptr());
4925     const TypePtr* speculative = xmeet_speculative(tp);
4926     int depth = meet_inline_depth(tp->inline_depth());
4927     switch (tp->ptr()) {
4928     case TopPTR:
4929       return this;
4930     case BotPTR:
4931     case NotNull:
4932       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4933     case Null:
4934       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4935       // else fall through to AnyNull
4936     case AnyNull: {
4937       int instance_id = meet_instance_id(InstanceTop);
4938       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4939                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4940     }
4941     default: ShouldNotReachHere();
4942     }
4943   }
4944 
4945   case MetadataPtr:
4946   case KlassPtr:
4947   case InstKlassPtr:
4948   case AryKlassPtr:
4949   case RawPtr: return TypePtr::BOTTOM;
4950 
4951   case AryPtr: {                // Meeting 2 references?
4952     const TypeAryPtr *tap = t->is_aryptr();
4953     int off = meet_offset(tap->offset());

4954     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
4955     PTR ptr = meet_ptr(tap->ptr());
4956     int instance_id = meet_instance_id(tap->instance_id());
4957     const TypePtr* speculative = xmeet_speculative(tap);
4958     int depth = meet_inline_depth(tap->inline_depth());
4959 
4960     ciKlass* res_klass = nullptr;
4961     bool res_xk = false;



4962     const Type* elem = tary->_elem;
4963     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk) == NOT_SUBTYPE) {
4964       instance_id = InstanceBot;














4965     }
4966 
4967     ciObject* o = nullptr;             // Assume not constant when done
4968     ciObject* this_oop = const_oop();
4969     ciObject* tap_oop = tap->const_oop();
4970     if (ptr == Constant) {
4971       if (this_oop != nullptr && tap_oop != nullptr &&
4972           this_oop->equals(tap_oop)) {
4973         o = tap_oop;
4974       } else if (above_centerline(_ptr)) {
4975         o = tap_oop;
4976       } else if (above_centerline(tap->_ptr)) {
4977         o = this_oop;
4978       } else {
4979         ptr = NotNull;
4980       }
4981     }
4982     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4983   }
4984 
4985   // All arrays inherit from Object class
4986   case InstPtr: {
4987     const TypeInstPtr *tp = t->is_instptr();
4988     int offset = meet_offset(tp->offset());
4989     PTR ptr = meet_ptr(tp->ptr());
4990     int instance_id = meet_instance_id(tp->instance_id());
4991     const TypePtr* speculative = xmeet_speculative(tp);
4992     int depth = meet_inline_depth(tp->inline_depth());
4993     const TypeInterfaces* interfaces = meet_interfaces(tp);
4994     const TypeInterfaces* tp_interfaces = tp->_interfaces;
4995     const TypeInterfaces* this_interfaces = _interfaces;
4996 
4997     switch (ptr) {
4998     case TopPTR:
4999     case AnyNull:                // Fall 'down' to dual of object klass
5000       // For instances when a subclass meets a superclass we fall
5001       // below the centerline when the superclass is exact. We need to
5002       // do the same here.
5003       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5004         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5005       } else {
5006         // cannot subclass, so the meet has to fall badly below the centerline
5007         ptr = NotNull;
5008         instance_id = InstanceBot;
5009         interfaces = this_interfaces->intersection_with(tp_interfaces);
5010         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
5011       }
5012     case Constant:
5013     case NotNull:
5014     case BotPTR:                // Fall down to object klass
5015       // LCA is object_klass, but if we subclass from the top we can do better
5016       if (above_centerline(tp->ptr())) {
5017         // If 'tp'  is above the centerline and it is Object class
5018         // then we can subclass in the Java class hierarchy.
5019         // For instances when a subclass meets a superclass we fall
5020         // below the centerline when the superclass is exact. We need
5021         // to do the same here.
5022         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5023           // that is, my array type is a subtype of 'tp' klass
5024           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5025                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5026         }
5027       }
5028       // The other case cannot happen, since t cannot be a subtype of an array.
5029       // The meet falls down to Object class below centerline.
5030       if (ptr == Constant) {
5031          ptr = NotNull;
5032       }
5033       if (instance_id > 0) {
5034         instance_id = InstanceBot;
5035       }
5036       interfaces = this_interfaces->intersection_with(tp_interfaces);
5037       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
5038     default: typerr(t);
5039     }
5040   }
5041   }
5042   return this;                  // Lint noise
5043 }
5044 
5045 
5046 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5047                                                            const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5048   int dummy;
5049   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5050   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5051   ciKlass* this_klass = this_ary->klass();
5052   ciKlass* other_klass = other_ary->klass();
5053   bool this_xk = this_ary->klass_is_exact();
5054   bool other_xk = other_ary->klass_is_exact();
5055   PTR this_ptr = this_ary->ptr();
5056   PTR other_ptr = other_ary->ptr();






5057   res_klass = nullptr;
5058   MeetResult result = SUBTYPE;




5059   if (elem->isa_int()) {
5060     // Integral array element types have irrelevant lattice relations.
5061     // It is the klass that determines array layout, not the element type.
5062     if (this_top_or_bottom)
5063       res_klass = other_klass;
5064     else if (other_top_or_bottom || other_klass == this_klass) {
5065       res_klass = this_klass;
5066     } else {
5067       // Something like byte[int+] meets char[int+].
5068       // This must fall to bottom, not (int[-128..65535])[int+].
5069       // instance_id = InstanceBot;
5070       elem = Type::BOTTOM;
5071       result = NOT_SUBTYPE;
5072       if (above_centerline(ptr) || ptr == Constant) {
5073         ptr = NotNull;
5074         res_xk = false;
5075         return NOT_SUBTYPE;
5076       }
5077     }
5078   } else {// Non integral arrays.
5079     // Must fall to bottom if exact klasses in upper lattice
5080     // are not equal or super klass is exact.
5081     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5082         // meet with top[] and bottom[] are processed further down:
5083         !this_top_or_bottom && !other_top_or_bottom &&
5084         // both are exact and not equal:

5086          // 'tap'  is exact and super or unrelated:
5087          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5088          // 'this' is exact and super or unrelated:
5089          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5090       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5091         elem = Type::BOTTOM;
5092       }
5093       ptr = NotNull;
5094       res_xk = false;
5095       return NOT_SUBTYPE;
5096     }
5097   }
5098 
5099   res_xk = false;
5100   switch (other_ptr) {
5101     case AnyNull:
5102     case TopPTR:
5103       // Compute new klass on demand, do not use tap->_klass
5104       if (below_centerline(this_ptr)) {
5105         res_xk = this_xk;



5106       } else {
5107         res_xk = (other_xk || this_xk);
5108       }
5109       return result;
5110     case Constant: {
5111       if (this_ptr == Constant) {
5112         res_xk = true;
5113       } else if(above_centerline(this_ptr)) {
5114         res_xk = true;
5115       } else {
5116         // Only precise for identical arrays
5117         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));




5118       }
5119       return result;
5120     }
5121     case NotNull:
5122     case BotPTR:
5123       // Compute new klass on demand, do not use tap->_klass
5124       if (above_centerline(this_ptr)) {
5125         res_xk = other_xk;



5126       } else {
5127         res_xk = (other_xk && this_xk) &&
5128                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays




5129       }
5130       return result;
5131     default:  {
5132       ShouldNotReachHere();
5133       return result;
5134     }
5135   }
5136   return result;
5137 }
5138 
5139 
5140 //------------------------------xdual------------------------------------------
5141 // Dual: compute field-by-field dual
5142 const Type *TypeAryPtr::xdual() const {
5143   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());









5144 }
5145 
5146 //------------------------------dump2------------------------------------------
5147 #ifndef PRODUCT
5148 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5149   _ary->dump2(d,depth,st);
5150   _interfaces->dump(st);
5151 
5152   switch( _ptr ) {
5153   case Constant:
5154     const_oop()->print(st);
5155     break;
5156   case BotPTR:
5157     if (!WizardMode && !Verbose) {
5158       if( _klass_is_exact ) st->print(":exact");
5159       break;
5160     }
5161   case TopPTR:
5162   case AnyNull:
5163   case NotNull:
5164     st->print(":%s", ptr_msg[_ptr]);
5165     if( _klass_is_exact ) st->print(":exact");
5166     break;
5167   default:
5168     break;
5169   }
5170 
5171   if( _offset != 0 ) {









5172     int header_size = objArrayOopDesc::header_size() * wordSize;
5173     if( _offset == OffsetTop )       st->print("+undefined");
5174     else if( _offset == OffsetBot )  st->print("+any");
5175     else if( _offset < header_size ) st->print("+%d", _offset);
5176     else {
5177       BasicType basic_elem_type = elem()->basic_type();
5178       if (basic_elem_type == T_ILLEGAL) {
5179         st->print("+any");
5180       } else {
5181         int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5182         int elem_size = type2aelembytes(basic_elem_type);
5183         st->print("[%d]", (_offset - array_base)/elem_size);
5184       }
5185     }
5186   }
5187   st->print(" *");
5188   if (_instance_id == InstanceTop)
5189     st->print(",iid=top");
5190   else if (_instance_id != InstanceBot)
5191     st->print(",iid=%d",_instance_id);
5192 
5193   dump_inline_depth(st);
5194   dump_speculative(st);
5195 }
5196 #endif
5197 
5198 bool TypeAryPtr::empty(void) const {
5199   if (_ary->empty())       return true;




5200   return TypeOopPtr::empty();
5201 }
5202 
5203 //------------------------------add_offset-------------------------------------
5204 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5205   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5206 }
5207 
5208 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5209   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5210 }
5211 
5212 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5213   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5214 }
5215 
5216 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5217   if (_speculative == nullptr) {
5218     return this;
5219   }
5220   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5221   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);













5222 }
5223 
5224 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5225   if (!UseInlineDepthForSpeculativeTypes) {
5226     return this;
5227   }
5228   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);











































5229 }
5230 
5231 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5232   assert(is_known_instance(), "should be known");
5233   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5234 }
5235 
5236 //=============================================================================
5237 

5238 //------------------------------hash-------------------------------------------
5239 // Type-specific hashing function.
5240 uint TypeNarrowPtr::hash(void) const {
5241   return _ptrtype->hash() + 7;
5242 }
5243 
5244 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5245   return _ptrtype->singleton();
5246 }
5247 
5248 bool TypeNarrowPtr::empty(void) const {
5249   return _ptrtype->empty();
5250 }
5251 
5252 intptr_t TypeNarrowPtr::get_con() const {
5253   return _ptrtype->get_con();
5254 }
5255 
5256 bool TypeNarrowPtr::eq( const Type *t ) const {
5257   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5308 
5309   case Int:                     // Mixing ints & oops happens when javac
5310   case Long:                    // reuses local variables
5311   case FloatTop:
5312   case FloatCon:
5313   case FloatBot:
5314   case DoubleTop:
5315   case DoubleCon:
5316   case DoubleBot:
5317   case AnyPtr:
5318   case RawPtr:
5319   case OopPtr:
5320   case InstPtr:
5321   case AryPtr:
5322   case MetadataPtr:
5323   case KlassPtr:
5324   case InstKlassPtr:
5325   case AryKlassPtr:
5326   case NarrowOop:
5327   case NarrowKlass:
5328 
5329   case Bottom:                  // Ye Olde Default
5330     return Type::BOTTOM;
5331   case Top:
5332     return this;
5333 
5334   default:                      // All else is a mistake
5335     typerr(t);
5336 
5337   } // End of switch
5338 
5339   return this;
5340 }
5341 
5342 #ifndef PRODUCT
5343 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5344   _ptrtype->dump2(d, depth, st);
5345 }
5346 #endif
5347 
5348 const TypeNarrowOop *TypeNarrowOop::BOTTOM;

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

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


5585       xk = true;
5586     }
5587   }
5588   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5589 }
5590 
5591 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5592   if (klass->is_instance_klass()) {
5593     return TypeInstKlassPtr::make(klass, interface_handling);
5594   }
5595   return TypeAryKlassPtr::make(klass, interface_handling);
5596 }
5597 
5598 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5599   if (klass->is_instance_klass()) {
5600     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5601     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5602   }
5603   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5604 }
5605 
5606 
5607 //------------------------------TypeKlassPtr-----------------------------------
5608 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5609   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5610   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5611          klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5612 }
5613 
5614 // Is there a single ciKlass* that can represent that type?
5615 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5616   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5617   if (_interfaces->empty()) {
5618     return _klass;
5619   }
5620   if (_klass != ciEnv::current()->Object_klass()) {
5621     if (_interfaces->eq(_klass->as_instance_klass())) {
5622       return _klass;
5623     }
5624     return nullptr;
5625   }
5626   return _interfaces->exact_klass();
5627 }
5628 
5629 //------------------------------eq---------------------------------------------
5630 // Structural equality check for Type representations
5631 bool TypeKlassPtr::eq(const Type *t) const {
5632   const TypeKlassPtr *p = t->is_klassptr();
5633   return
5634     _interfaces->eq(p->_interfaces) &&
5635     TypePtr::eq(p);
5636 }
5637 
5638 //------------------------------hash-------------------------------------------
5639 // Type-specific hashing function.
5640 uint TypeKlassPtr::hash(void) const {
5641   return TypePtr::hash() + _interfaces->hash();
5642 }
5643 
5644 //------------------------------singleton--------------------------------------
5645 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5646 // constants
5647 bool TypeKlassPtr::singleton(void) const {
5648   // detune optimizer to not generate constant klass + constant offset as a constant!
5649   // TopPTR, Null, AnyNull, Constant are all singletons
5650   return (_offset == 0) && !below_centerline(_ptr);
5651 }
5652 
5653 // Do not allow interface-vs.-noninterface joins to collapse to top.
5654 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5655   // logic here mirrors the one from TypeOopPtr::filter. See comments
5656   // there.
5657   const Type* ft = join_helper(kills, include_speculative);
5658   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
5659   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
5660 
5661   if (ft->empty()) {
5662     return Type::TOP;           // Canonical empty value
5663   }
5664 
5665   return ft;
5666 }
5667 
5668 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5669   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5670     return _interfaces->union_with(other->_interfaces);
5671   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5672     return other->_interfaces;
5673   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5674     return _interfaces;
5675   }
5676   return _interfaces->intersection_with(other->_interfaces);
5677 }
5678 
5679 //------------------------------get_con----------------------------------------
5680 intptr_t TypeKlassPtr::get_con() const {
5681   assert( _ptr == Null || _ptr == Constant, "" );
5682   assert( _offset >= 0, "" );
5683 
5684   if (_offset != 0) {
5685     // After being ported to the compiler interface, the compiler no longer
5686     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5687     // to a handle at compile time.  This handle is embedded in the generated
5688     // code and dereferenced at the time the nmethod is made.  Until that time,
5689     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5690     // have access to the addresses!).  This does not seem to currently happen,
5691     // but this assertion here is to help prevent its occurrence.
5692     tty->print_cr("Found oop constant with non-zero offset");
5693     ShouldNotReachHere();
5694   }
5695 
5696   ciKlass* k = exact_klass();
5697 
5698   return (intptr_t)k->constant_encoding();
5699 }
5700 
5701 //------------------------------dump2------------------------------------------
5702 // Dump Klass Type
5703 #ifndef PRODUCT
5704 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {

5708   case NotNull:
5709     {
5710       const char *name = klass()->name()->as_utf8();
5711       if (name) {
5712         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5713       } else {
5714         ShouldNotReachHere();
5715       }
5716       _interfaces->dump(st);
5717     }
5718   case BotPTR:
5719     if (!WizardMode && !Verbose && _ptr != Constant) break;
5720   case TopPTR:
5721   case AnyNull:
5722     st->print(":%s", ptr_msg[_ptr]);
5723     if (_ptr == Constant) st->print(":exact");
5724     break;
5725   default:
5726     break;
5727   }
5728 
5729   if (_offset) {               // Dump offset, if any
5730     if (_offset == OffsetBot)      { st->print("+any"); }
5731     else if (_offset == OffsetTop) { st->print("+unknown"); }
5732     else                            { st->print("+%d", _offset); }
5733   }
5734 
5735   st->print(" *");
5736 }
5737 #endif
5738 
5739 //=============================================================================
5740 // Convenience common pre-built types.
5741 
5742 // Not-null object klass or below
5743 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5744 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5745 
5746 bool TypeInstKlassPtr::eq(const Type *t) const {
5747   const TypeKlassPtr *p = t->is_klassptr();
5748   return
5749     klass()->equals(p->klass()) &&

5750     TypeKlassPtr::eq(p);
5751 }
5752 
5753 uint TypeInstKlassPtr::hash(void) const {
5754   return klass()->hash() + TypeKlassPtr::hash();
5755 }
5756 
5757 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {


5758   TypeInstKlassPtr *r =
5759     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5760 
5761   return r;
5762 }
5763 
5764 //------------------------------add_offset-------------------------------------
5765 // Access internals of klass object
5766 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5767   return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5768 }
5769 
5770 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5771   return make(_ptr, klass(), _interfaces, offset);
5772 }
5773 
5774 //------------------------------cast_to_ptr_type-------------------------------
5775 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5776   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5777   if( ptr == _ptr ) return this;
5778   return make(ptr, _klass, _interfaces, _offset);
5779 }
5780 
5781 
5782 bool TypeInstKlassPtr::must_be_exact() const {
5783   if (!_klass->is_loaded())  return false;
5784   ciInstanceKlass* ik = _klass->as_instance_klass();
5785   if (ik->is_final())  return true;  // cannot clear xk
5786   return false;
5787 }
5788 
5789 //-----------------------------cast_to_exactness-------------------------------
5790 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5791   if (klass_is_exact == (_ptr == Constant)) return this;
5792   if (must_be_exact()) return this;
5793   ciKlass* k = klass();
5794   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5795 }
5796 
5797 
5798 //-----------------------------as_instance_type--------------------------------
5799 // Corresponding type for an instance of the given class.
5800 // It will be NotNull, and exact if and only if the klass type is exact.
5801 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5802   ciKlass* k = klass();
5803   bool xk = klass_is_exact();
5804   Compile* C = Compile::current();
5805   Dependencies* deps = C->dependencies();
5806   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5807   // Element is an instance
5808   bool klass_is_exact = false;
5809   const TypeInterfaces* interfaces = _interfaces;
5810   if (k->is_loaded()) {
5811     // Try to set klass_is_exact.
5812     ciInstanceKlass* ik = k->as_instance_klass();
5813     klass_is_exact = ik->is_final();
5814     if (!klass_is_exact && klass_change
5815         && deps != nullptr && UseUniqueSubclasses) {
5816       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5817       if (sub != nullptr) {
5818         if (_interfaces->eq(sub)) {
5819           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5820           k = ik = sub;
5821           xk = sub->is_final();
5822         }
5823       }
5824     }
5825   }
5826   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5827 }
5828 
5829 //------------------------------xmeet------------------------------------------
5830 // Compute the MEET of two types, return a new Type object.
5831 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5832   // Perform a fast test for common case; meeting the same types together.
5833   if( this == t ) return this;  // Meeting same type-rep?
5834 
5835   // Current "this->_base" is Pointer
5836   switch (t->base()) {          // switch on original type
5837 
5838   case Int:                     // Mixing ints & oops happens when javac
5839   case Long:                    // reuses local variables
5840   case FloatTop:
5841   case FloatCon:
5842   case FloatBot:
5843   case DoubleTop:
5844   case DoubleCon:
5845   case DoubleBot:
5846   case NarrowOop:
5847   case NarrowKlass:
5848   case Bottom:                  // Ye Olde Default
5849     return Type::BOTTOM;
5850   case Top:
5851     return this;
5852 
5853   default:                      // All else is a mistake
5854     typerr(t);
5855 
5856   case AnyPtr: {                // Meeting to AnyPtrs
5857     // Found an AnyPtr type vs self-KlassPtr type
5858     const TypePtr *tp = t->is_ptr();
5859     int offset = meet_offset(tp->offset());
5860     PTR ptr = meet_ptr(tp->ptr());
5861     switch (tp->ptr()) {
5862     case TopPTR:
5863       return this;
5864     case Null:
5865       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5866     case AnyNull:
5867       return make( ptr, klass(), _interfaces, offset );
5868     case BotPTR:
5869     case NotNull:
5870       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5871     default: typerr(t);
5872     }
5873   }
5874 
5875   case RawPtr:
5876   case MetadataPtr:
5877   case OopPtr:
5878   case AryPtr:                  // Meet with AryPtr
5879   case InstPtr:                 // Meet with InstPtr
5880     return TypePtr::BOTTOM;
5881 
5882   //
5883   //             A-top         }
5884   //           /   |   \       }  Tops
5885   //       B-top A-any C-top   }
5886   //          | /  |  \ |      }  Any-nulls
5887   //       B-any   |   C-any   }
5888   //          |    |    |
5889   //       B-con A-con C-con   } constants; not comparable across classes
5890   //          |    |    |
5891   //       B-not   |   C-not   }
5892   //          | \  |  / |      }  not-nulls
5893   //       B-bot A-not C-bot   }
5894   //           \   |   /       }  Bottoms
5895   //             A-bot         }
5896   //
5897 
5898   case InstKlassPtr: {  // Meet two KlassPtr types
5899     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5900     int  off     = meet_offset(tkls->offset());
5901     PTR  ptr     = meet_ptr(tkls->ptr());
5902     const TypeInterfaces* interfaces = meet_interfaces(tkls);
5903 
5904     ciKlass* res_klass = nullptr;
5905     bool res_xk = false;
5906     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {

5907       case UNLOADED:
5908         ShouldNotReachHere();
5909       case SUBTYPE:
5910       case NOT_SUBTYPE:
5911       case LCA:
5912       case QUICK: {
5913         assert(res_xk == (ptr == Constant), "");
5914         const Type* res = make(ptr, res_klass, interfaces, off);
5915         return res;
5916       }
5917       default:
5918         ShouldNotReachHere();
5919     }
5920   } // End of case KlassPtr
5921   case AryKlassPtr: {                // All arrays inherit from Object class
5922     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5923     int offset = meet_offset(tp->offset());
5924     PTR ptr = meet_ptr(tp->ptr());
5925     const TypeInterfaces* interfaces = meet_interfaces(tp);
5926     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5927     const TypeInterfaces* this_interfaces = _interfaces;
5928 
5929     switch (ptr) {
5930     case TopPTR:
5931     case AnyNull:                // Fall 'down' to dual of object klass
5932       // For instances when a subclass meets a superclass we fall
5933       // below the centerline when the superclass is exact. We need to
5934       // do the same here.
5935       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5936         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5937       } else {
5938         // cannot subclass, so the meet has to fall badly below the centerline
5939         ptr = NotNull;
5940         interfaces = _interfaces->intersection_with(tp->_interfaces);
5941         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5942       }
5943     case Constant:
5944     case NotNull:
5945     case BotPTR:                // Fall down to object klass
5946       // LCA is object_klass, but if we subclass from the top we can do better
5947       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5948         // If 'this' (InstPtr) is above the centerline and it is Object class
5949         // then we can subclass in the Java class hierarchy.
5950         // For instances when a subclass meets a superclass we fall
5951         // below the centerline when the superclass is exact. We need
5952         // to do the same here.
5953         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5954           // that is, tp's array type is a subtype of my klass
5955           return TypeAryKlassPtr::make(ptr,
5956                                        tp->elem(), tp->klass(), offset);
5957         }
5958       }
5959       // The other case cannot happen, since I cannot be a subtype of an array.
5960       // The meet falls down to Object class below centerline.
5961       if( ptr == Constant )
5962          ptr = NotNull;
5963       interfaces = this_interfaces->intersection_with(tp_interfaces);
5964       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5965     default: typerr(t);
5966     }
5967   }
5968 
5969   } // End of switch
5970   return this;                  // Return the double constant
5971 }
5972 
5973 //------------------------------xdual------------------------------------------
5974 // Dual: compute field-by-field dual
5975 const Type    *TypeInstKlassPtr::xdual() const {
5976   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5977 }
5978 
5979 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
5980   static_assert(std::is_base_of<T2, T1>::value, "");
5981   if (!this_one->is_loaded() || !other->is_loaded()) {
5982     return false;
5983   }
5984   if (!this_one->is_instance_type(other)) {
5985     return false;
5986   }
5987 
5988   if (!other_exact) {
5989     return false;
5990   }
5991 
5992   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
5993     return true;
5994   }
5995 
5996   return this_one->_klass->is_subtype_of(other->_klass) && this_one->_interfaces->contains(other->_interfaces);

6057   const TypeInterfaces* interfaces = _interfaces;
6058   if (k->is_loaded()) {
6059     ciInstanceKlass* ik = k->as_instance_klass();
6060     bool klass_is_exact = ik->is_final();
6061     if (!klass_is_exact &&
6062         deps != nullptr) {
6063       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6064       if (sub != nullptr) {
6065         if (_interfaces->eq(sub)) {
6066           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6067           k = ik = sub;
6068           klass_is_exact = sub->is_final();
6069           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6070         }
6071       }
6072     }
6073   }
6074   return this;
6075 }
6076 







6077 
6078 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6079   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6080 }
6081 
6082 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {








6083   if (k->is_obj_array_klass()) {
6084     // Element is an object array. Recursively call ourself.
6085     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6086     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6087     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);




6088   } else if (k->is_type_array_klass()) {
6089     // Element is an typeArray
6090     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6091     return TypeAryKlassPtr::make(ptr, etype, k, offset);




6092   } else {
6093     ShouldNotReachHere();
6094     return nullptr;
6095   }
6096 }
6097 











6098 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6099   return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6100 }
6101 
6102 //------------------------------eq---------------------------------------------
6103 // Structural equality check for Type representations
6104 bool TypeAryKlassPtr::eq(const Type *t) const {
6105   const TypeAryKlassPtr *p = t->is_aryklassptr();
6106   return
6107     _elem == p->_elem &&  // Check array



6108     TypeKlassPtr::eq(p);  // Check sub-parts
6109 }
6110 
6111 //------------------------------hash-------------------------------------------
6112 // Type-specific hashing function.
6113 uint TypeAryKlassPtr::hash(void) const {
6114   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();

6115 }
6116 
6117 //----------------------compute_klass------------------------------------------
6118 // Compute the defining klass for this class
6119 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
6120   // Compute _klass based on element type.
6121   ciKlass* k_ary = nullptr;
6122   const TypeInstPtr *tinst;
6123   const TypeAryPtr *tary;
6124   const Type* el = elem();
6125   if (el->isa_narrowoop()) {
6126     el = el->make_ptr();
6127   }
6128 
6129   // Get element klass
6130   if ((tinst = el->isa_instptr()) != nullptr) {
6131     // Leave k_ary at null.





6132   } else if ((tary = el->isa_aryptr()) != nullptr) {
6133     // Leave k_ary at null.
6134   } else if ((el->base() == Type::Top) ||
6135              (el->base() == Type::Bottom)) {
6136     // element type of Bottom occurs from meet of basic type
6137     // and object; Top occurs when doing join on Bottom.
6138     // Leave k_ary at null.
6139   } else {
6140     // Cannot compute array klass directly from basic type,
6141     // since subtypes of TypeInt all have basic type T_INT.
6142 #ifdef ASSERT
6143     if (verify && el->isa_int()) {
6144       // Check simple cases when verifying klass.
6145       BasicType bt = T_ILLEGAL;
6146       if (el == TypeInt::BYTE) {
6147         bt = T_BYTE;
6148       } else if (el == TypeInt::SHORT) {
6149         bt = T_SHORT;
6150       } else if (el == TypeInt::CHAR) {
6151         bt = T_CHAR;
6152       } else if (el == TypeInt::INT) {
6153         bt = T_INT;

6182     // type TypeAryPtr::OOPS.  This Type is shared between all
6183     // active compilations.  However, the ciKlass which represents
6184     // this Type is *not* shared between compilations, so caching
6185     // this value would result in fetching a dangling pointer.
6186     //
6187     // Recomputing the underlying ciKlass for each request is
6188     // a bit less efficient than caching, but calls to
6189     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6190     ((TypeAryPtr*)this)->_klass = k_ary;
6191   }
6192   return k_ary;
6193 }
6194 
6195 // Is there a single ciKlass* that can represent that type?
6196 ciKlass* TypeAryPtr::exact_klass_helper() const {
6197   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6198     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6199     if (k == nullptr) {
6200       return nullptr;
6201     }
6202     k = ciObjArrayKlass::make(k);
6203     return k;
6204   }
6205 
6206   return klass();
6207 }
6208 
6209 const Type* TypeAryPtr::base_element_type(int& dims) const {
6210   const Type* elem = this->elem();
6211   dims = 1;
6212   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6213     elem = elem->make_ptr()->is_aryptr()->elem();
6214     dims++;
6215   }
6216   return elem;
6217 }
6218 
6219 //------------------------------add_offset-------------------------------------
6220 // Access internals of klass object
6221 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6222   return make(_ptr, elem(), klass(), xadd_offset(offset));
6223 }
6224 
6225 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6226   return make(_ptr, elem(), klass(), offset);
6227 }
6228 
6229 //------------------------------cast_to_ptr_type-------------------------------
6230 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6231   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6232   if (ptr == _ptr) return this;
6233   return make(ptr, elem(), _klass, _offset);
6234 }
6235 
6236 bool TypeAryKlassPtr::must_be_exact() const {
6237   if (_elem == Type::BOTTOM) return false;
6238   if (_elem == Type::TOP   ) return false;
6239   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6240   if (!tk)             return true;   // a primitive type, like int




6241   return tk->must_be_exact();
6242 }
6243 
6244 
6245 //-----------------------------cast_to_exactness-------------------------------
6246 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6247   if (must_be_exact()) return this;  // cannot clear xk



6248   ciKlass* k = _klass;
6249   const Type* elem = this->elem();
6250   if (elem->isa_klassptr() && !klass_is_exact) {
6251     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6252   }
6253   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);















6254 }
6255 
6256 
6257 //-----------------------------as_instance_type--------------------------------
6258 // Corresponding type for an instance of the given class.
6259 // It will be NotNull, and exact if and only if the klass type is exact.
6260 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6261   ciKlass* k = klass();
6262   bool    xk = klass_is_exact();
6263   const Type* el = nullptr;
6264   if (elem()->isa_klassptr()) {
6265     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6266     k = nullptr;
6267   } else {
6268     el = elem();
6269   }
6270   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);




6271 }
6272 
6273 
6274 //------------------------------xmeet------------------------------------------
6275 // Compute the MEET of two types, return a new Type object.
6276 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6277   // Perform a fast test for common case; meeting the same types together.
6278   if( this == t ) return this;  // Meeting same type-rep?
6279 
6280   // Current "this->_base" is Pointer
6281   switch (t->base()) {          // switch on original type
6282 
6283   case Int:                     // Mixing ints & oops happens when javac
6284   case Long:                    // reuses local variables
6285   case FloatTop:
6286   case FloatCon:
6287   case FloatBot:
6288   case DoubleTop:
6289   case DoubleCon:
6290   case DoubleBot:
6291   case NarrowOop:
6292   case NarrowKlass:
6293   case Bottom:                  // Ye Olde Default
6294     return Type::BOTTOM;
6295   case Top:
6296     return this;
6297 
6298   default:                      // All else is a mistake
6299     typerr(t);
6300 
6301   case AnyPtr: {                // Meeting to AnyPtrs
6302     // Found an AnyPtr type vs self-KlassPtr type
6303     const TypePtr *tp = t->is_ptr();
6304     int offset = meet_offset(tp->offset());
6305     PTR ptr = meet_ptr(tp->ptr());
6306     switch (tp->ptr()) {
6307     case TopPTR:
6308       return this;
6309     case Null:
6310       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6311     case AnyNull:
6312       return make( ptr, _elem, klass(), offset );
6313     case BotPTR:
6314     case NotNull:
6315       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6316     default: typerr(t);
6317     }
6318   }
6319 
6320   case RawPtr:
6321   case MetadataPtr:
6322   case OopPtr:
6323   case AryPtr:                  // Meet with AryPtr
6324   case InstPtr:                 // Meet with InstPtr
6325     return TypePtr::BOTTOM;
6326 
6327   //
6328   //             A-top         }
6329   //           /   |   \       }  Tops
6330   //       B-top A-any C-top   }
6331   //          | /  |  \ |      }  Any-nulls
6332   //       B-any   |   C-any   }
6333   //          |    |    |
6334   //       B-con A-con C-con   } constants; not comparable across classes
6335   //          |    |    |
6336   //       B-not   |   C-not   }
6337   //          | \  |  / |      }  not-nulls
6338   //       B-bot A-not C-bot   }
6339   //           \   |   /       }  Bottoms
6340   //             A-bot         }
6341   //
6342 
6343   case AryKlassPtr: {  // Meet two KlassPtr types
6344     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6345     int off = meet_offset(tap->offset());
6346     const Type* elem = _elem->meet(tap->_elem);
6347 
6348     PTR ptr = meet_ptr(tap->ptr());
6349     ciKlass* res_klass = nullptr;
6350     bool res_xk = false;
6351     meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);




6352     assert(res_xk == (ptr == Constant), "");
6353     return make(ptr, elem, res_klass, off);












6354   } // End of case KlassPtr
6355   case InstKlassPtr: {
6356     const TypeInstKlassPtr *tp = t->is_instklassptr();
6357     int offset = meet_offset(tp->offset());
6358     PTR ptr = meet_ptr(tp->ptr());
6359     const TypeInterfaces* interfaces = meet_interfaces(tp);
6360     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6361     const TypeInterfaces* this_interfaces = _interfaces;
6362 
6363     switch (ptr) {
6364     case TopPTR:
6365     case AnyNull:                // Fall 'down' to dual of object klass
6366       // For instances when a subclass meets a superclass we fall
6367       // below the centerline when the superclass is exact. We need to
6368       // do the same here.
6369       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->intersection_with(tp_interfaces)->eq(tp_interfaces) && !tp->klass_is_exact()) {
6370         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6371       } else {
6372         // cannot subclass, so the meet has to fall badly below the centerline
6373         ptr = NotNull;
6374         interfaces = this_interfaces->intersection_with(tp->_interfaces);
6375         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6376       }
6377     case Constant:
6378     case NotNull:
6379     case BotPTR:                // Fall down to object klass
6380       // LCA is object_klass, but if we subclass from the top we can do better
6381       if (above_centerline(tp->ptr())) {
6382         // If 'tp'  is above the centerline and it is Object class
6383         // then we can subclass in the Java class hierarchy.
6384         // For instances when a subclass meets a superclass we fall
6385         // below the centerline when the superclass is exact. We need
6386         // to do the same here.
6387         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->intersection_with(tp_interfaces)->eq(tp_interfaces) && !tp->klass_is_exact()) {
6388           // that is, my array type is a subtype of 'tp' klass
6389           return make(ptr, _elem, _klass, offset);
6390         }
6391       }
6392       // The other case cannot happen, since t cannot be a subtype of an array.
6393       // The meet falls down to Object class below centerline.
6394       if (ptr == Constant)
6395          ptr = NotNull;
6396       interfaces = this_interfaces->intersection_with(tp_interfaces);
6397       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6398     default: typerr(t);
6399     }
6400   }
6401 
6402   } // End of switch
6403   return this;                  // Return the double constant
6404 }
6405 
6406 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6407   static_assert(std::is_base_of<T2, T1>::value, "");
6408 
6409   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6410     return true;
6411   }
6412 
6413   int dummy;
6414   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6415 
6416   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6417     return false;
6418   }
6419 
6420   if (this_one->is_instance_type(other)) {
6421     return other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->intersection_with(this_one->_interfaces)->eq(other->_interfaces) && other_exact;
6422   }
6423 
6424   assert(this_one->is_array_type(other), "");
6425   const T1* other_ary = this_one->is_array_type(other);
6426   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6427   if (other_top_or_bottom) {
6428     return false;
6429   }
6430 
6431   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6432   const TypePtr* this_elem = this_one->elem()->make_ptr();
6433   if (this_elem != nullptr && other_elem != nullptr) {



6434     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6435   }
6436   if (this_elem == nullptr && other_elem == nullptr) {
6437     return this_one->_klass->is_subtype_of(other->_klass);
6438   }
6439   return false;
6440 }
6441 
6442 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6443   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6444 }
6445 
6446 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6447   static_assert(std::is_base_of<T2, T1>::value, "");
6448 
6449   int dummy;
6450   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6451 
6452   if (!this_one->is_array_type(other) ||
6453       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

6501   }
6502 
6503   const TypePtr* this_elem = this_one->elem()->make_ptr();
6504   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6505   if (other_elem != nullptr && this_elem != nullptr) {
6506     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6507   }
6508   if (other_elem == nullptr && this_elem == nullptr) {
6509     return this_one->_klass->is_subtype_of(other->_klass);
6510   }
6511   return false;
6512 }
6513 
6514 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6515   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6516 }
6517 
6518 //------------------------------xdual------------------------------------------
6519 // Dual: compute field-by-field dual
6520 const Type    *TypeAryKlassPtr::xdual() const {
6521   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6522 }
6523 
6524 // Is there a single ciKlass* that can represent that type?
6525 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6526   if (elem()->isa_klassptr()) {
6527     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6528     if (k == nullptr) {
6529       return nullptr;
6530     }
6531     k = ciObjArrayKlass::make(k);
6532     return k;
6533   }
6534 
6535   return klass();
6536 }
6537 
6538 ciKlass* TypeAryKlassPtr::klass() const {
6539   if (_klass != nullptr) {
6540     return _klass;
6541   }
6542   ciKlass* k = nullptr;
6543   if (elem()->isa_klassptr()) {
6544     // leave null
6545   } else if ((elem()->base() == Type::Top) ||
6546              (elem()->base() == Type::Bottom)) {
6547   } else {
6548     k = ciTypeArrayKlass::make(elem()->basic_type());
6549     ((TypeAryKlassPtr*)this)->_klass = k;
6550   }
6551   return k;

6558   switch( _ptr ) {
6559   case Constant:
6560     st->print("precise ");
6561   case NotNull:
6562     {
6563       st->print("[");
6564       _elem->dump2(d, depth, st);
6565       _interfaces->dump(st);
6566       st->print(": ");
6567     }
6568   case BotPTR:
6569     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6570   case TopPTR:
6571   case AnyNull:
6572     st->print(":%s", ptr_msg[_ptr]);
6573     if( _ptr == Constant ) st->print(":exact");
6574     break;
6575   default:
6576     break;
6577   }
6578 
6579   if( _offset ) {               // Dump offset, if any
6580     if( _offset == OffsetBot )      { st->print("+any"); }
6581     else if( _offset == OffsetTop ) { st->print("+unknown"); }
6582     else                            { st->print("+%d", _offset); }
6583   }
6584 


6585   st->print(" *");
6586 }
6587 #endif
6588 
6589 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6590   const Type* elem = this->elem();
6591   dims = 1;
6592   while (elem->isa_aryklassptr()) {
6593     elem = elem->is_aryklassptr()->elem();
6594     dims++;
6595   }
6596   return elem;
6597 }
6598 
6599 //=============================================================================
6600 // Convenience common pre-built types.
6601 
6602 //------------------------------make-------------------------------------------
6603 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6604   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();












6605 }
6606 
6607 //------------------------------make-------------------------------------------
6608 const TypeFunc *TypeFunc::make(ciMethod* method) {
6609   Compile* C = Compile::current();
6610   const TypeFunc* tf = C->last_tf(method); // check cache
6611   if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
6612   const TypeTuple *domain;
6613   if (method->is_static()) {
6614     domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6615   } else {
6616     domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);

















6617   }
6618   const TypeTuple *range  = TypeTuple::make_range(method->signature(), ignore_interfaces);
6619   tf = TypeFunc::make(domain, range);
6620   C->set_last_tf(method, tf);  // fill cache
6621   return tf;
6622 }
6623 
6624 //------------------------------meet-------------------------------------------
6625 // Compute the MEET of two types.  It returns a new Type object.
6626 const Type *TypeFunc::xmeet( const Type *t ) const {
6627   // Perform a fast test for common case; meeting the same types together.
6628   if( this == t ) return this;  // Meeting same type-rep?
6629 
6630   // Current "this->_base" is Func
6631   switch (t->base()) {          // switch on original type
6632 
6633   case Bottom:                  // Ye Olde Default
6634     return t;
6635 
6636   default:                      // All else is a mistake
6637     typerr(t);
6638 
6639   case Top:
6640     break;
6641   }
6642   return this;                  // Return the double constant
6643 }
6644 
6645 //------------------------------xdual------------------------------------------
6646 // Dual: compute field-by-field dual
6647 const Type *TypeFunc::xdual() const {
6648   return this;
6649 }
6650 
6651 //------------------------------eq---------------------------------------------
6652 // Structural equality check for Type representations
6653 bool TypeFunc::eq( const Type *t ) const {
6654   const TypeFunc *a = (const TypeFunc*)t;
6655   return _domain == a->_domain &&
6656     _range == a->_range;


6657 }
6658 
6659 //------------------------------hash-------------------------------------------
6660 // Type-specific hashing function.
6661 uint TypeFunc::hash(void) const {
6662   return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6663 }
6664 
6665 //------------------------------dump2------------------------------------------
6666 // Dump Function Type
6667 #ifndef PRODUCT
6668 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6669   if( _range->cnt() <= Parms )
6670     st->print("void");
6671   else {
6672     uint i;
6673     for (i = Parms; i < _range->cnt()-1; i++) {
6674       _range->field_at(i)->dump2(d,depth,st);
6675       st->print("/");
6676     }
6677     _range->field_at(i)->dump2(d,depth,st);
6678   }
6679   st->print(" ");
6680   st->print("( ");
6681   if( !depth || d[this] ) {     // Check for recursive dump
6682     st->print("...)");
6683     return;
6684   }
6685   d.Insert((void*)this,(void*)this);    // Stop recursion
6686   if (Parms < _domain->cnt())
6687     _domain->field_at(Parms)->dump2(d,depth-1,st);
6688   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6689     st->print(", ");
6690     _domain->field_at(i)->dump2(d,depth-1,st);
6691   }
6692   st->print(" )");
6693 }
6694 #endif
6695 
6696 //------------------------------singleton--------------------------------------
6697 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6698 // constants (Ldi nodes).  Singletons are integer, float or double constants
6699 // or a single symbol.
6700 bool TypeFunc::singleton(void) const {
6701   return false;                 // Never a singleton
6702 }
6703 
6704 bool TypeFunc::empty(void) const {
6705   return false;                 // Never empty
6706 }
6707 
6708 
6709 BasicType TypeFunc::return_type() const{
6710   if (range()->cnt() == TypeFunc::Parms) {
6711     return T_VOID;
6712   }
6713   return range()->field_at(TypeFunc::Parms)->basic_type();
6714 }

   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/checkedCast.hpp"
  46 #include "utilities/powerOfTwo.hpp"
  47 #include "utilities/stringUtils.hpp"
  48 
  49 // Portions of code courtesy of Clifford Click
  50 
  51 // Optimization - Graph Style
  52 
  53 // Dictionary of types shared among compilations.
  54 Dict* Type::_shared_type_dict = nullptr;
  55 const Type::Offset Type::Offset::top(Type::OffsetTop);
  56 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
  57 
  58 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
  59   // Either is 'TOP' offset?  Return the other offset!
  60   if (_offset == OffsetTop) return other;
  61   if (other._offset == OffsetTop) return *this;
  62   // If either is different, return 'BOTTOM' offset
  63   if (_offset != other._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   { Bad,             T_ARRAY,      "interfaces:",   false, Node::NotAMachineReg, relocInfo::none          },  // Interfaces
 114 
 115 #if defined(PPC64)
 116   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 117   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 118   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 119   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD

 254   case ciTypeFlow::StateVector::T_NULL:
 255     assert(type == ciTypeFlow::StateVector::null_type(), "");
 256     return TypePtr::NULL_PTR;
 257 
 258   case ciTypeFlow::StateVector::T_LONG2:
 259     // The ciTypeFlow pass pushes a long, then the half.
 260     // We do the same.
 261     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 262     return TypeInt::TOP;
 263 
 264   case ciTypeFlow::StateVector::T_DOUBLE2:
 265     // The ciTypeFlow pass pushes double, then the half.
 266     // Our convention is the same.
 267     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 268     return Type::TOP;
 269 
 270   case T_ADDRESS:
 271     assert(type->is_return_address(), "");
 272     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 273 
 274   case T_OBJECT:
 275     return Type::get_const_type(type->unwrap())->join_speculative(type->is_null_free() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
 276 
 277   default:
 278     // make sure we did not mix up the cases:
 279     assert(type != ciTypeFlow::StateVector::bottom_type(), "");
 280     assert(type != ciTypeFlow::StateVector::top_type(), "");
 281     assert(type != ciTypeFlow::StateVector::null_type(), "");
 282     assert(type != ciTypeFlow::StateVector::long2_type(), "");
 283     assert(type != ciTypeFlow::StateVector::double2_type(), "");
 284     assert(!type->is_return_address(), "");
 285 
 286     return Type::get_const_type(type);
 287   }
 288 }
 289 
 290 
 291 //-----------------------make_from_constant------------------------------------
 292 const Type* Type::make_from_constant(ciConstant constant, bool require_constant,
 293                                      int stable_dimension, bool is_narrow_oop,
 294                                      bool is_autobox_cache) {
 295   switch (constant.basic_type()) {
 296     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());

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

2161 
2162 bool TypeLong::empty(void) const {
2163   return _lo > _hi;
2164 }
2165 
2166 //=============================================================================
2167 // Convenience common pre-built types.
2168 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2169 const TypeTuple *TypeTuple::IFFALSE;
2170 const TypeTuple *TypeTuple::IFTRUE;
2171 const TypeTuple *TypeTuple::IFNEITHER;
2172 const TypeTuple *TypeTuple::LOOPBODY;
2173 const TypeTuple *TypeTuple::MEMBAR;
2174 const TypeTuple *TypeTuple::STORECONDITIONAL;
2175 const TypeTuple *TypeTuple::START_I2C;
2176 const TypeTuple *TypeTuple::INT_PAIR;
2177 const TypeTuple *TypeTuple::LONG_PAIR;
2178 const TypeTuple *TypeTuple::INT_CC_PAIR;
2179 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2180 
2181 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2182   for (int j = 0; j < vk->nof_nonstatic_fields(); j++) {
2183     ciField* field = vk->nonstatic_field_at(j);
2184     // TODO 8325106 The field could be null free, right? Shouldn't we set the type to null-free here?
2185     BasicType bt = field->type()->basic_type();
2186     const Type* ft = Type::get_const_type(field->type());
2187     field_array[pos++] = ft;
2188     if (type2size[bt] == 2) {
2189       field_array[pos++] = Type::HALF;
2190     }
2191   }
2192 }
2193 
2194 //------------------------------make-------------------------------------------
2195 // Make a TypeTuple from the range of a method signature
2196 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields) {
2197   ciType* return_type = sig->return_type();
2198   uint arg_cnt = return_type->size();
2199   if (ret_vt_fields) {
2200     arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2201     if (!sig->returns_null_free_inline_type()) {
2202       // InlineTypeNode::IsInit field used for null checking
2203       arg_cnt++;
2204     }
2205   }
2206   const Type **field_array = fields(arg_cnt);
2207   switch (return_type->basic_type()) {
2208   case T_LONG:
2209     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2210     field_array[TypeFunc::Parms+1] = Type::HALF;
2211     break;
2212   case T_DOUBLE:
2213     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2214     field_array[TypeFunc::Parms+1] = Type::HALF;
2215     break;
2216   case T_OBJECT:
2217     if (return_type->is_inlinetype() && ret_vt_fields) {
2218       uint pos = TypeFunc::Parms;
2219       field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2220       collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2221       if (!sig->returns_null_free_inline_type()) {
2222         // InlineTypeNode::IsInit field used for null checking
2223         field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2224       }
2225       break;
2226     } else {
2227       field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(sig->returns_null_free_inline_type() ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2228     }
2229     break;
2230   case T_ARRAY:
2231   case T_BOOLEAN:
2232   case T_CHAR:
2233   case T_FLOAT:
2234   case T_BYTE:
2235   case T_SHORT:
2236   case T_INT:
2237     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2238     break;
2239   case T_VOID:
2240     break;
2241   default:
2242     ShouldNotReachHere();
2243   }
2244   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2245 }
2246 
2247 // Make a TypeTuple from the domain of a method signature
2248 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2249   ciSignature* sig = method->signature();
2250   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2251   if (vt_fields_as_args) {
2252     arg_cnt = 0;
2253     assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2254     for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2255       arg_cnt += type2size[(*sig_cc)._bt];
2256     }
2257   }
2258 
2259   uint pos = TypeFunc::Parms;
2260   const Type** field_array = fields(arg_cnt);
2261   if (!method->is_static()) {
2262     ciInstanceKlass* recv = method->holder();
2263     if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields()) {
2264       collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2265     } else {
2266       field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2267     }
2268   }
2269 
2270   int i = 0;
2271   while (pos < TypeFunc::Parms + arg_cnt) {
2272     ciType* type = sig->type_at(i);
2273     BasicType bt = type->basic_type();
2274 
2275     switch (bt) {
2276     case T_LONG:
2277       field_array[pos++] = TypeLong::LONG;
2278       field_array[pos++] = Type::HALF;
2279       break;
2280     case T_DOUBLE:
2281       field_array[pos++] = Type::DOUBLE;
2282       field_array[pos++] = Type::HALF;
2283       break;
2284     case T_OBJECT:
2285       if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2286         if (!sig->is_null_free_at(i)) {
2287           // InlineTypeNode::IsInit field used for null checking
2288           field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2289         }
2290         collect_inline_fields(type->as_inline_klass(), field_array, pos);
2291       } else {
2292         field_array[pos++] = get_const_type(type, interface_handling)->join_speculative(sig->is_null_free_at(i) ? TypePtr::NOTNULL : TypePtr::BOTTOM);
2293       }
2294       break;
2295     case T_ARRAY:
2296     case T_FLOAT:
2297     case T_INT:
2298       field_array[pos++] = get_const_type(type, interface_handling);
2299       break;
2300     case T_BOOLEAN:
2301     case T_CHAR:
2302     case T_BYTE:
2303     case T_SHORT:
2304       field_array[pos++] = TypeInt::INT;
2305       break;
2306     default:
2307       ShouldNotReachHere();
2308     }
2309     i++;
2310   }
2311   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2312 
2313   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2314 }
2315 
2316 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2317   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2318 }
2319 
2320 //------------------------------fields-----------------------------------------
2321 // Subroutine call type with space allocated for argument types
2322 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2323 const Type **TypeTuple::fields( uint arg_cnt ) {
2324   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2325   flds[TypeFunc::Control  ] = Type::CONTROL;
2326   flds[TypeFunc::I_O      ] = Type::ABIO;
2327   flds[TypeFunc::Memory   ] = Type::MEMORY;
2328   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2329   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2330 
2331   return flds;

2426     if (_fields[i]->empty())  return true;
2427   }
2428   return false;
2429 }
2430 
2431 //=============================================================================
2432 // Convenience common pre-built types.
2433 
2434 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2435   // Certain normalizations keep us sane when comparing types.
2436   // We do not want arrayOop variables to differ only by the wideness
2437   // of their index types.  Pick minimum wideness, since that is the
2438   // forced wideness of small ranges anyway.
2439   if (size->_widen != Type::WidenMin)
2440     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2441   else
2442     return size;
2443 }
2444 
2445 //------------------------------make-------------------------------------------
2446 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2447                              bool flat, bool not_flat, bool not_null_free) {
2448   if (UseCompressedOops && elem->isa_oopptr()) {
2449     elem = elem->make_narrowoop();
2450   }
2451   size = normalize_array_size(size);
2452   return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free))->hashcons();
2453 }
2454 
2455 //------------------------------meet-------------------------------------------
2456 // Compute the MEET of two types.  It returns a new Type object.
2457 const Type *TypeAry::xmeet( const Type *t ) const {
2458   // Perform a fast test for common case; meeting the same types together.
2459   if( this == t ) return this;  // Meeting same type-rep?
2460 
2461   // Current "this->_base" is Ary
2462   switch (t->base()) {          // switch on original type
2463 
2464   case Bottom:                  // Ye Olde Default
2465     return t;
2466 
2467   default:                      // All else is a mistake
2468     typerr(t);
2469 
2470   case Array: {                 // Meeting 2 arrays?
2471     const TypeAry *a = t->is_ary();
2472     return TypeAry::make(_elem->meet_speculative(a->_elem),
2473                          _size->xmeet(a->_size)->is_int(),
2474                          _stable && a->_stable,
2475                          _flat && a->_flat,
2476                          _not_flat && a->_not_flat,
2477                          _not_null_free && a->_not_null_free);
2478   }
2479   case Top:
2480     break;
2481   }
2482   return this;                  // Return the double constant
2483 }
2484 
2485 //------------------------------xdual------------------------------------------
2486 // Dual: compute field-by-field dual
2487 const Type *TypeAry::xdual() const {
2488   const TypeInt* size_dual = _size->dual()->is_int();
2489   size_dual = normalize_array_size(size_dual);
2490   return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free);
2491 }
2492 
2493 //------------------------------eq---------------------------------------------
2494 // Structural equality check for Type representations
2495 bool TypeAry::eq( const Type *t ) const {
2496   const TypeAry *a = (const TypeAry*)t;
2497   return _elem == a->_elem &&
2498     _stable == a->_stable &&
2499     _size == a->_size &&
2500     _flat == a->_flat &&
2501     _not_flat == a->_not_flat &&
2502     _not_null_free == a->_not_null_free;
2503 
2504 }
2505 
2506 //------------------------------hash-------------------------------------------
2507 // Type-specific hashing function.
2508 uint TypeAry::hash(void) const {
2509   return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0) +
2510       (uint)(_flat ? 44 : 0) + (uint)(_not_flat ? 45 : 0) + (uint)(_not_null_free ? 46 : 0);
2511 }
2512 
2513 /**
2514  * Return same type without a speculative part in the element
2515  */
2516 const TypeAry* TypeAry::remove_speculative() const {
2517   return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free);
2518 }
2519 
2520 /**
2521  * Return same type with cleaned up speculative part of element
2522  */
2523 const Type* TypeAry::cleanup_speculative() const {
2524   return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free);
2525 }
2526 
2527 /**
2528  * Return same type but with a different inline depth (used for speculation)
2529  *
2530  * @param depth  depth to meet with
2531  */
2532 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2533   if (!UseInlineDepthForSpeculativeTypes) {
2534     return this;
2535   }
2536   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2537 }
2538 
2539 //------------------------------dump2------------------------------------------
2540 #ifndef PRODUCT
2541 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2542   if (_stable)  st->print("stable:");
2543   if (_flat) st->print("flat:");
2544   if (Verbose) {
2545     if (_not_flat) st->print("not flat:");
2546     if (_not_null_free) st->print("not null free:");
2547   }
2548   _elem->dump2(d, depth, st);
2549   st->print("[");
2550   _size->dump2(d, depth, st);
2551   st->print("]");
2552 }
2553 #endif
2554 
2555 //------------------------------singleton--------------------------------------
2556 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2557 // constants (Ldi nodes).  Singletons are integer, float or double constants
2558 // or a single symbol.
2559 bool TypeAry::singleton(void) const {
2560   return false;                 // Never a singleton
2561 }
2562 
2563 bool TypeAry::empty(void) const {
2564   return _elem->empty() || _size->empty();
2565 }
2566 
2567 //--------------------------ary_must_be_exact----------------------------------
2568 bool TypeAry::ary_must_be_exact() const {
2569   // This logic looks at the element type of an array, and returns true
2570   // if the element type is either a primitive or a final instance class.
2571   // In such cases, an array built on this ary must have no subclasses.
2572   if (_elem == BOTTOM)      return false;  // general array not exact
2573   if (_elem == TOP   )      return false;  // inverted general array not exact
2574   const TypeOopPtr*  toop = nullptr;
2575   if (UseCompressedOops && _elem->isa_narrowoop()) {
2576     toop = _elem->make_ptr()->isa_oopptr();
2577   } else {
2578     toop = _elem->isa_oopptr();
2579   }
2580   if (!toop)                return true;   // a primitive type, like int
2581   if (!toop->is_loaded())   return false;  // unloaded class
2582   const TypeInstPtr* tinst;
2583   if (_elem->isa_narrowoop())
2584     tinst = _elem->make_ptr()->isa_instptr();
2585   else
2586     tinst = _elem->isa_instptr();
2587   if (tinst) {
2588     if (tinst->instance_klass()->is_final()) {
2589       // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
2590       if (tinst->is_inlinetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2591         return false;
2592       }
2593       return true;
2594     }
2595     return false;
2596   }
2597   const TypeAryPtr*  tap;
2598   if (_elem->isa_narrowoop())
2599     tap = _elem->make_ptr()->isa_aryptr();
2600   else
2601     tap = _elem->isa_aryptr();
2602   if (tap)
2603     return tap->ary()->ary_must_be_exact();
2604   return false;
2605 }
2606 
2607 //==============================TypeVect=======================================
2608 // Convenience common pre-built types.
2609 const TypeVect *TypeVect::VECTA = nullptr; // vector length agnostic
2610 const TypeVect *TypeVect::VECTS = nullptr; //  32-bit vectors
2611 const TypeVect *TypeVect::VECTD = nullptr; //  64-bit vectors
2612 const TypeVect *TypeVect::VECTX = nullptr; // 128-bit vectors
2613 const TypeVect *TypeVect::VECTY = nullptr; // 256-bit vectors
2614 const TypeVect *TypeVect::VECTZ = nullptr; // 512-bit vectors
2615 const TypeVect *TypeVect::VECTMASK = nullptr; // predicate/mask vector
2616 

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

2857     int depth = meet_inline_depth(tp->inline_depth());
2858     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2859   }
2860   case RawPtr:                  // For these, flip the call around to cut down
2861   case OopPtr:
2862   case InstPtr:                 // on the cases I have to handle.
2863   case AryPtr:
2864   case MetadataPtr:
2865   case KlassPtr:
2866   case InstKlassPtr:
2867   case AryKlassPtr:
2868     return t->xmeet(this);      // Call in reverse direction
2869   default:                      // All else is a mistake
2870     typerr(t);
2871 
2872   }
2873   return this;
2874 }
2875 
2876 //------------------------------meet_offset------------------------------------
2877 Type::Offset TypePtr::meet_offset(int offset) const {
2878   return _offset.meet(Offset(offset));





2879 }
2880 
2881 //------------------------------dual_offset------------------------------------
2882 Type::Offset TypePtr::dual_offset() const {
2883   return _offset.dual();


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











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

3165   }
3166   // We already know the speculative type is always null
3167   if (speculative_always_null()) {
3168     return false;
3169   }
3170   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3171     return false;
3172   }
3173   return true;
3174 }
3175 
3176 //------------------------------dump2------------------------------------------
3177 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3178   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3179 };
3180 
3181 #ifndef PRODUCT
3182 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3183   if( _ptr == Null ) st->print("null");
3184   else st->print("%s *", ptr_msg[_ptr]);
3185   _offset.dump2(st);


3186   dump_inline_depth(st);
3187   dump_speculative(st);
3188 }
3189 
3190 /**
3191  *dump the speculative part of the type
3192  */
3193 void TypePtr::dump_speculative(outputStream *st) const {
3194   if (_speculative != nullptr) {
3195     st->print(" (speculative=");
3196     _speculative->dump_on(st);
3197     st->print(")");
3198   }
3199 }
3200 
3201 /**
3202  *dump the inline depth of the type
3203  */
3204 void TypePtr::dump_inline_depth(outputStream *st) const {
3205   if (_inline_depth != InlineDepthBottom) {
3206     if (_inline_depth == InlineDepthTop) {
3207       st->print(" (inline_depth=InlineDepthTop)");
3208     } else {
3209       st->print(" (inline_depth=%d)", _inline_depth);
3210     }
3211   }
3212 }
3213 #endif
3214 
3215 //------------------------------singleton--------------------------------------
3216 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3217 // constants
3218 bool TypePtr::singleton(void) const {
3219   // TopPTR, Null, AnyNull, Constant are all singletons
3220   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3221 }
3222 
3223 bool TypePtr::empty(void) const {
3224   return (_offset == Offset::top) || above_centerline(_ptr);
3225 }
3226 
3227 //=============================================================================
3228 // Convenience common pre-built types.
3229 const TypeRawPtr *TypeRawPtr::BOTTOM;
3230 const TypeRawPtr *TypeRawPtr::NOTNULL;
3231 
3232 //------------------------------make-------------------------------------------
3233 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3234   assert( ptr != Constant, "what is the constant?" );
3235   assert( ptr != Null, "Use TypePtr for null" );
3236   return (TypeRawPtr*)(new TypeRawPtr(ptr,0))->hashcons();
3237 }
3238 
3239 const TypeRawPtr *TypeRawPtr::make( address bits ) {
3240   assert( bits, "Use TypePtr for null" );
3241   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3242 }
3243 
3244 //------------------------------cast_to_ptr_type-------------------------------

3596 void TypeInterfaces::verify_is_loaded() const {
3597   for (int i = 0; i < _list.length(); i++) {
3598     ciKlass* interface = _list.at(i);
3599     assert(interface->is_loaded(), "Interface not loaded");
3600   }
3601 }
3602 #endif
3603 
3604 // Can't be implemented because there's no way to know if the type is above or below the center line.
3605 const Type* TypeInterfaces::xmeet(const Type* t) const {
3606   ShouldNotReachHere();
3607   return Type::xmeet(t);
3608 }
3609 
3610 bool TypeInterfaces::singleton(void) const {
3611   ShouldNotReachHere();
3612   return Type::singleton();
3613 }
3614 
3615 //------------------------------TypeOopPtr-------------------------------------
3616 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3617                        int instance_id, const TypePtr* speculative, int inline_depth)
3618   : TypePtr(t, ptr, offset, speculative, inline_depth),
3619     _const_oop(o), _klass(k),
3620     _interfaces(interfaces),
3621     _klass_is_exact(xk),
3622     _is_ptr_to_narrowoop(false),
3623     _is_ptr_to_narrowklass(false),
3624     _is_ptr_to_boxed_value(false),
3625     _instance_id(instance_id) {
3626 #ifdef ASSERT
3627   if (klass() != nullptr && klass()->is_loaded()) {
3628     interfaces->verify_is_loaded();
3629   }
3630 #endif
3631   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3632       (offset.get() > 0) && xk && (k != 0) && k->is_instance_klass()) {
3633     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3634   }
3635 #ifdef _LP64
3636   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3637     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3638       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3639     } else if (klass() == nullptr) {
3640       // Array with unknown body type
3641       assert(this->isa_aryptr(), "only arrays without klass");
3642       _is_ptr_to_narrowoop = UseCompressedOops;
3643     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3644       if (klass()->is_obj_array_klass()) {
3645         _is_ptr_to_narrowoop = true;
3646       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3647         // Check if the field of the inline type array element contains oops
3648         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3649         int foffset = field_offset.get() + vk->first_field_offset();
3650         ciField* field = vk->get_field_by_offset(foffset, false);
3651         assert(field != nullptr, "missing field");
3652         BasicType bt = field->layout_type();
3653         _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(bt);
3654       }
3655     } else if (klass()->is_instance_klass()) {

3656       if (this->isa_klassptr()) {
3657         // Perm objects don't use compressed references
3658       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3659         // unsafe access
3660         _is_ptr_to_narrowoop = UseCompressedOops;
3661       } else {
3662         assert(this->isa_instptr(), "must be an instance ptr.");

3663         if (klass() == ciEnv::current()->Class_klass() &&
3664             (this->offset() == java_lang_Class::klass_offset() ||
3665              this->offset() == java_lang_Class::array_klass_offset())) {
3666           // Special hidden fields from the Class.
3667           assert(this->isa_instptr(), "must be an instance ptr.");
3668           _is_ptr_to_narrowoop = false;
3669         } else if (klass() == ciEnv::current()->Class_klass() &&
3670                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3671           // Static fields
3672           ciField* field = nullptr;
3673           if (const_oop() != nullptr) {
3674             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3675             if (k->is_inlinetype() && this->offset() == k->as_inline_klass()->default_value_offset()) {
3676               // Special hidden field that contains the oop of the default inline type
3677               // basic_elem_type = T_PRIMITIVE_OBJECT;
3678              _is_ptr_to_narrowoop = UseCompressedOops;
3679             } else {
3680               field = k->get_field_by_offset(this->offset(), true);
3681               if (field != nullptr) {
3682                 BasicType basic_elem_type = field->layout_type();
3683                 _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3684               } else {
3685                 // unsafe access
3686                 _is_ptr_to_narrowoop = UseCompressedOops;
3687               }
3688             }
3689           }
3690         } else {
3691           // Instance fields which contains a compressed oop references.
3692           ciInstanceKlass* ik = klass()->as_instance_klass();
3693           ciField* field = ik->get_field_by_offset(this->offset(), false);
3694           if (field != nullptr) {
3695             BasicType basic_elem_type = field->layout_type();
3696             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3697           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3698             // Compile::find_alias_type() cast exactness on all types to verify
3699             // that it does not affect alias type.
3700             _is_ptr_to_narrowoop = UseCompressedOops;
3701           } else {
3702             // Type for the copy start in LibraryCallKit::inline_native_clone().
3703             _is_ptr_to_narrowoop = UseCompressedOops;
3704           }
3705         }
3706       }
3707     }
3708   }
3709 #endif
3710 }
3711 
3712 //------------------------------make-------------------------------------------
3713 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3714                                    const TypePtr* speculative, int inline_depth) {
3715   assert(ptr != Constant, "no constant generic pointers");
3716   ciKlass*  k = Compile::current()->env()->Object_klass();
3717   bool      xk = false;
3718   ciObject* o = nullptr;
3719   const TypeInterfaces* interfaces = TypeInterfaces::make();
3720   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3721 }
3722 
3723 
3724 //------------------------------cast_to_ptr_type-------------------------------
3725 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3726   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3727   if( ptr == _ptr ) return this;
3728   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3729 }
3730 
3731 //-----------------------------cast_to_instance_id----------------------------
3732 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3733   // There are no instances of a general oop.
3734   // Return self unchanged.
3735   return this;
3736 }
3737 
3738 //-----------------------------cast_to_exactness-------------------------------
3739 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3740   // There is no such thing as an exact general oop.
3741   // Return self unchanged.
3742   return this;
3743 }
3744 

3745 //------------------------------as_klass_type----------------------------------
3746 // Return the klass type corresponding to this instance or array type.
3747 // It is the type that is loaded from an object of this type.
3748 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3749   ShouldNotReachHere();
3750   return nullptr;
3751 }
3752 
3753 //------------------------------meet-------------------------------------------
3754 // Compute the MEET of two types.  It returns a new Type object.
3755 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3756   // Perform a fast test for common case; meeting the same types together.
3757   if( this == t ) return this;  // Meeting same type-rep?
3758 
3759   // Current "this->_base" is OopPtr
3760   switch (t->base()) {          // switch on original type
3761 
3762   case Int:                     // Mixing ints & oops happens when javac
3763   case Long:                    // reuses local variables
3764   case FloatTop:

3770   case NarrowOop:
3771   case NarrowKlass:
3772   case Bottom:                  // Ye Olde Default
3773     return Type::BOTTOM;
3774   case Top:
3775     return this;
3776 
3777   default:                      // All else is a mistake
3778     typerr(t);
3779 
3780   case RawPtr:
3781   case MetadataPtr:
3782   case KlassPtr:
3783   case InstKlassPtr:
3784   case AryKlassPtr:
3785     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3786 
3787   case AnyPtr: {
3788     // Found an AnyPtr type vs self-OopPtr type
3789     const TypePtr *tp = t->is_ptr();
3790     Offset offset = meet_offset(tp->offset());
3791     PTR ptr = meet_ptr(tp->ptr());
3792     const TypePtr* speculative = xmeet_speculative(tp);
3793     int depth = meet_inline_depth(tp->inline_depth());
3794     switch (tp->ptr()) {
3795     case Null:
3796       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3797       // else fall through:
3798     case TopPTR:
3799     case AnyNull: {
3800       int instance_id = meet_instance_id(InstanceTop);
3801       return make(ptr, offset, instance_id, speculative, depth);
3802     }
3803     case BotPTR:
3804     case NotNull:
3805       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3806     default: typerr(t);
3807     }
3808   }
3809 
3810   case OopPtr: {                 // Meeting to other OopPtrs

3812     int instance_id = meet_instance_id(tp->instance_id());
3813     const TypePtr* speculative = xmeet_speculative(tp);
3814     int depth = meet_inline_depth(tp->inline_depth());
3815     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3816   }
3817 
3818   case InstPtr:                  // For these, flip the call around to cut down
3819   case AryPtr:
3820     return t->xmeet(this);      // Call in reverse direction
3821 
3822   } // End of switch
3823   return this;                  // Return the double constant
3824 }
3825 
3826 
3827 //------------------------------xdual------------------------------------------
3828 // Dual of a pure heap pointer.  No relevant klass or oop information.
3829 const Type *TypeOopPtr::xdual() const {
3830   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3831   assert(const_oop() == nullptr,             "no constants here");
3832   return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), Offset::bottom, dual_instance_id(), dual_speculative(), dual_inline_depth());
3833 }
3834 
3835 //--------------------------make_from_klass_common-----------------------------
3836 // Computes the element-type given a klass.
3837 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3838   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3839     Compile* C = Compile::current();
3840     Dependencies* deps = C->dependencies();
3841     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3842     // Element is an instance
3843     bool klass_is_exact = false;
3844     if (klass->is_loaded()) {
3845       // Try to set klass_is_exact.
3846       ciInstanceKlass* ik = klass->as_instance_klass();
3847       klass_is_exact = ik->is_final();
3848       if (!klass_is_exact && klass_change
3849           && deps != nullptr && UseUniqueSubclasses) {
3850         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3851         if (sub != nullptr) {
3852           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3853           klass = ik = sub;
3854           klass_is_exact = sub->is_final();
3855         }
3856       }
3857       if (!klass_is_exact && try_for_exact && deps != nullptr &&
3858           !ik->is_interface() && !ik->has_subklass()) {
3859         // Add a dependence; if concrete subclass added we need to recompile
3860         deps->assert_leaf_type(ik);
3861         klass_is_exact = true;
3862       }
3863     }
3864     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3865     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0));
3866   } else if (klass->is_obj_array_klass()) {
3867     // Element is an object or inline type array. Recursively call ourself.
3868     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3869     bool null_free = klass->as_array_klass()->is_elem_null_free();
3870     if (null_free) {
3871       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3872     }
3873     // Determine null-free/flat properties
3874     const TypeOopPtr* exact_etype = etype;
3875     if (etype->can_be_inline_type()) {
3876       // Use exact type if element can be an inline type
3877       exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3878     }
3879     bool not_null_free = !exact_etype->can_be_inline_type();
3880     bool not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flat_in_array());
3881 
3882     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
3883     bool xk = etype->klass_is_exact() && (!etype->is_inlinetypeptr() || null_free);
3884     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, not_flat, not_null_free);
3885     // We used to pass NotNull in here, asserting that the sub-arrays
3886     // are all not-null.  This is not true in generally, as code can
3887     // slam nullptrs down in the subarrays.
3888     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
3889     return arr;
3890   } else if (klass->is_type_array_klass()) {
3891     // Element is an typeArray
3892     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3893     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
3894                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3895     // We used to pass NotNull in here, asserting that the array pointer
3896     // is not-null. That was not true in general.
3897     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3898     return arr;
3899   } else if (klass->is_flat_array_klass()) {
3900     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3901     etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3902     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ true);
3903     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
3904     return arr;
3905   } else {
3906     ShouldNotReachHere();
3907     return nullptr;
3908   }
3909 }
3910 
3911 //------------------------------make_from_constant-----------------------------
3912 // Make a java pointer from an oop constant
3913 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3914   assert(!o->is_null_object(), "null object not yet handled here.");
3915 
3916   const bool make_constant = require_constant || o->should_be_constant();
3917 
3918   ciKlass* klass = o->klass();
3919   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3920     // Element is an instance or inline type
3921     if (make_constant) {
3922       return TypeInstPtr::make(o);
3923     } else {
3924       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
3925     }
3926   } else if (klass->is_obj_array_klass()) {
3927     // Element is an object array. Recursively call ourself.
3928     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3929     bool null_free = false;
3930     if (klass->as_array_klass()->is_elem_null_free()) {
3931       null_free = true;
3932       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3933     }
3934     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3935                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ !null_free);
3936     // We used to pass NotNull in here, asserting that the sub-arrays
3937     // are all not-null.  This is not true in generally, as code can
3938     // slam nulls down in the subarrays.
3939     if (make_constant) {
3940       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3941     } else {
3942       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3943     }
3944   } else if (klass->is_type_array_klass()) {
3945     // Element is an typeArray
3946     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3947     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
3948                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
3949     // We used to pass NotNull in here, asserting that the array pointer
3950     // is not-null. That was not true in general.
3951     if (make_constant) {
3952       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3953     } else {
3954       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3955     }
3956   } else if (klass->is_flat_array_klass()) {
3957     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
3958     etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
3959     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ true);
3960     // We used to pass NotNull in here, asserting that the sub-arrays
3961     // are all not-null.  This is not true in generally, as code can
3962     // slam nullptrs down in the subarrays.
3963     if (make_constant) {
3964       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
3965     } else {
3966       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
3967     }
3968   }
3969 
3970   fatal("unhandled object type");
3971   return nullptr;
3972 }
3973 
3974 //------------------------------get_con----------------------------------------
3975 intptr_t TypeOopPtr::get_con() const {
3976   assert( _ptr == Null || _ptr == Constant, "" );
3977   assert(offset() >= 0, "");
3978 
3979   if (offset() != 0) {
3980     // After being ported to the compiler interface, the compiler no longer
3981     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3982     // to a handle at compile time.  This handle is embedded in the generated
3983     // code and dereferenced at the time the nmethod is made.  Until that time,
3984     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3985     // have access to the addresses!).  This does not seem to currently happen,
3986     // but this assertion here is to help prevent its occurrence.
3987     tty->print_cr("Found oop constant with non-zero offset");
3988     ShouldNotReachHere();
3989   }
3990 
3991   return (intptr_t)const_oop()->constant_encoding();
3992 }
3993 
3994 
3995 //-----------------------------filter------------------------------------------
3996 // Do not allow interface-vs.-noninterface joins to collapse to top.
3997 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3998 
3999   const Type* ft = join_helper(kills, include_speculative);

4020   } else {
4021     return one->equals(two) && TypePtr::eq(t);
4022   }
4023 }
4024 
4025 //------------------------------hash-------------------------------------------
4026 // Type-specific hashing function.
4027 uint TypeOopPtr::hash(void) const {
4028   return
4029     (uint)(const_oop() ? const_oop()->hash() : 0) +
4030     (uint)_klass_is_exact +
4031     (uint)_instance_id + TypePtr::hash();
4032 }
4033 
4034 //------------------------------dump2------------------------------------------
4035 #ifndef PRODUCT
4036 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4037   st->print("oopptr:%s", ptr_msg[_ptr]);
4038   if( _klass_is_exact ) st->print(":exact");
4039   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4040   _offset.dump2(st);





4041   if (_instance_id == InstanceTop)
4042     st->print(",iid=top");
4043   else if (_instance_id != InstanceBot)
4044     st->print(",iid=%d",_instance_id);
4045 
4046   dump_inline_depth(st);
4047   dump_speculative(st);
4048 }
4049 #endif
4050 
4051 //------------------------------singleton--------------------------------------
4052 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4053 // constants
4054 bool TypeOopPtr::singleton(void) const {
4055   // detune optimizer to not generate constant oop + constant offset as a constant!
4056   // TopPTR, Null, AnyNull, Constant are all singletons
4057   return (offset() == 0) && !below_centerline(_ptr);
4058 }
4059 
4060 //------------------------------add_offset-------------------------------------
4061 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4062   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4063 }
4064 
4065 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4066   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4067 }
4068 
4069 /**
4070  * Return same type without a speculative part
4071  */
4072 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4073   if (_speculative == nullptr) {
4074     return this;
4075   }
4076   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4077   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4078 }
4079 
4080 /**
4081  * Return same type but drop speculative part if we know we won't use
4082  * it
4083  */
4084 const Type* TypeOopPtr::cleanup_speculative() const {
4085   // If the klass is exact and the ptr is not null then there's
4086   // nothing that the speculative type can help us with

4159 const TypeInstPtr *TypeInstPtr::BOTTOM;
4160 const TypeInstPtr *TypeInstPtr::MIRROR;
4161 const TypeInstPtr *TypeInstPtr::MARK;
4162 const TypeInstPtr *TypeInstPtr::KLASS;
4163 
4164 // Is there a single ciKlass* that can represent that type?
4165 ciKlass* TypeInstPtr::exact_klass_helper() const {
4166   if (_interfaces->empty()) {
4167     return _klass;
4168   }
4169   if (_klass != ciEnv::current()->Object_klass()) {
4170     if (_interfaces->eq(_klass->as_instance_klass())) {
4171       return _klass;
4172     }
4173     return nullptr;
4174   }
4175   return _interfaces->exact_klass();
4176 }
4177 
4178 //------------------------------TypeInstPtr-------------------------------------
4179 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4180                          bool flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4181   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4182     _flat_in_array(flat_in_array) {
4183   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4184   assert(k != nullptr &&
4185          (k->is_loaded() || o == nullptr),
4186          "cannot have constants with non-loaded klass");
4187   assert(!klass()->flat_in_array() || flat_in_array, "Should be flat in array");
4188   assert(!flat_in_array || can_be_inline_type(), "Only inline types can be flat in array");
4189 };
4190 
4191 //------------------------------make-------------------------------------------
4192 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4193                                      ciKlass* k,
4194                                      const TypeInterfaces* interfaces,
4195                                      bool xk,
4196                                      ciObject* o,
4197                                      Offset offset,
4198                                      bool flat_in_array,
4199                                      int instance_id,
4200                                      const TypePtr* speculative,
4201                                      int inline_depth) {
4202   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4203   // Either const_oop() is null or else ptr is Constant
4204   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4205           "constant pointers must have a value supplied" );
4206   // Ptr is never Null
4207   assert( ptr != Null, "null pointers are not typed" );
4208 
4209   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4210   if (ptr == Constant) {
4211     // Note:  This case includes meta-object constants, such as methods.
4212     xk = true;
4213   } else if (k->is_loaded()) {
4214     ciInstanceKlass* ik = k->as_instance_klass();
4215     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4216     assert(!ik->is_interface(), "no interface here");
4217     if (xk && ik->is_interface())  xk = false;  // no exact interface
4218   }
4219 
4220   // Check if this type is known to be flat in arrays
4221   flat_in_array = flat_in_array || k->flat_in_array();
4222 
4223   // Now hash this baby
4224   TypeInstPtr *result =
4225     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4226 
4227   return result;
4228 }
4229 
4230 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4231   if (k->is_instance_klass()) {
4232     if (k->is_loaded()) {
4233       if (k->is_interface() && interface_handling == ignore_interfaces) {
4234         assert(interface, "no interface expected");
4235         k = ciEnv::current()->Object_klass();
4236         const TypeInterfaces* interfaces = TypeInterfaces::make();
4237         return interfaces;
4238       }
4239       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4240       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4241       if (k->is_interface()) {
4242         assert(interface, "no interface expected");
4243         k = ciEnv::current()->Object_klass();
4244       } else {
4245         assert(klass, "no instance klass expected");

4271   switch (bt) {
4272     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4273     case T_INT:      return TypeInt::make(constant.as_int());
4274     case T_CHAR:     return TypeInt::make(constant.as_char());
4275     case T_BYTE:     return TypeInt::make(constant.as_byte());
4276     case T_SHORT:    return TypeInt::make(constant.as_short());
4277     case T_FLOAT:    return TypeF::make(constant.as_float());
4278     case T_DOUBLE:   return TypeD::make(constant.as_double());
4279     case T_LONG:     return TypeLong::make(constant.as_long());
4280     default:         break;
4281   }
4282   fatal("Invalid boxed value type '%s'", type2name(bt));
4283   return nullptr;
4284 }
4285 
4286 //------------------------------cast_to_ptr_type-------------------------------
4287 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4288   if( ptr == _ptr ) return this;
4289   // Reconstruct _sig info here since not a problem with later lazy
4290   // construction, _sig will show up on demand.
4291   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4292 }
4293 
4294 
4295 //-----------------------------cast_to_exactness-------------------------------
4296 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4297   if( klass_is_exact == _klass_is_exact ) return this;
4298   if (!_klass->is_loaded())  return this;
4299   ciInstanceKlass* ik = _klass->as_instance_klass();
4300   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4301   assert(!ik->is_interface(), "no interface here");
4302   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4303 }
4304 
4305 //-----------------------------cast_to_instance_id----------------------------
4306 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4307   if( instance_id == _instance_id ) return this;
4308   return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4309 }
4310 
4311 //------------------------------xmeet_unloaded---------------------------------
4312 // Compute the MEET of two InstPtrs when at least one is unloaded.
4313 // Assume classes are different since called after check for same name/class-loader
4314 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4315   Offset off = meet_offset(tinst->offset());
4316   PTR ptr = meet_ptr(tinst->ptr());
4317   int instance_id = meet_instance_id(tinst->instance_id());
4318   const TypePtr* speculative = xmeet_speculative(tinst);
4319   int depth = meet_inline_depth(tinst->inline_depth());
4320 
4321   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4322   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4323   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4324     //
4325     // Meet unloaded class with java/lang/Object
4326     //
4327     // Meet
4328     //          |                     Unloaded Class
4329     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4330     //  ===================================================================
4331     //   TOP    | ..........................Unloaded......................|
4332     //  AnyNull |  U-AN    |................Unloaded......................|
4333     // Constant | ... O-NN .................................. |   O-BOT   |
4334     //  NotNull | ... O-NN .................................. |   O-BOT   |
4335     //  BOTTOM  | ........................Object-BOTTOM ..................|
4336     //
4337     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4338     //
4339     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded; }
4340     else if (loaded->ptr() == TypePtr::AnyNull)  { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, false, instance_id, speculative, depth); }
4341     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM; }
4342     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4343       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM;  }
4344       else                                       { return TypeInstPtr::NOTNULL; }
4345     }
4346     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded; }
4347 
4348     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr();
4349   }
4350 
4351   // Both are unloaded, not the same class, not Object
4352   // Or meet unloaded with a different loaded class, not java/lang/Object
4353   if (ptr != TypePtr::BotPTR) {
4354     return TypeInstPtr::NOTNULL;
4355   }
4356   return TypeInstPtr::BOTTOM;
4357 }
4358 
4359 
4360 //------------------------------meet-------------------------------------------

4381   case Top:
4382     return this;
4383 
4384   default:                      // All else is a mistake
4385     typerr(t);
4386 
4387   case MetadataPtr:
4388   case KlassPtr:
4389   case InstKlassPtr:
4390   case AryKlassPtr:
4391   case RawPtr: return TypePtr::BOTTOM;
4392 
4393   case AryPtr: {                // All arrays inherit from Object class
4394     // Call in reverse direction to avoid duplication
4395     return t->is_aryptr()->xmeet_helper(this);
4396   }
4397 
4398   case OopPtr: {                // Meeting to OopPtrs
4399     // Found a OopPtr type vs self-InstPtr type
4400     const TypeOopPtr *tp = t->is_oopptr();
4401     Offset offset = meet_offset(tp->offset());
4402     PTR ptr = meet_ptr(tp->ptr());
4403     switch (tp->ptr()) {
4404     case TopPTR:
4405     case AnyNull: {
4406       int instance_id = meet_instance_id(InstanceTop);
4407       const TypePtr* speculative = xmeet_speculative(tp);
4408       int depth = meet_inline_depth(tp->inline_depth());
4409       return make(ptr, klass(), _interfaces, klass_is_exact(),
4410                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4411     }
4412     case NotNull:
4413     case BotPTR: {
4414       int instance_id = meet_instance_id(tp->instance_id());
4415       const TypePtr* speculative = xmeet_speculative(tp);
4416       int depth = meet_inline_depth(tp->inline_depth());
4417       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4418     }
4419     default: typerr(t);
4420     }
4421   }
4422 
4423   case AnyPtr: {                // Meeting to AnyPtrs
4424     // Found an AnyPtr type vs self-InstPtr type
4425     const TypePtr *tp = t->is_ptr();
4426     Offset offset = meet_offset(tp->offset());
4427     PTR ptr = meet_ptr(tp->ptr());
4428     int instance_id = meet_instance_id(InstanceTop);
4429     const TypePtr* speculative = xmeet_speculative(tp);
4430     int depth = meet_inline_depth(tp->inline_depth());
4431     switch (tp->ptr()) {
4432     case Null:
4433       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4434       // else fall through to AnyNull
4435     case TopPTR:
4436     case AnyNull: {
4437       return make(ptr, klass(), _interfaces, klass_is_exact(),
4438                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4439     }
4440     case NotNull:
4441     case BotPTR:
4442       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4443     default: typerr(t);
4444     }
4445   }
4446 
4447   /*
4448                  A-top         }
4449                /   |   \       }  Tops
4450            B-top A-any C-top   }
4451               | /  |  \ |      }  Any-nulls
4452            B-any   |   C-any   }
4453               |    |    |
4454            B-con A-con C-con   } constants; not comparable across classes
4455               |    |    |
4456            B-not   |   C-not   }
4457               | \  |  / |      }  not-nulls
4458            B-bot A-not C-bot   }
4459                \   |   /       }  Bottoms
4460                  A-bot         }
4461   */
4462 
4463   case InstPtr: {                // Meeting 2 Oops?
4464     // Found an InstPtr sub-type vs self-InstPtr type
4465     const TypeInstPtr *tinst = t->is_instptr();
4466     Offset off = meet_offset(tinst->offset());
4467     PTR ptr = meet_ptr(tinst->ptr());
4468     int instance_id = meet_instance_id(tinst->instance_id());
4469     const TypePtr* speculative = xmeet_speculative(tinst);
4470     int depth = meet_inline_depth(tinst->inline_depth());
4471     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4472 
4473     ciKlass* tinst_klass = tinst->klass();
4474     ciKlass* this_klass  = klass();
4475 
4476     ciKlass* res_klass = nullptr;
4477     bool res_xk = false;
4478     bool res_flat_in_array = false;
4479     const Type* res;
4480     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk, res_flat_in_array);
4481 
4482     if (kind == UNLOADED) {
4483       // One of these classes has not been loaded
4484       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4485 #ifndef PRODUCT
4486       if (PrintOpto && Verbose) {
4487         tty->print("meet of unloaded classes resulted in: ");
4488         unloaded_meet->dump();
4489         tty->cr();
4490         tty->print("  this == ");
4491         dump();
4492         tty->cr();
4493         tty->print(" tinst == ");
4494         tinst->dump();
4495         tty->cr();
4496       }
4497 #endif
4498       res = unloaded_meet;
4499     } else {
4500       if (kind == NOT_SUBTYPE && instance_id > 0) {
4501         instance_id = InstanceBot;
4502       } else if (kind == LCA) {
4503         instance_id = InstanceBot;
4504       }
4505       ciObject* o = nullptr;             // Assume not constant when done
4506       ciObject* this_oop = const_oop();
4507       ciObject* tinst_oop = tinst->const_oop();
4508       if (ptr == Constant) {
4509         if (this_oop != nullptr && tinst_oop != nullptr &&
4510             this_oop->equals(tinst_oop))
4511           o = this_oop;
4512         else if (above_centerline(_ptr)) {
4513           assert(!tinst_klass->is_interface(), "");
4514           o = tinst_oop;
4515         } else if (above_centerline(tinst->_ptr)) {
4516           assert(!this_klass->is_interface(), "");
4517           o = this_oop;
4518         } else
4519           ptr = NotNull;
4520       }
4521       res = make(ptr, res_klass, interfaces, res_xk, o, off, res_flat_in_array, instance_id, speculative, depth);
4522     }
4523 
4524     return res;
4525 
4526   } // End of case InstPtr
4527 
4528   } // End of switch
4529   return this;                  // Return the double constant
4530 }
4531 
4532 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4533                                                             ciKlass*& res_klass, bool& res_xk, bool& res_flat_in_array) {
4534   ciKlass* this_klass = this_type->klass();
4535   ciKlass* other_klass = other_type->klass();
4536   bool this_flat_in_array = this_type->flat_in_array();
4537   bool other_flat_in_array = other_type->flat_in_array();
4538   bool this_flat_in_array_orig = this_flat_in_array;
4539   bool other_flat_in_array_orig = other_flat_in_array;
4540   bool this_xk = this_type->klass_is_exact();
4541   bool other_xk = other_type->klass_is_exact();
4542   PTR this_ptr = this_type->ptr();
4543   PTR other_ptr = other_type->ptr();
4544   const TypeInterfaces* this_interfaces = this_type->interfaces();
4545   const TypeInterfaces* other_interfaces = other_type->interfaces();
4546   // Check for easy case; klasses are equal (and perhaps not loaded!)
4547   // If we have constants, then we created oops so classes are loaded
4548   // and we can handle the constants further down.  This case handles
4549   // both-not-loaded or both-loaded classes
4550   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk && this_flat_in_array == other_flat_in_array) {
4551     res_klass = this_klass;
4552     res_xk = this_xk;
4553     res_flat_in_array = this_flat_in_array;
4554     return QUICK;
4555   }
4556 
4557   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4558   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4559     return UNLOADED;
4560   }
4561 
4562   // !!! Here's how the symmetry requirement breaks down into invariants:
4563   // If we split one up & one down AND they subtype, take the down man.
4564   // If we split one up & one down AND they do NOT subtype, "fall hard".
4565   // If both are up and they subtype, take the subtype class.
4566   // If both are up and they do NOT subtype, "fall hard".
4567   // If both are down and they subtype, take the supertype class.
4568   // If both are down and they do NOT subtype, "fall hard".
4569   // Constants treated as down.
4570 
4571   // Now, reorder the above list; observe that both-down+subtype is also
4572   // "fall hard"; "fall hard" becomes the default case:
4573   // If we split one up & one down AND they subtype, take the down man.
4574   // If both are up and they subtype, take the subtype class.
4575 
4576   // If both are down and they subtype, "fall hard".
4577   // If both are down and they do NOT subtype, "fall hard".
4578   // If both are up and they do NOT subtype, "fall hard".
4579   // If we split one up & one down AND they do NOT subtype, "fall hard".
4580 
4581   // If a proper subtype is exact, and we return it, we return it exactly.
4582   // If a proper supertype is exact, there can be no subtyping relationship!
4583   // If both types are equal to the subtype, exactness is and-ed below the
4584   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4585 
4586   // Check for subtyping:
4587   const T* subtype = nullptr;
4588   bool subtype_exact = false;
4589   bool flat_array = false;
4590   if (this_type->is_same_java_type_as(other_type)) {
4591     subtype = this_type;
4592     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4593     flat_array = below_centerline(ptr) ? (this_flat_in_array && other_flat_in_array) : (this_flat_in_array || other_flat_in_array);
4594   } else if (!other_xk && this_type->is_meet_subtype_of(other_type) && (!other_flat_in_array || this_flat_in_array)) {
4595     subtype = this_type;     // Pick subtyping class
4596     subtype_exact = this_xk;
4597     flat_array = this_flat_in_array;
4598   } else if (!this_xk && other_type->is_meet_subtype_of(this_type) && (!this_flat_in_array || other_flat_in_array)) {
4599     subtype = other_type;    // Pick subtyping class
4600     subtype_exact = other_xk;
4601     flat_array = other_flat_in_array;
4602   }
4603 
4604   if (subtype) {
4605     if (above_centerline(ptr)) { // both are up?
4606       this_type = other_type = subtype;
4607       this_xk = other_xk = subtype_exact;
4608       this_flat_in_array = other_flat_in_array = flat_array;
4609     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4610       this_type = other_type; // tinst is down; keep down man
4611       this_xk = other_xk;
4612       this_flat_in_array = other_flat_in_array;
4613     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4614       other_type = this_type; // this is down; keep down man
4615       other_xk = this_xk;
4616       other_flat_in_array = this_flat_in_array;
4617     } else {
4618       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4619       this_flat_in_array = flat_array;
4620     }
4621   }
4622 
4623   // Check for classes now being equal
4624   if (this_type->is_same_java_type_as(other_type)) {
4625     // If the klasses are equal, the constants may still differ.  Fall to
4626     // NotNull if they do (neither constant is null; that is a special case
4627     // handled elsewhere).
4628     res_klass = this_type->klass();
4629     res_xk = this_xk;
4630     res_flat_in_array = this_flat_in_array;
4631     return SUBTYPE;
4632   } // Else classes are not equal
4633 
4634   // Since klasses are different, we require a LCA in the Java
4635   // class hierarchy - which means we have to fall to at least NotNull.
4636   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4637     ptr = NotNull;
4638   }
4639 
4640   interfaces = this_interfaces->intersection_with(other_interfaces);
4641 
4642   // Now we find the LCA of Java classes
4643   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4644 
4645   res_klass = k;
4646   res_xk = false;
4647   res_flat_in_array = this_flat_in_array_orig && other_flat_in_array_orig;
4648 
4649   return LCA;
4650 }
4651 
4652 //------------------------java_mirror_type--------------------------------------
4653 ciType* TypeInstPtr::java_mirror_type(bool* is_val_mirror) const {
4654   // must be a singleton type
4655   if( const_oop() == nullptr )  return nullptr;
4656 
4657   // must be of type java.lang.Class
4658   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;
4659   return const_oop()->as_instance()->java_mirror_type(is_val_mirror);

4660 }
4661 
4662 
4663 //------------------------------xdual------------------------------------------
4664 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4665 // inheritance mechanism.
4666 const Type *TypeInstPtr::xdual() const {
4667   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), flat_in_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4668 }
4669 
4670 //------------------------------eq---------------------------------------------
4671 // Structural equality check for Type representations
4672 bool TypeInstPtr::eq( const Type *t ) const {
4673   const TypeInstPtr *p = t->is_instptr();
4674   return
4675     klass()->equals(p->klass()) &&
4676     flat_in_array() == p->flat_in_array() &&
4677     _interfaces->eq(p->_interfaces) &&
4678     TypeOopPtr::eq(p);          // Check sub-type stuff
4679 }
4680 
4681 //------------------------------hash-------------------------------------------
4682 // Type-specific hashing function.
4683 uint TypeInstPtr::hash(void) const {
4684   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + (uint)flat_in_array();
4685 }
4686 
4687 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4688   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4689 }
4690 
4691 
4692 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4693   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4694 }
4695 
4696 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4697   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4698 }
4699 
4700 
4701 //------------------------------dump2------------------------------------------
4702 // Dump oop Type
4703 #ifndef PRODUCT
4704 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {

4718       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4719       char* buf = ss.as_string(/* c_heap= */false);
4720       StringUtils::replace_no_expand(buf, "\n", "");
4721       st->print_raw(buf);
4722     }
4723   case BotPTR:
4724     if (!WizardMode && !Verbose) {
4725       if( _klass_is_exact ) st->print(":exact");
4726       break;
4727     }
4728   case TopPTR:
4729   case AnyNull:
4730   case NotNull:
4731     st->print(":%s", ptr_msg[_ptr]);
4732     if( _klass_is_exact ) st->print(":exact");
4733     break;
4734   default:
4735     break;
4736   }
4737 
4738   _offset.dump2(st);




4739 
4740   st->print(" *");
4741 
4742   if (flat_in_array() && !klass()->is_inlinetype()) {
4743     st->print(" (flat in array)");
4744   }
4745 
4746   if (_instance_id == InstanceTop)
4747     st->print(",iid=top");
4748   else if (_instance_id != InstanceBot)
4749     st->print(",iid=%d",_instance_id);
4750 
4751   dump_inline_depth(st);
4752   dump_speculative(st);
4753 }
4754 #endif
4755 
4756 //------------------------------add_offset-------------------------------------
4757 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4758   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), flat_in_array(),
4759               _instance_id, add_offset_speculative(offset), _inline_depth);
4760 }
4761 
4762 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4763   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), flat_in_array(),
4764               _instance_id, with_offset_speculative(offset), _inline_depth);
4765 }
4766 
4767 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4768   if (_speculative == nullptr) {
4769     return this;
4770   }
4771   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4772   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(),
4773               _instance_id, nullptr, _inline_depth);
4774 }
4775 
4776 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4777   if (!UseInlineDepthForSpeculativeTypes) {
4778     return this;
4779   }
4780   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, _speculative, depth);
4781 }
4782 
4783 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4784   assert(is_known_instance(), "should be known");
4785   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), instance_id, _speculative, _inline_depth);
4786 }
4787 
4788 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4789   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4790 }
4791 
4792 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4793   bool xk = klass_is_exact();
4794   ciInstanceKlass* ik = klass()->as_instance_klass();
4795   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4796     if (_interfaces->eq(ik)) {
4797       Compile* C = Compile::current();
4798       Dependencies* deps = C->dependencies();
4799       deps->assert_leaf_type(ik);
4800       xk = true;
4801     }
4802   }
4803   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array());
4804 }
4805 
4806 template <class T1, class T2> bool TypePtr::is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk) {
4807   static_assert(std::is_base_of<T2, T1>::value, "");
4808 
4809   if (!this_one->is_instance_type(other)) {
4810     return false;
4811   }
4812 
4813   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4814     return true;
4815   }
4816 
4817   return this_one->klass()->is_subtype_of(other->klass()) &&
4818          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4819 }
4820 
4821 
4822 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4823   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);

4828   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4829     return true;
4830   }
4831 
4832   if (this_one->is_instance_type(other)) {
4833     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4834   }
4835 
4836   int dummy;
4837   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4838   if (this_top_or_bottom) {
4839     return false;
4840   }
4841 
4842   const T1* other_ary = this_one->is_array_type(other);
4843   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4844   const TypePtr* this_elem = this_one->elem()->make_ptr();
4845   if (other_elem != nullptr && this_elem != nullptr) {
4846     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4847   }

4848   if (other_elem == nullptr && this_elem == nullptr) {
4849     return this_one->_klass->is_subtype_of(other->_klass);
4850   }
4851 
4852   return false;
4853 }
4854 
4855 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4856   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4857 }
4858 
4859 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4860   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4861 }
4862 
4863 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4864   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4865 }
4866 
4867 //=============================================================================
4868 // Convenience common pre-built types.
4869 const TypeAryPtr *TypeAryPtr::RANGE;
4870 const TypeAryPtr *TypeAryPtr::OOPS;
4871 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4872 const TypeAryPtr *TypeAryPtr::BYTES;
4873 const TypeAryPtr *TypeAryPtr::SHORTS;
4874 const TypeAryPtr *TypeAryPtr::CHARS;
4875 const TypeAryPtr *TypeAryPtr::INTS;
4876 const TypeAryPtr *TypeAryPtr::LONGS;
4877 const TypeAryPtr *TypeAryPtr::FLOATS;
4878 const TypeAryPtr *TypeAryPtr::DOUBLES;
4879 const TypeAryPtr *TypeAryPtr::INLINES;
4880 
4881 //------------------------------make-------------------------------------------
4882 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4883                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4884   assert(!(k == nullptr && ary->_elem->isa_int()),
4885          "integral arrays must be pre-equipped with a class");
4886   if (!xk)  xk = ary->ary_must_be_exact();
4887   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4888   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4889       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4890     k = nullptr;
4891   }
4892   if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
4893     k = nullptr;
4894   }
4895   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4896 }
4897 
4898 //------------------------------make-------------------------------------------
4899 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4900                                    int instance_id, const TypePtr* speculative, int inline_depth,
4901                                    bool is_autobox_cache) {
4902   assert(!(k == nullptr && ary->_elem->isa_int()),
4903          "integral arrays must be pre-equipped with a class");
4904   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4905   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
4906   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4907   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4908       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4909     k = nullptr;
4910   }
4911   if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
4912     k = nullptr;
4913   }
4914   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4915 }
4916 
4917 //------------------------------cast_to_ptr_type-------------------------------
4918 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4919   if( ptr == _ptr ) return this;
4920   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4921 }
4922 
4923 
4924 //-----------------------------cast_to_exactness-------------------------------
4925 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4926   if( klass_is_exact == _klass_is_exact ) return this;
4927   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4928   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4929 }
4930 
4931 //-----------------------------cast_to_instance_id----------------------------
4932 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4933   if( instance_id == _instance_id ) return this;
4934   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
4935 }
4936 
4937 
4938 //-----------------------------max_array_length-------------------------------
4939 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4940 jint TypeAryPtr::max_array_length(BasicType etype) {
4941   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4942     if (etype == T_NARROWOOP) {
4943       etype = T_OBJECT;
4944     } else if (etype == T_ILLEGAL) { // bottom[]
4945       etype = T_BYTE; // will produce conservatively high value
4946     } else {
4947       fatal("not an element type: %s", type2name(etype));
4948     }
4949   }
4950   return arrayOopDesc::max_array_length(etype);
4951 }
4952 
4953 //-----------------------------narrow_size_type-------------------------------
4954 // Narrow the given size type to the index range for the given array base type.

4970   if (hi > max_hi) {
4971     hi = max_hi;
4972     if (size->is_con()) {
4973       lo = hi;
4974     }
4975     chg = true;
4976   }
4977   // Negative length arrays will produce weird intermediate dead fast-path code
4978   if (lo > hi)
4979     return TypeInt::ZERO;
4980   if (!chg)
4981     return size;
4982   return TypeInt::make(lo, hi, Type::WidenMin);
4983 }
4984 
4985 //-------------------------------cast_to_size----------------------------------
4986 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4987   assert(new_size != nullptr, "");
4988   new_size = narrow_size_type(new_size);
4989   if (new_size == size())  return this;
4990   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free());
4991   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4992 }
4993 
4994 //-------------------------------cast_to_not_flat------------------------------
4995 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
4996   if (not_flat == is_not_flat()) {
4997     return this;
4998   }
4999   assert(!not_flat || !is_flat(), "inconsistency");
5000   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free());
5001   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5002   // We keep the speculative part if it contains information about flat-/nullability.
5003   // Make sure it's removed if it's not better than the non-speculative type anymore.
5004   if (res->speculative() == res->remove_speculative()) {
5005     return res->remove_speculative();
5006   }
5007   return res;
5008 }
5009 
5010 //-------------------------------cast_to_not_null_free-------------------------
5011 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5012   if (not_null_free == is_not_null_free()) {
5013     return this;
5014   }
5015   assert(!not_null_free || !is_flat(), "inconsistency");
5016   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), /* not_flat= */ not_null_free ? true : is_not_flat(), not_null_free);
5017   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5018                                _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5019   // We keep the speculative part if it contains information about flat-/nullability.
5020   // Make sure it's removed if it's not better than the non-speculative type anymore.
5021   if (res->speculative() == res->remove_speculative()) {
5022     return res->remove_speculative();
5023   }
5024   return res;
5025 }
5026 
5027 //---------------------------------update_properties---------------------------
5028 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5029   if ((from->is_flat()          && is_not_flat()) ||
5030       (from->is_not_flat()      && is_flat()) ||
5031       (from->is_null_free()     && is_not_null_free()) ||
5032       (from->is_not_null_free() && is_null_free())) {
5033     return nullptr; // Inconsistent properties
5034   } else if (from->is_not_null_free()) {
5035     return cast_to_not_null_free(); // Implies not flat
5036   } else if (from->is_not_flat()) {
5037     return cast_to_not_flat();
5038   }
5039   return this;
5040 }
5041 
5042 jint TypeAryPtr::flat_layout_helper() const {
5043   return klass()->as_flat_array_klass()->layout_helper();
5044 }
5045 
5046 int TypeAryPtr::flat_elem_size() const {
5047   return klass()->as_flat_array_klass()->element_byte_size();
5048 }
5049 
5050 int TypeAryPtr::flat_log_elem_size() const {
5051   return klass()->as_flat_array_klass()->log2_element_size();
5052 }
5053 
5054 //------------------------------cast_to_stable---------------------------------
5055 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5056   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5057     return this;
5058 
5059   const Type* elem = this->elem();
5060   const TypePtr* elem_ptr = elem->make_ptr();
5061 
5062   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5063     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5064     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5065   }
5066 
5067   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free());
5068 
5069   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5070 }
5071 
5072 //-----------------------------stable_dimension--------------------------------
5073 int TypeAryPtr::stable_dimension() const {
5074   if (!is_stable())  return 0;
5075   int dim = 1;
5076   const TypePtr* elem_ptr = elem()->make_ptr();
5077   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5078     dim += elem_ptr->is_aryptr()->stable_dimension();
5079   return dim;
5080 }
5081 
5082 //----------------------cast_to_autobox_cache-----------------------------------
5083 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5084   if (is_autobox_cache())  return this;
5085   const TypeOopPtr* etype = elem()->make_oopptr();
5086   if (etype == nullptr)  return this;
5087   // The pointers in the autobox arrays are always non-null.
5088   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5089   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free());
5090   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5091 }
5092 
5093 //------------------------------eq---------------------------------------------
5094 // Structural equality check for Type representations
5095 bool TypeAryPtr::eq( const Type *t ) const {
5096   const TypeAryPtr *p = t->is_aryptr();
5097   return
5098     _ary == p->_ary &&  // Check array
5099     TypeOopPtr::eq(p) &&// Check sub-parts
5100     _field_offset == p->_field_offset;
5101 }
5102 
5103 //------------------------------hash-------------------------------------------
5104 // Type-specific hashing function.
5105 uint TypeAryPtr::hash(void) const {
5106   return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5107 }
5108 
5109 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5110   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5111 }
5112 
5113 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5114   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5115 }
5116 
5117 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5118   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5119 }
5120 //------------------------------meet-------------------------------------------
5121 // Compute the MEET of two types.  It returns a new Type object.
5122 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5123   // Perform a fast test for common case; meeting the same types together.
5124   if( this == t ) return this;  // Meeting same type-rep?
5125   // Current "this->_base" is Pointer
5126   switch (t->base()) {          // switch on original type

5130   case Long:
5131   case FloatTop:
5132   case FloatCon:
5133   case FloatBot:
5134   case DoubleTop:
5135   case DoubleCon:
5136   case DoubleBot:
5137   case NarrowOop:
5138   case NarrowKlass:
5139   case Bottom:                  // Ye Olde Default
5140     return Type::BOTTOM;
5141   case Top:
5142     return this;
5143 
5144   default:                      // All else is a mistake
5145     typerr(t);
5146 
5147   case OopPtr: {                // Meeting to OopPtrs
5148     // Found a OopPtr type vs self-AryPtr type
5149     const TypeOopPtr *tp = t->is_oopptr();
5150     Offset offset = meet_offset(tp->offset());
5151     PTR ptr = meet_ptr(tp->ptr());
5152     int depth = meet_inline_depth(tp->inline_depth());
5153     const TypePtr* speculative = xmeet_speculative(tp);
5154     switch (tp->ptr()) {
5155     case TopPTR:
5156     case AnyNull: {
5157       int instance_id = meet_instance_id(InstanceTop);
5158       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5159                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5160     }
5161     case BotPTR:
5162     case NotNull: {
5163       int instance_id = meet_instance_id(tp->instance_id());
5164       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5165     }
5166     default: ShouldNotReachHere();
5167     }
5168   }
5169 
5170   case AnyPtr: {                // Meeting two AnyPtrs
5171     // Found an AnyPtr type vs self-AryPtr type
5172     const TypePtr *tp = t->is_ptr();
5173     Offset offset = meet_offset(tp->offset());
5174     PTR ptr = meet_ptr(tp->ptr());
5175     const TypePtr* speculative = xmeet_speculative(tp);
5176     int depth = meet_inline_depth(tp->inline_depth());
5177     switch (tp->ptr()) {
5178     case TopPTR:
5179       return this;
5180     case BotPTR:
5181     case NotNull:
5182       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5183     case Null:
5184       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5185       // else fall through to AnyNull
5186     case AnyNull: {
5187       int instance_id = meet_instance_id(InstanceTop);
5188       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5189                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5190     }
5191     default: ShouldNotReachHere();
5192     }
5193   }
5194 
5195   case MetadataPtr:
5196   case KlassPtr:
5197   case InstKlassPtr:
5198   case AryKlassPtr:
5199   case RawPtr: return TypePtr::BOTTOM;
5200 
5201   case AryPtr: {                // Meeting 2 references?
5202     const TypeAryPtr *tap = t->is_aryptr();
5203     Offset off = meet_offset(tap->offset());
5204     Offset field_off = meet_field_offset(tap->field_offset());
5205     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5206     PTR ptr = meet_ptr(tap->ptr());
5207     int instance_id = meet_instance_id(tap->instance_id());
5208     const TypePtr* speculative = xmeet_speculative(tap);
5209     int depth = meet_inline_depth(tap->inline_depth());
5210 
5211     ciKlass* res_klass = nullptr;
5212     bool res_xk = false;
5213     bool res_flat = false;
5214     bool res_not_flat = false;
5215     bool res_not_null_free = false;
5216     const Type* elem = tary->_elem;
5217     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
5218       instance_id = InstanceBot;
5219     } else if (this->is_flat() != tap->is_flat()) {
5220       // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5221       if (tary->_flat) {
5222         // Result is in a flat representation
5223         off = Offset(is_flat() ? offset() : tap->offset());
5224         field_off = is_flat() ? field_offset() : tap->field_offset();
5225       } else if (below_centerline(ptr)) {
5226         // Result is in a non-flat representation
5227         off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5228         field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5229       } else if (flat_offset() == tap->flat_offset()) {
5230         off = Offset(!is_flat() ? offset() : tap->offset());
5231         field_off = !is_flat() ? field_offset() : tap->field_offset();
5232       }
5233     }
5234 
5235     ciObject* o = nullptr;             // Assume not constant when done
5236     ciObject* this_oop = const_oop();
5237     ciObject* tap_oop = tap->const_oop();
5238     if (ptr == Constant) {
5239       if (this_oop != nullptr && tap_oop != nullptr &&
5240           this_oop->equals(tap_oop)) {
5241         o = tap_oop;
5242       } else if (above_centerline(_ptr)) {
5243         o = tap_oop;
5244       } else if (above_centerline(tap->_ptr)) {
5245         o = this_oop;
5246       } else {
5247         ptr = NotNull;
5248       }
5249     }
5250     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable, res_flat, res_not_flat, res_not_null_free), res_klass, res_xk, off, field_off, instance_id, speculative, depth);
5251   }
5252 
5253   // All arrays inherit from Object class
5254   case InstPtr: {
5255     const TypeInstPtr *tp = t->is_instptr();
5256     Offset offset = meet_offset(tp->offset());
5257     PTR ptr = meet_ptr(tp->ptr());
5258     int instance_id = meet_instance_id(tp->instance_id());
5259     const TypePtr* speculative = xmeet_speculative(tp);
5260     int depth = meet_inline_depth(tp->inline_depth());
5261     const TypeInterfaces* interfaces = meet_interfaces(tp);
5262     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5263     const TypeInterfaces* this_interfaces = _interfaces;
5264 
5265     switch (ptr) {
5266     case TopPTR:
5267     case AnyNull:                // Fall 'down' to dual of object klass
5268       // For instances when a subclass meets a superclass we fall
5269       // below the centerline when the superclass is exact. We need to
5270       // do the same here.
5271       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5272         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5273       } else {
5274         // cannot subclass, so the meet has to fall badly below the centerline
5275         ptr = NotNull;
5276         instance_id = InstanceBot;
5277         interfaces = this_interfaces->intersection_with(tp_interfaces);
5278         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5279       }
5280     case Constant:
5281     case NotNull:
5282     case BotPTR:                // Fall down to object klass
5283       // LCA is object_klass, but if we subclass from the top we can do better
5284       if (above_centerline(tp->ptr())) {
5285         // If 'tp'  is above the centerline and it is Object class
5286         // then we can subclass in the Java class hierarchy.
5287         // For instances when a subclass meets a superclass we fall
5288         // below the centerline when the superclass is exact. We need
5289         // to do the same here.
5290         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5291           // that is, my array type is a subtype of 'tp' klass
5292           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5293                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5294         }
5295       }
5296       // The other case cannot happen, since t cannot be a subtype of an array.
5297       // The meet falls down to Object class below centerline.
5298       if (ptr == Constant) {
5299          ptr = NotNull;
5300       }
5301       if (instance_id > 0) {
5302         instance_id = InstanceBot;
5303       }
5304       interfaces = this_interfaces->intersection_with(tp_interfaces);
5305       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5306     default: typerr(t);
5307     }
5308   }
5309   }
5310   return this;                  // Lint noise
5311 }
5312 
5313 
5314 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5315                                                            ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free) {
5316   int dummy;
5317   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5318   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5319   ciKlass* this_klass = this_ary->klass();
5320   ciKlass* other_klass = other_ary->klass();
5321   bool this_xk = this_ary->klass_is_exact();
5322   bool other_xk = other_ary->klass_is_exact();
5323   PTR this_ptr = this_ary->ptr();
5324   PTR other_ptr = other_ary->ptr();
5325   bool this_flat = this_ary->is_flat();
5326   bool this_not_flat = this_ary->is_not_flat();
5327   bool other_flat = other_ary->is_flat();
5328   bool other_not_flat = other_ary->is_not_flat();
5329   bool this_not_null_free = this_ary->is_not_null_free();
5330   bool other_not_null_free = other_ary->is_not_null_free();
5331   res_klass = nullptr;
5332   MeetResult result = SUBTYPE;
5333   res_flat = this_flat && other_flat;
5334   res_not_flat = this_not_flat && other_not_flat;
5335   res_not_null_free = this_not_null_free && other_not_null_free;
5336 
5337   if (elem->isa_int()) {
5338     // Integral array element types have irrelevant lattice relations.
5339     // It is the klass that determines array layout, not the element type.
5340       if (this_top_or_bottom) {
5341         res_klass = other_klass;
5342       } else if (other_top_or_bottom || other_klass == this_klass) {
5343       res_klass = this_klass;
5344     } else {
5345       // Something like byte[int+] meets char[int+].
5346       // This must fall to bottom, not (int[-128..65535])[int+].
5347       // instance_id = InstanceBot;
5348       elem = Type::BOTTOM;
5349       result = NOT_SUBTYPE;
5350       if (above_centerline(ptr) || ptr == Constant) {
5351         ptr = NotNull;
5352         res_xk = false;
5353         return NOT_SUBTYPE;
5354       }
5355     }
5356   } else {// Non integral arrays.
5357     // Must fall to bottom if exact klasses in upper lattice
5358     // are not equal or super klass is exact.
5359     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5360         // meet with top[] and bottom[] are processed further down:
5361         !this_top_or_bottom && !other_top_or_bottom &&
5362         // both are exact and not equal:

5364          // 'tap'  is exact and super or unrelated:
5365          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5366          // 'this' is exact and super or unrelated:
5367          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5368       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5369         elem = Type::BOTTOM;
5370       }
5371       ptr = NotNull;
5372       res_xk = false;
5373       return NOT_SUBTYPE;
5374     }
5375   }
5376 
5377   res_xk = false;
5378   switch (other_ptr) {
5379     case AnyNull:
5380     case TopPTR:
5381       // Compute new klass on demand, do not use tap->_klass
5382       if (below_centerline(this_ptr)) {
5383         res_xk = this_xk;
5384         if (this_ary->is_flat()) {
5385           elem = this_ary->elem();
5386         }
5387       } else {
5388         res_xk = (other_xk || this_xk);
5389       }
5390       break;
5391     case Constant: {
5392       if (this_ptr == Constant) {
5393         res_xk = true;
5394       } else if (above_centerline(this_ptr)) {
5395         res_xk = true;
5396       } else {
5397         // Only precise for identical arrays
5398         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5399         // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5400         if (res_xk && !res_not_null_free) {
5401           res_xk = false;
5402         }
5403       }
5404       break;
5405     }
5406     case NotNull:
5407     case BotPTR:
5408       // Compute new klass on demand, do not use tap->_klass
5409       if (above_centerline(this_ptr)) {
5410         res_xk = other_xk;
5411         if (other_ary->is_flat()) {
5412           elem = other_ary->elem();
5413         }
5414       } else {
5415         res_xk = (other_xk && this_xk) &&
5416                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5417         // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5418         if (res_xk && !res_not_null_free) {
5419           res_xk = false;
5420         }
5421       }
5422       break;
5423     default:  {
5424       ShouldNotReachHere();
5425       return result;
5426     }
5427   }
5428   return result;
5429 }
5430 
5431 
5432 //------------------------------xdual------------------------------------------
5433 // Dual: compute field-by-field dual
5434 const Type *TypeAryPtr::xdual() const {
5435   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());
5436 }
5437 
5438 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5439   return _field_offset.meet(offset);
5440 }
5441 
5442 //------------------------------dual_offset------------------------------------
5443 Type::Offset TypeAryPtr::dual_field_offset() const {
5444   return _field_offset.dual();
5445 }
5446 
5447 //------------------------------dump2------------------------------------------
5448 #ifndef PRODUCT
5449 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5450   _ary->dump2(d,depth,st);
5451   _interfaces->dump(st);
5452 
5453   switch( _ptr ) {
5454   case Constant:
5455     const_oop()->print(st);
5456     break;
5457   case BotPTR:
5458     if (!WizardMode && !Verbose) {
5459       if( _klass_is_exact ) st->print(":exact");
5460       break;
5461     }
5462   case TopPTR:
5463   case AnyNull:
5464   case NotNull:
5465     st->print(":%s", ptr_msg[_ptr]);
5466     if( _klass_is_exact ) st->print(":exact");
5467     break;
5468   default:
5469     break;
5470   }
5471 
5472   if (is_flat()) {
5473     st->print(":flat");
5474     st->print("(");
5475     _field_offset.dump2(st);
5476     st->print(")");
5477   }
5478   if (is_null_free()) {
5479     st->print(":null_free");
5480   }
5481   if (offset() != 0) {
5482     int header_size = objArrayOopDesc::header_size() * wordSize;
5483     if( _offset == Offset::top )       st->print("+undefined");
5484     else if( _offset == Offset::bottom )  st->print("+any");
5485     else if( offset() < header_size ) st->print("+%d", offset());
5486     else {
5487       BasicType basic_elem_type = elem()->basic_type();
5488       if (basic_elem_type == T_ILLEGAL) {
5489         st->print("+any");
5490       } else {
5491         int array_base = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5492         int elem_size = type2aelembytes(basic_elem_type);
5493         st->print("[%d]", (offset() - array_base)/elem_size);
5494       }
5495     }
5496   }
5497   st->print(" *");
5498   if (_instance_id == InstanceTop)
5499     st->print(",iid=top");
5500   else if (_instance_id != InstanceBot)
5501     st->print(",iid=%d",_instance_id);
5502 
5503   dump_inline_depth(st);
5504   dump_speculative(st);
5505 }
5506 #endif
5507 
5508 bool TypeAryPtr::empty(void) const {
5509   if (_ary->empty())       return true;
5510   // FIXME: Does this belong here? Or in the meet code itself?
5511   if (is_flat() && is_not_flat()) {
5512     return true;
5513   }
5514   return TypeOopPtr::empty();
5515 }
5516 
5517 //------------------------------add_offset-------------------------------------
5518 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5519   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);
5520 }
5521 
5522 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5523   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, Offset(offset), _field_offset, _instance_id, with_offset_speculative(offset), _inline_depth, _is_autobox_cache);
5524 }
5525 
5526 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5527   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5528 }
5529 
5530 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5531   if (_speculative == nullptr) {
5532     return this;
5533   }
5534   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5535   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, nullptr, _inline_depth, _is_autobox_cache);
5536 }
5537 
5538 const Type* TypeAryPtr::cleanup_speculative() const {
5539   if (speculative() == nullptr) {
5540     return this;
5541   }
5542   // Keep speculative part if it contains information about flat-/nullability
5543   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5544   if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5545       (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5546     return this;
5547   }
5548   return TypeOopPtr::cleanup_speculative();
5549 }
5550 
5551 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5552   if (!UseInlineDepthForSpeculativeTypes) {
5553     return this;
5554   }
5555   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5556 }
5557 
5558 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5559   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);
5560 }
5561 
5562 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5563   int adj = 0;
5564   if (is_flat() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5565     if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5566       adj = _offset.get();
5567       offset += _offset.get();
5568     }
5569     uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5570     if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5571       offset += _field_offset.get();
5572       if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5573         offset += header;
5574       }
5575     }
5576     if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5577       // Try to get the field of the inline type array element we are pointing to
5578       ciInlineKlass* vk = elem()->inline_klass();
5579       int shift = flat_log_elem_size();
5580       int mask = (1 << shift) - 1;
5581       intptr_t field_offset = ((offset - header) & mask);
5582       ciField* field = vk->get_field_by_offset(field_offset + vk->first_field_offset(), false);
5583       if (field != nullptr) {
5584         return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5585       }
5586     }
5587   }
5588   return add_offset(offset - adj);
5589 }
5590 
5591 // Return offset incremented by field_offset for flat inline type arrays
5592 int TypeAryPtr::flat_offset() const {
5593   int offset = _offset.get();
5594   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5595       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5596     offset += _field_offset.get();
5597   }
5598   return offset;
5599 }
5600 
5601 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5602   assert(is_known_instance(), "should be known");
5603   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5604 }
5605 
5606 //=============================================================================
5607 
5608 
5609 //------------------------------hash-------------------------------------------
5610 // Type-specific hashing function.
5611 uint TypeNarrowPtr::hash(void) const {
5612   return _ptrtype->hash() + 7;
5613 }
5614 
5615 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5616   return _ptrtype->singleton();
5617 }
5618 
5619 bool TypeNarrowPtr::empty(void) const {
5620   return _ptrtype->empty();
5621 }
5622 
5623 intptr_t TypeNarrowPtr::get_con() const {
5624   return _ptrtype->get_con();
5625 }
5626 
5627 bool TypeNarrowPtr::eq( const Type *t ) const {
5628   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5679 
5680   case Int:                     // Mixing ints & oops happens when javac
5681   case Long:                    // reuses local variables
5682   case FloatTop:
5683   case FloatCon:
5684   case FloatBot:
5685   case DoubleTop:
5686   case DoubleCon:
5687   case DoubleBot:
5688   case AnyPtr:
5689   case RawPtr:
5690   case OopPtr:
5691   case InstPtr:
5692   case AryPtr:
5693   case MetadataPtr:
5694   case KlassPtr:
5695   case InstKlassPtr:
5696   case AryKlassPtr:
5697   case NarrowOop:
5698   case NarrowKlass:

5699   case Bottom:                  // Ye Olde Default
5700     return Type::BOTTOM;
5701   case Top:
5702     return this;
5703 
5704   default:                      // All else is a mistake
5705     typerr(t);
5706 
5707   } // End of switch
5708 
5709   return this;
5710 }
5711 
5712 #ifndef PRODUCT
5713 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5714   _ptrtype->dump2(d, depth, st);
5715 }
5716 #endif
5717 
5718 const TypeNarrowOop *TypeNarrowOop::BOTTOM;

5762     return (one == two) && TypePtr::eq(t);
5763   } else {
5764     return one->equals(two) && TypePtr::eq(t);
5765   }
5766 }
5767 
5768 //------------------------------hash-------------------------------------------
5769 // Type-specific hashing function.
5770 uint TypeMetadataPtr::hash(void) const {
5771   return
5772     (metadata() ? metadata()->hash() : 0) +
5773     TypePtr::hash();
5774 }
5775 
5776 //------------------------------singleton--------------------------------------
5777 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5778 // constants
5779 bool TypeMetadataPtr::singleton(void) const {
5780   // detune optimizer to not generate constant metadata + constant offset as a constant!
5781   // TopPTR, Null, AnyNull, Constant are all singletons
5782   return (offset() == 0) && !below_centerline(_ptr);
5783 }
5784 
5785 //------------------------------add_offset-------------------------------------
5786 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5787   return make( _ptr, _metadata, xadd_offset(offset));
5788 }
5789 
5790 //-----------------------------filter------------------------------------------
5791 // Do not allow interface-vs.-noninterface joins to collapse to top.
5792 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5793   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5794   if (ft == nullptr || ft->empty())
5795     return Type::TOP;           // Canonical empty value
5796   return ft;
5797 }
5798 
5799  //------------------------------get_con----------------------------------------
5800 intptr_t TypeMetadataPtr::get_con() const {
5801   assert( _ptr == Null || _ptr == Constant, "" );
5802   assert(offset() >= 0, "");
5803 
5804   if (offset() != 0) {
5805     // After being ported to the compiler interface, the compiler no longer
5806     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5807     // to a handle at compile time.  This handle is embedded in the generated
5808     // code and dereferenced at the time the nmethod is made.  Until that time,
5809     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5810     // have access to the addresses!).  This does not seem to currently happen,
5811     // but this assertion here is to help prevent its occurrence.
5812     tty->print_cr("Found oop constant with non-zero offset");
5813     ShouldNotReachHere();
5814   }
5815 
5816   return (intptr_t)metadata()->constant_encoding();
5817 }
5818 
5819 //------------------------------cast_to_ptr_type-------------------------------
5820 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5821   if( ptr == _ptr ) return this;
5822   return make(ptr, metadata(), _offset);
5823 }
5824 

5835   case Long:                    // reuses local variables
5836   case FloatTop:
5837   case FloatCon:
5838   case FloatBot:
5839   case DoubleTop:
5840   case DoubleCon:
5841   case DoubleBot:
5842   case NarrowOop:
5843   case NarrowKlass:
5844   case Bottom:                  // Ye Olde Default
5845     return Type::BOTTOM;
5846   case Top:
5847     return this;
5848 
5849   default:                      // All else is a mistake
5850     typerr(t);
5851 
5852   case AnyPtr: {
5853     // Found an AnyPtr type vs self-OopPtr type
5854     const TypePtr *tp = t->is_ptr();
5855     Offset offset = meet_offset(tp->offset());
5856     PTR ptr = meet_ptr(tp->ptr());
5857     switch (tp->ptr()) {
5858     case Null:
5859       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5860       // else fall through:
5861     case TopPTR:
5862     case AnyNull: {
5863       return make(ptr, _metadata, offset);
5864     }
5865     case BotPTR:
5866     case NotNull:
5867       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5868     default: typerr(t);
5869     }
5870   }
5871 
5872   case RawPtr:
5873   case KlassPtr:
5874   case InstKlassPtr:
5875   case AryKlassPtr:
5876   case OopPtr:
5877   case InstPtr:
5878   case AryPtr:
5879     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5880 
5881   case MetadataPtr: {
5882     const TypeMetadataPtr *tp = t->is_metadataptr();
5883     Offset offset = meet_offset(tp->offset());
5884     PTR tptr = tp->ptr();
5885     PTR ptr = meet_ptr(tptr);
5886     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5887     if (tptr == TopPTR || _ptr == TopPTR ||
5888         metadata()->equals(tp->metadata())) {
5889       return make(ptr, md, offset);
5890     }
5891     // metadata is different
5892     if( ptr == Constant ) {  // Cannot be equal constants, so...
5893       if( tptr == Constant && _ptr != Constant)  return t;
5894       if( _ptr == Constant && tptr != Constant)  return this;
5895       ptr = NotNull;            // Fall down in lattice
5896     }
5897     return make(ptr, nullptr, offset);
5898     break;
5899   }
5900   } // End of switch
5901   return this;                  // Return the double constant
5902 }
5903 
5904 
5905 //------------------------------xdual------------------------------------------
5906 // Dual of a pure metadata pointer.
5907 const Type *TypeMetadataPtr::xdual() const {
5908   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5909 }
5910 
5911 //------------------------------dump2------------------------------------------
5912 #ifndef PRODUCT
5913 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5914   st->print("metadataptr:%s", ptr_msg[_ptr]);
5915   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5916   switch (offset()) {
5917   case OffsetTop: st->print("+top"); break;
5918   case OffsetBot: st->print("+any"); break;
5919   case         0: break;
5920   default:        st->print("+%d",offset()); break;
5921   }
5922 }
5923 #endif
5924 
5925 
5926 //=============================================================================
5927 // Convenience common pre-built type.
5928 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5929 
5930 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
5931   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5932 }
5933 
5934 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5935   return make(Constant, m, Offset(0));
5936 }
5937 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5938   return make(Constant, m, Offset(0));
5939 }
5940 
5941 //------------------------------make-------------------------------------------
5942 // Create a meta data constant
5943 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
5944   assert(m == nullptr || !m->is_klass(), "wrong type");
5945   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5946 }
5947 
5948 
5949 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5950   const Type* elem = _ary->_elem;
5951   bool xk = klass_is_exact();
5952   if (elem->make_oopptr() != nullptr) {
5953     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5954     if (elem->is_klassptr()->klass_is_exact() &&
5955         // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
5956         (is_null_free() || is_flat() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
5957       xk = true;
5958     }
5959   }
5960   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
5961 }
5962 
5963 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
5964   if (klass->is_instance_klass()) {
5965     return TypeInstKlassPtr::make(klass, interface_handling);
5966   }
5967   return TypeAryKlassPtr::make(klass, interface_handling);
5968 }
5969 
5970 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling) {
5971   if (klass->is_instance_klass()) {
5972     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5973     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5974   }
5975   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5976 }
5977 
5978 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)


5979   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5980   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5981          klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5982 }
5983 
5984 // Is there a single ciKlass* that can represent that type?
5985 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5986   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5987   if (_interfaces->empty()) {
5988     return _klass;
5989   }
5990   if (_klass != ciEnv::current()->Object_klass()) {
5991     if (_interfaces->eq(_klass->as_instance_klass())) {
5992       return _klass;
5993     }
5994     return nullptr;
5995   }
5996   return _interfaces->exact_klass();
5997 }
5998 
5999 //------------------------------eq---------------------------------------------
6000 // Structural equality check for Type representations
6001 bool TypeKlassPtr::eq(const Type *t) const {
6002   const TypeKlassPtr *p = t->is_klassptr();
6003   return
6004     _interfaces->eq(p->_interfaces) &&
6005     TypePtr::eq(p);
6006 }
6007 
6008 //------------------------------hash-------------------------------------------
6009 // Type-specific hashing function.
6010 uint TypeKlassPtr::hash(void) const {
6011   return TypePtr::hash() + _interfaces->hash();
6012 }
6013 
6014 //------------------------------singleton--------------------------------------
6015 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6016 // constants
6017 bool TypeKlassPtr::singleton(void) const {
6018   // detune optimizer to not generate constant klass + constant offset as a constant!
6019   // TopPTR, Null, AnyNull, Constant are all singletons
6020   return (offset() == 0) && !below_centerline(_ptr);
6021 }
6022 
6023 // Do not allow interface-vs.-noninterface joins to collapse to top.
6024 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6025   // logic here mirrors the one from TypeOopPtr::filter. See comments
6026   // there.
6027   const Type* ft = join_helper(kills, include_speculative);
6028   const TypeKlassPtr* ftkp = ft->isa_instklassptr();
6029   const TypeKlassPtr* ktkp = kills->isa_instklassptr();
6030 
6031   if (ft->empty()) {
6032     return Type::TOP;           // Canonical empty value
6033   }
6034 
6035   return ft;
6036 }
6037 
6038 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6039   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6040     return _interfaces->union_with(other->_interfaces);
6041   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6042     return other->_interfaces;
6043   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6044     return _interfaces;
6045   }
6046   return _interfaces->intersection_with(other->_interfaces);
6047 }
6048 
6049 //------------------------------get_con----------------------------------------
6050 intptr_t TypeKlassPtr::get_con() const {
6051   assert( _ptr == Null || _ptr == Constant, "" );
6052   assert( offset() >= 0, "" );
6053 
6054   if (offset() != 0) {
6055     // After being ported to the compiler interface, the compiler no longer
6056     // directly manipulates the addresses of oops.  Rather, it only has a pointer
6057     // to a handle at compile time.  This handle is embedded in the generated
6058     // code and dereferenced at the time the nmethod is made.  Until that time,
6059     // it is not reasonable to do arithmetic with the addresses of oops (we don't
6060     // have access to the addresses!).  This does not seem to currently happen,
6061     // but this assertion here is to help prevent its occurrence.
6062     tty->print_cr("Found oop constant with non-zero offset");
6063     ShouldNotReachHere();
6064   }
6065 
6066   ciKlass* k = exact_klass();
6067 
6068   return (intptr_t)k->constant_encoding();
6069 }
6070 
6071 //------------------------------dump2------------------------------------------
6072 // Dump Klass Type
6073 #ifndef PRODUCT
6074 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {

6078   case NotNull:
6079     {
6080       const char *name = klass()->name()->as_utf8();
6081       if (name) {
6082         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
6083       } else {
6084         ShouldNotReachHere();
6085       }
6086       _interfaces->dump(st);
6087     }
6088   case BotPTR:
6089     if (!WizardMode && !Verbose && _ptr != Constant) break;
6090   case TopPTR:
6091   case AnyNull:
6092     st->print(":%s", ptr_msg[_ptr]);
6093     if (_ptr == Constant) st->print(":exact");
6094     break;
6095   default:
6096     break;
6097   }
6098   if (Verbose) {
6099     if (isa_instklassptr() && is_instklassptr()->flat_in_array()) st->print(":flat in array");



6100   }
6101   _offset.dump2(st);
6102   st->print(" *");
6103 }
6104 #endif
6105 
6106 //=============================================================================
6107 // Convenience common pre-built types.
6108 
6109 // Not-null object klass or below
6110 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6111 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6112 
6113 bool TypeInstKlassPtr::eq(const Type *t) const {
6114   const TypeKlassPtr *p = t->is_klassptr();
6115   return
6116     klass()->equals(p->klass()) &&
6117     flat_in_array() == p->flat_in_array() &&
6118     TypeKlassPtr::eq(p);
6119 }
6120 
6121 uint TypeInstKlassPtr::hash(void) const {
6122   return klass()->hash() + TypeKlassPtr::hash() + (uint)flat_in_array();
6123 }
6124 
6125 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array) {
6126   flat_in_array = flat_in_array || k->flat_in_array();
6127 
6128   TypeInstKlassPtr *r =
6129     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6130 
6131   return r;
6132 }
6133 
6134 //------------------------------add_offset-------------------------------------
6135 // Access internals of klass object
6136 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6137   return make(_ptr, klass(), _interfaces, xadd_offset(offset), flat_in_array());
6138 }
6139 
6140 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6141   return make(_ptr, klass(), _interfaces, Offset(offset), flat_in_array());
6142 }
6143 
6144 //------------------------------cast_to_ptr_type-------------------------------
6145 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6146   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6147   if( ptr == _ptr ) return this;
6148   return make(ptr, _klass, _interfaces, _offset, flat_in_array());
6149 }
6150 
6151 
6152 bool TypeInstKlassPtr::must_be_exact() const {
6153   if (!_klass->is_loaded())  return false;
6154   ciInstanceKlass* ik = _klass->as_instance_klass();
6155   if (ik->is_final())  return true;  // cannot clear xk
6156   return false;
6157 }
6158 
6159 //-----------------------------cast_to_exactness-------------------------------
6160 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6161   if (klass_is_exact == (_ptr == Constant)) return this;
6162   if (must_be_exact()) return this;
6163   ciKlass* k = klass();
6164   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array());
6165 }
6166 
6167 
6168 //-----------------------------as_instance_type--------------------------------
6169 // Corresponding type for an instance of the given class.
6170 // It will be NotNull, and exact if and only if the klass type is exact.
6171 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6172   ciKlass* k = klass();
6173   bool xk = klass_is_exact();
6174   Compile* C = Compile::current();
6175   Dependencies* deps = C->dependencies();
6176   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6177   // Element is an instance
6178   bool klass_is_exact = false;
6179   const TypeInterfaces* interfaces = _interfaces;
6180   if (k->is_loaded()) {
6181     // Try to set klass_is_exact.
6182     ciInstanceKlass* ik = k->as_instance_klass();
6183     klass_is_exact = ik->is_final();
6184     if (!klass_is_exact && klass_change
6185         && deps != nullptr && UseUniqueSubclasses) {
6186       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6187       if (sub != nullptr) {
6188         if (_interfaces->eq(sub)) {
6189           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6190           k = ik = sub;
6191           xk = sub->is_final();
6192         }
6193       }
6194     }
6195   }
6196   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array() && !klass()->is_inlinetype());
6197 }
6198 
6199 //------------------------------xmeet------------------------------------------
6200 // Compute the MEET of two types, return a new Type object.
6201 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6202   // Perform a fast test for common case; meeting the same types together.
6203   if( this == t ) return this;  // Meeting same type-rep?
6204 
6205   // Current "this->_base" is Pointer
6206   switch (t->base()) {          // switch on original type
6207 
6208   case Int:                     // Mixing ints & oops happens when javac
6209   case Long:                    // reuses local variables
6210   case FloatTop:
6211   case FloatCon:
6212   case FloatBot:
6213   case DoubleTop:
6214   case DoubleCon:
6215   case DoubleBot:
6216   case NarrowOop:
6217   case NarrowKlass:
6218   case Bottom:                  // Ye Olde Default
6219     return Type::BOTTOM;
6220   case Top:
6221     return this;
6222 
6223   default:                      // All else is a mistake
6224     typerr(t);
6225 
6226   case AnyPtr: {                // Meeting to AnyPtrs
6227     // Found an AnyPtr type vs self-KlassPtr type
6228     const TypePtr *tp = t->is_ptr();
6229     Offset offset = meet_offset(tp->offset());
6230     PTR ptr = meet_ptr(tp->ptr());
6231     switch (tp->ptr()) {
6232     case TopPTR:
6233       return this;
6234     case Null:
6235       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6236     case AnyNull:
6237       return make(ptr, klass(), _interfaces, offset, flat_in_array());
6238     case BotPTR:
6239     case NotNull:
6240       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6241     default: typerr(t);
6242     }
6243   }
6244 
6245   case RawPtr:
6246   case MetadataPtr:
6247   case OopPtr:
6248   case AryPtr:                  // Meet with AryPtr
6249   case InstPtr:                 // Meet with InstPtr
6250       return TypePtr::BOTTOM;
6251 
6252   //
6253   //             A-top         }
6254   //           /   |   \       }  Tops
6255   //       B-top A-any C-top   }
6256   //          | /  |  \ |      }  Any-nulls
6257   //       B-any   |   C-any   }
6258   //          |    |    |
6259   //       B-con A-con C-con   } constants; not comparable across classes
6260   //          |    |    |
6261   //       B-not   |   C-not   }
6262   //          | \  |  / |      }  not-nulls
6263   //       B-bot A-not C-bot   }
6264   //           \   |   /       }  Bottoms
6265   //             A-bot         }
6266   //
6267 
6268   case InstKlassPtr: {  // Meet two KlassPtr types
6269     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6270     Offset  off     = meet_offset(tkls->offset());
6271     PTR  ptr     = meet_ptr(tkls->ptr());
6272     const TypeInterfaces* interfaces = meet_interfaces(tkls);
6273 
6274     ciKlass* res_klass = nullptr;
6275     bool res_xk = false;
6276     bool res_flat_in_array = false;
6277     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk, res_flat_in_array)) {
6278       case UNLOADED:
6279         ShouldNotReachHere();
6280       case SUBTYPE:
6281       case NOT_SUBTYPE:
6282       case LCA:
6283       case QUICK: {
6284         assert(res_xk == (ptr == Constant), "");
6285         const Type* res = make(ptr, res_klass, interfaces, off, res_flat_in_array);
6286         return res;
6287       }
6288       default:
6289         ShouldNotReachHere();
6290     }
6291   } // End of case KlassPtr
6292   case AryKlassPtr: {                // All arrays inherit from Object class
6293     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6294     Offset offset = meet_offset(tp->offset());
6295     PTR ptr = meet_ptr(tp->ptr());
6296     const TypeInterfaces* interfaces = meet_interfaces(tp);
6297     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6298     const TypeInterfaces* this_interfaces = _interfaces;
6299 
6300     switch (ptr) {
6301     case TopPTR:
6302     case AnyNull:                // Fall 'down' to dual of object klass
6303       // For instances when a subclass meets a superclass we fall
6304       // below the centerline when the superclass is exact. We need to
6305       // do the same here.
6306       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6307         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6308       } else {
6309         // cannot subclass, so the meet has to fall badly below the centerline
6310         ptr = NotNull;
6311         interfaces = _interfaces->intersection_with(tp->_interfaces);
6312         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6313       }
6314     case Constant:
6315     case NotNull:
6316     case BotPTR:                // Fall down to object klass
6317       // LCA is object_klass, but if we subclass from the top we can do better
6318       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6319         // If 'this' (InstPtr) is above the centerline and it is Object class
6320         // then we can subclass in the Java class hierarchy.
6321         // For instances when a subclass meets a superclass we fall
6322         // below the centerline when the superclass is exact. We need
6323         // to do the same here.
6324         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6325           // that is, tp's array type is a subtype of my klass
6326           return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());

6327         }
6328       }
6329       // The other case cannot happen, since I cannot be a subtype of an array.
6330       // The meet falls down to Object class below centerline.
6331       if( ptr == Constant )
6332          ptr = NotNull;
6333       interfaces = this_interfaces->intersection_with(tp_interfaces);
6334       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6335     default: typerr(t);
6336     }
6337   }
6338 
6339   } // End of switch
6340   return this;                  // Return the double constant
6341 }
6342 
6343 //------------------------------xdual------------------------------------------
6344 // Dual: compute field-by-field dual
6345 const Type    *TypeInstKlassPtr::xdual() const {
6346   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flat_in_array());
6347 }
6348 
6349 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6350   static_assert(std::is_base_of<T2, T1>::value, "");
6351   if (!this_one->is_loaded() || !other->is_loaded()) {
6352     return false;
6353   }
6354   if (!this_one->is_instance_type(other)) {
6355     return false;
6356   }
6357 
6358   if (!other_exact) {
6359     return false;
6360   }
6361 
6362   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6363     return true;
6364   }
6365 
6366   return this_one->_klass->is_subtype_of(other->_klass) && this_one->_interfaces->contains(other->_interfaces);

6427   const TypeInterfaces* interfaces = _interfaces;
6428   if (k->is_loaded()) {
6429     ciInstanceKlass* ik = k->as_instance_klass();
6430     bool klass_is_exact = ik->is_final();
6431     if (!klass_is_exact &&
6432         deps != nullptr) {
6433       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6434       if (sub != nullptr) {
6435         if (_interfaces->eq(sub)) {
6436           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6437           k = ik = sub;
6438           klass_is_exact = sub->is_final();
6439           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6440         }
6441       }
6442     }
6443   }
6444   return this;
6445 }
6446 
6447 bool TypeInstKlassPtr::can_be_inline_array() const {
6448   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6449 }
6450 
6451 bool TypeAryKlassPtr::can_be_inline_array() const {
6452   return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6453 }
6454 
6455 bool TypeInstPtr::can_be_inline_array() const {
6456   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6457 }
6458 
6459 bool TypeAryPtr::can_be_inline_array() const {
6460   return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6461 }
6462 
6463 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
6464   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, null_free))->hashcons();
6465 }
6466 
6467 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool null_free) {
6468   if (k->is_obj_array_klass()) {
6469     // Element is an object array. Recursively call ourself.
6470     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6471     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6472     // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
6473     if (etype->klass_is_exact() && etype->isa_instklassptr() && etype->is_instklassptr()->klass()->is_inlinetype() && !null_free) {
6474       etype = TypeInstKlassPtr::make(NotNull, etype->is_instklassptr()->klass(), Offset(etype->is_instklassptr()->offset()));
6475     }
6476     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset, not_flat, not_null_free, null_free);
6477   } else if (k->is_type_array_klass()) {
6478     // Element is an typeArray
6479     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6480     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6481   } else if (k->is_flat_array_klass()) {
6482     ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6483     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass);
6484     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6485   } else {
6486     ShouldNotReachHere();
6487     return nullptr;
6488   }
6489 }
6490 
6491 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling) {
6492   bool null_free = k->as_array_klass()->is_elem_null_free();
6493   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));
6494 
6495   bool not_flat = !UseFlatArray || not_null_free || (k->as_array_klass()->element_klass() != nullptr &&
6496                                                      k->as_array_klass()->element_klass()->is_inlinetype() &&
6497                                                      !k->as_array_klass()->element_klass()->flat_in_array());
6498 
6499   return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, null_free);
6500 }
6501 
6502 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6503   return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling);
6504 }
6505 
6506 //------------------------------eq---------------------------------------------
6507 // Structural equality check for Type representations
6508 bool TypeAryKlassPtr::eq(const Type *t) const {
6509   const TypeAryKlassPtr *p = t->is_aryklassptr();
6510   return
6511     _elem == p->_elem &&  // Check array
6512     _not_flat == p->_not_flat &&
6513     _not_null_free == p->_not_null_free &&
6514     _null_free == p->_null_free &&
6515     TypeKlassPtr::eq(p);  // Check sub-parts
6516 }
6517 
6518 //------------------------------hash-------------------------------------------
6519 // Type-specific hashing function.
6520 uint TypeAryKlassPtr::hash(void) const {
6521   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6522       (uint)(_not_null_free ? 44 : 0) + (uint)(_null_free ? 45 : 0);
6523 }
6524 
6525 //----------------------compute_klass------------------------------------------
6526 // Compute the defining klass for this class
6527 ciKlass* TypeAryPtr::compute_klass(DEBUG_ONLY(bool verify)) const {
6528   // Compute _klass based on element type.
6529   ciKlass* k_ary = nullptr;
6530   const TypeInstPtr *tinst;
6531   const TypeAryPtr *tary;
6532   const Type* el = elem();
6533   if (el->isa_narrowoop()) {
6534     el = el->make_ptr();
6535   }
6536 
6537   // Get element klass
6538   if (is_flat() && el->is_inlinetypeptr()) {
6539     // Klass is required by TypeAryPtr::flat_layout_helper() and others
6540     if (el->inline_klass() != nullptr) {
6541       k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6542     }
6543   } else if ((tinst = el->isa_instptr()) != nullptr) {
6544     // Leave k_ary at nullptr.
6545   } else if ((tary = el->isa_aryptr()) != nullptr) {
6546     // Leave k_ary at nullptr.
6547   } else if ((el->base() == Type::Top) ||
6548              (el->base() == Type::Bottom)) {
6549     // element type of Bottom occurs from meet of basic type
6550     // and object; Top occurs when doing join on Bottom.
6551     // Leave k_ary at null.
6552   } else {
6553     // Cannot compute array klass directly from basic type,
6554     // since subtypes of TypeInt all have basic type T_INT.
6555 #ifdef ASSERT
6556     if (verify && el->isa_int()) {
6557       // Check simple cases when verifying klass.
6558       BasicType bt = T_ILLEGAL;
6559       if (el == TypeInt::BYTE) {
6560         bt = T_BYTE;
6561       } else if (el == TypeInt::SHORT) {
6562         bt = T_SHORT;
6563       } else if (el == TypeInt::CHAR) {
6564         bt = T_CHAR;
6565       } else if (el == TypeInt::INT) {
6566         bt = T_INT;

6595     // type TypeAryPtr::OOPS.  This Type is shared between all
6596     // active compilations.  However, the ciKlass which represents
6597     // this Type is *not* shared between compilations, so caching
6598     // this value would result in fetching a dangling pointer.
6599     //
6600     // Recomputing the underlying ciKlass for each request is
6601     // a bit less efficient than caching, but calls to
6602     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6603     ((TypeAryPtr*)this)->_klass = k_ary;
6604   }
6605   return k_ary;
6606 }
6607 
6608 // Is there a single ciKlass* that can represent that type?
6609 ciKlass* TypeAryPtr::exact_klass_helper() const {
6610   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6611     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6612     if (k == nullptr) {
6613       return nullptr;
6614     }
6615     k = ciArrayKlass::make(k, is_null_free());
6616     return k;
6617   }
6618 
6619   return klass();
6620 }
6621 
6622 const Type* TypeAryPtr::base_element_type(int& dims) const {
6623   const Type* elem = this->elem();
6624   dims = 1;
6625   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6626     elem = elem->make_ptr()->is_aryptr()->elem();
6627     dims++;
6628   }
6629   return elem;
6630 }
6631 
6632 //------------------------------add_offset-------------------------------------
6633 // Access internals of klass object
6634 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6635   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6636 }
6637 
6638 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6639   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6640 }
6641 
6642 //------------------------------cast_to_ptr_type-------------------------------
6643 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6644   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6645   if (ptr == _ptr) return this;
6646   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6647 }
6648 
6649 bool TypeAryKlassPtr::must_be_exact() const {
6650   if (_elem == Type::BOTTOM) return false;
6651   if (_elem == Type::TOP   ) return false;
6652   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6653   if (!tk)             return true;   // a primitive type, like int
6654   // Even if MyValue is exact, [LMyValue is not exact due to [QMyValue <: [LMyValue.
6655   if (tk->isa_instklassptr() && tk->klass()->is_inlinetype() && !is_null_free()) {
6656     return false;
6657   }
6658   return tk->must_be_exact();
6659 }
6660 
6661 
6662 //-----------------------------cast_to_exactness-------------------------------
6663 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6664   if (must_be_exact() && !klass_is_exact) return this;  // cannot clear xk
6665   if (klass_is_exact == this->klass_is_exact()) {
6666     return this;
6667   }
6668   ciKlass* k = _klass;
6669   const Type* elem = this->elem();
6670   if (elem->isa_klassptr() && !klass_is_exact) {
6671     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6672   }
6673   bool not_flat = is_not_flat();
6674   bool not_null_free = is_not_null_free();
6675   if (_elem->isa_klassptr()) {
6676     if (klass_is_exact || _elem->isa_aryklassptr()) {
6677       assert(!is_null_free() && !is_flat(), "null-free (or flat) inline type arrays should always be exact");
6678       // An array can't be null-free (or flat) if the klass is exact
6679       not_null_free = true;
6680       not_flat = true;
6681     } else {
6682       // Klass is not exact (anymore), re-compute null-free/flat properties
6683       const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(_elem->is_instklassptr()->instance_klass());
6684       not_null_free = !exact_etype->can_be_inline_type();
6685       not_flat = !UseFlatArray || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flat_in_array());
6686     }
6687   }
6688   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6689 }
6690 
6691 
6692 //-----------------------------as_instance_type--------------------------------
6693 // Corresponding type for an instance of the given class.
6694 // It will be NotNull, and exact if and only if the klass type is exact.
6695 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6696   ciKlass* k = klass();
6697   bool    xk = klass_is_exact();
6698   const Type* el = nullptr;
6699   if (elem()->isa_klassptr()) {
6700     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6701     k = nullptr;
6702   } else {
6703     el = elem();
6704   }
6705   bool null_free = _null_free;
6706   if (null_free && el->isa_ptr()) {
6707     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6708   }
6709   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free()), k, xk, Offset(0));
6710 }
6711 
6712 
6713 //------------------------------xmeet------------------------------------------
6714 // Compute the MEET of two types, return a new Type object.
6715 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6716   // Perform a fast test for common case; meeting the same types together.
6717   if( this == t ) return this;  // Meeting same type-rep?
6718 
6719   // Current "this->_base" is Pointer
6720   switch (t->base()) {          // switch on original type
6721 
6722   case Int:                     // Mixing ints & oops happens when javac
6723   case Long:                    // reuses local variables
6724   case FloatTop:
6725   case FloatCon:
6726   case FloatBot:
6727   case DoubleTop:
6728   case DoubleCon:
6729   case DoubleBot:
6730   case NarrowOop:
6731   case NarrowKlass:
6732   case Bottom:                  // Ye Olde Default
6733     return Type::BOTTOM;
6734   case Top:
6735     return this;
6736 
6737   default:                      // All else is a mistake
6738     typerr(t);
6739 
6740   case AnyPtr: {                // Meeting to AnyPtrs
6741     // Found an AnyPtr type vs self-KlassPtr type
6742     const TypePtr *tp = t->is_ptr();
6743     Offset offset = meet_offset(tp->offset());
6744     PTR ptr = meet_ptr(tp->ptr());
6745     switch (tp->ptr()) {
6746     case TopPTR:
6747       return this;
6748     case Null:
6749       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6750     case AnyNull:
6751       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_null_free());
6752     case BotPTR:
6753     case NotNull:
6754       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6755     default: typerr(t);
6756     }
6757   }
6758 
6759   case RawPtr:
6760   case MetadataPtr:
6761   case OopPtr:
6762   case AryPtr:                  // Meet with AryPtr
6763   case InstPtr:                 // Meet with InstPtr
6764     return TypePtr::BOTTOM;
6765 
6766   //
6767   //             A-top         }
6768   //           /   |   \       }  Tops
6769   //       B-top A-any C-top   }
6770   //          | /  |  \ |      }  Any-nulls
6771   //       B-any   |   C-any   }
6772   //          |    |    |
6773   //       B-con A-con C-con   } constants; not comparable across classes
6774   //          |    |    |
6775   //       B-not   |   C-not   }
6776   //          | \  |  / |      }  not-nulls
6777   //       B-bot A-not C-bot   }
6778   //           \   |   /       }  Bottoms
6779   //             A-bot         }
6780   //
6781 
6782   case AryKlassPtr: {  // Meet two KlassPtr types
6783     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6784     Offset off = meet_offset(tap->offset());
6785     const Type* elem = _elem->meet(tap->_elem);

6786     PTR ptr = meet_ptr(tap->ptr());
6787     ciKlass* res_klass = nullptr;
6788     bool res_xk = false;
6789     bool res_flat = false;
6790     bool res_not_flat = false;
6791     bool res_not_null_free = false;
6792     MeetResult res = meet_aryptr(ptr, elem, this, tap,
6793                                  res_klass, res_xk, res_flat, res_not_flat, res_not_null_free);
6794     assert(res_xk == (ptr == Constant), "");
6795     bool null_free = meet_null_free(tap->_null_free);
6796     if (res == NOT_SUBTYPE) {
6797       null_free = false;
6798     } else if (res == SUBTYPE) {
6799       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6800         null_free = _null_free;
6801       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6802         null_free = tap->_null_free;
6803       } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
6804         null_free = _null_free || tap->_null_free;
6805       }
6806     }
6807     return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
6808   } // End of case KlassPtr
6809   case InstKlassPtr: {
6810     const TypeInstKlassPtr *tp = t->is_instklassptr();
6811     Offset offset = meet_offset(tp->offset());
6812     PTR ptr = meet_ptr(tp->ptr());
6813     const TypeInterfaces* interfaces = meet_interfaces(tp);
6814     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6815     const TypeInterfaces* this_interfaces = _interfaces;
6816 
6817     switch (ptr) {
6818     case TopPTR:
6819     case AnyNull:                // Fall 'down' to dual of object klass
6820       // For instances when a subclass meets a superclass we fall
6821       // below the centerline when the superclass is exact. We need to
6822       // do the same here.
6823       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->intersection_with(tp_interfaces)->eq(tp_interfaces) && !tp->klass_is_exact()) {
6824         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
6825       } else {
6826         // cannot subclass, so the meet has to fall badly below the centerline
6827         ptr = NotNull;
6828         interfaces = this_interfaces->intersection_with(tp->_interfaces);
6829         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6830       }
6831     case Constant:
6832     case NotNull:
6833     case BotPTR:                // Fall down to object klass
6834       // LCA is object_klass, but if we subclass from the top we can do better
6835       if (above_centerline(tp->ptr())) {
6836         // If 'tp'  is above the centerline and it is Object class
6837         // then we can subclass in the Java class hierarchy.
6838         // For instances when a subclass meets a superclass we fall
6839         // below the centerline when the superclass is exact. We need
6840         // to do the same here.
6841         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->intersection_with(tp_interfaces)->eq(tp_interfaces) && !tp->klass_is_exact()) {
6842           // that is, my array type is a subtype of 'tp' klass
6843           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
6844         }
6845       }
6846       // The other case cannot happen, since t cannot be a subtype of an array.
6847       // The meet falls down to Object class below centerline.
6848       if (ptr == Constant)
6849          ptr = NotNull;
6850       interfaces = this_interfaces->intersection_with(tp_interfaces);
6851       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6852     default: typerr(t);
6853     }
6854   }
6855 
6856   } // End of switch
6857   return this;                  // Return the double constant
6858 }
6859 
6860 template <class T1, class T2> bool TypePtr::is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact) {
6861   static_assert(std::is_base_of<T2, T1>::value, "");
6862 
6863   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6864     return true;
6865   }
6866 
6867   int dummy;
6868   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6869 
6870   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6871     return false;
6872   }
6873 
6874   if (this_one->is_instance_type(other)) {
6875     return other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->intersection_with(this_one->_interfaces)->eq(other->_interfaces) && other_exact;
6876   }
6877 
6878   assert(this_one->is_array_type(other), "");
6879   const T1* other_ary = this_one->is_array_type(other);
6880   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6881   if (other_top_or_bottom) {
6882     return false;
6883   }
6884 
6885   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6886   const TypePtr* this_elem = this_one->elem()->make_ptr();
6887   if (this_elem != nullptr && other_elem != nullptr) {
6888     if (other->is_null_free() && !this_one->is_null_free()) {
6889       return false; // [LMyValue is not a subtype of [QMyValue
6890     }
6891     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6892   }
6893   if (this_elem == nullptr && other_elem == nullptr) {
6894     return this_one->_klass->is_subtype_of(other->_klass);
6895   }
6896   return false;
6897 }
6898 
6899 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6900   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6901 }
6902 
6903 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6904   static_assert(std::is_base_of<T2, T1>::value, "");
6905 
6906   int dummy;
6907   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6908 
6909   if (!this_one->is_array_type(other) ||
6910       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

6958   }
6959 
6960   const TypePtr* this_elem = this_one->elem()->make_ptr();
6961   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6962   if (other_elem != nullptr && this_elem != nullptr) {
6963     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6964   }
6965   if (other_elem == nullptr && this_elem == nullptr) {
6966     return this_one->_klass->is_subtype_of(other->_klass);
6967   }
6968   return false;
6969 }
6970 
6971 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6972   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6973 }
6974 
6975 //------------------------------xdual------------------------------------------
6976 // Dual: compute field-by-field dual
6977 const Type    *TypeAryKlassPtr::xdual() const {
6978   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
6979 }
6980 
6981 // Is there a single ciKlass* that can represent that type?
6982 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6983   if (elem()->isa_klassptr()) {
6984     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6985     if (k == nullptr) {
6986       return nullptr;
6987     }
6988     k = ciArrayKlass::make(k, _null_free);
6989     return k;
6990   }
6991 
6992   return klass();
6993 }
6994 
6995 ciKlass* TypeAryKlassPtr::klass() const {
6996   if (_klass != nullptr) {
6997     return _klass;
6998   }
6999   ciKlass* k = nullptr;
7000   if (elem()->isa_klassptr()) {
7001     // leave null
7002   } else if ((elem()->base() == Type::Top) ||
7003              (elem()->base() == Type::Bottom)) {
7004   } else {
7005     k = ciTypeArrayKlass::make(elem()->basic_type());
7006     ((TypeAryKlassPtr*)this)->_klass = k;
7007   }
7008   return k;

7015   switch( _ptr ) {
7016   case Constant:
7017     st->print("precise ");
7018   case NotNull:
7019     {
7020       st->print("[");
7021       _elem->dump2(d, depth, st);
7022       _interfaces->dump(st);
7023       st->print(": ");
7024     }
7025   case BotPTR:
7026     if( !WizardMode && !Verbose && _ptr != Constant ) break;
7027   case TopPTR:
7028   case AnyNull:
7029     st->print(":%s", ptr_msg[_ptr]);
7030     if( _ptr == Constant ) st->print(":exact");
7031     break;
7032   default:
7033     break;
7034   }
7035   if (is_flat()) st->print(":flat");
7036   if (_null_free) st->print(":null free");
7037   if (Verbose) {
7038     if (_not_flat) st->print(":not flat");
7039     if (_not_null_free) st->print(":not null free");
7040   }
7041 
7042   _offset.dump2(st);
7043 
7044   st->print(" *");
7045 }
7046 #endif
7047 
7048 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7049   const Type* elem = this->elem();
7050   dims = 1;
7051   while (elem->isa_aryklassptr()) {
7052     elem = elem->is_aryklassptr()->elem();
7053     dims++;
7054   }
7055   return elem;
7056 }
7057 
7058 //=============================================================================
7059 // Convenience common pre-built types.
7060 
7061 //------------------------------make-------------------------------------------
7062 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7063                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
7064   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7065 }
7066 
7067 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7068   return make(domain, domain, range, range);
7069 }
7070 
7071 //------------------------------osr_domain-----------------------------
7072 const TypeTuple* osr_domain() {
7073   const Type **fields = TypeTuple::fields(2);
7074   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
7075   return TypeTuple::make(TypeFunc::Parms+1, fields);
7076 }
7077 
7078 //------------------------------make-------------------------------------------
7079 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7080   Compile* C = Compile::current();
7081   const TypeFunc* tf = nullptr;
7082   if (!is_osr_compilation) {
7083     tf = C->last_tf(method); // check cache
7084     if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
7085   }
7086   // Inline types are not passed/returned by reference, instead each field of
7087   // the inline type is passed/returned as an argument. We maintain two views of
7088   // the argument/return list here: one based on the signature (with an inline
7089   // type argument/return as a single slot), one based on the actual calling
7090   // convention (with an inline type argument/return as a list of its fields).
7091   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7092   // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7093   if (method != C->method() && method->get_Method()->mismatch()) {
7094     has_scalar_args = false;
7095   }
7096   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7097   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7098   ciSignature* sig = method->signature();
7099   bool has_scalar_ret = sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7100   const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7101   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7102   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7103   if (!is_osr_compilation) {
7104     C->set_last_tf(method, tf);  // fill cache
7105   }



7106   return tf;
7107 }
7108 
7109 //------------------------------meet-------------------------------------------
7110 // Compute the MEET of two types.  It returns a new Type object.
7111 const Type *TypeFunc::xmeet( const Type *t ) const {
7112   // Perform a fast test for common case; meeting the same types together.
7113   if( this == t ) return this;  // Meeting same type-rep?
7114 
7115   // Current "this->_base" is Func
7116   switch (t->base()) {          // switch on original type
7117 
7118   case Bottom:                  // Ye Olde Default
7119     return t;
7120 
7121   default:                      // All else is a mistake
7122     typerr(t);
7123 
7124   case Top:
7125     break;
7126   }
7127   return this;                  // Return the double constant
7128 }
7129 
7130 //------------------------------xdual------------------------------------------
7131 // Dual: compute field-by-field dual
7132 const Type *TypeFunc::xdual() const {
7133   return this;
7134 }
7135 
7136 //------------------------------eq---------------------------------------------
7137 // Structural equality check for Type representations
7138 bool TypeFunc::eq( const Type *t ) const {
7139   const TypeFunc *a = (const TypeFunc*)t;
7140   return _domain_sig == a->_domain_sig &&
7141     _domain_cc == a->_domain_cc &&
7142     _range_sig == a->_range_sig &&
7143     _range_cc == a->_range_cc;
7144 }
7145 
7146 //------------------------------hash-------------------------------------------
7147 // Type-specific hashing function.
7148 uint TypeFunc::hash(void) const {
7149   return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7150 }
7151 
7152 //------------------------------dump2------------------------------------------
7153 // Dump Function Type
7154 #ifndef PRODUCT
7155 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7156   if( _range_sig->cnt() <= Parms )
7157     st->print("void");
7158   else {
7159     uint i;
7160     for (i = Parms; i < _range_sig->cnt()-1; i++) {
7161       _range_sig->field_at(i)->dump2(d,depth,st);
7162       st->print("/");
7163     }
7164     _range_sig->field_at(i)->dump2(d,depth,st);
7165   }
7166   st->print(" ");
7167   st->print("( ");
7168   if( !depth || d[this] ) {     // Check for recursive dump
7169     st->print("...)");
7170     return;
7171   }
7172   d.Insert((void*)this,(void*)this);    // Stop recursion
7173   if (Parms < _domain_sig->cnt())
7174     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7175   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7176     st->print(", ");
7177     _domain_sig->field_at(i)->dump2(d,depth-1,st);
7178   }
7179   st->print(" )");
7180 }
7181 #endif
7182 
7183 //------------------------------singleton--------------------------------------
7184 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
7185 // constants (Ldi nodes).  Singletons are integer, float or double constants
7186 // or a single symbol.
7187 bool TypeFunc::singleton(void) const {
7188   return false;                 // Never a singleton
7189 }
7190 
7191 bool TypeFunc::empty(void) const {
7192   return false;                 // Never empty
7193 }
7194 
7195 
7196 BasicType TypeFunc::return_type() const{
7197   if (range_sig()->cnt() == TypeFunc::Parms) {
7198     return T_VOID;
7199   }
7200   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7201 }
< prev index next >