< prev index next >

src/hotspot/share/opto/type.cpp

Print this page

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



  25 #include "ci/ciMethodData.hpp"
  26 #include "ci/ciTypeFlow.hpp"
  27 #include "classfile/javaClasses.hpp"
  28 #include "classfile/symbolTable.hpp"
  29 #include "classfile/vmSymbols.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/callnode.hpp"
  39 #include "opto/arraycopynode.hpp"
  40 #include "opto/matcher.hpp"
  41 #include "opto/node.hpp"
  42 #include "opto/opcodes.hpp"
  43 #include "opto/runtime.hpp"
  44 #include "opto/type.hpp"
  45 #include "utilities/checkedCast.hpp"
  46 #include "utilities/powerOfTwo.hpp"
  47 #include "utilities/stringUtils.hpp"
  48 #include "runtime/stubRoutines.hpp"
  49 
  50 // Portions of code courtesy of Clifford Click
  51 
  52 // Optimization - Graph Style
  53 
  54 // Dictionary of types shared among compilations.
  55 Dict* Type::_shared_type_dict = nullptr;













































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

 214   case ciTypeFlow::StateVector::T_NULL:
 215     assert(type == ciTypeFlow::StateVector::null_type(), "");
 216     return TypePtr::NULL_PTR;
 217 
 218   case ciTypeFlow::StateVector::T_LONG2:
 219     // The ciTypeFlow pass pushes a long, then the half.
 220     // We do the same.
 221     assert(type == ciTypeFlow::StateVector::long2_type(), "");
 222     return TypeInt::TOP;
 223 
 224   case ciTypeFlow::StateVector::T_DOUBLE2:
 225     // The ciTypeFlow pass pushes double, then the half.
 226     // Our convention is the same.
 227     assert(type == ciTypeFlow::StateVector::double2_type(), "");
 228     return Type::TOP;
 229 
 230   case T_ADDRESS:
 231     assert(type->is_return_address(), "");
 232     return TypeRawPtr::make((address)(intptr_t)type->as_return_address()->bci());
 233 



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

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

 623 
 624   // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
 625   TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
 626   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;

 627   TypeAryPtr::_array_body_type[T_ARRAY]   = TypeAryPtr::OOPS; // arrays are stored in oop arrays
 628   TypeAryPtr::_array_body_type[T_BYTE]    = TypeAryPtr::BYTES;
 629   TypeAryPtr::_array_body_type[T_BOOLEAN] = TypeAryPtr::BYTES;  // boolean[] is a byte array
 630   TypeAryPtr::_array_body_type[T_SHORT]   = TypeAryPtr::SHORTS;
 631   TypeAryPtr::_array_body_type[T_CHAR]    = TypeAryPtr::CHARS;
 632   TypeAryPtr::_array_body_type[T_INT]     = TypeAryPtr::INTS;
 633   TypeAryPtr::_array_body_type[T_LONG]    = TypeAryPtr::LONGS;
 634   TypeAryPtr::_array_body_type[T_FLOAT]   = TypeAryPtr::FLOATS;
 635   TypeAryPtr::_array_body_type[T_DOUBLE]  = TypeAryPtr::DOUBLES;
 636 
 637   TypeInstKlassPtr::OBJECT = TypeInstKlassPtr::make(TypePtr::NotNull, current->env()->Object_klass(), 0);
 638   TypeInstKlassPtr::OBJECT_OR_NULL = TypeInstKlassPtr::make(TypePtr::BotPTR, current->env()->Object_klass(), 0);
 639 
 640   const Type **fi2c = TypeTuple::fields(2);
 641   fi2c[TypeFunc::Parms+0] = TypeInstPtr::BOTTOM; // Method*
 642   fi2c[TypeFunc::Parms+1] = TypeRawPtr::BOTTOM; // argument pointer
 643   TypeTuple::START_I2C = TypeTuple::make(TypeFunc::Parms+2, fi2c);
 644 
 645   const Type **intpair = TypeTuple::fields(2);
 646   intpair[0] = TypeInt::INT;
 647   intpair[1] = TypeInt::INT;
 648   TypeTuple::INT_PAIR = TypeTuple::make(2, intpair);
 649 
 650   const Type **longpair = TypeTuple::fields(2);
 651   longpair[0] = TypeLong::LONG;
 652   longpair[1] = TypeLong::LONG;
 653   TypeTuple::LONG_PAIR = TypeTuple::make(2, longpair);
 654 
 655   const Type **intccpair = TypeTuple::fields(2);
 656   intccpair[0] = TypeInt::INT;
 657   intccpair[1] = TypeInt::CC;
 658   TypeTuple::INT_CC_PAIR = TypeTuple::make(2, intccpair);
 659 
 660   const Type **longccpair = TypeTuple::fields(2);
 661   longccpair[0] = TypeLong::LONG;
 662   longccpair[1] = TypeInt::CC;
 663   TypeTuple::LONG_CC_PAIR = TypeTuple::make(2, longccpair);
 664 
 665   _const_basic_type[T_NARROWOOP]   = TypeNarrowOop::BOTTOM;
 666   _const_basic_type[T_NARROWKLASS] = Type::BOTTOM;
 667   _const_basic_type[T_BOOLEAN]     = TypeInt::BOOL;
 668   _const_basic_type[T_CHAR]        = TypeInt::CHAR;
 669   _const_basic_type[T_BYTE]        = TypeInt::BYTE;
 670   _const_basic_type[T_SHORT]       = TypeInt::SHORT;
 671   _const_basic_type[T_INT]         = TypeInt::INT;
 672   _const_basic_type[T_LONG]        = TypeLong::LONG;
 673   _const_basic_type[T_FLOAT]       = Type::FLOAT;
 674   _const_basic_type[T_DOUBLE]      = Type::DOUBLE;
 675   _const_basic_type[T_OBJECT]      = TypeInstPtr::BOTTOM;
 676   _const_basic_type[T_ARRAY]       = TypeInstPtr::BOTTOM; // there is no separate bottom for arrays

 677   _const_basic_type[T_VOID]        = TypePtr::NULL_PTR;   // reflection represents void this way
 678   _const_basic_type[T_ADDRESS]     = TypeRawPtr::BOTTOM;  // both interpreter return addresses & random raw ptrs
 679   _const_basic_type[T_CONFLICT]    = Type::BOTTOM;        // why not?
 680 
 681   _zero_type[T_NARROWOOP]   = TypeNarrowOop::NULL_PTR;
 682   _zero_type[T_NARROWKLASS] = TypeNarrowKlass::NULL_PTR;
 683   _zero_type[T_BOOLEAN]     = TypeInt::ZERO;     // false == 0
 684   _zero_type[T_CHAR]        = TypeInt::ZERO;     // '\0' == 0
 685   _zero_type[T_BYTE]        = TypeInt::ZERO;     // 0x00 == 0
 686   _zero_type[T_SHORT]       = TypeInt::ZERO;     // 0x0000 == 0
 687   _zero_type[T_INT]         = TypeInt::ZERO;
 688   _zero_type[T_LONG]        = TypeLong::ZERO;
 689   _zero_type[T_FLOAT]       = TypeF::ZERO;
 690   _zero_type[T_DOUBLE]      = TypeD::ZERO;
 691   _zero_type[T_OBJECT]      = TypePtr::NULL_PTR;
 692   _zero_type[T_ARRAY]       = TypePtr::NULL_PTR; // null array is null oop

 693   _zero_type[T_ADDRESS]     = TypePtr::NULL_PTR; // raw pointers use the same null
 694   _zero_type[T_VOID]        = Type::TOP;         // the only void value is no value at all
 695 
 696   // get_zero_type() should not happen for T_CONFLICT
 697   _zero_type[T_CONFLICT]= nullptr;
 698 
 699   TypeVect::VECTMASK = (TypeVect*)(new TypeVectMask(T_BOOLEAN, MaxVectorSize))->hashcons();
 700   mreg2type[Op_RegVectMask] = TypeVect::VECTMASK;
 701 
 702   if (Matcher::supports_scalable_vector()) {
 703     TypeVect::VECTA = TypeVect::make(T_BYTE, Matcher::scalable_vector_reg_size(T_BYTE));
 704   }
 705 
 706   // Vector predefined types, it needs initialized _const_basic_type[].
 707   if (Matcher::vector_size_supported(T_BYTE, 4)) {
 708     TypeVect::VECTS = TypeVect::make(T_BYTE, 4);
 709   }
 710   if (Matcher::vector_size_supported(T_FLOAT, 2)) {
 711     TypeVect::VECTD = TypeVect::make(T_FLOAT, 2);
 712   }

 947   ~VerifyMeet() {
 948     assert(_C->_type_verify->_depth != 0, "");
 949     _C->_type_verify->_depth--;
 950     if (_C->_type_verify->_depth == 0) {
 951       _C->_type_verify->_cache.trunc_to(0);
 952     }
 953   }
 954 
 955   const Type* meet(const Type* t1, const Type* t2) const {
 956     return _C->_type_verify->meet(t1, t2);
 957   }
 958 
 959   void add(const Type* t1, const Type* t2, const Type* res) const {
 960     _C->_type_verify->add(t1, t2, res);
 961   }
 962 };
 963 
 964 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
 965   Compile* C = Compile::current();
 966   const Type* mt2 = verify.meet(t, this);



 967   if (mt != mt2) {
 968     tty->print_cr("=== Meet Not Commutative ===");
 969     tty->print("t           = ");   t->dump(); tty->cr();
 970     tty->print("this        = ");      dump(); tty->cr();
 971     tty->print("t meet this = "); mt2->dump(); tty->cr();
 972     tty->print("this meet t = ");  mt->dump(); tty->cr();
 973     fatal("meet not commutative");
 974   }
 975   const Type* dual_join = mt->_dual;
 976   const Type* t2t    = verify.meet(dual_join,t->_dual);
 977   const Type* t2this = verify.meet(dual_join,this->_dual);
 978 
 979   // Interface meet Oop is Not Symmetric:
 980   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
 981   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
 982 









 983   if (t2t != t->_dual || t2this != this->_dual) {
 984     tty->print_cr("=== Meet Not Symmetric ===");
 985     tty->print("t   =                   ");              t->dump(); tty->cr();
 986     tty->print("this=                   ");                 dump(); tty->cr();
 987     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
 988 
 989     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
 990     tty->print("this_dual=              ");          _dual->dump(); tty->cr();
 991     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
 992 

 993     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();

 994     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
 995 
 996     fatal("meet not symmetric");
 997   }
 998 }
 999 #endif
1000 
1001 //------------------------------meet-------------------------------------------
1002 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
1003 // commutative and the lattice is symmetric.
1004 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1005   if (isa_narrowoop() && t->isa_narrowoop()) {
1006     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1007     return result->make_narrowoop();
1008   }
1009   if (isa_narrowklass() && t->isa_narrowklass()) {
1010     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1011     return result->make_narrowklass();
1012   }
1013 

2294 
2295 bool TypeLong::empty(void) const {
2296   return _lo > _hi;
2297 }
2298 
2299 //=============================================================================
2300 // Convenience common pre-built types.
2301 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2302 const TypeTuple *TypeTuple::IFFALSE;
2303 const TypeTuple *TypeTuple::IFTRUE;
2304 const TypeTuple *TypeTuple::IFNEITHER;
2305 const TypeTuple *TypeTuple::LOOPBODY;
2306 const TypeTuple *TypeTuple::MEMBAR;
2307 const TypeTuple *TypeTuple::STORECONDITIONAL;
2308 const TypeTuple *TypeTuple::START_I2C;
2309 const TypeTuple *TypeTuple::INT_PAIR;
2310 const TypeTuple *TypeTuple::LONG_PAIR;
2311 const TypeTuple *TypeTuple::INT_CC_PAIR;
2312 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2313 





















2314 //------------------------------make-------------------------------------------
2315 // Make a TypeTuple from the range of a method signature
2316 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
2317   ciType* return_type = sig->return_type();
2318   uint arg_cnt = return_type->size();





2319   const Type **field_array = fields(arg_cnt);
2320   switch (return_type->basic_type()) {
2321   case T_LONG:
2322     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2323     field_array[TypeFunc::Parms+1] = Type::HALF;
2324     break;
2325   case T_DOUBLE:
2326     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2327     field_array[TypeFunc::Parms+1] = Type::HALF;
2328     break;
2329   case T_OBJECT:












2330   case T_ARRAY:
2331   case T_BOOLEAN:
2332   case T_CHAR:
2333   case T_FLOAT:
2334   case T_BYTE:
2335   case T_SHORT:
2336   case T_INT:
2337     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2338     break;
2339   case T_VOID:
2340     break;
2341   default:
2342     ShouldNotReachHere();
2343   }
2344   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2345 }
2346 
2347 // Make a TypeTuple from the domain of a method signature
2348 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2349   uint arg_cnt = sig->size();








2350 
2351   uint pos = TypeFunc::Parms;
2352   const Type **field_array;
2353   if (recv != nullptr) {
2354     arg_cnt++;
2355     field_array = fields(arg_cnt);
2356     // Use get_const_type here because it respects UseUniqueSubclasses:
2357     field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2358   } else {
2359     field_array = fields(arg_cnt);
2360   }
2361 
2362   int i = 0;
2363   while (pos < TypeFunc::Parms + arg_cnt) {
2364     ciType* type = sig->type_at(i);

2365 
2366     switch (type->basic_type()) {
2367     case T_LONG:
2368       field_array[pos++] = TypeLong::LONG;
2369       field_array[pos++] = Type::HALF;
2370       break;
2371     case T_DOUBLE:
2372       field_array[pos++] = Type::DOUBLE;
2373       field_array[pos++] = Type::HALF;
2374       break;
2375     case T_OBJECT:








2376     case T_ARRAY:
2377     case T_FLOAT:
2378     case T_INT:
2379       field_array[pos++] = get_const_type(type, interface_handling);
2380       break;
2381     case T_BOOLEAN:
2382     case T_CHAR:
2383     case T_BYTE:
2384     case T_SHORT:
2385       field_array[pos++] = TypeInt::INT;
2386       break;
2387     default:
2388       ShouldNotReachHere();
2389     }
2390     i++;
2391   }

2392 
2393   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2394 }
2395 
2396 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2397   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2398 }
2399 
2400 //------------------------------fields-----------------------------------------
2401 // Subroutine call type with space allocated for argument types
2402 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2403 const Type **TypeTuple::fields( uint arg_cnt ) {
2404   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2405   flds[TypeFunc::Control  ] = Type::CONTROL;
2406   flds[TypeFunc::I_O      ] = Type::ABIO;
2407   flds[TypeFunc::Memory   ] = Type::MEMORY;
2408   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2409   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2410 
2411   return flds;

2506     if (_fields[i]->empty())  return true;
2507   }
2508   return false;
2509 }
2510 
2511 //=============================================================================
2512 // Convenience common pre-built types.
2513 
2514 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2515   // Certain normalizations keep us sane when comparing types.
2516   // We do not want arrayOop variables to differ only by the wideness
2517   // of their index types.  Pick minimum wideness, since that is the
2518   // forced wideness of small ranges anyway.
2519   if (size->_widen != Type::WidenMin)
2520     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2521   else
2522     return size;
2523 }
2524 
2525 //------------------------------make-------------------------------------------
2526 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {

2527   if (UseCompressedOops && elem->isa_oopptr()) {
2528     elem = elem->make_narrowoop();
2529   }
2530   size = normalize_array_size(size);
2531   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2532 }
2533 
2534 //------------------------------meet-------------------------------------------
2535 // Compute the MEET of two types.  It returns a new Type object.
2536 const Type *TypeAry::xmeet( const Type *t ) const {
2537   // Perform a fast test for common case; meeting the same types together.
2538   if( this == t ) return this;  // Meeting same type-rep?
2539 
2540   // Current "this->_base" is Ary
2541   switch (t->base()) {          // switch on original type
2542 
2543   case Bottom:                  // Ye Olde Default
2544     return t;
2545 
2546   default:                      // All else is a mistake
2547     typerr(t);
2548 
2549   case Array: {                 // Meeting 2 arrays?
2550     const TypeAry *a = t->is_ary();
2551     return TypeAry::make(_elem->meet_speculative(a->_elem),
2552                          _size->xmeet(a->_size)->is_int(),
2553                          _stable && a->_stable);



2554   }
2555   case Top:
2556     break;
2557   }
2558   return this;                  // Return the double constant
2559 }
2560 
2561 //------------------------------xdual------------------------------------------
2562 // Dual: compute field-by-field dual
2563 const Type *TypeAry::xdual() const {
2564   const TypeInt* size_dual = _size->dual()->is_int();
2565   size_dual = normalize_array_size(size_dual);
2566   return new TypeAry(_elem->dual(), size_dual, !_stable);
2567 }
2568 
2569 //------------------------------eq---------------------------------------------
2570 // Structural equality check for Type representations
2571 bool TypeAry::eq( const Type *t ) const {
2572   const TypeAry *a = (const TypeAry*)t;
2573   return _elem == a->_elem &&
2574     _stable == a->_stable &&
2575     _size == a->_size;




2576 }
2577 
2578 //------------------------------hash-------------------------------------------
2579 // Type-specific hashing function.
2580 uint TypeAry::hash(void) const {
2581   return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);

2582 }
2583 
2584 /**
2585  * Return same type without a speculative part in the element
2586  */
2587 const TypeAry* TypeAry::remove_speculative() const {
2588   return make(_elem->remove_speculative(), _size, _stable);
2589 }
2590 
2591 /**
2592  * Return same type with cleaned up speculative part of element
2593  */
2594 const Type* TypeAry::cleanup_speculative() const {
2595   return make(_elem->cleanup_speculative(), _size, _stable);
2596 }
2597 
2598 /**
2599  * Return same type but with a different inline depth (used for speculation)
2600  *
2601  * @param depth  depth to meet with
2602  */
2603 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2604   if (!UseInlineDepthForSpeculativeTypes) {
2605     return this;
2606   }
2607   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2608 }
2609 
2610 //------------------------------dump2------------------------------------------
2611 #ifndef PRODUCT
2612 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2613   if (_stable)  st->print("stable:");





2614   _elem->dump2(d, depth, st);
2615   st->print("[");
2616   _size->dump2(d, depth, st);
2617   st->print("]");
2618 }
2619 #endif
2620 
2621 //------------------------------singleton--------------------------------------
2622 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2623 // constants (Ldi nodes).  Singletons are integer, float or double constants
2624 // or a single symbol.
2625 bool TypeAry::singleton(void) const {
2626   return false;                 // Never a singleton
2627 }
2628 
2629 bool TypeAry::empty(void) const {
2630   return _elem->empty() || _size->empty();
2631 }
2632 
2633 //--------------------------ary_must_be_exact----------------------------------
2634 bool TypeAry::ary_must_be_exact() const {
2635   // This logic looks at the element type of an array, and returns true
2636   // if the element type is either a primitive or a final instance class.
2637   // In such cases, an array built on this ary must have no subclasses.
2638   if (_elem == BOTTOM)      return false;  // general array not exact
2639   if (_elem == TOP   )      return false;  // inverted general array not exact
2640   const TypeOopPtr*  toop = nullptr;
2641   if (UseCompressedOops && _elem->isa_narrowoop()) {
2642     toop = _elem->make_ptr()->isa_oopptr();
2643   } else {
2644     toop = _elem->isa_oopptr();
2645   }
2646   if (!toop)                return true;   // a primitive type, like int
2647   if (!toop->is_loaded())   return false;  // unloaded class
2648   const TypeInstPtr* tinst;
2649   if (_elem->isa_narrowoop())
2650     tinst = _elem->make_ptr()->isa_instptr();
2651   else
2652     tinst = _elem->isa_instptr();
2653   if (tinst)
2654     return tinst->instance_klass()->is_final();








2655   const TypeAryPtr*  tap;
2656   if (_elem->isa_narrowoop())
2657     tap = _elem->make_ptr()->isa_aryptr();
2658   else
2659     tap = _elem->isa_aryptr();
2660   if (tap)
2661     return tap->ary()->ary_must_be_exact();
2662   return false;
2663 }
2664 
2665 //==============================TypeVect=======================================
2666 // Convenience common pre-built types.
2667 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2668 const TypeVect* TypeVect::VECTS = nullptr; //  32-bit vectors
2669 const TypeVect* TypeVect::VECTD = nullptr; //  64-bit vectors
2670 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2671 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2672 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2673 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2674 

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

2897     int depth = meet_inline_depth(tp->inline_depth());
2898     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2899   }
2900   case RawPtr:                  // For these, flip the call around to cut down
2901   case OopPtr:
2902   case InstPtr:                 // on the cases I have to handle.
2903   case AryPtr:
2904   case MetadataPtr:
2905   case KlassPtr:
2906   case InstKlassPtr:
2907   case AryKlassPtr:
2908     return t->xmeet(this);      // Call in reverse direction
2909   default:                      // All else is a mistake
2910     typerr(t);
2911 
2912   }
2913   return this;
2914 }
2915 
2916 //------------------------------meet_offset------------------------------------
2917 int TypePtr::meet_offset( int offset ) const {
2918   // Either is 'TOP' offset?  Return the other offset!
2919   if( _offset == OffsetTop ) return offset;
2920   if( offset == OffsetTop ) return _offset;
2921   // If either is different, return 'BOTTOM' offset
2922   if( _offset != offset ) return OffsetBot;
2923   return _offset;
2924 }
2925 
2926 //------------------------------dual_offset------------------------------------
2927 int TypePtr::dual_offset( ) const {
2928   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2929   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2930   return _offset;               // Map everything else into self
2931 }
2932 
2933 //------------------------------xdual------------------------------------------
2934 // Dual: compute field-by-field dual
2935 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2936   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2937 };
2938 const Type *TypePtr::xdual() const {
2939   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2940 }
2941 
2942 //------------------------------xadd_offset------------------------------------
2943 int TypePtr::xadd_offset( intptr_t offset ) const {
2944   // Adding to 'TOP' offset?  Return 'TOP'!
2945   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2946   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2947   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2948   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2949   offset += (intptr_t)_offset;
2950   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2951 
2952   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2953   // It is possible to construct a negative offset during PhaseCCP
2954 
2955   return (int)offset;        // Sum valid offsets
2956 }
2957 
2958 //------------------------------add_offset-------------------------------------
2959 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2960   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2961 }
2962 
2963 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2964   return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2965 }
2966 
2967 //------------------------------eq---------------------------------------------
2968 // Structural equality check for Type representations
2969 bool TypePtr::eq( const Type *t ) const {
2970   const TypePtr *a = (const TypePtr*)t;
2971   return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2972 }
2973 
2974 //------------------------------hash-------------------------------------------
2975 // Type-specific hashing function.
2976 uint TypePtr::hash(void) const {
2977   return (uint)_ptr + (uint)_offset + (uint)hash_speculative() + (uint)_inline_depth;
2978 }
2979 
2980 /**
2981  * Return same type without a speculative part
2982  */
2983 const TypePtr* TypePtr::remove_speculative() const {
2984   if (_speculative == nullptr) {
2985     return this;
2986   }
2987   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2988   return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2989 }
2990 
2991 /**
2992  * Return same type but drop speculative part if we know we won't use
2993  * it
2994  */
2995 const Type* TypePtr::cleanup_speculative() const {
2996   if (speculative() == nullptr) {
2997     return this;

3223   }
3224   // We already know the speculative type is always null
3225   if (speculative_always_null()) {
3226     return false;
3227   }
3228   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3229     return false;
3230   }
3231   return true;
3232 }
3233 
3234 //------------------------------dump2------------------------------------------
3235 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3236   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3237 };
3238 
3239 #ifndef PRODUCT
3240 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3241   if( _ptr == Null ) st->print("null");
3242   else st->print("%s *", ptr_msg[_ptr]);
3243   if( _offset == OffsetTop ) st->print("+top");
3244   else if( _offset == OffsetBot ) st->print("+bot");
3245   else if( _offset ) st->print("+%d", _offset);
3246   dump_inline_depth(st);
3247   dump_speculative(st);
3248 }
3249 
3250 /**
3251  *dump the speculative part of the type
3252  */
3253 void TypePtr::dump_speculative(outputStream *st) const {
3254   if (_speculative != nullptr) {
3255     st->print(" (speculative=");
3256     _speculative->dump_on(st);
3257     st->print(")");
3258   }
3259 }
3260 
3261 /**
3262  *dump the inline depth of the type
3263  */
3264 void TypePtr::dump_inline_depth(outputStream *st) const {
3265   if (_inline_depth != InlineDepthBottom) {
3266     if (_inline_depth == InlineDepthTop) {
3267       st->print(" (inline_depth=InlineDepthTop)");
3268     } else {
3269       st->print(" (inline_depth=%d)", _inline_depth);
3270     }
3271   }
3272 }
3273 #endif
3274 
3275 //------------------------------singleton--------------------------------------
3276 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3277 // constants
3278 bool TypePtr::singleton(void) const {
3279   // TopPTR, Null, AnyNull, Constant are all singletons
3280   return (_offset != OffsetBot) && !below_centerline(_ptr);
3281 }
3282 
3283 bool TypePtr::empty(void) const {
3284   return (_offset == OffsetTop) || above_centerline(_ptr);
3285 }
3286 
3287 //=============================================================================
3288 // Convenience common pre-built types.
3289 const TypeRawPtr *TypeRawPtr::BOTTOM;
3290 const TypeRawPtr *TypeRawPtr::NOTNULL;
3291 
3292 //------------------------------make-------------------------------------------
3293 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3294   assert( ptr != Constant, "what is the constant?" );
3295   assert( ptr != Null, "Use TypePtr for null" );
3296   return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3297 }
3298 
3299 const TypeRawPtr *TypeRawPtr::make(address bits) {
3300   assert(bits != nullptr, "Use TypePtr for null");
3301   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3302 }
3303 
3304 //------------------------------cast_to_ptr_type-------------------------------

3665 void TypeInterfaces::verify_is_loaded() const {
3666   for (int i = 0; i < _interfaces.length(); i++) {
3667     ciKlass* interface = _interfaces.at(i);
3668     assert(interface->is_loaded(), "Interface not loaded");
3669   }
3670 }
3671 #endif
3672 
3673 // Can't be implemented because there's no way to know if the type is above or below the center line.
3674 const Type* TypeInterfaces::xmeet(const Type* t) const {
3675   ShouldNotReachHere();
3676   return Type::xmeet(t);
3677 }
3678 
3679 bool TypeInterfaces::singleton(void) const {
3680   ShouldNotReachHere();
3681   return Type::singleton();
3682 }
3683 
3684 //------------------------------TypeOopPtr-------------------------------------
3685 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3686                        int instance_id, const TypePtr* speculative, int inline_depth)
3687   : TypePtr(t, ptr, offset, speculative, inline_depth),
3688     _const_oop(o), _klass(k),
3689     _interfaces(interfaces),
3690     _klass_is_exact(xk),
3691     _is_ptr_to_narrowoop(false),
3692     _is_ptr_to_narrowklass(false),
3693     _is_ptr_to_boxed_value(false),
3694     _instance_id(instance_id) {
3695 #ifdef ASSERT
3696   if (klass() != nullptr && klass()->is_loaded()) {
3697     interfaces->verify_is_loaded();
3698   }
3699 #endif
3700   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3701       (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3702     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3703   }
3704 #ifdef _LP64
3705   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3706     if (_offset == oopDesc::klass_offset_in_bytes()) {
3707       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3708     } else if (klass() == nullptr) {
3709       // Array with unknown body type
3710       assert(this->isa_aryptr(), "only arrays without klass");
3711       _is_ptr_to_narrowoop = UseCompressedOops;
3712     } else if (this->isa_aryptr()) {
3713       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3714                              _offset != arrayOopDesc::length_offset_in_bytes());









3715     } else if (klass()->is_instance_klass()) {
3716       ciInstanceKlass* ik = klass()->as_instance_klass();
3717       if (this->isa_klassptr()) {
3718         // Perm objects don't use compressed references
3719       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3720         // unsafe access
3721         _is_ptr_to_narrowoop = UseCompressedOops;
3722       } else {
3723         assert(this->isa_instptr(), "must be an instance ptr.");
3724 
3725         if (klass() == ciEnv::current()->Class_klass() &&
3726             (_offset == java_lang_Class::klass_offset() ||
3727              _offset == java_lang_Class::array_klass_offset())) {
3728           // Special hidden fields from the Class.
3729           assert(this->isa_instptr(), "must be an instance ptr.");
3730           _is_ptr_to_narrowoop = false;
3731         } else if (klass() == ciEnv::current()->Class_klass() &&
3732                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3733           // Static fields
3734           ciField* field = nullptr;
3735           if (const_oop() != nullptr) {
3736             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3737             field = k->get_field_by_offset(_offset, true);
3738           }
3739           if (field != nullptr) {
3740             BasicType basic_elem_type = field->layout_type();
3741             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3742           } else {
3743             // unsafe access
3744             _is_ptr_to_narrowoop = UseCompressedOops;
3745           }
3746         } else {
3747           // Instance fields which contains a compressed oop references.
3748           ciField* field = ik->get_field_by_offset(_offset, false);

3749           if (field != nullptr) {
3750             BasicType basic_elem_type = field->layout_type();
3751             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3752           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3753             // Compile::find_alias_type() cast exactness on all types to verify
3754             // that it does not affect alias type.
3755             _is_ptr_to_narrowoop = UseCompressedOops;
3756           } else {
3757             // Type for the copy start in LibraryCallKit::inline_native_clone().
3758             _is_ptr_to_narrowoop = UseCompressedOops;
3759           }
3760         }
3761       }
3762     }
3763   }
3764 #endif
3765 }
3766 
3767 //------------------------------make-------------------------------------------
3768 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3769                                      const TypePtr* speculative, int inline_depth) {
3770   assert(ptr != Constant, "no constant generic pointers");
3771   ciKlass*  k = Compile::current()->env()->Object_klass();
3772   bool      xk = false;
3773   ciObject* o = nullptr;
3774   const TypeInterfaces* interfaces = TypeInterfaces::make();
3775   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3776 }
3777 
3778 
3779 //------------------------------cast_to_ptr_type-------------------------------
3780 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3781   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3782   if( ptr == _ptr ) return this;
3783   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3784 }
3785 
3786 //-----------------------------cast_to_instance_id----------------------------
3787 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3788   // There are no instances of a general oop.
3789   // Return self unchanged.
3790   return this;
3791 }
3792 
3793 //-----------------------------cast_to_exactness-------------------------------
3794 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3795   // There is no such thing as an exact general oop.
3796   // Return self unchanged.
3797   return this;
3798 }
3799 
3800 
3801 //------------------------------as_klass_type----------------------------------
3802 // Return the klass type corresponding to this instance or array type.
3803 // It is the type that is loaded from an object of this type.
3804 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3805   ShouldNotReachHere();
3806   return nullptr;
3807 }
3808 
3809 //------------------------------meet-------------------------------------------
3810 // Compute the MEET of two types.  It returns a new Type object.
3811 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3812   // Perform a fast test for common case; meeting the same types together.
3813   if( this == t ) return this;  // Meeting same type-rep?
3814 
3815   // Current "this->_base" is OopPtr
3816   switch (t->base()) {          // switch on original type
3817 
3818   case Int:                     // Mixing ints & oops happens when javac
3819   case Long:                    // reuses local variables
3820   case HalfFloatTop:

3829   case NarrowOop:
3830   case NarrowKlass:
3831   case Bottom:                  // Ye Olde Default
3832     return Type::BOTTOM;
3833   case Top:
3834     return this;
3835 
3836   default:                      // All else is a mistake
3837     typerr(t);
3838 
3839   case RawPtr:
3840   case MetadataPtr:
3841   case KlassPtr:
3842   case InstKlassPtr:
3843   case AryKlassPtr:
3844     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3845 
3846   case AnyPtr: {
3847     // Found an AnyPtr type vs self-OopPtr type
3848     const TypePtr *tp = t->is_ptr();
3849     int offset = meet_offset(tp->offset());
3850     PTR ptr = meet_ptr(tp->ptr());
3851     const TypePtr* speculative = xmeet_speculative(tp);
3852     int depth = meet_inline_depth(tp->inline_depth());
3853     switch (tp->ptr()) {
3854     case Null:
3855       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3856       // else fall through:
3857     case TopPTR:
3858     case AnyNull: {
3859       int instance_id = meet_instance_id(InstanceTop);
3860       return make(ptr, offset, instance_id, speculative, depth);
3861     }
3862     case BotPTR:
3863     case NotNull:
3864       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3865     default: typerr(t);
3866     }
3867   }
3868 
3869   case OopPtr: {                 // Meeting to other OopPtrs

3871     int instance_id = meet_instance_id(tp->instance_id());
3872     const TypePtr* speculative = xmeet_speculative(tp);
3873     int depth = meet_inline_depth(tp->inline_depth());
3874     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3875   }
3876 
3877   case InstPtr:                  // For these, flip the call around to cut down
3878   case AryPtr:
3879     return t->xmeet(this);      // Call in reverse direction
3880 
3881   } // End of switch
3882   return this;                  // Return the double constant
3883 }
3884 
3885 
3886 //------------------------------xdual------------------------------------------
3887 // Dual of a pure heap pointer.  No relevant klass or oop information.
3888 const Type *TypeOopPtr::xdual() const {
3889   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3890   assert(const_oop() == nullptr,             "no constants here");
3891   return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3892 }
3893 
3894 //--------------------------make_from_klass_common-----------------------------
3895 // Computes the element-type given a klass.
3896 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3897   if (klass->is_instance_klass()) {
3898     Compile* C = Compile::current();
3899     Dependencies* deps = C->dependencies();
3900     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3901     // Element is an instance
3902     bool klass_is_exact = false;
3903     if (klass->is_loaded()) {
3904       // Try to set klass_is_exact.
3905       ciInstanceKlass* ik = klass->as_instance_klass();
3906       klass_is_exact = ik->is_final();
3907       if (!klass_is_exact && klass_change
3908           && deps != nullptr && UseUniqueSubclasses) {
3909         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3910         if (sub != nullptr) {
3911           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3912           klass = ik = sub;
3913           klass_is_exact = sub->is_final();
3914         }
3915       }
3916       if (!klass_is_exact && try_for_exact && deps != nullptr &&
3917           !ik->is_interface() && !ik->has_subklass()) {
3918         // Add a dependence; if concrete subclass added we need to recompile
3919         deps->assert_leaf_type(ik);
3920         klass_is_exact = true;
3921       }
3922     }
3923     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3924     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3925   } else if (klass->is_obj_array_klass()) {
3926     // Element is an object array. Recursively call ourself.
3927     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3928     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3929     bool xk = etype->klass_is_exact();
3930     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);








3931     // We used to pass NotNull in here, asserting that the sub-arrays
3932     // are all not-null.  This is not true in generally, as code can
3933     // slam nulls down in the subarrays.
3934     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3935     return arr;
3936   } else if (klass->is_type_array_klass()) {
3937     // Element is an typeArray
3938     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3939     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

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






3943     return arr;
3944   } else {
3945     ShouldNotReachHere();
3946     return nullptr;
3947   }
3948 }
3949 
3950 //------------------------------make_from_constant-----------------------------
3951 // Make a java pointer from an oop constant
3952 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3953   assert(!o->is_null_object(), "null object not yet handled here.");
3954 
3955   const bool make_constant = require_constant || o->should_be_constant();
3956 
3957   ciKlass* klass = o->klass();
3958   if (klass->is_instance_klass()) {
3959     // Element is an instance
3960     if (make_constant) {
3961       return TypeInstPtr::make(o);
3962     } else {
3963       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3964     }
3965   } else if (klass->is_obj_array_klass()) {
3966     // Element is an object array. Recursively call ourself.
3967     const TypeOopPtr *etype =
3968       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3969     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));





3970     // We used to pass NotNull in here, asserting that the sub-arrays
3971     // are all not-null.  This is not true in generally, as code can
3972     // slam nulls down in the subarrays.
3973     if (make_constant) {
3974       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3975     } else {
3976       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3977     }
3978   } else if (klass->is_type_array_klass()) {
3979     // Element is an typeArray
3980     const Type* etype =
3981       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3982     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3983     // We used to pass NotNull in here, asserting that the array pointer
3984     // is not-null. That was not true in general.
3985     if (make_constant) {
3986       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3987     } else {
3988       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);












3989     }
3990   }
3991 
3992   fatal("unhandled object type");
3993   return nullptr;
3994 }
3995 
3996 //------------------------------get_con----------------------------------------
3997 intptr_t TypeOopPtr::get_con() const {
3998   assert( _ptr == Null || _ptr == Constant, "" );
3999   assert( _offset >= 0, "" );
4000 
4001   if (_offset != 0) {
4002     // After being ported to the compiler interface, the compiler no longer
4003     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4004     // to a handle at compile time.  This handle is embedded in the generated
4005     // code and dereferenced at the time the nmethod is made.  Until that time,
4006     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4007     // have access to the addresses!).  This does not seem to currently happen,
4008     // but this assertion here is to help prevent its occurrence.
4009     tty->print_cr("Found oop constant with non-zero offset");
4010     ShouldNotReachHere();
4011   }
4012 
4013   return (intptr_t)const_oop()->constant_encoding();
4014 }
4015 
4016 
4017 //-----------------------------filter------------------------------------------
4018 // Do not allow interface-vs.-noninterface joins to collapse to top.
4019 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4020 
4021   const Type* ft = join_helper(kills, include_speculative);

4040   } else {
4041     return one->equals(two) && TypePtr::eq(t);
4042   }
4043 }
4044 
4045 //------------------------------hash-------------------------------------------
4046 // Type-specific hashing function.
4047 uint TypeOopPtr::hash(void) const {
4048   return
4049     (uint)(const_oop() ? const_oop()->hash() : 0) +
4050     (uint)_klass_is_exact +
4051     (uint)_instance_id + TypePtr::hash();
4052 }
4053 
4054 //------------------------------dump2------------------------------------------
4055 #ifndef PRODUCT
4056 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4057   st->print("oopptr:%s", ptr_msg[_ptr]);
4058   if( _klass_is_exact ) st->print(":exact");
4059   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4060   switch( _offset ) {
4061   case OffsetTop: st->print("+top"); break;
4062   case OffsetBot: st->print("+any"); break;
4063   case         0: break;
4064   default:        st->print("+%d",_offset); break;
4065   }
4066   if (_instance_id == InstanceTop)
4067     st->print(",iid=top");
4068   else if (_instance_id != InstanceBot)
4069     st->print(",iid=%d",_instance_id);
4070 
4071   dump_inline_depth(st);
4072   dump_speculative(st);
4073 }
4074 #endif
4075 
4076 //------------------------------singleton--------------------------------------
4077 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4078 // constants
4079 bool TypeOopPtr::singleton(void) const {
4080   // detune optimizer to not generate constant oop + constant offset as a constant!
4081   // TopPTR, Null, AnyNull, Constant are all singletons
4082   return (_offset == 0) && !below_centerline(_ptr);
4083 }
4084 
4085 //------------------------------add_offset-------------------------------------
4086 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4087   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4088 }
4089 
4090 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4091   return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
4092 }
4093 
4094 /**
4095  * Return same type without a speculative part
4096  */
4097 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4098   if (_speculative == nullptr) {
4099     return this;
4100   }
4101   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4102   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4103 }
4104 
4105 /**
4106  * Return same type but drop speculative part if we know we won't use
4107  * it
4108  */
4109 const Type* TypeOopPtr::cleanup_speculative() const {
4110   // If the klass is exact and the ptr is not null then there's
4111   // nothing that the speculative type can help us with

4184 const TypeInstPtr *TypeInstPtr::BOTTOM;
4185 const TypeInstPtr *TypeInstPtr::MIRROR;
4186 const TypeInstPtr *TypeInstPtr::MARK;
4187 const TypeInstPtr *TypeInstPtr::KLASS;
4188 
4189 // Is there a single ciKlass* that can represent that type?
4190 ciKlass* TypeInstPtr::exact_klass_helper() const {
4191   if (_interfaces->empty()) {
4192     return _klass;
4193   }
4194   if (_klass != ciEnv::current()->Object_klass()) {
4195     if (_interfaces->eq(_klass->as_instance_klass())) {
4196       return _klass;
4197     }
4198     return nullptr;
4199   }
4200   return _interfaces->exact_klass();
4201 }
4202 
4203 //------------------------------TypeInstPtr-------------------------------------
4204 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
4205                          int instance_id, const TypePtr* speculative, int inline_depth)
4206   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {

4207   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4208   assert(k != nullptr &&
4209          (k->is_loaded() || o == nullptr),
4210          "cannot have constants with non-loaded klass");


4211 };
4212 
4213 //------------------------------make-------------------------------------------
4214 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4215                                      ciKlass* k,
4216                                      const TypeInterfaces* interfaces,
4217                                      bool xk,
4218                                      ciObject* o,
4219                                      int offset,

4220                                      int instance_id,
4221                                      const TypePtr* speculative,
4222                                      int inline_depth) {
4223   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4224   // Either const_oop() is null or else ptr is Constant
4225   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4226           "constant pointers must have a value supplied" );
4227   // Ptr is never Null
4228   assert( ptr != Null, "null pointers are not typed" );
4229 
4230   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4231   if (ptr == Constant) {
4232     // Note:  This case includes meta-object constants, such as methods.
4233     xk = true;
4234   } else if (k->is_loaded()) {
4235     ciInstanceKlass* ik = k->as_instance_klass();
4236     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4237     assert(!ik->is_interface(), "no interface here");
4238     if (xk && ik->is_interface())  xk = false;  // no exact interface
4239   }
4240 



4241   // Now hash this baby
4242   TypeInstPtr *result =
4243     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4244 
4245   return result;
4246 }
4247 
4248 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4249   if (k->is_instance_klass()) {
4250     if (k->is_loaded()) {
4251       if (k->is_interface() && interface_handling == ignore_interfaces) {
4252         assert(interface, "no interface expected");
4253         k = ciEnv::current()->Object_klass();
4254         const TypeInterfaces* interfaces = TypeInterfaces::make();
4255         return interfaces;
4256       }
4257       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4258       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4259       if (k->is_interface()) {
4260         assert(interface, "no interface expected");
4261         k = ciEnv::current()->Object_klass();
4262       } else {
4263         assert(klass, "no instance klass expected");

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

4402   case Top:
4403     return this;
4404 
4405   default:                      // All else is a mistake
4406     typerr(t);
4407 
4408   case MetadataPtr:
4409   case KlassPtr:
4410   case InstKlassPtr:
4411   case AryKlassPtr:
4412   case RawPtr: return TypePtr::BOTTOM;
4413 
4414   case AryPtr: {                // All arrays inherit from Object class
4415     // Call in reverse direction to avoid duplication
4416     return t->is_aryptr()->xmeet_helper(this);
4417   }
4418 
4419   case OopPtr: {                // Meeting to OopPtrs
4420     // Found a OopPtr type vs self-InstPtr type
4421     const TypeOopPtr *tp = t->is_oopptr();
4422     int offset = meet_offset(tp->offset());
4423     PTR ptr = meet_ptr(tp->ptr());
4424     switch (tp->ptr()) {
4425     case TopPTR:
4426     case AnyNull: {
4427       int instance_id = meet_instance_id(InstanceTop);
4428       const TypePtr* speculative = xmeet_speculative(tp);
4429       int depth = meet_inline_depth(tp->inline_depth());
4430       return make(ptr, klass(), _interfaces, klass_is_exact(),
4431                   (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4432     }
4433     case NotNull:
4434     case BotPTR: {
4435       int instance_id = meet_instance_id(tp->instance_id());
4436       const TypePtr* speculative = xmeet_speculative(tp);
4437       int depth = meet_inline_depth(tp->inline_depth());
4438       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4439     }
4440     default: typerr(t);
4441     }
4442   }
4443 
4444   case AnyPtr: {                // Meeting to AnyPtrs
4445     // Found an AnyPtr type vs self-InstPtr type
4446     const TypePtr *tp = t->is_ptr();
4447     int offset = meet_offset(tp->offset());
4448     PTR ptr = meet_ptr(tp->ptr());
4449     int instance_id = meet_instance_id(InstanceTop);
4450     const TypePtr* speculative = xmeet_speculative(tp);
4451     int depth = meet_inline_depth(tp->inline_depth());
4452     switch (tp->ptr()) {
4453     case Null:
4454       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4455       // else fall through to AnyNull
4456     case TopPTR:
4457     case AnyNull: {
4458       return make(ptr, klass(), _interfaces, klass_is_exact(),
4459                   (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4460     }
4461     case NotNull:
4462     case BotPTR:
4463       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4464     default: typerr(t);
4465     }
4466   }
4467 
4468   /*
4469                  A-top         }
4470                /   |   \       }  Tops
4471            B-top A-any C-top   }
4472               | /  |  \ |      }  Any-nulls
4473            B-any   |   C-any   }
4474               |    |    |
4475            B-con A-con C-con   } constants; not comparable across classes
4476               |    |    |
4477            B-not   |   C-not   }
4478               | \  |  / |      }  not-nulls
4479            B-bot A-not C-bot   }
4480                \   |   /       }  Bottoms
4481                  A-bot         }
4482   */
4483 
4484   case InstPtr: {                // Meeting 2 Oops?
4485     // Found an InstPtr sub-type vs self-InstPtr type
4486     const TypeInstPtr *tinst = t->is_instptr();
4487     int off = meet_offset(tinst->offset());
4488     PTR ptr = meet_ptr(tinst->ptr());
4489     int instance_id = meet_instance_id(tinst->instance_id());
4490     const TypePtr* speculative = xmeet_speculative(tinst);
4491     int depth = meet_inline_depth(tinst->inline_depth());
4492     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4493 
4494     ciKlass* tinst_klass = tinst->klass();
4495     ciKlass* this_klass  = klass();
4496 
4497     ciKlass* res_klass = nullptr;
4498     bool res_xk = false;

4499     const Type* res;
4500     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4501 
4502     if (kind == UNLOADED) {
4503       // One of these classes has not been loaded
4504       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4505 #ifndef PRODUCT
4506       if (PrintOpto && Verbose) {
4507         tty->print("meet of unloaded classes resulted in: ");
4508         unloaded_meet->dump();
4509         tty->cr();
4510         tty->print("  this == ");
4511         dump();
4512         tty->cr();
4513         tty->print(" tinst == ");
4514         tinst->dump();
4515         tty->cr();
4516       }
4517 #endif
4518       res = unloaded_meet;
4519     } else {
4520       if (kind == NOT_SUBTYPE && instance_id > 0) {
4521         instance_id = InstanceBot;
4522       } else if (kind == LCA) {
4523         instance_id = InstanceBot;
4524       }
4525       ciObject* o = nullptr;             // Assume not constant when done
4526       ciObject* this_oop = const_oop();
4527       ciObject* tinst_oop = tinst->const_oop();
4528       if (ptr == Constant) {
4529         if (this_oop != nullptr && tinst_oop != nullptr &&
4530             this_oop->equals(tinst_oop))
4531           o = this_oop;
4532         else if (above_centerline(_ptr)) {
4533           assert(!tinst_klass->is_interface(), "");
4534           o = tinst_oop;
4535         } else if (above_centerline(tinst->_ptr)) {
4536           assert(!this_klass->is_interface(), "");
4537           o = this_oop;
4538         } else
4539           ptr = NotNull;
4540       }
4541       res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4542     }
4543 
4544     return res;
4545 
4546   } // End of case InstPtr
4547 
4548   } // End of switch
4549   return this;                  // Return the double constant
4550 }
4551 
4552 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4553                                                             ciKlass*& res_klass, bool& res_xk) {
4554   ciKlass* this_klass = this_type->klass();
4555   ciKlass* other_klass = other_type->klass();





4556   bool this_xk = this_type->klass_is_exact();
4557   bool other_xk = other_type->klass_is_exact();
4558   PTR this_ptr = this_type->ptr();
4559   PTR other_ptr = other_type->ptr();
4560   const TypeInterfaces* this_interfaces = this_type->interfaces();
4561   const TypeInterfaces* other_interfaces = other_type->interfaces();
4562   // Check for easy case; klasses are equal (and perhaps not loaded!)
4563   // If we have constants, then we created oops so classes are loaded
4564   // and we can handle the constants further down.  This case handles
4565   // both-not-loaded or both-loaded classes
4566   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4567     res_klass = this_klass;
4568     res_xk = this_xk;

4569     return QUICK;
4570   }
4571 
4572   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4573   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4574     return UNLOADED;
4575   }
4576 
4577   // !!! Here's how the symmetry requirement breaks down into invariants:
4578   // If we split one up & one down AND they subtype, take the down man.
4579   // If we split one up & one down AND they do NOT subtype, "fall hard".
4580   // If both are up and they subtype, take the subtype class.
4581   // If both are up and they do NOT subtype, "fall hard".
4582   // If both are down and they subtype, take the supertype class.
4583   // If both are down and they do NOT subtype, "fall hard".
4584   // Constants treated as down.
4585 
4586   // Now, reorder the above list; observe that both-down+subtype is also
4587   // "fall hard"; "fall hard" becomes the default case:
4588   // If we split one up & one down AND they subtype, take the down man.
4589   // If both are up and they subtype, take the subtype class.
4590 
4591   // If both are down and they subtype, "fall hard".
4592   // If both are down and they do NOT subtype, "fall hard".
4593   // If both are up and they do NOT subtype, "fall hard".
4594   // If we split one up & one down AND they do NOT subtype, "fall hard".
4595 
4596   // If a proper subtype is exact, and we return it, we return it exactly.
4597   // If a proper supertype is exact, there can be no subtyping relationship!
4598   // If both types are equal to the subtype, exactness is and-ed below the
4599   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4600 
4601   // Check for subtyping:
























































4602   const T* subtype = nullptr;
4603   bool subtype_exact = false;


4604   if (this_type->is_same_java_type_as(other_type)) {

4605     subtype = this_type;
4606     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4607   } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {





4608     subtype = this_type;     // Pick subtyping class
4609     subtype_exact = this_xk;
4610   } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {








4611     subtype = other_type;    // Pick subtyping class
4612     subtype_exact = other_xk;








4613   }
4614 
4615   if (subtype) {
4616     if (above_centerline(ptr)) { // both are up?


4617       this_type = other_type = subtype;
4618       this_xk = other_xk = subtype_exact;





4619     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4620       this_type = other_type; // tinst is down; keep down man

4621       this_xk = other_xk;

4622     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {

4623       other_type = this_type; // this is down; keep down man
4624       other_xk = this_xk;
4625     } else {

4626       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA



4627     }
4628   }
4629 
4630   // Check for classes now being equal
4631   if (this_type->is_same_java_type_as(other_type)) {
4632     // If the klasses are equal, the constants may still differ.  Fall to
4633     // NotNull if they do (neither constant is null; that is a special case
4634     // handled elsewhere).
4635     res_klass = this_type->klass();
4636     res_xk = this_xk;

4637     return SUBTYPE;
4638   } // Else classes are not equal
4639 
4640   // Since klasses are different, we require a LCA in the Java
4641   // class hierarchy - which means we have to fall to at least NotNull.
4642   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4643     ptr = NotNull;
4644   }
4645 
4646   interfaces = this_interfaces->intersection_with(other_interfaces);
4647 
4648   // Now we find the LCA of Java classes
4649   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4650 
4651   res_klass = k;
4652   res_xk = false;

4653 
4654   return LCA;
4655 }
4656 




4657 //------------------------java_mirror_type--------------------------------------
4658 ciType* TypeInstPtr::java_mirror_type() const {
4659   // must be a singleton type
4660   if( const_oop() == nullptr )  return nullptr;
4661 
4662   // must be of type java.lang.Class
4663   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;
4664 
4665   return const_oop()->as_instance()->java_mirror_type();
4666 }
4667 
4668 
4669 //------------------------------xdual------------------------------------------
4670 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4671 // inheritance mechanism.
4672 const Type *TypeInstPtr::xdual() const {
4673   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4674 }
4675 
4676 //------------------------------eq---------------------------------------------
4677 // Structural equality check for Type representations
4678 bool TypeInstPtr::eq( const Type *t ) const {
4679   const TypeInstPtr *p = t->is_instptr();
4680   return
4681     klass()->equals(p->klass()) &&

4682     _interfaces->eq(p->_interfaces) &&
4683     TypeOopPtr::eq(p);          // Check sub-type stuff
4684 }
4685 
4686 //------------------------------hash-------------------------------------------
4687 // Type-specific hashing function.
4688 uint TypeInstPtr::hash(void) const {
4689   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4690 }
4691 
4692 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4693   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4694 }
4695 
4696 
4697 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4698   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4699 }
4700 
4701 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4702   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4703 }
4704 
4705 
4706 //------------------------------dump2------------------------------------------
4707 // Dump oop Type
4708 #ifndef PRODUCT
4709 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {

4723       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4724       char* buf = ss.as_string(/* c_heap= */false);
4725       StringUtils::replace_no_expand(buf, "\n", "");
4726       st->print_raw(buf);
4727     }
4728   case BotPTR:
4729     if (!WizardMode && !Verbose) {
4730       if( _klass_is_exact ) st->print(":exact");
4731       break;
4732     }
4733   case TopPTR:
4734   case AnyNull:
4735   case NotNull:
4736     st->print(":%s", ptr_msg[_ptr]);
4737     if( _klass_is_exact ) st->print(":exact");
4738     break;
4739   default:
4740     break;
4741   }
4742 
4743   if( _offset ) {               // Dump offset, if any
4744     if( _offset == OffsetBot )      st->print("+any");
4745     else if( _offset == OffsetTop ) st->print("+unknown");
4746     else st->print("+%d", _offset);
4747   }
4748 
4749   st->print(" *");





4750   if (_instance_id == InstanceTop)
4751     st->print(",iid=top");
4752   else if (_instance_id != InstanceBot)
4753     st->print(",iid=%d",_instance_id);
4754 
4755   dump_inline_depth(st);
4756   dump_speculative(st);
4757 }
4758 #endif
4759 
4760 //------------------------------add_offset-------------------------------------
4761 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4762   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4763               _instance_id, add_offset_speculative(offset), _inline_depth);
4764 }
4765 
4766 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4767   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4768               _instance_id, with_offset_speculative(offset), _inline_depth);
4769 }
4770 
4771 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4772   if (_speculative == nullptr) {
4773     return this;
4774   }
4775   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4776   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4777               _instance_id, nullptr, _inline_depth);
4778 }
4779 
4780 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4781   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4782 }
4783 
4784 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4785   if (!UseInlineDepthForSpeculativeTypes) {
4786     return this;
4787   }
4788   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4789 }
4790 
4791 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4792   assert(is_known_instance(), "should be known");
4793   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);




4794 }
4795 
4796 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4797   bool xk = klass_is_exact();
4798   ciInstanceKlass* ik = klass()->as_instance_klass();
4799   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4800     if (_interfaces->eq(ik)) {
4801       Compile* C = Compile::current();
4802       Dependencies* deps = C->dependencies();
4803       deps->assert_leaf_type(ik);
4804       xk = true;
4805     }
4806   }
4807   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4808 }
4809 
4810 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) {
4811   static_assert(std::is_base_of<T2, T1>::value, "");
4812 
4813   if (!this_one->is_instance_type(other)) {
4814     return false;
4815   }
4816 
4817   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4818     return true;
4819   }
4820 
4821   return this_one->klass()->is_subtype_of(other->klass()) &&
4822          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4823 }
4824 
4825 
4826 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4827   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);

4832   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4833     return true;
4834   }
4835 
4836   if (this_one->is_instance_type(other)) {
4837     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4838   }
4839 
4840   int dummy;
4841   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4842   if (this_top_or_bottom) {
4843     return false;
4844   }
4845 
4846   const T1* other_ary = this_one->is_array_type(other);
4847   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4848   const TypePtr* this_elem = this_one->elem()->make_ptr();
4849   if (other_elem != nullptr && this_elem != nullptr) {
4850     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4851   }
4852 
4853   if (other_elem == nullptr && this_elem == nullptr) {
4854     return this_one->klass()->is_subtype_of(other->klass());
4855   }
4856 
4857   return false;
4858 }
4859 
4860 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4861   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4862 }
4863 
4864 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4865   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4866 }
4867 
4868 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4869   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4870 }
4871 
4872 //=============================================================================
4873 // Convenience common pre-built types.
4874 const TypeAryPtr* TypeAryPtr::BOTTOM;
4875 const TypeAryPtr* TypeAryPtr::RANGE;
4876 const TypeAryPtr* TypeAryPtr::OOPS;
4877 const TypeAryPtr* TypeAryPtr::NARROWOOPS;
4878 const TypeAryPtr* TypeAryPtr::BYTES;
4879 const TypeAryPtr* TypeAryPtr::SHORTS;
4880 const TypeAryPtr* TypeAryPtr::CHARS;
4881 const TypeAryPtr* TypeAryPtr::INTS;
4882 const TypeAryPtr* TypeAryPtr::LONGS;
4883 const TypeAryPtr* TypeAryPtr::FLOATS;
4884 const TypeAryPtr* TypeAryPtr::DOUBLES;

4885 
4886 //------------------------------make-------------------------------------------
4887 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4888                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4889   assert(!(k == nullptr && ary->_elem->isa_int()),
4890          "integral arrays must be pre-equipped with a class");
4891   if (!xk)  xk = ary->ary_must_be_exact();
4892   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4893   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4894       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4895     k = nullptr;
4896   }
4897   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();



4898 }
4899 
4900 //------------------------------make-------------------------------------------
4901 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4902                                    int instance_id, const TypePtr* speculative, int inline_depth,
4903                                    bool is_autobox_cache) {
4904   assert(!(k == nullptr && ary->_elem->isa_int()),
4905          "integral arrays must be pre-equipped with a class");
4906   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4907   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
4908   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4909   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4910       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4911     k = nullptr;
4912   }
4913   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();



4914 }
4915 
4916 //------------------------------cast_to_ptr_type-------------------------------
4917 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4918   if( ptr == _ptr ) return this;
4919   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4920 }
4921 
4922 
4923 //-----------------------------cast_to_exactness-------------------------------
4924 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4925   if( klass_is_exact == _klass_is_exact ) return this;
4926   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4927   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4928 }
4929 
4930 //-----------------------------cast_to_instance_id----------------------------
4931 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4932   if( instance_id == _instance_id ) return this;
4933   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4934 }
4935 
4936 
4937 //-----------------------------max_array_length-------------------------------
4938 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4939 jint TypeAryPtr::max_array_length(BasicType etype) {
4940   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4941     if (etype == T_NARROWOOP) {
4942       etype = T_OBJECT;
4943     } else if (etype == T_ILLEGAL) { // bottom[]
4944       etype = T_BYTE; // will produce conservatively high value
4945     } else {
4946       fatal("not an element type: %s", type2name(etype));
4947     }
4948   }
4949   return arrayOopDesc::max_array_length(etype);
4950 }
4951 
4952 //-----------------------------narrow_size_type-------------------------------
4953 // Narrow the given size type to the index range for the given array base type.

4969   if (hi > max_hi) {
4970     hi = max_hi;
4971     if (size->is_con()) {
4972       lo = hi;
4973     }
4974     chg = true;
4975   }
4976   // Negative length arrays will produce weird intermediate dead fast-path code
4977   if (lo > hi)
4978     return TypeInt::ZERO;
4979   if (!chg)
4980     return size;
4981   return TypeInt::make(lo, hi, Type::WidenMin);
4982 }
4983 
4984 //-------------------------------cast_to_size----------------------------------
4985 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4986   assert(new_size != nullptr, "");
4987   new_size = narrow_size_type(new_size);
4988   if (new_size == size())  return this;
4989   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4990   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);




























































4991 }
4992 
4993 //------------------------------cast_to_stable---------------------------------
4994 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4995   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4996     return this;
4997 
4998   const Type* elem = this->elem();
4999   const TypePtr* elem_ptr = elem->make_ptr();
5000 
5001   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5002     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5003     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5004   }
5005 
5006   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
5007 
5008   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
5009 }
5010 
5011 //-----------------------------stable_dimension--------------------------------
5012 int TypeAryPtr::stable_dimension() const {
5013   if (!is_stable())  return 0;
5014   int dim = 1;
5015   const TypePtr* elem_ptr = elem()->make_ptr();
5016   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5017     dim += elem_ptr->is_aryptr()->stable_dimension();
5018   return dim;
5019 }
5020 
5021 //----------------------cast_to_autobox_cache-----------------------------------
5022 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5023   if (is_autobox_cache())  return this;
5024   const TypeOopPtr* etype = elem()->make_oopptr();
5025   if (etype == nullptr)  return this;
5026   // The pointers in the autobox arrays are always non-null.
5027   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5028   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
5029   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5030 }
5031 
5032 //------------------------------eq---------------------------------------------
5033 // Structural equality check for Type representations
5034 bool TypeAryPtr::eq( const Type *t ) const {
5035   const TypeAryPtr *p = t->is_aryptr();
5036   return
5037     _ary == p->_ary &&  // Check array
5038     TypeOopPtr::eq(p);  // Check sub-parts

5039 }
5040 
5041 //------------------------------hash-------------------------------------------
5042 // Type-specific hashing function.
5043 uint TypeAryPtr::hash(void) const {
5044   return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
5045 }
5046 
5047 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5048   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5049 }
5050 
5051 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5052   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5053 }
5054 
5055 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5056   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5057 }
5058 //------------------------------meet-------------------------------------------
5059 // Compute the MEET of two types.  It returns a new Type object.
5060 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5061   // Perform a fast test for common case; meeting the same types together.
5062   if( this == t ) return this;  // Meeting same type-rep?
5063   // Current "this->_base" is Pointer
5064   switch (t->base()) {          // switch on original type

5071   case HalfFloatBot:
5072   case FloatTop:
5073   case FloatCon:
5074   case FloatBot:
5075   case DoubleTop:
5076   case DoubleCon:
5077   case DoubleBot:
5078   case NarrowOop:
5079   case NarrowKlass:
5080   case Bottom:                  // Ye Olde Default
5081     return Type::BOTTOM;
5082   case Top:
5083     return this;
5084 
5085   default:                      // All else is a mistake
5086     typerr(t);
5087 
5088   case OopPtr: {                // Meeting to OopPtrs
5089     // Found a OopPtr type vs self-AryPtr type
5090     const TypeOopPtr *tp = t->is_oopptr();
5091     int offset = meet_offset(tp->offset());
5092     PTR ptr = meet_ptr(tp->ptr());
5093     int depth = meet_inline_depth(tp->inline_depth());
5094     const TypePtr* speculative = xmeet_speculative(tp);
5095     switch (tp->ptr()) {
5096     case TopPTR:
5097     case AnyNull: {
5098       int instance_id = meet_instance_id(InstanceTop);
5099       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5100                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5101     }
5102     case BotPTR:
5103     case NotNull: {
5104       int instance_id = meet_instance_id(tp->instance_id());
5105       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5106     }
5107     default: ShouldNotReachHere();
5108     }
5109   }
5110 
5111   case AnyPtr: {                // Meeting two AnyPtrs
5112     // Found an AnyPtr type vs self-AryPtr type
5113     const TypePtr *tp = t->is_ptr();
5114     int offset = meet_offset(tp->offset());
5115     PTR ptr = meet_ptr(tp->ptr());
5116     const TypePtr* speculative = xmeet_speculative(tp);
5117     int depth = meet_inline_depth(tp->inline_depth());
5118     switch (tp->ptr()) {
5119     case TopPTR:
5120       return this;
5121     case BotPTR:
5122     case NotNull:
5123       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5124     case Null:
5125       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5126       // else fall through to AnyNull
5127     case AnyNull: {
5128       int instance_id = meet_instance_id(InstanceTop);
5129       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5130                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5131     }
5132     default: ShouldNotReachHere();
5133     }
5134   }
5135 
5136   case MetadataPtr:
5137   case KlassPtr:
5138   case InstKlassPtr:
5139   case AryKlassPtr:
5140   case RawPtr: return TypePtr::BOTTOM;
5141 
5142   case AryPtr: {                // Meeting 2 references?
5143     const TypeAryPtr *tap = t->is_aryptr();
5144     int off = meet_offset(tap->offset());

5145     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5146     PTR ptr = meet_ptr(tap->ptr());
5147     int instance_id = meet_instance_id(tap->instance_id());
5148     const TypePtr* speculative = xmeet_speculative(tap);
5149     int depth = meet_inline_depth(tap->inline_depth());
5150 
5151     ciKlass* res_klass = nullptr;
5152     bool res_xk = false;



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














5156     }
5157 
5158     ciObject* o = nullptr;             // Assume not constant when done
5159     ciObject* this_oop = const_oop();
5160     ciObject* tap_oop = tap->const_oop();
5161     if (ptr == Constant) {
5162       if (this_oop != nullptr && tap_oop != nullptr &&
5163           this_oop->equals(tap_oop)) {
5164         o = tap_oop;
5165       } else if (above_centerline(_ptr)) {
5166         o = tap_oop;
5167       } else if (above_centerline(tap->_ptr)) {
5168         o = this_oop;
5169       } else {
5170         ptr = NotNull;
5171       }
5172     }
5173     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
5174   }
5175 
5176   // All arrays inherit from Object class
5177   case InstPtr: {
5178     const TypeInstPtr *tp = t->is_instptr();
5179     int offset = meet_offset(tp->offset());
5180     PTR ptr = meet_ptr(tp->ptr());
5181     int instance_id = meet_instance_id(tp->instance_id());
5182     const TypePtr* speculative = xmeet_speculative(tp);
5183     int depth = meet_inline_depth(tp->inline_depth());
5184     const TypeInterfaces* interfaces = meet_interfaces(tp);
5185     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5186     const TypeInterfaces* this_interfaces = _interfaces;
5187 
5188     switch (ptr) {
5189     case TopPTR:
5190     case AnyNull:                // Fall 'down' to dual of object klass
5191       // For instances when a subclass meets a superclass we fall
5192       // below the centerline when the superclass is exact. We need to
5193       // do the same here.
5194       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5195         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5196       } else {
5197         // cannot subclass, so the meet has to fall badly below the centerline
5198         ptr = NotNull;
5199         instance_id = InstanceBot;
5200         interfaces = this_interfaces->intersection_with(tp_interfaces);
5201         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
5202       }
5203     case Constant:
5204     case NotNull:
5205     case BotPTR:                // Fall down to object klass
5206       // LCA is object_klass, but if we subclass from the top we can do better
5207       if (above_centerline(tp->ptr())) {
5208         // If 'tp'  is above the centerline and it is Object class
5209         // then we can subclass in the Java class hierarchy.
5210         // For instances when a subclass meets a superclass we fall
5211         // below the centerline when the superclass is exact. We need
5212         // to do the same here.
5213         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
5214           // that is, my array type is a subtype of 'tp' klass
5215           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5216                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
5217         }
5218       }
5219       // The other case cannot happen, since t cannot be a subtype of an array.
5220       // The meet falls down to Object class below centerline.
5221       if (ptr == Constant) {
5222          ptr = NotNull;
5223       }
5224       if (instance_id > 0) {
5225         instance_id = InstanceBot;
5226       }
5227       interfaces = this_interfaces->intersection_with(tp_interfaces);
5228       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
5229     default: typerr(t);
5230     }
5231   }
5232   }
5233   return this;                  // Lint noise
5234 }
5235 
5236 
5237 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5238                                                            const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5239   int dummy;
5240   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5241   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5242   ciKlass* this_klass = this_ary->klass();
5243   ciKlass* other_klass = other_ary->klass();
5244   bool this_xk = this_ary->klass_is_exact();
5245   bool other_xk = other_ary->klass_is_exact();
5246   PTR this_ptr = this_ary->ptr();
5247   PTR other_ptr = other_ary->ptr();






5248   res_klass = nullptr;
5249   MeetResult result = SUBTYPE;




5250   if (elem->isa_int()) {
5251     // Integral array element types have irrelevant lattice relations.
5252     // It is the klass that determines array layout, not the element type.
5253     if (this_top_or_bottom)
5254       res_klass = other_klass;
5255     else if (other_top_or_bottom || other_klass == this_klass) {
5256       res_klass = this_klass;
5257     } else {
5258       // Something like byte[int+] meets char[int+].
5259       // This must fall to bottom, not (int[-128..65535])[int+].
5260       // instance_id = InstanceBot;
5261       elem = Type::BOTTOM;
5262       result = NOT_SUBTYPE;
5263       if (above_centerline(ptr) || ptr == Constant) {
5264         ptr = NotNull;
5265         res_xk = false;
5266         return NOT_SUBTYPE;
5267       }
5268     }
5269   } else {// Non integral arrays.
5270     // Must fall to bottom if exact klasses in upper lattice
5271     // are not equal or super klass is exact.
5272     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5273         // meet with top[] and bottom[] are processed further down:
5274         !this_top_or_bottom && !other_top_or_bottom &&
5275         // both are exact and not equal:

5277          // 'tap'  is exact and super or unrelated:
5278          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5279          // 'this' is exact and super or unrelated:
5280          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5281       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5282         elem = Type::BOTTOM;
5283       }
5284       ptr = NotNull;
5285       res_xk = false;
5286       return NOT_SUBTYPE;
5287     }
5288   }
5289 
5290   res_xk = false;
5291   switch (other_ptr) {
5292     case AnyNull:
5293     case TopPTR:
5294       // Compute new klass on demand, do not use tap->_klass
5295       if (below_centerline(this_ptr)) {
5296         res_xk = this_xk;



5297       } else {
5298         res_xk = (other_xk || this_xk);
5299       }
5300       return result;
5301     case Constant: {
5302       if (this_ptr == Constant) {
5303         res_xk = true;
5304       } else if(above_centerline(this_ptr)) {
5305         res_xk = true;
5306       } else {
5307         // Only precise for identical arrays
5308         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));





5309       }
5310       return result;
5311     }
5312     case NotNull:
5313     case BotPTR:
5314       // Compute new klass on demand, do not use tap->_klass
5315       if (above_centerline(this_ptr)) {
5316         res_xk = other_xk;



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





5320       }
5321       return result;
5322     default:  {
5323       ShouldNotReachHere();
5324       return result;
5325     }
5326   }
5327   return result;
5328 }
5329 
5330 
5331 //------------------------------xdual------------------------------------------
5332 // Dual: compute field-by-field dual
5333 const Type *TypeAryPtr::xdual() const {
5334   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());









5335 }
5336 
5337 //------------------------------dump2------------------------------------------
5338 #ifndef PRODUCT
5339 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5340   _ary->dump2(d,depth,st);
5341   _interfaces->dump(st);
5342 
5343   switch( _ptr ) {
5344   case Constant:
5345     const_oop()->print(st);
5346     break;
5347   case BotPTR:
5348     if (!WizardMode && !Verbose) {
5349       if( _klass_is_exact ) st->print(":exact");
5350       break;
5351     }
5352   case TopPTR:
5353   case AnyNull:
5354   case NotNull:
5355     st->print(":%s", ptr_msg[_ptr]);
5356     if( _klass_is_exact ) st->print(":exact");
5357     break;
5358   default:
5359     break;
5360   }
5361 
5362   if( _offset != 0 ) {









5363     BasicType basic_elem_type = elem()->basic_type();
5364     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5365     if( _offset == OffsetTop )       st->print("+undefined");
5366     else if( _offset == OffsetBot )  st->print("+any");
5367     else if( _offset < header_size ) st->print("+%d", _offset);
5368     else {
5369       if (basic_elem_type == T_ILLEGAL) {
5370         st->print("+any");
5371       } else {
5372         int elem_size = type2aelembytes(basic_elem_type);
5373         st->print("[%d]", (_offset - header_size)/elem_size);
5374       }
5375     }
5376   }
5377   st->print(" *");
5378   if (_instance_id == InstanceTop)
5379     st->print(",iid=top");
5380   else if (_instance_id != InstanceBot)
5381     st->print(",iid=%d",_instance_id);
5382 
5383   dump_inline_depth(st);
5384   dump_speculative(st);
5385 }
5386 #endif
5387 
5388 bool TypeAryPtr::empty(void) const {
5389   if (_ary->empty())       return true;




5390   return TypeOopPtr::empty();
5391 }
5392 
5393 //------------------------------add_offset-------------------------------------
5394 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5395   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5396 }
5397 
5398 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5399   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5400 }
5401 
5402 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5403   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5404 }
5405 
5406 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5407   if (_speculative == nullptr) {
5408     return this;
5409   }
5410   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5411   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);













5412 }
5413 
5414 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5415   if (!UseInlineDepthForSpeculativeTypes) {
5416     return this;
5417   }
5418   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);











































5419 }
5420 
5421 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5422   assert(is_known_instance(), "should be known");
5423   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5424 }
5425 
5426 //=============================================================================
5427 

5428 //------------------------------hash-------------------------------------------
5429 // Type-specific hashing function.
5430 uint TypeNarrowPtr::hash(void) const {
5431   return _ptrtype->hash() + 7;
5432 }
5433 
5434 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5435   return _ptrtype->singleton();
5436 }
5437 
5438 bool TypeNarrowPtr::empty(void) const {
5439   return _ptrtype->empty();
5440 }
5441 
5442 intptr_t TypeNarrowPtr::get_con() const {
5443   return _ptrtype->get_con();
5444 }
5445 
5446 bool TypeNarrowPtr::eq( const Type *t ) const {
5447   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5501   case HalfFloatTop:
5502   case HalfFloatCon:
5503   case HalfFloatBot:
5504   case FloatTop:
5505   case FloatCon:
5506   case FloatBot:
5507   case DoubleTop:
5508   case DoubleCon:
5509   case DoubleBot:
5510   case AnyPtr:
5511   case RawPtr:
5512   case OopPtr:
5513   case InstPtr:
5514   case AryPtr:
5515   case MetadataPtr:
5516   case KlassPtr:
5517   case InstKlassPtr:
5518   case AryKlassPtr:
5519   case NarrowOop:
5520   case NarrowKlass:
5521 
5522   case Bottom:                  // Ye Olde Default
5523     return Type::BOTTOM;
5524   case Top:
5525     return this;
5526 
5527   default:                      // All else is a mistake
5528     typerr(t);
5529 
5530   } // End of switch
5531 
5532   return this;
5533 }
5534 
5535 #ifndef PRODUCT
5536 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5537   _ptrtype->dump2(d, depth, st);
5538 }
5539 #endif
5540 
5541 const TypeNarrowOop *TypeNarrowOop::BOTTOM;

5585     return (one == two) && TypePtr::eq(t);
5586   } else {
5587     return one->equals(two) && TypePtr::eq(t);
5588   }
5589 }
5590 
5591 //------------------------------hash-------------------------------------------
5592 // Type-specific hashing function.
5593 uint TypeMetadataPtr::hash(void) const {
5594   return
5595     (metadata() ? metadata()->hash() : 0) +
5596     TypePtr::hash();
5597 }
5598 
5599 //------------------------------singleton--------------------------------------
5600 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5601 // constants
5602 bool TypeMetadataPtr::singleton(void) const {
5603   // detune optimizer to not generate constant metadata + constant offset as a constant!
5604   // TopPTR, Null, AnyNull, Constant are all singletons
5605   return (_offset == 0) && !below_centerline(_ptr);
5606 }
5607 
5608 //------------------------------add_offset-------------------------------------
5609 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5610   return make( _ptr, _metadata, xadd_offset(offset));
5611 }
5612 
5613 //-----------------------------filter------------------------------------------
5614 // Do not allow interface-vs.-noninterface joins to collapse to top.
5615 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5616   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5617   if (ft == nullptr || ft->empty())
5618     return Type::TOP;           // Canonical empty value
5619   return ft;
5620 }
5621 
5622  //------------------------------get_con----------------------------------------
5623 intptr_t TypeMetadataPtr::get_con() const {
5624   assert( _ptr == Null || _ptr == Constant, "" );
5625   assert( _offset >= 0, "" );
5626 
5627   if (_offset != 0) {
5628     // After being ported to the compiler interface, the compiler no longer
5629     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5630     // to a handle at compile time.  This handle is embedded in the generated
5631     // code and dereferenced at the time the nmethod is made.  Until that time,
5632     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5633     // have access to the addresses!).  This does not seem to currently happen,
5634     // but this assertion here is to help prevent its occurrence.
5635     tty->print_cr("Found oop constant with non-zero offset");
5636     ShouldNotReachHere();
5637   }
5638 
5639   return (intptr_t)metadata()->constant_encoding();
5640 }
5641 
5642 //------------------------------cast_to_ptr_type-------------------------------
5643 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5644   if( ptr == _ptr ) return this;
5645   return make(ptr, metadata(), _offset);
5646 }
5647 

5661   case HalfFloatBot:
5662   case FloatTop:
5663   case FloatCon:
5664   case FloatBot:
5665   case DoubleTop:
5666   case DoubleCon:
5667   case DoubleBot:
5668   case NarrowOop:
5669   case NarrowKlass:
5670   case Bottom:                  // Ye Olde Default
5671     return Type::BOTTOM;
5672   case Top:
5673     return this;
5674 
5675   default:                      // All else is a mistake
5676     typerr(t);
5677 
5678   case AnyPtr: {
5679     // Found an AnyPtr type vs self-OopPtr type
5680     const TypePtr *tp = t->is_ptr();
5681     int offset = meet_offset(tp->offset());
5682     PTR ptr = meet_ptr(tp->ptr());
5683     switch (tp->ptr()) {
5684     case Null:
5685       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5686       // else fall through:
5687     case TopPTR:
5688     case AnyNull: {
5689       return make(ptr, _metadata, offset);
5690     }
5691     case BotPTR:
5692     case NotNull:
5693       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5694     default: typerr(t);
5695     }
5696   }
5697 
5698   case RawPtr:
5699   case KlassPtr:
5700   case InstKlassPtr:
5701   case AryKlassPtr:
5702   case OopPtr:
5703   case InstPtr:
5704   case AryPtr:
5705     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5706 
5707   case MetadataPtr: {
5708     const TypeMetadataPtr *tp = t->is_metadataptr();
5709     int offset = meet_offset(tp->offset());
5710     PTR tptr = tp->ptr();
5711     PTR ptr = meet_ptr(tptr);
5712     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5713     if (tptr == TopPTR || _ptr == TopPTR ||
5714         metadata()->equals(tp->metadata())) {
5715       return make(ptr, md, offset);
5716     }
5717     // metadata is different
5718     if( ptr == Constant ) {  // Cannot be equal constants, so...
5719       if( tptr == Constant && _ptr != Constant)  return t;
5720       if( _ptr == Constant && tptr != Constant)  return this;
5721       ptr = NotNull;            // Fall down in lattice
5722     }
5723     return make(ptr, nullptr, offset);
5724     break;
5725   }
5726   } // End of switch
5727   return this;                  // Return the double constant
5728 }
5729 
5730 
5731 //------------------------------xdual------------------------------------------
5732 // Dual of a pure metadata pointer.
5733 const Type *TypeMetadataPtr::xdual() const {
5734   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5735 }
5736 
5737 //------------------------------dump2------------------------------------------
5738 #ifndef PRODUCT
5739 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5740   st->print("metadataptr:%s", ptr_msg[_ptr]);
5741   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5742   switch( _offset ) {
5743   case OffsetTop: st->print("+top"); break;
5744   case OffsetBot: st->print("+any"); break;
5745   case         0: break;
5746   default:        st->print("+%d",_offset); break;
5747   }
5748 }
5749 #endif
5750 
5751 
5752 //=============================================================================
5753 // Convenience common pre-built type.
5754 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5755 
5756 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5757   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5758 }
5759 
5760 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5761   return make(Constant, m, 0);
5762 }
5763 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5764   return make(Constant, m, 0);
5765 }
5766 
5767 //------------------------------make-------------------------------------------
5768 // Create a meta data constant
5769 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5770   assert(m == nullptr || !m->is_klass(), "wrong type");
5771   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5772 }
5773 
5774 
5775 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5776   const Type* elem = _ary->_elem;
5777   bool xk = klass_is_exact();
5778   if (elem->make_oopptr() != nullptr) {
5779     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5780     if (elem->is_klassptr()->klass_is_exact()) {



5781       xk = true;
5782     }
5783   }
5784   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5785 }
5786 
5787 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5788   if (klass->is_instance_klass()) {
5789     return TypeInstKlassPtr::make(klass, interface_handling);
5790   }
5791   return TypeAryKlassPtr::make(klass, interface_handling);
5792 }
5793 
5794 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5795   if (klass->is_instance_klass()) {
5796     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5797     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5798   }
5799   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5800 }
5801 
5802 
5803 //------------------------------TypeKlassPtr-----------------------------------
5804 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5805   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5806   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5807          klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5808 }
5809 
5810 // Is there a single ciKlass* that can represent that type?
5811 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5812   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5813   if (_interfaces->empty()) {
5814     return _klass;
5815   }
5816   if (_klass != ciEnv::current()->Object_klass()) {
5817     if (_interfaces->eq(_klass->as_instance_klass())) {
5818       return _klass;
5819     }
5820     return nullptr;
5821   }
5822   return _interfaces->exact_klass();
5823 }
5824 
5825 //------------------------------eq---------------------------------------------
5826 // Structural equality check for Type representations
5827 bool TypeKlassPtr::eq(const Type *t) const {
5828   const TypeKlassPtr *p = t->is_klassptr();
5829   return
5830     _interfaces->eq(p->_interfaces) &&
5831     TypePtr::eq(p);
5832 }
5833 
5834 //------------------------------hash-------------------------------------------
5835 // Type-specific hashing function.
5836 uint TypeKlassPtr::hash(void) const {
5837   return TypePtr::hash() + _interfaces->hash();
5838 }
5839 
5840 //------------------------------singleton--------------------------------------
5841 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5842 // constants
5843 bool TypeKlassPtr::singleton(void) const {
5844   // detune optimizer to not generate constant klass + constant offset as a constant!
5845   // TopPTR, Null, AnyNull, Constant are all singletons
5846   return (_offset == 0) && !below_centerline(_ptr);
5847 }
5848 
5849 // Do not allow interface-vs.-noninterface joins to collapse to top.
5850 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5851   // logic here mirrors the one from TypeOopPtr::filter. See comments
5852   // there.
5853   const Type* ft = join_helper(kills, include_speculative);
5854 
5855   if (ft->empty()) {
5856     return Type::TOP;           // Canonical empty value
5857   }
5858 
5859   return ft;
5860 }
5861 
5862 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5863   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5864     return _interfaces->union_with(other->_interfaces);
5865   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5866     return other->_interfaces;
5867   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5868     return _interfaces;
5869   }
5870   return _interfaces->intersection_with(other->_interfaces);
5871 }
5872 
5873 //------------------------------get_con----------------------------------------
5874 intptr_t TypeKlassPtr::get_con() const {
5875   assert( _ptr == Null || _ptr == Constant, "" );
5876   assert( _offset >= 0, "" );
5877 
5878   if (_offset != 0) {
5879     // After being ported to the compiler interface, the compiler no longer
5880     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5881     // to a handle at compile time.  This handle is embedded in the generated
5882     // code and dereferenced at the time the nmethod is made.  Until that time,
5883     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5884     // have access to the addresses!).  This does not seem to currently happen,
5885     // but this assertion here is to help prevent its occurrence.
5886     tty->print_cr("Found oop constant with non-zero offset");
5887     ShouldNotReachHere();
5888   }
5889 
5890   ciKlass* k = exact_klass();
5891 
5892   return (intptr_t)k->constant_encoding();
5893 }
5894 
5895 //------------------------------dump2------------------------------------------
5896 // Dump Klass Type
5897 #ifndef PRODUCT
5898 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {

5902   case NotNull:
5903     {
5904       const char *name = klass()->name()->as_utf8();
5905       if (name) {
5906         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5907       } else {
5908         ShouldNotReachHere();
5909       }
5910       _interfaces->dump(st);
5911     }
5912   case BotPTR:
5913     if (!WizardMode && !Verbose && _ptr != Constant) break;
5914   case TopPTR:
5915   case AnyNull:
5916     st->print(":%s", ptr_msg[_ptr]);
5917     if (_ptr == Constant) st->print(":exact");
5918     break;
5919   default:
5920     break;
5921   }
5922 
5923   if (_offset) {               // Dump offset, if any
5924     if (_offset == OffsetBot)      { st->print("+any"); }
5925     else if (_offset == OffsetTop) { st->print("+unknown"); }
5926     else                            { st->print("+%d", _offset); }
5927   }
5928 
5929   st->print(" *");




5930 }
5931 #endif
5932 
5933 //=============================================================================
5934 // Convenience common pre-built types.
5935 
5936 // Not-null object klass or below
5937 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5938 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5939 
5940 bool TypeInstKlassPtr::eq(const Type *t) const {
5941   const TypeKlassPtr *p = t->is_klassptr();
5942   return
5943     klass()->equals(p->klass()) &&

5944     TypeKlassPtr::eq(p);
5945 }
5946 
5947 uint TypeInstKlassPtr::hash(void) const {
5948   return klass()->hash() + TypeKlassPtr::hash();
5949 }
5950 
5951 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {


5952   TypeInstKlassPtr *r =
5953     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5954 
5955   return r;
5956 }
5957 
5958 //------------------------------add_offset-------------------------------------
5959 // Access internals of klass object
5960 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5961   return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5962 }
5963 
5964 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5965   return make(_ptr, klass(), _interfaces, offset);
5966 }
5967 
5968 //------------------------------cast_to_ptr_type-------------------------------
5969 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5970   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5971   if( ptr == _ptr ) return this;
5972   return make(ptr, _klass, _interfaces, _offset);
5973 }
5974 
5975 
5976 bool TypeInstKlassPtr::must_be_exact() const {
5977   if (!_klass->is_loaded())  return false;
5978   ciInstanceKlass* ik = _klass->as_instance_klass();
5979   if (ik->is_final())  return true;  // cannot clear xk
5980   return false;
5981 }
5982 
5983 //-----------------------------cast_to_exactness-------------------------------
5984 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5985   if (klass_is_exact == (_ptr == Constant)) return this;
5986   if (must_be_exact()) return this;
5987   ciKlass* k = klass();
5988   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5989 }
5990 
5991 
5992 //-----------------------------as_instance_type--------------------------------
5993 // Corresponding type for an instance of the given class.
5994 // It will be NotNull, and exact if and only if the klass type is exact.
5995 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5996   ciKlass* k = klass();
5997   bool xk = klass_is_exact();
5998   Compile* C = Compile::current();
5999   Dependencies* deps = C->dependencies();
6000   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6001   // Element is an instance
6002   bool klass_is_exact = false;
6003   const TypeInterfaces* interfaces = _interfaces;
6004   if (k->is_loaded()) {
6005     // Try to set klass_is_exact.
6006     ciInstanceKlass* ik = k->as_instance_klass();
6007     klass_is_exact = ik->is_final();
6008     if (!klass_is_exact && klass_change
6009         && deps != nullptr && UseUniqueSubclasses) {
6010       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6011       if (sub != nullptr) {
6012         if (_interfaces->eq(sub)) {
6013           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6014           k = ik = sub;
6015           xk = sub->is_final();
6016         }
6017       }
6018     }
6019   }
6020   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
6021 }
6022 
6023 //------------------------------xmeet------------------------------------------
6024 // Compute the MEET of two types, return a new Type object.
6025 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6026   // Perform a fast test for common case; meeting the same types together.
6027   if( this == t ) return this;  // Meeting same type-rep?
6028 
6029   // Current "this->_base" is Pointer
6030   switch (t->base()) {          // switch on original type
6031 
6032   case Int:                     // Mixing ints & oops happens when javac
6033   case Long:                    // reuses local variables
6034   case HalfFloatTop:
6035   case HalfFloatCon:
6036   case HalfFloatBot:
6037   case FloatTop:
6038   case FloatCon:
6039   case FloatBot:
6040   case DoubleTop:
6041   case DoubleCon:
6042   case DoubleBot:
6043   case NarrowOop:
6044   case NarrowKlass:
6045   case Bottom:                  // Ye Olde Default
6046     return Type::BOTTOM;
6047   case Top:
6048     return this;
6049 
6050   default:                      // All else is a mistake
6051     typerr(t);
6052 
6053   case AnyPtr: {                // Meeting to AnyPtrs
6054     // Found an AnyPtr type vs self-KlassPtr type
6055     const TypePtr *tp = t->is_ptr();
6056     int offset = meet_offset(tp->offset());
6057     PTR ptr = meet_ptr(tp->ptr());
6058     switch (tp->ptr()) {
6059     case TopPTR:
6060       return this;
6061     case Null:
6062       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6063     case AnyNull:
6064       return make( ptr, klass(), _interfaces, offset );
6065     case BotPTR:
6066     case NotNull:
6067       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6068     default: typerr(t);
6069     }
6070   }
6071 
6072   case RawPtr:
6073   case MetadataPtr:
6074   case OopPtr:
6075   case AryPtr:                  // Meet with AryPtr
6076   case InstPtr:                 // Meet with InstPtr
6077     return TypePtr::BOTTOM;
6078 
6079   //
6080   //             A-top         }
6081   //           /   |   \       }  Tops
6082   //       B-top A-any C-top   }
6083   //          | /  |  \ |      }  Any-nulls
6084   //       B-any   |   C-any   }
6085   //          |    |    |
6086   //       B-con A-con C-con   } constants; not comparable across classes
6087   //          |    |    |
6088   //       B-not   |   C-not   }
6089   //          | \  |  / |      }  not-nulls
6090   //       B-bot A-not C-bot   }
6091   //           \   |   /       }  Bottoms
6092   //             A-bot         }
6093   //
6094 
6095   case InstKlassPtr: {  // Meet two KlassPtr types
6096     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6097     int  off     = meet_offset(tkls->offset());
6098     PTR  ptr     = meet_ptr(tkls->ptr());
6099     const TypeInterfaces* interfaces = meet_interfaces(tkls);
6100 
6101     ciKlass* res_klass = nullptr;
6102     bool res_xk = false;
6103     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {

6104       case UNLOADED:
6105         ShouldNotReachHere();
6106       case SUBTYPE:
6107       case NOT_SUBTYPE:
6108       case LCA:
6109       case QUICK: {
6110         assert(res_xk == (ptr == Constant), "");
6111         const Type* res = make(ptr, res_klass, interfaces, off);
6112         return res;
6113       }
6114       default:
6115         ShouldNotReachHere();
6116     }
6117   } // End of case KlassPtr
6118   case AryKlassPtr: {                // All arrays inherit from Object class
6119     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6120     int offset = meet_offset(tp->offset());
6121     PTR ptr = meet_ptr(tp->ptr());
6122     const TypeInterfaces* interfaces = meet_interfaces(tp);
6123     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6124     const TypeInterfaces* this_interfaces = _interfaces;
6125 
6126     switch (ptr) {
6127     case TopPTR:
6128     case AnyNull:                // Fall 'down' to dual of object klass
6129       // For instances when a subclass meets a superclass we fall
6130       // below the centerline when the superclass is exact. We need to
6131       // do the same here.
6132       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6133         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
6134       } else {
6135         // cannot subclass, so the meet has to fall badly below the centerline
6136         ptr = NotNull;
6137         interfaces = _interfaces->intersection_with(tp->_interfaces);
6138         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6139       }
6140     case Constant:
6141     case NotNull:
6142     case BotPTR:                // Fall down to object klass
6143       // LCA is object_klass, but if we subclass from the top we can do better
6144       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6145         // If 'this' (InstPtr) is above the centerline and it is Object class
6146         // then we can subclass in the Java class hierarchy.
6147         // For instances when a subclass meets a superclass we fall
6148         // below the centerline when the superclass is exact. We need
6149         // to do the same here.
6150         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6151           // that is, tp's array type is a subtype of my klass
6152           return TypeAryKlassPtr::make(ptr,
6153                                        tp->elem(), tp->klass(), offset);
6154         }
6155       }
6156       // The other case cannot happen, since I cannot be a subtype of an array.
6157       // The meet falls down to Object class below centerline.
6158       if( ptr == Constant )
6159          ptr = NotNull;
6160       interfaces = this_interfaces->intersection_with(tp_interfaces);
6161       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6162     default: typerr(t);
6163     }
6164   }
6165 
6166   } // End of switch
6167   return this;                  // Return the double constant
6168 }
6169 
6170 //------------------------------xdual------------------------------------------
6171 // Dual: compute field-by-field dual
6172 const Type    *TypeInstKlassPtr::xdual() const {
6173   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
6174 }
6175 
6176 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) {
6177   static_assert(std::is_base_of<T2, T1>::value, "");
6178   if (!this_one->is_loaded() || !other->is_loaded()) {
6179     return false;
6180   }
6181   if (!this_one->is_instance_type(other)) {
6182     return false;
6183   }
6184 
6185   if (!other_exact) {
6186     return false;
6187   }
6188 
6189   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6190     return true;
6191   }
6192 
6193   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);

6254   const TypeInterfaces* interfaces = _interfaces;
6255   if (k->is_loaded()) {
6256     ciInstanceKlass* ik = k->as_instance_klass();
6257     bool klass_is_exact = ik->is_final();
6258     if (!klass_is_exact &&
6259         deps != nullptr) {
6260       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6261       if (sub != nullptr) {
6262         if (_interfaces->eq(sub)) {
6263           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6264           k = ik = sub;
6265           klass_is_exact = sub->is_final();
6266           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6267         }
6268       }
6269     }
6270   }
6271   return this;
6272 }
6273 















6274 
6275 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6276   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6277 }
6278 
6279 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {
6280   if (k->is_obj_array_klass()) {
6281     // Element is an object array. Recursively call ourself.
6282     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6283     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6284     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6285   } else if (k->is_type_array_klass()) {
6286     // Element is an typeArray
6287     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6288     return TypeAryKlassPtr::make(ptr, etype, k, offset);




6289   } else {
6290     ShouldNotReachHere();
6291     return nullptr;
6292   }
6293 }
6294 











6295 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6296   return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6297 }
6298 
6299 //------------------------------eq---------------------------------------------
6300 // Structural equality check for Type representations
6301 bool TypeAryKlassPtr::eq(const Type *t) const {
6302   const TypeAryKlassPtr *p = t->is_aryklassptr();
6303   return
6304     _elem == p->_elem &&  // Check array



6305     TypeKlassPtr::eq(p);  // Check sub-parts
6306 }
6307 
6308 //------------------------------hash-------------------------------------------
6309 // Type-specific hashing function.
6310 uint TypeAryKlassPtr::hash(void) const {
6311   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();

6312 }
6313 
6314 //----------------------compute_klass------------------------------------------
6315 // Compute the defining klass for this class
6316 ciKlass* TypeAryPtr::compute_klass() const {
6317   // Compute _klass based on element type.
6318   ciKlass* k_ary = nullptr;
6319   const TypeInstPtr *tinst;
6320   const TypeAryPtr *tary;
6321   const Type* el = elem();
6322   if (el->isa_narrowoop()) {
6323     el = el->make_ptr();
6324   }
6325 
6326   // Get element klass
6327   if ((tinst = el->isa_instptr()) != nullptr) {
6328     // Leave k_ary at null.





6329   } else if ((tary = el->isa_aryptr()) != nullptr) {
6330     // Leave k_ary at null.
6331   } else if ((el->base() == Type::Top) ||
6332              (el->base() == Type::Bottom)) {
6333     // element type of Bottom occurs from meet of basic type
6334     // and object; Top occurs when doing join on Bottom.
6335     // Leave k_ary at null.
6336   } else {
6337     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6338     // Compute array klass directly from basic type
6339     k_ary = ciTypeArrayKlass::make(el->basic_type());
6340   }
6341   return k_ary;
6342 }
6343 
6344 //------------------------------klass------------------------------------------
6345 // Return the defining klass for this class
6346 ciKlass* TypeAryPtr::klass() const {
6347   if( _klass ) return _klass;   // Return cached value, if possible
6348 
6349   // Oops, need to compute _klass and cache it
6350   ciKlass* k_ary = compute_klass();

6358     // type TypeAryPtr::OOPS.  This Type is shared between all
6359     // active compilations.  However, the ciKlass which represents
6360     // this Type is *not* shared between compilations, so caching
6361     // this value would result in fetching a dangling pointer.
6362     //
6363     // Recomputing the underlying ciKlass for each request is
6364     // a bit less efficient than caching, but calls to
6365     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6366     ((TypeAryPtr*)this)->_klass = k_ary;
6367   }
6368   return k_ary;
6369 }
6370 
6371 // Is there a single ciKlass* that can represent that type?
6372 ciKlass* TypeAryPtr::exact_klass_helper() const {
6373   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6374     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6375     if (k == nullptr) {
6376       return nullptr;
6377     }
6378     k = ciObjArrayKlass::make(k);
6379     return k;
6380   }
6381 
6382   return klass();
6383 }
6384 
6385 const Type* TypeAryPtr::base_element_type(int& dims) const {
6386   const Type* elem = this->elem();
6387   dims = 1;
6388   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6389     elem = elem->make_ptr()->is_aryptr()->elem();
6390     dims++;
6391   }
6392   return elem;
6393 }
6394 
6395 //------------------------------add_offset-------------------------------------
6396 // Access internals of klass object
6397 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6398   return make(_ptr, elem(), klass(), xadd_offset(offset));
6399 }
6400 
6401 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6402   return make(_ptr, elem(), klass(), offset);
6403 }
6404 
6405 //------------------------------cast_to_ptr_type-------------------------------
6406 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6407   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6408   if (ptr == _ptr) return this;
6409   return make(ptr, elem(), _klass, _offset);
6410 }
6411 
6412 bool TypeAryKlassPtr::must_be_exact() const {
6413   if (_elem == Type::BOTTOM) return false;
6414   if (_elem == Type::TOP   ) return false;
6415   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6416   if (!tk)             return true;   // a primitive type, like int





6417   return tk->must_be_exact();
6418 }
6419 
6420 
6421 //-----------------------------cast_to_exactness-------------------------------
6422 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6423   if (must_be_exact()) return this;  // cannot clear xk



6424   ciKlass* k = _klass;
6425   const Type* elem = this->elem();
6426   if (elem->isa_klassptr() && !klass_is_exact) {
6427     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6428   }
6429   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);

















6430 }
6431 



6432 
6433 //-----------------------------as_instance_type--------------------------------
6434 // Corresponding type for an instance of the given class.
6435 // It will be NotNull, and exact if and only if the klass type is exact.
6436 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6437   ciKlass* k = klass();
6438   bool    xk = klass_is_exact();
6439   const Type* el = nullptr;
6440   if (elem()->isa_klassptr()) {
6441     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6442     k = nullptr;
6443   } else {
6444     el = elem();
6445   }
6446   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);




6447 }
6448 
6449 
6450 //------------------------------xmeet------------------------------------------
6451 // Compute the MEET of two types, return a new Type object.
6452 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6453   // Perform a fast test for common case; meeting the same types together.
6454   if( this == t ) return this;  // Meeting same type-rep?
6455 
6456   // Current "this->_base" is Pointer
6457   switch (t->base()) {          // switch on original type
6458 
6459   case Int:                     // Mixing ints & oops happens when javac
6460   case Long:                    // reuses local variables
6461   case HalfFloatTop:
6462   case HalfFloatCon:
6463   case HalfFloatBot:
6464   case FloatTop:
6465   case FloatCon:
6466   case FloatBot:
6467   case DoubleTop:
6468   case DoubleCon:
6469   case DoubleBot:
6470   case NarrowOop:
6471   case NarrowKlass:
6472   case Bottom:                  // Ye Olde Default
6473     return Type::BOTTOM;
6474   case Top:
6475     return this;
6476 
6477   default:                      // All else is a mistake
6478     typerr(t);
6479 
6480   case AnyPtr: {                // Meeting to AnyPtrs
6481     // Found an AnyPtr type vs self-KlassPtr type
6482     const TypePtr *tp = t->is_ptr();
6483     int offset = meet_offset(tp->offset());
6484     PTR ptr = meet_ptr(tp->ptr());
6485     switch (tp->ptr()) {
6486     case TopPTR:
6487       return this;
6488     case Null:
6489       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6490     case AnyNull:
6491       return make( ptr, _elem, klass(), offset );
6492     case BotPTR:
6493     case NotNull:
6494       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6495     default: typerr(t);
6496     }
6497   }
6498 
6499   case RawPtr:
6500   case MetadataPtr:
6501   case OopPtr:
6502   case AryPtr:                  // Meet with AryPtr
6503   case InstPtr:                 // Meet with InstPtr
6504     return TypePtr::BOTTOM;
6505 
6506   //
6507   //             A-top         }
6508   //           /   |   \       }  Tops
6509   //       B-top A-any C-top   }
6510   //          | /  |  \ |      }  Any-nulls
6511   //       B-any   |   C-any   }
6512   //          |    |    |
6513   //       B-con A-con C-con   } constants; not comparable across classes
6514   //          |    |    |
6515   //       B-not   |   C-not   }
6516   //          | \  |  / |      }  not-nulls
6517   //       B-bot A-not C-bot   }
6518   //           \   |   /       }  Bottoms
6519   //             A-bot         }
6520   //
6521 
6522   case AryKlassPtr: {  // Meet two KlassPtr types
6523     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6524     int off = meet_offset(tap->offset());
6525     const Type* elem = _elem->meet(tap->_elem);
6526 
6527     PTR ptr = meet_ptr(tap->ptr());
6528     ciKlass* res_klass = nullptr;
6529     bool res_xk = false;
6530     meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);




6531     assert(res_xk == (ptr == Constant), "");
6532     return make(ptr, elem, res_klass, off);












6533   } // End of case KlassPtr
6534   case InstKlassPtr: {
6535     const TypeInstKlassPtr *tp = t->is_instklassptr();
6536     int offset = meet_offset(tp->offset());
6537     PTR ptr = meet_ptr(tp->ptr());
6538     const TypeInterfaces* interfaces = meet_interfaces(tp);
6539     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6540     const TypeInterfaces* this_interfaces = _interfaces;
6541 
6542     switch (ptr) {
6543     case TopPTR:
6544     case AnyNull:                // Fall 'down' to dual of object klass
6545       // For instances when a subclass meets a superclass we fall
6546       // below the centerline when the superclass is exact. We need to
6547       // do the same here.
6548       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6549           !tp->klass_is_exact()) {
6550         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6551       } else {
6552         // cannot subclass, so the meet has to fall badly below the centerline
6553         ptr = NotNull;
6554         interfaces = this_interfaces->intersection_with(tp->_interfaces);
6555         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6556       }
6557     case Constant:
6558     case NotNull:
6559     case BotPTR:                // Fall down to object klass
6560       // LCA is object_klass, but if we subclass from the top we can do better
6561       if (above_centerline(tp->ptr())) {
6562         // If 'tp'  is above the centerline and it is Object class
6563         // then we can subclass in the Java class hierarchy.
6564         // For instances when a subclass meets a superclass we fall
6565         // below the centerline when the superclass is exact. We need
6566         // to do the same here.
6567         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6568             !tp->klass_is_exact()) {
6569           // that is, my array type is a subtype of 'tp' klass
6570           return make(ptr, _elem, _klass, offset);
6571         }
6572       }
6573       // The other case cannot happen, since t cannot be a subtype of an array.
6574       // The meet falls down to Object class below centerline.
6575       if (ptr == Constant)
6576          ptr = NotNull;
6577       interfaces = this_interfaces->intersection_with(tp_interfaces);
6578       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6579     default: typerr(t);
6580     }
6581   }
6582 
6583   } // End of switch
6584   return this;                  // Return the double constant
6585 }
6586 
6587 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) {
6588   static_assert(std::is_base_of<T2, T1>::value, "");
6589 
6590   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6591     return true;
6592   }
6593 
6594   int dummy;
6595   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6596 
6597   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6598     return false;
6599   }
6600 
6601   if (this_one->is_instance_type(other)) {
6602     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6603            other_exact;
6604   }
6605 
6606   assert(this_one->is_array_type(other), "");
6607   const T1* other_ary = this_one->is_array_type(other);
6608   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6609   if (other_top_or_bottom) {
6610     return false;
6611   }
6612 
6613   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6614   const TypePtr* this_elem = this_one->elem()->make_ptr();
6615   if (this_elem != nullptr && other_elem != nullptr) {



6616     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6617   }
6618   if (this_elem == nullptr && other_elem == nullptr) {
6619     return this_one->klass()->is_subtype_of(other->klass());
6620   }
6621   return false;
6622 }
6623 
6624 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6625   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6626 }
6627 
6628 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6629   static_assert(std::is_base_of<T2, T1>::value, "");
6630 
6631   int dummy;
6632   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6633 
6634   if (!this_one->is_array_type(other) ||
6635       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

6688   }
6689 
6690   const TypePtr* this_elem = this_one->elem()->make_ptr();
6691   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6692   if (other_elem != nullptr && this_elem != nullptr) {
6693     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6694   }
6695   if (other_elem == nullptr && this_elem == nullptr) {
6696     return this_one->klass()->is_subtype_of(other->klass());
6697   }
6698   return false;
6699 }
6700 
6701 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6702   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6703 }
6704 
6705 //------------------------------xdual------------------------------------------
6706 // Dual: compute field-by-field dual
6707 const Type    *TypeAryKlassPtr::xdual() const {
6708   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6709 }
6710 
6711 // Is there a single ciKlass* that can represent that type?
6712 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6713   if (elem()->isa_klassptr()) {
6714     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6715     if (k == nullptr) {
6716       return nullptr;
6717     }
6718     k = ciObjArrayKlass::make(k);
6719     return k;
6720   }
6721 
6722   return klass();
6723 }
6724 
6725 ciKlass* TypeAryKlassPtr::klass() const {
6726   if (_klass != nullptr) {
6727     return _klass;
6728   }
6729   ciKlass* k = nullptr;
6730   if (elem()->isa_klassptr()) {
6731     // leave null
6732   } else if ((elem()->base() == Type::Top) ||
6733              (elem()->base() == Type::Bottom)) {
6734   } else {
6735     k = ciTypeArrayKlass::make(elem()->basic_type());
6736     ((TypeAryKlassPtr*)this)->_klass = k;
6737   }
6738   return k;

6745   switch( _ptr ) {
6746   case Constant:
6747     st->print("precise ");
6748   case NotNull:
6749     {
6750       st->print("[");
6751       _elem->dump2(d, depth, st);
6752       _interfaces->dump(st);
6753       st->print(": ");
6754     }
6755   case BotPTR:
6756     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6757   case TopPTR:
6758   case AnyNull:
6759     st->print(":%s", ptr_msg[_ptr]);
6760     if( _ptr == Constant ) st->print(":exact");
6761     break;
6762   default:
6763     break;
6764   }
6765 
6766   if( _offset ) {               // Dump offset, if any
6767     if( _offset == OffsetBot )      { st->print("+any"); }
6768     else if( _offset == OffsetTop ) { st->print("+unknown"); }
6769     else                            { st->print("+%d", _offset); }
6770   }
6771 


6772   st->print(" *");
6773 }
6774 #endif
6775 
6776 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6777   const Type* elem = this->elem();
6778   dims = 1;
6779   while (elem->isa_aryklassptr()) {
6780     elem = elem->is_aryklassptr()->elem();
6781     dims++;
6782   }
6783   return elem;
6784 }
6785 
6786 //=============================================================================
6787 // Convenience common pre-built types.
6788 
6789 //------------------------------make-------------------------------------------
6790 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6791   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();












6792 }
6793 
6794 //------------------------------make-------------------------------------------
6795 const TypeFunc *TypeFunc::make(ciMethod* method) {
6796   Compile* C = Compile::current();
6797   const TypeFunc* tf = C->last_tf(method); // check cache
6798   if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
6799   const TypeTuple *domain;
6800   if (method->is_static()) {
6801     domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6802   } else {
6803     domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);

















6804   }
6805   const TypeTuple *range  = TypeTuple::make_range(method->signature(), ignore_interfaces);
6806   tf = TypeFunc::make(domain, range);
6807   C->set_last_tf(method, tf);  // fill cache
6808   return tf;
6809 }
6810 
6811 //------------------------------meet-------------------------------------------
6812 // Compute the MEET of two types.  It returns a new Type object.
6813 const Type *TypeFunc::xmeet( const Type *t ) const {
6814   // Perform a fast test for common case; meeting the same types together.
6815   if( this == t ) return this;  // Meeting same type-rep?
6816 
6817   // Current "this->_base" is Func
6818   switch (t->base()) {          // switch on original type
6819 
6820   case Bottom:                  // Ye Olde Default
6821     return t;
6822 
6823   default:                      // All else is a mistake
6824     typerr(t);
6825 
6826   case Top:
6827     break;
6828   }
6829   return this;                  // Return the double constant
6830 }
6831 
6832 //------------------------------xdual------------------------------------------
6833 // Dual: compute field-by-field dual
6834 const Type *TypeFunc::xdual() const {
6835   return this;
6836 }
6837 
6838 //------------------------------eq---------------------------------------------
6839 // Structural equality check for Type representations
6840 bool TypeFunc::eq( const Type *t ) const {
6841   const TypeFunc *a = (const TypeFunc*)t;
6842   return _domain == a->_domain &&
6843     _range == a->_range;


6844 }
6845 
6846 //------------------------------hash-------------------------------------------
6847 // Type-specific hashing function.
6848 uint TypeFunc::hash(void) const {
6849   return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6850 }
6851 
6852 //------------------------------dump2------------------------------------------
6853 // Dump Function Type
6854 #ifndef PRODUCT
6855 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6856   if( _range->cnt() <= Parms )
6857     st->print("void");
6858   else {
6859     uint i;
6860     for (i = Parms; i < _range->cnt()-1; i++) {
6861       _range->field_at(i)->dump2(d,depth,st);
6862       st->print("/");
6863     }
6864     _range->field_at(i)->dump2(d,depth,st);
6865   }
6866   st->print(" ");
6867   st->print("( ");
6868   if( !depth || d[this] ) {     // Check for recursive dump
6869     st->print("...)");
6870     return;
6871   }
6872   d.Insert((void*)this,(void*)this);    // Stop recursion
6873   if (Parms < _domain->cnt())
6874     _domain->field_at(Parms)->dump2(d,depth-1,st);
6875   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6876     st->print(", ");
6877     _domain->field_at(i)->dump2(d,depth-1,st);
6878   }
6879   st->print(" )");
6880 }
6881 #endif
6882 
6883 //------------------------------singleton--------------------------------------
6884 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6885 // constants (Ldi nodes).  Singletons are integer, float or double constants
6886 // or a single symbol.
6887 bool TypeFunc::singleton(void) const {
6888   return false;                 // Never a singleton
6889 }
6890 
6891 bool TypeFunc::empty(void) const {
6892   return false;                 // Never empty
6893 }
6894 
6895 
6896 BasicType TypeFunc::return_type() const{
6897   if (range()->cnt() == TypeFunc::Parms) {
6898     return T_VOID;
6899   }
6900   return range()->field_at(TypeFunc::Parms)->basic_type();
6901 }

   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "ci/ciFlatArrayKlass.hpp"
  26 #include "ci/ciField.hpp"
  27 #include "ci/ciInlineKlass.hpp"
  28 #include "ci/ciMethodData.hpp"
  29 #include "ci/ciTypeFlow.hpp"
  30 #include "classfile/javaClasses.hpp"
  31 #include "classfile/symbolTable.hpp"
  32 #include "classfile/vmSymbols.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/callnode.hpp"
  42 #include "opto/arraycopynode.hpp"
  43 #include "opto/matcher.hpp"
  44 #include "opto/node.hpp"
  45 #include "opto/opcodes.hpp"
  46 #include "opto/runtime.hpp"
  47 #include "opto/type.hpp"
  48 #include "utilities/checkedCast.hpp"
  49 #include "utilities/powerOfTwo.hpp"
  50 #include "utilities/stringUtils.hpp"
  51 #include "runtime/stubRoutines.hpp"
  52 
  53 // Portions of code courtesy of Clifford Click
  54 
  55 // Optimization - Graph Style
  56 
  57 // Dictionary of types shared among compilations.
  58 Dict* Type::_shared_type_dict = nullptr;
  59 const Type::Offset Type::Offset::top(Type::OffsetTop);
  60 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
  61 
  62 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
  63   // Either is 'TOP' offset?  Return the other offset!
  64   if (_offset == OffsetTop) return other;
  65   if (other._offset == OffsetTop) return *this;
  66   // If either is different, return 'BOTTOM' offset
  67   if (_offset != other._offset) return bottom;
  68   return Offset(_offset);
  69 }
  70 
  71 const Type::Offset Type::Offset::dual() const {
  72   if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
  73   if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
  74   return Offset(_offset);               // Map everything else into self
  75 }
  76 
  77 const Type::Offset Type::Offset::add(intptr_t offset) const {
  78   // Adding to 'TOP' offset?  Return 'TOP'!
  79   if (_offset == OffsetTop || offset == OffsetTop) return top;
  80   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  81   if (_offset == OffsetBot || offset == OffsetBot) return bottom;
  82   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  83   offset += (intptr_t)_offset;
  84   if (offset != (int)offset || offset == OffsetTop) return bottom;
  85 
  86   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  87   // It is possible to construct a negative offset during PhaseCCP
  88 
  89   return Offset((int)offset);        // Sum valid offsets
  90 }
  91 
  92 void Type::Offset::dump2(outputStream *st) const {
  93   if (_offset == 0) {
  94     return;
  95   } else if (_offset == OffsetTop) {
  96     st->print("+top");
  97   }
  98   else if (_offset == OffsetBot) {
  99     st->print("+bot");
 100   } else if (_offset) {
 101     st->print("+%d", _offset);
 102   }
 103 }
 104 
 105 // Array which maps compiler types to Basic Types
 106 const Type::TypeInfo Type::_type_info[Type::lastype] = {
 107   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
 108   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
 109   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
 110   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
 111   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
 112   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
 113   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
 114   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
 115   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
 116   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
 117   { Bad,             T_ARRAY,      "interfaces:",   false, Node::NotAMachineReg, relocInfo::none          },  // Interfaces
 118 
 119 #if defined(PPC64)
 120   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 121   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 122   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 123   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD

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

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

1002   ~VerifyMeet() {
1003     assert(_C->_type_verify->_depth != 0, "");
1004     _C->_type_verify->_depth--;
1005     if (_C->_type_verify->_depth == 0) {
1006       _C->_type_verify->_cache.trunc_to(0);
1007     }
1008   }
1009 
1010   const Type* meet(const Type* t1, const Type* t2) const {
1011     return _C->_type_verify->meet(t1, t2);
1012   }
1013 
1014   void add(const Type* t1, const Type* t2, const Type* res) const {
1015     _C->_type_verify->add(t1, t2, res);
1016   }
1017 };
1018 
1019 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
1020   Compile* C = Compile::current();
1021   const Type* mt2 = verify.meet(t, this);
1022 
1023   // Verify that:
1024   //      this meet t == t meet this
1025   if (mt != mt2) {
1026     tty->print_cr("=== Meet Not Commutative ===");
1027     tty->print("t           = ");   t->dump(); tty->cr();
1028     tty->print("this        = ");      dump(); tty->cr();
1029     tty->print("t meet this = "); mt2->dump(); tty->cr();
1030     tty->print("this meet t = ");  mt->dump(); tty->cr();
1031     fatal("meet not commutative");
1032   }
1033   const Type* dual_join = mt->_dual;
1034   const Type* t2t    = verify.meet(dual_join,t->_dual);
1035   const Type* t2this = verify.meet(dual_join,this->_dual);
1036 
1037   // Interface meet Oop is Not Symmetric:
1038   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
1039   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
1040 
1041   // Verify that:
1042   // 1)     mt_dual meet t_dual    == t_dual
1043   //    which corresponds to
1044   //       !(t meet this)  meet !t ==
1045   //       (!t join !this) meet !t == !t
1046   // 2)    mt_dual meet this_dual     == this_dual
1047   //    which corresponds to
1048   //       !(t meet this)  meet !this ==
1049   //       (!t join !this) meet !this == !this
1050   if (t2t != t->_dual || t2this != this->_dual) {
1051     tty->print_cr("=== Meet Not Symmetric ===");
1052     tty->print("t   =                   ");              t->dump(); tty->cr();
1053     tty->print("this=                   ");                 dump(); tty->cr();
1054     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
1055 
1056     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
1057     tty->print("this_dual=              ");          _dual->dump(); tty->cr();
1058     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
1059 
1060     // 1)
1061     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
1062     // 2)
1063     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
1064 
1065     fatal("meet not symmetric");
1066   }
1067 }
1068 #endif
1069 
1070 //------------------------------meet-------------------------------------------
1071 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
1072 // commutative and the lattice is symmetric.
1073 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1074   if (isa_narrowoop() && t->isa_narrowoop()) {
1075     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1076     return result->make_narrowoop();
1077   }
1078   if (isa_narrowklass() && t->isa_narrowklass()) {
1079     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1080     return result->make_narrowklass();
1081   }
1082 

2363 
2364 bool TypeLong::empty(void) const {
2365   return _lo > _hi;
2366 }
2367 
2368 //=============================================================================
2369 // Convenience common pre-built types.
2370 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2371 const TypeTuple *TypeTuple::IFFALSE;
2372 const TypeTuple *TypeTuple::IFTRUE;
2373 const TypeTuple *TypeTuple::IFNEITHER;
2374 const TypeTuple *TypeTuple::LOOPBODY;
2375 const TypeTuple *TypeTuple::MEMBAR;
2376 const TypeTuple *TypeTuple::STORECONDITIONAL;
2377 const TypeTuple *TypeTuple::START_I2C;
2378 const TypeTuple *TypeTuple::INT_PAIR;
2379 const TypeTuple *TypeTuple::LONG_PAIR;
2380 const TypeTuple *TypeTuple::INT_CC_PAIR;
2381 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2382 
2383 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2384   for (int i = 0; i < vk->nof_declared_nonstatic_fields(); i++) {
2385     ciField* field = vk->declared_nonstatic_field_at(i);
2386     if (field->is_flat()) {
2387       collect_inline_fields(field->type()->as_inline_klass(), field_array, pos);
2388       if (!field->is_null_free()) {
2389         // Use T_INT instead of T_BOOLEAN here because the upper bits can contain garbage if the holder
2390         // is null and C2 will only zero them for T_INT assuming that T_BOOLEAN is already canonicalized.
2391         field_array[pos++] = Type::get_const_basic_type(T_INT);
2392       }
2393     } else {
2394       BasicType bt = field->type()->basic_type();
2395       const Type* ft = Type::get_const_type(field->type());
2396       field_array[pos++] = ft;
2397       if (type2size[bt] == 2) {
2398         field_array[pos++] = Type::HALF;
2399       }
2400     }
2401   }
2402 }
2403 
2404 //------------------------------make-------------------------------------------
2405 // Make a TypeTuple from the range of a method signature
2406 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields) {
2407   ciType* return_type = sig->return_type();
2408   uint arg_cnt = return_type->size();
2409   if (ret_vt_fields) {
2410     arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2411     // InlineTypeNode::IsInit field used for null checking
2412     arg_cnt++;
2413   }
2414   const Type **field_array = fields(arg_cnt);
2415   switch (return_type->basic_type()) {
2416   case T_LONG:
2417     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2418     field_array[TypeFunc::Parms+1] = Type::HALF;
2419     break;
2420   case T_DOUBLE:
2421     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2422     field_array[TypeFunc::Parms+1] = Type::HALF;
2423     break;
2424   case T_OBJECT:
2425     if (return_type->is_inlinetype() && ret_vt_fields) {
2426       uint pos = TypeFunc::Parms;
2427       field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2428       collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2429       // InlineTypeNode::IsInit field used for null checking
2430       field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2431       assert(pos == (TypeFunc::Parms + arg_cnt), "out of bounds");
2432       break;
2433     } else {
2434       field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(TypePtr::BOTTOM);
2435     }
2436     break;
2437   case T_ARRAY:
2438   case T_BOOLEAN:
2439   case T_CHAR:
2440   case T_FLOAT:
2441   case T_BYTE:
2442   case T_SHORT:
2443   case T_INT:
2444     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2445     break;
2446   case T_VOID:
2447     break;
2448   default:
2449     ShouldNotReachHere();
2450   }
2451   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2452 }
2453 
2454 // Make a TypeTuple from the domain of a method signature
2455 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2456   ciSignature* sig = method->signature();
2457   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2458   if (vt_fields_as_args) {
2459     arg_cnt = 0;
2460     assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2461     for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2462       arg_cnt += type2size[(*sig_cc)._bt];
2463     }
2464   }
2465 
2466   uint pos = TypeFunc::Parms;
2467   const Type** field_array = fields(arg_cnt);
2468   if (!method->is_static()) {
2469     ciInstanceKlass* recv = method->holder();
2470     if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields() && method->is_scalarized_arg(0)) {
2471       collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2472     } else {
2473       field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2474     }
2475   }
2476 
2477   int i = 0;
2478   while (pos < TypeFunc::Parms + arg_cnt) {
2479     ciType* type = sig->type_at(i);
2480     BasicType bt = type->basic_type();
2481 
2482     switch (bt) {
2483     case T_LONG:
2484       field_array[pos++] = TypeLong::LONG;
2485       field_array[pos++] = Type::HALF;
2486       break;
2487     case T_DOUBLE:
2488       field_array[pos++] = Type::DOUBLE;
2489       field_array[pos++] = Type::HALF;
2490       break;
2491     case T_OBJECT:
2492       if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2493         // InlineTypeNode::IsInit field used for null checking
2494         field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2495         collect_inline_fields(type->as_inline_klass(), field_array, pos);
2496       } else {
2497         field_array[pos++] = get_const_type(type, interface_handling);
2498       }
2499       break;
2500     case T_ARRAY:
2501     case T_FLOAT:
2502     case T_INT:
2503       field_array[pos++] = get_const_type(type, interface_handling);
2504       break;
2505     case T_BOOLEAN:
2506     case T_CHAR:
2507     case T_BYTE:
2508     case T_SHORT:
2509       field_array[pos++] = TypeInt::INT;
2510       break;
2511     default:
2512       ShouldNotReachHere();
2513     }
2514     i++;
2515   }
2516   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2517 
2518   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2519 }
2520 
2521 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2522   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2523 }
2524 
2525 //------------------------------fields-----------------------------------------
2526 // Subroutine call type with space allocated for argument types
2527 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2528 const Type **TypeTuple::fields( uint arg_cnt ) {
2529   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2530   flds[TypeFunc::Control  ] = Type::CONTROL;
2531   flds[TypeFunc::I_O      ] = Type::ABIO;
2532   flds[TypeFunc::Memory   ] = Type::MEMORY;
2533   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2534   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2535 
2536   return flds;

2631     if (_fields[i]->empty())  return true;
2632   }
2633   return false;
2634 }
2635 
2636 //=============================================================================
2637 // Convenience common pre-built types.
2638 
2639 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2640   // Certain normalizations keep us sane when comparing types.
2641   // We do not want arrayOop variables to differ only by the wideness
2642   // of their index types.  Pick minimum wideness, since that is the
2643   // forced wideness of small ranges anyway.
2644   if (size->_widen != Type::WidenMin)
2645     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2646   else
2647     return size;
2648 }
2649 
2650 //------------------------------make-------------------------------------------
2651 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2652                              bool flat, bool not_flat, bool not_null_free) {
2653   if (UseCompressedOops && elem->isa_oopptr()) {
2654     elem = elem->make_narrowoop();
2655   }
2656   size = normalize_array_size(size);
2657   return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free))->hashcons();
2658 }
2659 
2660 //------------------------------meet-------------------------------------------
2661 // Compute the MEET of two types.  It returns a new Type object.
2662 const Type *TypeAry::xmeet( const Type *t ) const {
2663   // Perform a fast test for common case; meeting the same types together.
2664   if( this == t ) return this;  // Meeting same type-rep?
2665 
2666   // Current "this->_base" is Ary
2667   switch (t->base()) {          // switch on original type
2668 
2669   case Bottom:                  // Ye Olde Default
2670     return t;
2671 
2672   default:                      // All else is a mistake
2673     typerr(t);
2674 
2675   case Array: {                 // Meeting 2 arrays?
2676     const TypeAry *a = t->is_ary();
2677     return TypeAry::make(_elem->meet_speculative(a->_elem),
2678                          _size->xmeet(a->_size)->is_int(),
2679                          _stable && a->_stable,
2680                          _flat && a->_flat,
2681                          _not_flat && a->_not_flat,
2682                          _not_null_free && a->_not_null_free);
2683   }
2684   case Top:
2685     break;
2686   }
2687   return this;                  // Return the double constant
2688 }
2689 
2690 //------------------------------xdual------------------------------------------
2691 // Dual: compute field-by-field dual
2692 const Type *TypeAry::xdual() const {
2693   const TypeInt* size_dual = _size->dual()->is_int();
2694   size_dual = normalize_array_size(size_dual);
2695   return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free);
2696 }
2697 
2698 //------------------------------eq---------------------------------------------
2699 // Structural equality check for Type representations
2700 bool TypeAry::eq( const Type *t ) const {
2701   const TypeAry *a = (const TypeAry*)t;
2702   return _elem == a->_elem &&
2703     _stable == a->_stable &&
2704     _size == a->_size &&
2705     _flat == a->_flat &&
2706     _not_flat == a->_not_flat &&
2707     _not_null_free == a->_not_null_free;
2708 
2709 }
2710 
2711 //------------------------------hash-------------------------------------------
2712 // Type-specific hashing function.
2713 uint TypeAry::hash(void) const {
2714   return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0) +
2715       (uint)(_flat ? 44 : 0) + (uint)(_not_flat ? 45 : 0) + (uint)(_not_null_free ? 46 : 0);
2716 }
2717 
2718 /**
2719  * Return same type without a speculative part in the element
2720  */
2721 const TypeAry* TypeAry::remove_speculative() const {
2722   return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free);
2723 }
2724 
2725 /**
2726  * Return same type with cleaned up speculative part of element
2727  */
2728 const Type* TypeAry::cleanup_speculative() const {
2729   return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free);
2730 }
2731 
2732 /**
2733  * Return same type but with a different inline depth (used for speculation)
2734  *
2735  * @param depth  depth to meet with
2736  */
2737 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2738   if (!UseInlineDepthForSpeculativeTypes) {
2739     return this;
2740   }
2741   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2742 }
2743 
2744 //------------------------------dump2------------------------------------------
2745 #ifndef PRODUCT
2746 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2747   if (_stable)  st->print("stable:");
2748   if (_flat) st->print("flat:");
2749   if (Verbose) {
2750     if (_not_flat) st->print("not flat:");
2751     if (_not_null_free) st->print("not null free:");
2752   }
2753   _elem->dump2(d, depth, st);
2754   st->print("[");
2755   _size->dump2(d, depth, st);
2756   st->print("]");
2757 }
2758 #endif
2759 
2760 //------------------------------singleton--------------------------------------
2761 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2762 // constants (Ldi nodes).  Singletons are integer, float or double constants
2763 // or a single symbol.
2764 bool TypeAry::singleton(void) const {
2765   return false;                 // Never a singleton
2766 }
2767 
2768 bool TypeAry::empty(void) const {
2769   return _elem->empty() || _size->empty();
2770 }
2771 
2772 //--------------------------ary_must_be_exact----------------------------------
2773 bool TypeAry::ary_must_be_exact() const {
2774   // This logic looks at the element type of an array, and returns true
2775   // if the element type is either a primitive or a final instance class.
2776   // In such cases, an array built on this ary must have no subclasses.
2777   if (_elem == BOTTOM)      return false;  // general array not exact
2778   if (_elem == TOP   )      return false;  // inverted general array not exact
2779   const TypeOopPtr*  toop = nullptr;
2780   if (UseCompressedOops && _elem->isa_narrowoop()) {
2781     toop = _elem->make_ptr()->isa_oopptr();
2782   } else {
2783     toop = _elem->isa_oopptr();
2784   }
2785   if (!toop)                return true;   // a primitive type, like int
2786   if (!toop->is_loaded())   return false;  // unloaded class
2787   const TypeInstPtr* tinst;
2788   if (_elem->isa_narrowoop())
2789     tinst = _elem->make_ptr()->isa_instptr();
2790   else
2791     tinst = _elem->isa_instptr();
2792   if (tinst) {
2793     if (tinst->instance_klass()->is_final()) {
2794       // Even though MyValue is final, [LMyValue is not exact because null-free [LMyValue is a subtype.
2795       if (tinst->is_inlinetypeptr() && (tinst->ptr() == TypePtr::BotPTR || tinst->ptr() == TypePtr::TopPTR)) {
2796         return false;
2797       }
2798       return true;
2799     }
2800     return false;
2801   }
2802   const TypeAryPtr*  tap;
2803   if (_elem->isa_narrowoop())
2804     tap = _elem->make_ptr()->isa_aryptr();
2805   else
2806     tap = _elem->isa_aryptr();
2807   if (tap)
2808     return tap->ary()->ary_must_be_exact();
2809   return false;
2810 }
2811 
2812 //==============================TypeVect=======================================
2813 // Convenience common pre-built types.
2814 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2815 const TypeVect* TypeVect::VECTS = nullptr; //  32-bit vectors
2816 const TypeVect* TypeVect::VECTD = nullptr; //  64-bit vectors
2817 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2818 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2819 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2820 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2821 

2956 
2957 //=============================================================================
2958 // Convenience common pre-built types.
2959 const TypePtr *TypePtr::NULL_PTR;
2960 const TypePtr *TypePtr::NOTNULL;
2961 const TypePtr *TypePtr::BOTTOM;
2962 
2963 //------------------------------meet-------------------------------------------
2964 // Meet over the PTR enum
2965 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2966   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2967   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2968   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2969   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2970   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2971   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2972   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2973 };
2974 
2975 //------------------------------make-------------------------------------------
2976 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2977   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2978 }
2979 
2980 //------------------------------cast_to_ptr_type-------------------------------
2981 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2982   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2983   if( ptr == _ptr ) return this;
2984   return make(_base, ptr, _offset, _speculative, _inline_depth);
2985 }
2986 
2987 //------------------------------get_con----------------------------------------
2988 intptr_t TypePtr::get_con() const {
2989   assert( _ptr == Null, "" );
2990   return offset();
2991 }
2992 
2993 //------------------------------meet-------------------------------------------
2994 // Compute the MEET of two types.  It returns a new Type object.
2995 const Type *TypePtr::xmeet(const Type *t) const {
2996   const Type* res = xmeet_helper(t);
2997   if (res->isa_ptr() == nullptr) {
2998     return res;
2999   }
3000 
3001   const TypePtr* res_ptr = res->is_ptr();
3002   if (res_ptr->speculative() != nullptr) {
3003     // type->speculative() is null means that speculation is no better
3004     // than type, i.e. type->speculative() == type. So there are 2
3005     // ways to represent the fact that we have no useful speculative
3006     // data and we should use a single one to be able to test for
3007     // equality between types. Check whether type->speculative() ==
3008     // type and set speculative to null if it is the case.
3009     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
3010       return res_ptr->remove_speculative();

3044     int depth = meet_inline_depth(tp->inline_depth());
3045     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
3046   }
3047   case RawPtr:                  // For these, flip the call around to cut down
3048   case OopPtr:
3049   case InstPtr:                 // on the cases I have to handle.
3050   case AryPtr:
3051   case MetadataPtr:
3052   case KlassPtr:
3053   case InstKlassPtr:
3054   case AryKlassPtr:
3055     return t->xmeet(this);      // Call in reverse direction
3056   default:                      // All else is a mistake
3057     typerr(t);
3058 
3059   }
3060   return this;
3061 }
3062 
3063 //------------------------------meet_offset------------------------------------
3064 Type::Offset TypePtr::meet_offset(int offset) const {
3065   return _offset.meet(Offset(offset));





3066 }
3067 
3068 //------------------------------dual_offset------------------------------------
3069 Type::Offset TypePtr::dual_offset() const {
3070   return _offset.dual();


3071 }
3072 
3073 //------------------------------xdual------------------------------------------
3074 // Dual: compute field-by-field dual
3075 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
3076   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
3077 };
3078 const Type *TypePtr::xdual() const {
3079   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
3080 }
3081 
3082 //------------------------------xadd_offset------------------------------------
3083 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
3084   return _offset.add(offset);











3085 }
3086 
3087 //------------------------------add_offset-------------------------------------
3088 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
3089   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
3090 }
3091 
3092 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
3093   return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
3094 }
3095 
3096 //------------------------------eq---------------------------------------------
3097 // Structural equality check for Type representations
3098 bool TypePtr::eq( const Type *t ) const {
3099   const TypePtr *a = (const TypePtr*)t;
3100   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
3101 }
3102 
3103 //------------------------------hash-------------------------------------------
3104 // Type-specific hashing function.
3105 uint TypePtr::hash(void) const {
3106   return (uint)_ptr + (uint)offset() + (uint)hash_speculative() + (uint)_inline_depth;
3107 }
3108 
3109 /**
3110  * Return same type without a speculative part
3111  */
3112 const TypePtr* TypePtr::remove_speculative() const {
3113   if (_speculative == nullptr) {
3114     return this;
3115   }
3116   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3117   return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
3118 }
3119 
3120 /**
3121  * Return same type but drop speculative part if we know we won't use
3122  * it
3123  */
3124 const Type* TypePtr::cleanup_speculative() const {
3125   if (speculative() == nullptr) {
3126     return this;

3352   }
3353   // We already know the speculative type is always null
3354   if (speculative_always_null()) {
3355     return false;
3356   }
3357   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3358     return false;
3359   }
3360   return true;
3361 }
3362 
3363 //------------------------------dump2------------------------------------------
3364 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3365   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3366 };
3367 
3368 #ifndef PRODUCT
3369 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3370   if( _ptr == Null ) st->print("null");
3371   else st->print("%s *", ptr_msg[_ptr]);
3372   _offset.dump2(st);


3373   dump_inline_depth(st);
3374   dump_speculative(st);
3375 }
3376 
3377 /**
3378  *dump the speculative part of the type
3379  */
3380 void TypePtr::dump_speculative(outputStream *st) const {
3381   if (_speculative != nullptr) {
3382     st->print(" (speculative=");
3383     _speculative->dump_on(st);
3384     st->print(")");
3385   }
3386 }
3387 
3388 /**
3389  *dump the inline depth of the type
3390  */
3391 void TypePtr::dump_inline_depth(outputStream *st) const {
3392   if (_inline_depth != InlineDepthBottom) {
3393     if (_inline_depth == InlineDepthTop) {
3394       st->print(" (inline_depth=InlineDepthTop)");
3395     } else {
3396       st->print(" (inline_depth=%d)", _inline_depth);
3397     }
3398   }
3399 }
3400 #endif
3401 
3402 //------------------------------singleton--------------------------------------
3403 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3404 // constants
3405 bool TypePtr::singleton(void) const {
3406   // TopPTR, Null, AnyNull, Constant are all singletons
3407   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3408 }
3409 
3410 bool TypePtr::empty(void) const {
3411   return (_offset == Offset::top) || above_centerline(_ptr);
3412 }
3413 
3414 //=============================================================================
3415 // Convenience common pre-built types.
3416 const TypeRawPtr *TypeRawPtr::BOTTOM;
3417 const TypeRawPtr *TypeRawPtr::NOTNULL;
3418 
3419 //------------------------------make-------------------------------------------
3420 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3421   assert( ptr != Constant, "what is the constant?" );
3422   assert( ptr != Null, "Use TypePtr for null" );
3423   return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3424 }
3425 
3426 const TypeRawPtr *TypeRawPtr::make(address bits) {
3427   assert(bits != nullptr, "Use TypePtr for null");
3428   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3429 }
3430 
3431 //------------------------------cast_to_ptr_type-------------------------------

3792 void TypeInterfaces::verify_is_loaded() const {
3793   for (int i = 0; i < _interfaces.length(); i++) {
3794     ciKlass* interface = _interfaces.at(i);
3795     assert(interface->is_loaded(), "Interface not loaded");
3796   }
3797 }
3798 #endif
3799 
3800 // Can't be implemented because there's no way to know if the type is above or below the center line.
3801 const Type* TypeInterfaces::xmeet(const Type* t) const {
3802   ShouldNotReachHere();
3803   return Type::xmeet(t);
3804 }
3805 
3806 bool TypeInterfaces::singleton(void) const {
3807   ShouldNotReachHere();
3808   return Type::singleton();
3809 }
3810 
3811 //------------------------------TypeOopPtr-------------------------------------
3812 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3813                        int instance_id, const TypePtr* speculative, int inline_depth)
3814   : TypePtr(t, ptr, offset, speculative, inline_depth),
3815     _const_oop(o), _klass(k),
3816     _interfaces(interfaces),
3817     _klass_is_exact(xk),
3818     _is_ptr_to_narrowoop(false),
3819     _is_ptr_to_narrowklass(false),
3820     _is_ptr_to_boxed_value(false),
3821     _instance_id(instance_id) {
3822 #ifdef ASSERT
3823   if (klass() != nullptr && klass()->is_loaded()) {
3824     interfaces->verify_is_loaded();
3825   }
3826 #endif
3827   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3828       (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3829     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3830   }
3831 #ifdef _LP64
3832   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3833     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3834       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3835     } else if (klass() == nullptr) {
3836       // Array with unknown body type
3837       assert(this->isa_aryptr(), "only arrays without klass");
3838       _is_ptr_to_narrowoop = UseCompressedOops;
3839     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3840       if (klass()->is_obj_array_klass()) {
3841         _is_ptr_to_narrowoop = true;
3842       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3843         // Check if the field of the inline type array element contains oops
3844         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3845         int foffset = field_offset.get() + vk->payload_offset();
3846         ciField* field = vk->get_field_by_offset(foffset, false);
3847         assert(field != nullptr, "missing field");
3848         BasicType bt = field->layout_type();
3849         _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(bt);
3850       }
3851     } else if (klass()->is_instance_klass()) {

3852       if (this->isa_klassptr()) {
3853         // Perm objects don't use compressed references
3854       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3855         // unsafe access
3856         _is_ptr_to_narrowoop = UseCompressedOops;
3857       } else {
3858         assert(this->isa_instptr(), "must be an instance ptr.");

3859         if (klass() == ciEnv::current()->Class_klass() &&
3860             (this->offset() == java_lang_Class::klass_offset() ||
3861              this->offset() == java_lang_Class::array_klass_offset())) {
3862           // Special hidden fields from the Class.
3863           assert(this->isa_instptr(), "must be an instance ptr.");
3864           _is_ptr_to_narrowoop = false;
3865         } else if (klass() == ciEnv::current()->Class_klass() &&
3866                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3867           // Static fields
3868           ciField* field = nullptr;
3869           if (const_oop() != nullptr) {
3870             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3871             field = k->get_field_by_offset(this->offset(), true);
3872           }
3873           if (field != nullptr) {
3874             BasicType basic_elem_type = field->layout_type();
3875             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3876           } else {
3877             // unsafe access
3878             _is_ptr_to_narrowoop = UseCompressedOops;
3879           }
3880         } else {
3881           // Instance fields which contains a compressed oop references.
3882           ciInstanceKlass* ik = klass()->as_instance_klass();
3883           ciField* field = ik->get_field_by_offset(this->offset(), false);
3884           if (field != nullptr) {
3885             BasicType basic_elem_type = field->layout_type();
3886             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3887           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3888             // Compile::find_alias_type() cast exactness on all types to verify
3889             // that it does not affect alias type.
3890             _is_ptr_to_narrowoop = UseCompressedOops;
3891           } else {
3892             // Type for the copy start in LibraryCallKit::inline_native_clone().
3893             _is_ptr_to_narrowoop = UseCompressedOops;
3894           }
3895         }
3896       }
3897     }
3898   }
3899 #endif
3900 }
3901 
3902 //------------------------------make-------------------------------------------
3903 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3904                                    const TypePtr* speculative, int inline_depth) {
3905   assert(ptr != Constant, "no constant generic pointers");
3906   ciKlass*  k = Compile::current()->env()->Object_klass();
3907   bool      xk = false;
3908   ciObject* o = nullptr;
3909   const TypeInterfaces* interfaces = TypeInterfaces::make();
3910   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3911 }
3912 
3913 
3914 //------------------------------cast_to_ptr_type-------------------------------
3915 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3916   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3917   if( ptr == _ptr ) return this;
3918   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3919 }
3920 
3921 //-----------------------------cast_to_instance_id----------------------------
3922 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3923   // There are no instances of a general oop.
3924   // Return self unchanged.
3925   return this;
3926 }
3927 
3928 //-----------------------------cast_to_exactness-------------------------------
3929 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3930   // There is no such thing as an exact general oop.
3931   // Return self unchanged.
3932   return this;
3933 }
3934 

3935 //------------------------------as_klass_type----------------------------------
3936 // Return the klass type corresponding to this instance or array type.
3937 // It is the type that is loaded from an object of this type.
3938 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3939   ShouldNotReachHere();
3940   return nullptr;
3941 }
3942 
3943 //------------------------------meet-------------------------------------------
3944 // Compute the MEET of two types.  It returns a new Type object.
3945 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3946   // Perform a fast test for common case; meeting the same types together.
3947   if( this == t ) return this;  // Meeting same type-rep?
3948 
3949   // Current "this->_base" is OopPtr
3950   switch (t->base()) {          // switch on original type
3951 
3952   case Int:                     // Mixing ints & oops happens when javac
3953   case Long:                    // reuses local variables
3954   case HalfFloatTop:

3963   case NarrowOop:
3964   case NarrowKlass:
3965   case Bottom:                  // Ye Olde Default
3966     return Type::BOTTOM;
3967   case Top:
3968     return this;
3969 
3970   default:                      // All else is a mistake
3971     typerr(t);
3972 
3973   case RawPtr:
3974   case MetadataPtr:
3975   case KlassPtr:
3976   case InstKlassPtr:
3977   case AryKlassPtr:
3978     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3979 
3980   case AnyPtr: {
3981     // Found an AnyPtr type vs self-OopPtr type
3982     const TypePtr *tp = t->is_ptr();
3983     Offset offset = meet_offset(tp->offset());
3984     PTR ptr = meet_ptr(tp->ptr());
3985     const TypePtr* speculative = xmeet_speculative(tp);
3986     int depth = meet_inline_depth(tp->inline_depth());
3987     switch (tp->ptr()) {
3988     case Null:
3989       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3990       // else fall through:
3991     case TopPTR:
3992     case AnyNull: {
3993       int instance_id = meet_instance_id(InstanceTop);
3994       return make(ptr, offset, instance_id, speculative, depth);
3995     }
3996     case BotPTR:
3997     case NotNull:
3998       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3999     default: typerr(t);
4000     }
4001   }
4002 
4003   case OopPtr: {                 // Meeting to other OopPtrs

4005     int instance_id = meet_instance_id(tp->instance_id());
4006     const TypePtr* speculative = xmeet_speculative(tp);
4007     int depth = meet_inline_depth(tp->inline_depth());
4008     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
4009   }
4010 
4011   case InstPtr:                  // For these, flip the call around to cut down
4012   case AryPtr:
4013     return t->xmeet(this);      // Call in reverse direction
4014 
4015   } // End of switch
4016   return this;                  // Return the double constant
4017 }
4018 
4019 
4020 //------------------------------xdual------------------------------------------
4021 // Dual of a pure heap pointer.  No relevant klass or oop information.
4022 const Type *TypeOopPtr::xdual() const {
4023   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
4024   assert(const_oop() == nullptr,             "no constants here");
4025   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());
4026 }
4027 
4028 //--------------------------make_from_klass_common-----------------------------
4029 // Computes the element-type given a klass.
4030 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
4031   if (klass->is_instance_klass() || klass->is_inlinetype()) {
4032     Compile* C = Compile::current();
4033     Dependencies* deps = C->dependencies();
4034     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
4035     // Element is an instance
4036     bool klass_is_exact = false;
4037     if (klass->is_loaded()) {
4038       // Try to set klass_is_exact.
4039       ciInstanceKlass* ik = klass->as_instance_klass();
4040       klass_is_exact = ik->is_final();
4041       if (!klass_is_exact && klass_change
4042           && deps != nullptr && UseUniqueSubclasses) {
4043         ciInstanceKlass* sub = ik->unique_concrete_subklass();
4044         if (sub != nullptr) {
4045           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
4046           klass = ik = sub;
4047           klass_is_exact = sub->is_final();
4048         }
4049       }
4050       if (!klass_is_exact && try_for_exact && deps != nullptr &&
4051           !ik->is_interface() && !ik->has_subklass()) {
4052         // Add a dependence; if concrete subclass added we need to recompile
4053         deps->assert_leaf_type(ik);
4054         klass_is_exact = true;
4055       }
4056     }
4057     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
4058     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0));
4059   } else if (klass->is_obj_array_klass()) {
4060     // Element is an object or inline type array. Recursively call ourself.
4061     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
4062     // Determine null-free/flat properties
4063     const TypeOopPtr* exact_etype = etype;
4064     if (etype->can_be_inline_type()) {
4065       // Use exact type if element can be an inline type
4066       exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
4067     }
4068     bool not_null_free = !exact_etype->can_be_inline_type();
4069     bool not_flat = !UseArrayFlattening || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flat_in_array());
4070     // Even though MyValue is final, [LMyValue is not exact because null-free [LMyValue is a subtype.
4071     bool xk = etype->klass_is_exact() && !etype->is_inlinetypeptr();
4072     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ false, not_flat, not_null_free);
4073     // We used to pass NotNull in here, asserting that the sub-arrays
4074     // are all not-null.  This is not true in generally, as code can
4075     // slam nullptrs down in the subarrays.
4076     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
4077     return arr;
4078   } else if (klass->is_type_array_klass()) {
4079     // Element is an typeArray
4080     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
4081     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
4082                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
4083     // We used to pass NotNull in here, asserting that the array pointer
4084     // is not-null. That was not true in general.
4085     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
4086     return arr;
4087   } else if (klass->is_flat_array_klass()) {
4088     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4089     etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4090     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, /* flat= */ true);
4091     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
4092     return arr;
4093   } else {
4094     ShouldNotReachHere();
4095     return nullptr;
4096   }
4097 }
4098 
4099 //------------------------------make_from_constant-----------------------------
4100 // Make a java pointer from an oop constant
4101 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
4102   assert(!o->is_null_object(), "null object not yet handled here.");
4103 
4104   const bool make_constant = require_constant || o->should_be_constant();
4105 
4106   ciKlass* klass = o->klass();
4107   if (klass->is_instance_klass() || klass->is_inlinetype()) {
4108     // Element is an instance or inline type
4109     if (make_constant) {
4110       return TypeInstPtr::make(o);
4111     } else {
4112       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
4113     }
4114   } else if (klass->is_obj_array_klass()) {
4115     // Element is an object array. Recursively call ourself.
4116     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4117     bool is_flat = o->as_obj_array()->is_flat();
4118     bool is_null_free = o->as_obj_array()->is_null_free();
4119     if (is_null_free) {
4120       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4121     }
4122     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
4123                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free);
4124     // We used to pass NotNull in here, asserting that the sub-arrays
4125     // are all not-null.  This is not true in generally, as code can
4126     // slam nulls down in the subarrays.
4127     if (make_constant) {
4128       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4129     } else {
4130       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4131     }
4132   } else if (klass->is_type_array_klass()) {
4133     // Element is an typeArray
4134     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
4135     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()),
4136                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true);
4137     // We used to pass NotNull in here, asserting that the array pointer
4138     // is not-null. That was not true in general.
4139     if (make_constant) {
4140       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4141     } else {
4142       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4143     }
4144   } else if (klass->is_flat_array_klass()) {
4145     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4146     etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4147     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ true);
4148     // We used to pass NotNull in here, asserting that the sub-arrays
4149     // are all not-null.  This is not true in generally, as code can
4150     // slam nullptrs down in the subarrays.
4151     if (make_constant) {
4152       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4153     } else {
4154       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4155     }
4156   }
4157 
4158   fatal("unhandled object type");
4159   return nullptr;
4160 }
4161 
4162 //------------------------------get_con----------------------------------------
4163 intptr_t TypeOopPtr::get_con() const {
4164   assert( _ptr == Null || _ptr == Constant, "" );
4165   assert(offset() >= 0, "");
4166 
4167   if (offset() != 0) {
4168     // After being ported to the compiler interface, the compiler no longer
4169     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4170     // to a handle at compile time.  This handle is embedded in the generated
4171     // code and dereferenced at the time the nmethod is made.  Until that time,
4172     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4173     // have access to the addresses!).  This does not seem to currently happen,
4174     // but this assertion here is to help prevent its occurrence.
4175     tty->print_cr("Found oop constant with non-zero offset");
4176     ShouldNotReachHere();
4177   }
4178 
4179   return (intptr_t)const_oop()->constant_encoding();
4180 }
4181 
4182 
4183 //-----------------------------filter------------------------------------------
4184 // Do not allow interface-vs.-noninterface joins to collapse to top.
4185 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4186 
4187   const Type* ft = join_helper(kills, include_speculative);

4206   } else {
4207     return one->equals(two) && TypePtr::eq(t);
4208   }
4209 }
4210 
4211 //------------------------------hash-------------------------------------------
4212 // Type-specific hashing function.
4213 uint TypeOopPtr::hash(void) const {
4214   return
4215     (uint)(const_oop() ? const_oop()->hash() : 0) +
4216     (uint)_klass_is_exact +
4217     (uint)_instance_id + TypePtr::hash();
4218 }
4219 
4220 //------------------------------dump2------------------------------------------
4221 #ifndef PRODUCT
4222 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4223   st->print("oopptr:%s", ptr_msg[_ptr]);
4224   if( _klass_is_exact ) st->print(":exact");
4225   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4226   _offset.dump2(st);





4227   if (_instance_id == InstanceTop)
4228     st->print(",iid=top");
4229   else if (_instance_id != InstanceBot)
4230     st->print(",iid=%d",_instance_id);
4231 
4232   dump_inline_depth(st);
4233   dump_speculative(st);
4234 }
4235 #endif
4236 
4237 //------------------------------singleton--------------------------------------
4238 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4239 // constants
4240 bool TypeOopPtr::singleton(void) const {
4241   // detune optimizer to not generate constant oop + constant offset as a constant!
4242   // TopPTR, Null, AnyNull, Constant are all singletons
4243   return (offset() == 0) && !below_centerline(_ptr);
4244 }
4245 
4246 //------------------------------add_offset-------------------------------------
4247 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4248   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4249 }
4250 
4251 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4252   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4253 }
4254 
4255 /**
4256  * Return same type without a speculative part
4257  */
4258 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4259   if (_speculative == nullptr) {
4260     return this;
4261   }
4262   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4263   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4264 }
4265 
4266 /**
4267  * Return same type but drop speculative part if we know we won't use
4268  * it
4269  */
4270 const Type* TypeOopPtr::cleanup_speculative() const {
4271   // If the klass is exact and the ptr is not null then there's
4272   // nothing that the speculative type can help us with

4345 const TypeInstPtr *TypeInstPtr::BOTTOM;
4346 const TypeInstPtr *TypeInstPtr::MIRROR;
4347 const TypeInstPtr *TypeInstPtr::MARK;
4348 const TypeInstPtr *TypeInstPtr::KLASS;
4349 
4350 // Is there a single ciKlass* that can represent that type?
4351 ciKlass* TypeInstPtr::exact_klass_helper() const {
4352   if (_interfaces->empty()) {
4353     return _klass;
4354   }
4355   if (_klass != ciEnv::current()->Object_klass()) {
4356     if (_interfaces->eq(_klass->as_instance_klass())) {
4357       return _klass;
4358     }
4359     return nullptr;
4360   }
4361   return _interfaces->exact_klass();
4362 }
4363 
4364 //------------------------------TypeInstPtr-------------------------------------
4365 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4366                          bool flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4367   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4368     _flat_in_array(flat_in_array) {
4369   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4370   assert(k != nullptr &&
4371          (k->is_loaded() || o == nullptr),
4372          "cannot have constants with non-loaded klass");
4373   assert(!klass()->flat_in_array() || flat_in_array, "Should be flat in array");
4374   assert(!flat_in_array || can_be_inline_type(), "Only inline types can be flat in array");
4375 };
4376 
4377 //------------------------------make-------------------------------------------
4378 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4379                                      ciKlass* k,
4380                                      const TypeInterfaces* interfaces,
4381                                      bool xk,
4382                                      ciObject* o,
4383                                      Offset offset,
4384                                      bool flat_in_array,
4385                                      int instance_id,
4386                                      const TypePtr* speculative,
4387                                      int inline_depth) {
4388   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4389   // Either const_oop() is null or else ptr is Constant
4390   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4391           "constant pointers must have a value supplied" );
4392   // Ptr is never Null
4393   assert( ptr != Null, "null pointers are not typed" );
4394 
4395   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4396   if (ptr == Constant) {
4397     // Note:  This case includes meta-object constants, such as methods.
4398     xk = true;
4399   } else if (k->is_loaded()) {
4400     ciInstanceKlass* ik = k->as_instance_klass();
4401     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4402     assert(!ik->is_interface(), "no interface here");
4403     if (xk && ik->is_interface())  xk = false;  // no exact interface
4404   }
4405 
4406   // Check if this type is known to be flat in arrays
4407   flat_in_array = flat_in_array || k->flat_in_array();
4408 
4409   // Now hash this baby
4410   TypeInstPtr *result =
4411     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4412 
4413   return result;
4414 }
4415 
4416 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4417   if (k->is_instance_klass()) {
4418     if (k->is_loaded()) {
4419       if (k->is_interface() && interface_handling == ignore_interfaces) {
4420         assert(interface, "no interface expected");
4421         k = ciEnv::current()->Object_klass();
4422         const TypeInterfaces* interfaces = TypeInterfaces::make();
4423         return interfaces;
4424       }
4425       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4426       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4427       if (k->is_interface()) {
4428         assert(interface, "no interface expected");
4429         k = ciEnv::current()->Object_klass();
4430       } else {
4431         assert(klass, "no instance klass expected");

4457   switch (bt) {
4458     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4459     case T_INT:      return TypeInt::make(constant.as_int());
4460     case T_CHAR:     return TypeInt::make(constant.as_char());
4461     case T_BYTE:     return TypeInt::make(constant.as_byte());
4462     case T_SHORT:    return TypeInt::make(constant.as_short());
4463     case T_FLOAT:    return TypeF::make(constant.as_float());
4464     case T_DOUBLE:   return TypeD::make(constant.as_double());
4465     case T_LONG:     return TypeLong::make(constant.as_long());
4466     default:         break;
4467   }
4468   fatal("Invalid boxed value type '%s'", type2name(bt));
4469   return nullptr;
4470 }
4471 
4472 //------------------------------cast_to_ptr_type-------------------------------
4473 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4474   if( ptr == _ptr ) return this;
4475   // Reconstruct _sig info here since not a problem with later lazy
4476   // construction, _sig will show up on demand.
4477   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4478 }
4479 
4480 
4481 //-----------------------------cast_to_exactness-------------------------------
4482 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4483   if( klass_is_exact == _klass_is_exact ) return this;
4484   if (!_klass->is_loaded())  return this;
4485   ciInstanceKlass* ik = _klass->as_instance_klass();
4486   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4487   assert(!ik->is_interface(), "no interface here");
4488   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4489 }
4490 
4491 //-----------------------------cast_to_instance_id----------------------------
4492 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4493   if( instance_id == _instance_id ) return this;
4494   return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4495 }
4496 
4497 //------------------------------xmeet_unloaded---------------------------------
4498 // Compute the MEET of two InstPtrs when at least one is unloaded.
4499 // Assume classes are different since called after check for same name/class-loader
4500 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4501   Offset off = meet_offset(tinst->offset());
4502   PTR ptr = meet_ptr(tinst->ptr());
4503   int instance_id = meet_instance_id(tinst->instance_id());
4504   const TypePtr* speculative = xmeet_speculative(tinst);
4505   int depth = meet_inline_depth(tinst->inline_depth());
4506 
4507   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4508   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4509   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4510     //
4511     // Meet unloaded class with java/lang/Object
4512     //
4513     // Meet
4514     //          |                     Unloaded Class
4515     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4516     //  ===================================================================
4517     //   TOP    | ..........................Unloaded......................|
4518     //  AnyNull |  U-AN    |................Unloaded......................|
4519     // Constant | ... O-NN .................................. |   O-BOT   |
4520     //  NotNull | ... O-NN .................................. |   O-BOT   |
4521     //  BOTTOM  | ........................Object-BOTTOM ..................|
4522     //
4523     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4524     //
4525     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded->with_speculative(speculative); }
4526     else if (loaded->ptr() == TypePtr::AnyNull)  { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, false, instance_id, speculative, depth); }
4527     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4528     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4529       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM->with_speculative(speculative);  }
4530       else                                       { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4531     }
4532     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4533 
4534     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4535   }
4536 
4537   // Both are unloaded, not the same class, not Object
4538   // Or meet unloaded with a different loaded class, not java/lang/Object
4539   if (ptr != TypePtr::BotPTR) {
4540     return TypeInstPtr::NOTNULL->with_speculative(speculative);
4541   }
4542   return TypeInstPtr::BOTTOM->with_speculative(speculative);
4543 }
4544 
4545 
4546 //------------------------------meet-------------------------------------------

4570   case Top:
4571     return this;
4572 
4573   default:                      // All else is a mistake
4574     typerr(t);
4575 
4576   case MetadataPtr:
4577   case KlassPtr:
4578   case InstKlassPtr:
4579   case AryKlassPtr:
4580   case RawPtr: return TypePtr::BOTTOM;
4581 
4582   case AryPtr: {                // All arrays inherit from Object class
4583     // Call in reverse direction to avoid duplication
4584     return t->is_aryptr()->xmeet_helper(this);
4585   }
4586 
4587   case OopPtr: {                // Meeting to OopPtrs
4588     // Found a OopPtr type vs self-InstPtr type
4589     const TypeOopPtr *tp = t->is_oopptr();
4590     Offset offset = meet_offset(tp->offset());
4591     PTR ptr = meet_ptr(tp->ptr());
4592     switch (tp->ptr()) {
4593     case TopPTR:
4594     case AnyNull: {
4595       int instance_id = meet_instance_id(InstanceTop);
4596       const TypePtr* speculative = xmeet_speculative(tp);
4597       int depth = meet_inline_depth(tp->inline_depth());
4598       return make(ptr, klass(), _interfaces, klass_is_exact(),
4599                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4600     }
4601     case NotNull:
4602     case BotPTR: {
4603       int instance_id = meet_instance_id(tp->instance_id());
4604       const TypePtr* speculative = xmeet_speculative(tp);
4605       int depth = meet_inline_depth(tp->inline_depth());
4606       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4607     }
4608     default: typerr(t);
4609     }
4610   }
4611 
4612   case AnyPtr: {                // Meeting to AnyPtrs
4613     // Found an AnyPtr type vs self-InstPtr type
4614     const TypePtr *tp = t->is_ptr();
4615     Offset offset = meet_offset(tp->offset());
4616     PTR ptr = meet_ptr(tp->ptr());
4617     int instance_id = meet_instance_id(InstanceTop);
4618     const TypePtr* speculative = xmeet_speculative(tp);
4619     int depth = meet_inline_depth(tp->inline_depth());
4620     switch (tp->ptr()) {
4621     case Null:
4622       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4623       // else fall through to AnyNull
4624     case TopPTR:
4625     case AnyNull: {
4626       return make(ptr, klass(), _interfaces, klass_is_exact(),
4627                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4628     }
4629     case NotNull:
4630     case BotPTR:
4631       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4632     default: typerr(t);
4633     }
4634   }
4635 
4636   /*
4637                  A-top         }
4638                /   |   \       }  Tops
4639            B-top A-any C-top   }
4640               | /  |  \ |      }  Any-nulls
4641            B-any   |   C-any   }
4642               |    |    |
4643            B-con A-con C-con   } constants; not comparable across classes
4644               |    |    |
4645            B-not   |   C-not   }
4646               | \  |  / |      }  not-nulls
4647            B-bot A-not C-bot   }
4648                \   |   /       }  Bottoms
4649                  A-bot         }
4650   */
4651 
4652   case InstPtr: {                // Meeting 2 Oops?
4653     // Found an InstPtr sub-type vs self-InstPtr type
4654     const TypeInstPtr *tinst = t->is_instptr();
4655     Offset off = meet_offset(tinst->offset());
4656     PTR ptr = meet_ptr(tinst->ptr());
4657     int instance_id = meet_instance_id(tinst->instance_id());
4658     const TypePtr* speculative = xmeet_speculative(tinst);
4659     int depth = meet_inline_depth(tinst->inline_depth());
4660     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4661 
4662     ciKlass* tinst_klass = tinst->klass();
4663     ciKlass* this_klass  = klass();
4664 
4665     ciKlass* res_klass = nullptr;
4666     bool res_xk = false;
4667     bool res_flat_in_array = false;
4668     const Type* res;
4669     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk, res_flat_in_array);
4670 
4671     if (kind == UNLOADED) {
4672       // One of these classes has not been loaded
4673       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4674 #ifndef PRODUCT
4675       if (PrintOpto && Verbose) {
4676         tty->print("meet of unloaded classes resulted in: ");
4677         unloaded_meet->dump();
4678         tty->cr();
4679         tty->print("  this == ");
4680         dump();
4681         tty->cr();
4682         tty->print(" tinst == ");
4683         tinst->dump();
4684         tty->cr();
4685       }
4686 #endif
4687       res = unloaded_meet;
4688     } else {
4689       if (kind == NOT_SUBTYPE && instance_id > 0) {
4690         instance_id = InstanceBot;
4691       } else if (kind == LCA) {
4692         instance_id = InstanceBot;
4693       }
4694       ciObject* o = nullptr;             // Assume not constant when done
4695       ciObject* this_oop = const_oop();
4696       ciObject* tinst_oop = tinst->const_oop();
4697       if (ptr == Constant) {
4698         if (this_oop != nullptr && tinst_oop != nullptr &&
4699             this_oop->equals(tinst_oop))
4700           o = this_oop;
4701         else if (above_centerline(_ptr)) {
4702           assert(!tinst_klass->is_interface(), "");
4703           o = tinst_oop;
4704         } else if (above_centerline(tinst->_ptr)) {
4705           assert(!this_klass->is_interface(), "");
4706           o = this_oop;
4707         } else
4708           ptr = NotNull;
4709       }
4710       res = make(ptr, res_klass, interfaces, res_xk, o, off, res_flat_in_array, instance_id, speculative, depth);
4711     }
4712 
4713     return res;
4714 
4715   } // End of case InstPtr
4716 
4717   } // End of switch
4718   return this;                  // Return the double constant
4719 }
4720 
4721 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4722                                                             ciKlass*& res_klass, bool& res_xk, bool& res_flat_in_array) {
4723   ciKlass* this_klass = this_type->klass();
4724   ciKlass* other_klass = other_type->klass();
4725   const bool this_flat_in_array = this_type->flat_in_array();
4726   const bool other_flat_in_array = other_type->flat_in_array();
4727   const bool this_not_flat_in_array = this_type->not_flat_in_array();
4728   const bool other_not_flat_in_array = other_type->not_flat_in_array();
4729 
4730   bool this_xk = this_type->klass_is_exact();
4731   bool other_xk = other_type->klass_is_exact();
4732   PTR this_ptr = this_type->ptr();
4733   PTR other_ptr = other_type->ptr();
4734   const TypeInterfaces* this_interfaces = this_type->interfaces();
4735   const TypeInterfaces* other_interfaces = other_type->interfaces();
4736   // Check for easy case; klasses are equal (and perhaps not loaded!)
4737   // If we have constants, then we created oops so classes are loaded
4738   // and we can handle the constants further down.  This case handles
4739   // both-not-loaded or both-loaded classes
4740   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk && this_flat_in_array == other_flat_in_array) {
4741     res_klass = this_klass;
4742     res_xk = this_xk;
4743     res_flat_in_array = this_flat_in_array;
4744     return QUICK;
4745   }
4746 
4747   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4748   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4749     return UNLOADED;
4750   }
4751 
4752   // !!! Here's how the symmetry requirement breaks down into invariants:
4753   // If we split one up & one down AND they subtype, take the down man.
4754   // If we split one up & one down AND they do NOT subtype, "fall hard".
4755   // If both are up and they subtype, take the subtype class.
4756   // If both are up and they do NOT subtype, "fall hard".
4757   // If both are down and they subtype, take the supertype class.
4758   // If both are down and they do NOT subtype, "fall hard".
4759   // Constants treated as down.
4760 
4761   // Now, reorder the above list; observe that both-down+subtype is also
4762   // "fall hard"; "fall hard" becomes the default case:
4763   // If we split one up & one down AND they subtype, take the down man.
4764   // If both are up and they subtype, take the subtype class.
4765 
4766   // If both are down and they subtype, "fall hard".
4767   // If both are down and they do NOT subtype, "fall hard".
4768   // If both are up and they do NOT subtype, "fall hard".
4769   // If we split one up & one down AND they do NOT subtype, "fall hard".
4770 
4771   // If a proper subtype is exact, and we return it, we return it exactly.
4772   // If a proper supertype is exact, there can be no subtyping relationship!
4773   // If both types are equal to the subtype, exactness is and-ed below the
4774   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4775 
4776   // Flat in Array property _flat_in_array.
4777   // For simplicity, _flat_in_array is a boolean but we actually have a tri state:
4778   // - Flat in array       -> flat_in_array()
4779   // - Not flat in array   -> not_flat_in_array()
4780   // - Maybe flat in array -> !not_flat_in_array()
4781   //
4782   // Maybe we should convert _flat_in_array to a proper lattice with four elements at some point:
4783   //
4784   //                  Top
4785   //    Flat in Array     Not Flat in Array
4786   //          Maybe Flat in Array
4787   //
4788   // where
4789   //     Top = dual(maybe Flat In Array) = "Flat in Array AND Not Flat in Array"
4790   //
4791   // But for now we stick with the current model with _flat_in_array as a boolean.
4792   //
4793   // When meeting two InstPtr types, we want to have the following behavior:
4794   //
4795   // (FiA-M) Meet(this, other):
4796   //     'this' and 'other' are either the same klass OR sub klasses:
4797   //
4798   //                yes maybe no
4799   //           yes   y    m    m                      y = Flat in Array
4800   //         maybe   m    m    m                      n = Not Flat in Array
4801   //            no   m    m    n                      m = Maybe Flat in Array
4802   //
4803   //  Join(this, other):
4804   //     (FiA-J-Same) 'this' and 'other' are the SAME klass:
4805   //
4806   //                yes maybe no                      E = Empty set
4807   //           yes   y    y    E                      y = Flat in Array
4808   //         maybe   y    m    m                      n = Not Flat in Array
4809   //            no   E    m    n                      m = Maybe Flat in Array
4810   //
4811   //     (FiA-J-Sub) 'this' and 'other' are SUB klasses:
4812   //
4813   //               yes maybe no   -> Super Klass      E = Empty set
4814   //          yes   y    y    y                       y = Flat in Array
4815   //        maybe   y    m    m                       n = Not Flat in Array
4816   //           no   E    m    n                       m = Maybe Flat in Array
4817   //           |
4818   //           v
4819   //       Sub Klass
4820   //
4821   //     Note the difference when joining a super klass that is not flat in array with a sub klass that is compared to
4822   //     the same klass case. We will take over the flat in array property of the sub klass. This can be done because
4823   //     the super klass could be Object (i.e. not an inline type and thus not flat in array) while the sub klass is a
4824   //     value class which can be flat in array.
4825   //
4826   //     The empty set is only a possible result when matching 'ptr' above the center line (i.e. joining). In this case,
4827   //     we can "fall hard" by setting 'ptr' to NotNull such that when we take the dual of that meet above the center
4828   //     line, we get an empty set again.
4829   //
4830   //     Note: When changing to a separate lattice with _flat_in_array we may want to add TypeInst(Klass)Ptr::empty()
4831   //           that returns true when the meet result is FlatInArray::Top (i.e. dual(maybe flat in array)).
4832 
4833   const T* subtype = nullptr;
4834   bool subtype_exact = false;
4835   bool flat_in_array = false;
4836   bool is_empty = false;
4837   if (this_type->is_same_java_type_as(other_type)) {
4838     // Same klass
4839     subtype = this_type;
4840     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4841     if (above_centerline(ptr)) {
4842       // Case (FiA-J-Same)
4843       // One is flat in array and the other not? Result is empty/"fall hard".
4844       is_empty = (this_flat_in_array && other_not_flat_in_array) || (this_not_flat_in_array && other_flat_in_array);
4845     }
4846   } else if (!other_xk && is_meet_subtype_of(this_type, other_type)) {
4847     subtype = this_type;     // Pick subtyping class
4848     subtype_exact = this_xk;
4849     if (above_centerline(ptr)) {
4850       // Case (FiA-J-Sub)
4851       is_empty = this_not_flat_in_array && other_flat_in_array;
4852       if (!is_empty) {
4853         bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4854         flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4855       }
4856     }
4857   } else if (!this_xk && is_meet_subtype_of(other_type, this_type)) {
4858     subtype = other_type;    // Pick subtyping class
4859     subtype_exact = other_xk;
4860     if (above_centerline(ptr)) {
4861       // Case (FiA-J-Sub)
4862       is_empty = this_flat_in_array && other_not_flat_in_array;
4863       if (!is_empty) {
4864         bool this_flat_other_maybe_flat = this_flat_in_array && (!other_flat_in_array && !other_not_flat_in_array);
4865         flat_in_array = other_flat_in_array || this_flat_other_maybe_flat;
4866       }
4867     }
4868   }
4869 
4870 
4871   if (subtype && !is_empty) {
4872     if (above_centerline(ptr)) {
4873       // Both types are empty.
4874       this_type = other_type = subtype;
4875       this_xk = other_xk = subtype_exact;
4876       // Case (FiA-J-Sub)
4877       bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4878       flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4879       // One is flat in array and the other not? Result is empty/"fall hard".
4880       is_empty = (this_flat_in_array && other_not_flat_in_array) || (this_not_flat_in_array && other_flat_in_array);
4881     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4882       // this_type is empty while other_type is not. Take other_type.
4883       this_type = other_type;
4884       this_xk = other_xk;
4885       flat_in_array = other_flat_in_array;
4886     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4887       // other_type is empty while this_type is not. Take this_type.
4888       other_type = this_type; // this is down; keep down man
4889       flat_in_array = this_flat_in_array;
4890     } else {
4891       // this_type and other_type are both non-empty.
4892       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4893       // Case (FiA-M)
4894       // Meeting two types below the center line: Only flat in array if both are.
4895       flat_in_array = this_flat_in_array && other_flat_in_array;
4896     }
4897   }
4898 
4899   // Check for classes now being equal
4900   if (this_type->is_same_java_type_as(other_type) && !is_empty) {
4901     // If the klasses are equal, the constants may still differ.  Fall to
4902     // NotNull if they do (neither constant is null; that is a special case
4903     // handled elsewhere).
4904     res_klass = this_type->klass();
4905     res_xk = this_xk;
4906     res_flat_in_array = flat_in_array;
4907     return SUBTYPE;
4908   } // Else classes are not equal
4909 
4910   // Since klasses are different, we require a LCA in the Java
4911   // class hierarchy - which means we have to fall to at least NotNull.
4912   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4913     ptr = NotNull;
4914   }
4915 
4916   interfaces = this_interfaces->intersection_with(other_interfaces);
4917 
4918   // Now we find the LCA of Java classes
4919   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4920 
4921   res_klass = k;
4922   res_xk = false;
4923   res_flat_in_array = this_flat_in_array && other_flat_in_array;
4924 
4925   return LCA;
4926 }
4927 
4928 template<class T> bool TypePtr::is_meet_subtype_of(const T* sub_type, const T* super_type) {
4929   return sub_type->is_meet_subtype_of(super_type) && !(super_type->flat_in_array() && sub_type->not_flat_in_array());
4930 }
4931 
4932 //------------------------java_mirror_type--------------------------------------
4933 ciType* TypeInstPtr::java_mirror_type(bool* is_null_free_array) const {
4934   // must be a singleton type
4935   if( const_oop() == nullptr )  return nullptr;
4936 
4937   // must be of type java.lang.Class
4938   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;
4939   return const_oop()->as_instance()->java_mirror_type(is_null_free_array);

4940 }
4941 
4942 
4943 //------------------------------xdual------------------------------------------
4944 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4945 // inheritance mechanism.
4946 const Type *TypeInstPtr::xdual() const {
4947   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());
4948 }
4949 
4950 //------------------------------eq---------------------------------------------
4951 // Structural equality check for Type representations
4952 bool TypeInstPtr::eq( const Type *t ) const {
4953   const TypeInstPtr *p = t->is_instptr();
4954   return
4955     klass()->equals(p->klass()) &&
4956     flat_in_array() == p->flat_in_array() &&
4957     _interfaces->eq(p->_interfaces) &&
4958     TypeOopPtr::eq(p);          // Check sub-type stuff
4959 }
4960 
4961 //------------------------------hash-------------------------------------------
4962 // Type-specific hashing function.
4963 uint TypeInstPtr::hash(void) const {
4964   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + (uint)flat_in_array();
4965 }
4966 
4967 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4968   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4969 }
4970 
4971 
4972 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4973   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4974 }
4975 
4976 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4977   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4978 }
4979 
4980 
4981 //------------------------------dump2------------------------------------------
4982 // Dump oop Type
4983 #ifndef PRODUCT
4984 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {

4998       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4999       char* buf = ss.as_string(/* c_heap= */false);
5000       StringUtils::replace_no_expand(buf, "\n", "");
5001       st->print_raw(buf);
5002     }
5003   case BotPTR:
5004     if (!WizardMode && !Verbose) {
5005       if( _klass_is_exact ) st->print(":exact");
5006       break;
5007     }
5008   case TopPTR:
5009   case AnyNull:
5010   case NotNull:
5011     st->print(":%s", ptr_msg[_ptr]);
5012     if( _klass_is_exact ) st->print(":exact");
5013     break;
5014   default:
5015     break;
5016   }
5017 
5018   _offset.dump2(st);




5019 
5020   st->print(" *");
5021 
5022   if (flat_in_array() && !klass()->is_inlinetype()) {
5023     st->print(" (flat in array)");
5024   }
5025 
5026   if (_instance_id == InstanceTop)
5027     st->print(",iid=top");
5028   else if (_instance_id != InstanceBot)
5029     st->print(",iid=%d",_instance_id);
5030 
5031   dump_inline_depth(st);
5032   dump_speculative(st);
5033 }
5034 #endif
5035 
5036 //------------------------------add_offset-------------------------------------
5037 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
5038   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), flat_in_array(),
5039               _instance_id, add_offset_speculative(offset), _inline_depth);
5040 }
5041 
5042 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
5043   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), flat_in_array(),
5044               _instance_id, with_offset_speculative(offset), _inline_depth);
5045 }
5046 
5047 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
5048   if (_speculative == nullptr) {
5049     return this;
5050   }
5051   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5052   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(),
5053               _instance_id, nullptr, _inline_depth);
5054 }
5055 
5056 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
5057   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, speculative, _inline_depth);
5058 }
5059 
5060 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
5061   if (!UseInlineDepthForSpeculativeTypes) {
5062     return this;
5063   }
5064   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, _speculative, depth);
5065 }
5066 
5067 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
5068   assert(is_known_instance(), "should be known");
5069   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), instance_id, _speculative, _inline_depth);
5070 }
5071 
5072 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
5073   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
5074 }
5075 
5076 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
5077   bool xk = klass_is_exact();
5078   ciInstanceKlass* ik = klass()->as_instance_klass();
5079   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
5080     if (_interfaces->eq(ik)) {
5081       Compile* C = Compile::current();
5082       Dependencies* deps = C->dependencies();
5083       deps->assert_leaf_type(ik);
5084       xk = true;
5085     }
5086   }
5087   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array());
5088 }
5089 
5090 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) {
5091   static_assert(std::is_base_of<T2, T1>::value, "");
5092 
5093   if (!this_one->is_instance_type(other)) {
5094     return false;
5095   }
5096 
5097   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
5098     return true;
5099   }
5100 
5101   return this_one->klass()->is_subtype_of(other->klass()) &&
5102          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
5103 }
5104 
5105 
5106 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
5107   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);

5112   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
5113     return true;
5114   }
5115 
5116   if (this_one->is_instance_type(other)) {
5117     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
5118   }
5119 
5120   int dummy;
5121   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
5122   if (this_top_or_bottom) {
5123     return false;
5124   }
5125 
5126   const T1* other_ary = this_one->is_array_type(other);
5127   const TypePtr* other_elem = other_ary->elem()->make_ptr();
5128   const TypePtr* this_elem = this_one->elem()->make_ptr();
5129   if (other_elem != nullptr && this_elem != nullptr) {
5130     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
5131   }

5132   if (other_elem == nullptr && this_elem == nullptr) {
5133     return this_one->klass()->is_subtype_of(other->klass());
5134   }
5135 
5136   return false;
5137 }
5138 
5139 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
5140   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5141 }
5142 
5143 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5144   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
5145 }
5146 
5147 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5148   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5149 }
5150 
5151 //=============================================================================
5152 // Convenience common pre-built types.
5153 const TypeAryPtr* TypeAryPtr::BOTTOM;
5154 const TypeAryPtr *TypeAryPtr::RANGE;
5155 const TypeAryPtr *TypeAryPtr::OOPS;
5156 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
5157 const TypeAryPtr *TypeAryPtr::BYTES;
5158 const TypeAryPtr *TypeAryPtr::SHORTS;
5159 const TypeAryPtr *TypeAryPtr::CHARS;
5160 const TypeAryPtr *TypeAryPtr::INTS;
5161 const TypeAryPtr *TypeAryPtr::LONGS;
5162 const TypeAryPtr *TypeAryPtr::FLOATS;
5163 const TypeAryPtr *TypeAryPtr::DOUBLES;
5164 const TypeAryPtr *TypeAryPtr::INLINES;
5165 
5166 //------------------------------make-------------------------------------------
5167 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5168                                    int instance_id, const TypePtr* speculative, int inline_depth) {
5169   assert(!(k == nullptr && ary->_elem->isa_int()),
5170          "integral arrays must be pre-equipped with a class");
5171   if (!xk)  xk = ary->ary_must_be_exact();
5172   assert(instance_id <= 0 || xk, "instances are always exactly typed");
5173   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5174       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5175     k = nullptr;
5176   }
5177   if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
5178     k = nullptr;
5179   }
5180   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
5181 }
5182 
5183 //------------------------------make-------------------------------------------
5184 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5185                                    int instance_id, const TypePtr* speculative, int inline_depth,
5186                                    bool is_autobox_cache) {
5187   assert(!(k == nullptr && ary->_elem->isa_int()),
5188          "integral arrays must be pre-equipped with a class");
5189   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
5190   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
5191   assert(instance_id <= 0 || xk, "instances are always exactly typed");
5192   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5193       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5194     k = nullptr;
5195   }
5196   if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
5197     k = nullptr;
5198   }
5199   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
5200 }
5201 
5202 //------------------------------cast_to_ptr_type-------------------------------
5203 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
5204   if( ptr == _ptr ) return this;
5205   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5206 }
5207 
5208 
5209 //-----------------------------cast_to_exactness-------------------------------
5210 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
5211   if( klass_is_exact == _klass_is_exact ) return this;
5212   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
5213   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5214 }
5215 
5216 //-----------------------------cast_to_instance_id----------------------------
5217 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
5218   if( instance_id == _instance_id ) return this;
5219   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
5220 }
5221 
5222 
5223 //-----------------------------max_array_length-------------------------------
5224 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
5225 jint TypeAryPtr::max_array_length(BasicType etype) {
5226   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5227     if (etype == T_NARROWOOP) {
5228       etype = T_OBJECT;
5229     } else if (etype == T_ILLEGAL) { // bottom[]
5230       etype = T_BYTE; // will produce conservatively high value
5231     } else {
5232       fatal("not an element type: %s", type2name(etype));
5233     }
5234   }
5235   return arrayOopDesc::max_array_length(etype);
5236 }
5237 
5238 //-----------------------------narrow_size_type-------------------------------
5239 // Narrow the given size type to the index range for the given array base type.

5255   if (hi > max_hi) {
5256     hi = max_hi;
5257     if (size->is_con()) {
5258       lo = hi;
5259     }
5260     chg = true;
5261   }
5262   // Negative length arrays will produce weird intermediate dead fast-path code
5263   if (lo > hi)
5264     return TypeInt::ZERO;
5265   if (!chg)
5266     return size;
5267   return TypeInt::make(lo, hi, Type::WidenMin);
5268 }
5269 
5270 //-------------------------------cast_to_size----------------------------------
5271 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5272   assert(new_size != nullptr, "");
5273   new_size = narrow_size_type(new_size);
5274   if (new_size == size())  return this;
5275   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free());
5276   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5277 }
5278 
5279 //-------------------------------cast_to_not_flat------------------------------
5280 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5281   if (not_flat == is_not_flat()) {
5282     return this;
5283   }
5284   assert(!not_flat || !is_flat(), "inconsistency");
5285   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free());
5286   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5287   // We keep the speculative part if it contains information about flat-/nullability.
5288   // Make sure it's removed if it's not better than the non-speculative type anymore.
5289   if (res->speculative() == res->remove_speculative()) {
5290     return res->remove_speculative();
5291   }
5292   return res;
5293 }
5294 
5295 //-------------------------------cast_to_not_null_free-------------------------
5296 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5297   if (not_null_free == is_not_null_free()) {
5298     return this;
5299   }
5300   assert(!not_null_free || !is_flat(), "inconsistency");
5301   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), /* not_flat= */ not_null_free ? true : is_not_flat(), not_null_free);
5302   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5303                                _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5304   // We keep the speculative part if it contains information about flat-/nullability.
5305   // Make sure it's removed if it's not better than the non-speculative type anymore.
5306   if (res->speculative() == res->remove_speculative()) {
5307     return res->remove_speculative();
5308   }
5309   return res;
5310 }
5311 
5312 //---------------------------------update_properties---------------------------
5313 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5314   if ((from->is_flat()          && is_not_flat()) ||
5315       (from->is_not_flat()      && is_flat()) ||
5316       (from->is_null_free()     && is_not_null_free()) ||
5317       (from->is_not_null_free() && is_null_free())) {
5318     return nullptr; // Inconsistent properties
5319   } else if (from->is_not_null_free()) {
5320     return cast_to_not_null_free(); // Implies not flat
5321   } else if (from->is_not_flat()) {
5322     return cast_to_not_flat();
5323   }
5324   return this;
5325 }
5326 
5327 jint TypeAryPtr::flat_layout_helper() const {
5328   return klass()->as_flat_array_klass()->layout_helper();
5329 }
5330 
5331 int TypeAryPtr::flat_elem_size() const {
5332   return klass()->as_flat_array_klass()->element_byte_size();
5333 }
5334 
5335 int TypeAryPtr::flat_log_elem_size() const {
5336   return klass()->as_flat_array_klass()->log2_element_size();
5337 }
5338 
5339 //------------------------------cast_to_stable---------------------------------
5340 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5341   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5342     return this;
5343 
5344   const Type* elem = this->elem();
5345   const TypePtr* elem_ptr = elem->make_ptr();
5346 
5347   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5348     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5349     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5350   }
5351 
5352   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free());
5353 
5354   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5355 }
5356 
5357 //-----------------------------stable_dimension--------------------------------
5358 int TypeAryPtr::stable_dimension() const {
5359   if (!is_stable())  return 0;
5360   int dim = 1;
5361   const TypePtr* elem_ptr = elem()->make_ptr();
5362   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5363     dim += elem_ptr->is_aryptr()->stable_dimension();
5364   return dim;
5365 }
5366 
5367 //----------------------cast_to_autobox_cache-----------------------------------
5368 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5369   if (is_autobox_cache())  return this;
5370   const TypeOopPtr* etype = elem()->make_oopptr();
5371   if (etype == nullptr)  return this;
5372   // The pointers in the autobox arrays are always non-null.
5373   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5374   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free());
5375   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5376 }
5377 
5378 //------------------------------eq---------------------------------------------
5379 // Structural equality check for Type representations
5380 bool TypeAryPtr::eq( const Type *t ) const {
5381   const TypeAryPtr *p = t->is_aryptr();
5382   return
5383     _ary == p->_ary &&  // Check array
5384     TypeOopPtr::eq(p) &&// Check sub-parts
5385     _field_offset == p->_field_offset;
5386 }
5387 
5388 //------------------------------hash-------------------------------------------
5389 // Type-specific hashing function.
5390 uint TypeAryPtr::hash(void) const {
5391   return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5392 }
5393 
5394 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5395   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5396 }
5397 
5398 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5399   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5400 }
5401 
5402 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5403   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5404 }
5405 //------------------------------meet-------------------------------------------
5406 // Compute the MEET of two types.  It returns a new Type object.
5407 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5408   // Perform a fast test for common case; meeting the same types together.
5409   if( this == t ) return this;  // Meeting same type-rep?
5410   // Current "this->_base" is Pointer
5411   switch (t->base()) {          // switch on original type

5418   case HalfFloatBot:
5419   case FloatTop:
5420   case FloatCon:
5421   case FloatBot:
5422   case DoubleTop:
5423   case DoubleCon:
5424   case DoubleBot:
5425   case NarrowOop:
5426   case NarrowKlass:
5427   case Bottom:                  // Ye Olde Default
5428     return Type::BOTTOM;
5429   case Top:
5430     return this;
5431 
5432   default:                      // All else is a mistake
5433     typerr(t);
5434 
5435   case OopPtr: {                // Meeting to OopPtrs
5436     // Found a OopPtr type vs self-AryPtr type
5437     const TypeOopPtr *tp = t->is_oopptr();
5438     Offset offset = meet_offset(tp->offset());
5439     PTR ptr = meet_ptr(tp->ptr());
5440     int depth = meet_inline_depth(tp->inline_depth());
5441     const TypePtr* speculative = xmeet_speculative(tp);
5442     switch (tp->ptr()) {
5443     case TopPTR:
5444     case AnyNull: {
5445       int instance_id = meet_instance_id(InstanceTop);
5446       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5447                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5448     }
5449     case BotPTR:
5450     case NotNull: {
5451       int instance_id = meet_instance_id(tp->instance_id());
5452       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5453     }
5454     default: ShouldNotReachHere();
5455     }
5456   }
5457 
5458   case AnyPtr: {                // Meeting two AnyPtrs
5459     // Found an AnyPtr type vs self-AryPtr type
5460     const TypePtr *tp = t->is_ptr();
5461     Offset offset = meet_offset(tp->offset());
5462     PTR ptr = meet_ptr(tp->ptr());
5463     const TypePtr* speculative = xmeet_speculative(tp);
5464     int depth = meet_inline_depth(tp->inline_depth());
5465     switch (tp->ptr()) {
5466     case TopPTR:
5467       return this;
5468     case BotPTR:
5469     case NotNull:
5470       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5471     case Null:
5472       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5473       // else fall through to AnyNull
5474     case AnyNull: {
5475       int instance_id = meet_instance_id(InstanceTop);
5476       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5477                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5478     }
5479     default: ShouldNotReachHere();
5480     }
5481   }
5482 
5483   case MetadataPtr:
5484   case KlassPtr:
5485   case InstKlassPtr:
5486   case AryKlassPtr:
5487   case RawPtr: return TypePtr::BOTTOM;
5488 
5489   case AryPtr: {                // Meeting 2 references?
5490     const TypeAryPtr *tap = t->is_aryptr();
5491     Offset off = meet_offset(tap->offset());
5492     Offset field_off = meet_field_offset(tap->field_offset());
5493     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5494     PTR ptr = meet_ptr(tap->ptr());
5495     int instance_id = meet_instance_id(tap->instance_id());
5496     const TypePtr* speculative = xmeet_speculative(tap);
5497     int depth = meet_inline_depth(tap->inline_depth());
5498 
5499     ciKlass* res_klass = nullptr;
5500     bool res_xk = false;
5501     bool res_flat = false;
5502     bool res_not_flat = false;
5503     bool res_not_null_free = false;
5504     const Type* elem = tary->_elem;
5505     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free) == NOT_SUBTYPE) {
5506       instance_id = InstanceBot;
5507     } else if (this->is_flat() != tap->is_flat()) {
5508       // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5509       if (tary->_flat) {
5510         // Result is in a flat representation
5511         off = Offset(is_flat() ? offset() : tap->offset());
5512         field_off = is_flat() ? field_offset() : tap->field_offset();
5513       } else if (below_centerline(ptr)) {
5514         // Result is in a non-flat representation
5515         off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5516         field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5517       } else if (flat_offset() == tap->flat_offset()) {
5518         off = Offset(!is_flat() ? offset() : tap->offset());
5519         field_off = !is_flat() ? field_offset() : tap->field_offset();
5520       }
5521     }
5522 
5523     ciObject* o = nullptr;             // Assume not constant when done
5524     ciObject* this_oop = const_oop();
5525     ciObject* tap_oop = tap->const_oop();
5526     if (ptr == Constant) {
5527       if (this_oop != nullptr && tap_oop != nullptr &&
5528           this_oop->equals(tap_oop)) {
5529         o = tap_oop;
5530       } else if (above_centerline(_ptr)) {
5531         o = tap_oop;
5532       } else if (above_centerline(tap->_ptr)) {
5533         o = this_oop;
5534       } else {
5535         ptr = NotNull;
5536       }
5537     }
5538     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);
5539   }
5540 
5541   // All arrays inherit from Object class
5542   case InstPtr: {
5543     const TypeInstPtr *tp = t->is_instptr();
5544     Offset offset = meet_offset(tp->offset());
5545     PTR ptr = meet_ptr(tp->ptr());
5546     int instance_id = meet_instance_id(tp->instance_id());
5547     const TypePtr* speculative = xmeet_speculative(tp);
5548     int depth = meet_inline_depth(tp->inline_depth());
5549     const TypeInterfaces* interfaces = meet_interfaces(tp);
5550     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5551     const TypeInterfaces* this_interfaces = _interfaces;
5552 
5553     switch (ptr) {
5554     case TopPTR:
5555     case AnyNull:                // Fall 'down' to dual of object klass
5556       // For instances when a subclass meets a superclass we fall
5557       // below the centerline when the superclass is exact. We need to
5558       // do the same here.
5559       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5560         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5561       } else {
5562         // cannot subclass, so the meet has to fall badly below the centerline
5563         ptr = NotNull;
5564         instance_id = InstanceBot;
5565         interfaces = this_interfaces->intersection_with(tp_interfaces);
5566         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5567       }
5568     case Constant:
5569     case NotNull:
5570     case BotPTR:                // Fall down to object klass
5571       // LCA is object_klass, but if we subclass from the top we can do better
5572       if (above_centerline(tp->ptr())) {
5573         // If 'tp'  is above the centerline and it is Object class
5574         // then we can subclass in the Java class hierarchy.
5575         // For instances when a subclass meets a superclass we fall
5576         // below the centerline when the superclass is exact. We need
5577         // to do the same here.
5578         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5579           // that is, my array type is a subtype of 'tp' klass
5580           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5581                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5582         }
5583       }
5584       // The other case cannot happen, since t cannot be a subtype of an array.
5585       // The meet falls down to Object class below centerline.
5586       if (ptr == Constant) {
5587          ptr = NotNull;
5588       }
5589       if (instance_id > 0) {
5590         instance_id = InstanceBot;
5591       }
5592       interfaces = this_interfaces->intersection_with(tp_interfaces);
5593       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5594     default: typerr(t);
5595     }
5596   }
5597   }
5598   return this;                  // Lint noise
5599 }
5600 
5601 
5602 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5603                                                            ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free) {
5604   int dummy;
5605   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5606   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5607   ciKlass* this_klass = this_ary->klass();
5608   ciKlass* other_klass = other_ary->klass();
5609   bool this_xk = this_ary->klass_is_exact();
5610   bool other_xk = other_ary->klass_is_exact();
5611   PTR this_ptr = this_ary->ptr();
5612   PTR other_ptr = other_ary->ptr();
5613   bool this_flat = this_ary->is_flat();
5614   bool this_not_flat = this_ary->is_not_flat();
5615   bool other_flat = other_ary->is_flat();
5616   bool other_not_flat = other_ary->is_not_flat();
5617   bool this_not_null_free = this_ary->is_not_null_free();
5618   bool other_not_null_free = other_ary->is_not_null_free();
5619   res_klass = nullptr;
5620   MeetResult result = SUBTYPE;
5621   res_flat = this_flat && other_flat;
5622   res_not_flat = this_not_flat && other_not_flat;
5623   res_not_null_free = this_not_null_free && other_not_null_free;
5624 
5625   if (elem->isa_int()) {
5626     // Integral array element types have irrelevant lattice relations.
5627     // It is the klass that determines array layout, not the element type.
5628       if (this_top_or_bottom) {
5629         res_klass = other_klass;
5630       } else if (other_top_or_bottom || other_klass == this_klass) {
5631       res_klass = this_klass;
5632     } else {
5633       // Something like byte[int+] meets char[int+].
5634       // This must fall to bottom, not (int[-128..65535])[int+].
5635       // instance_id = InstanceBot;
5636       elem = Type::BOTTOM;
5637       result = NOT_SUBTYPE;
5638       if (above_centerline(ptr) || ptr == Constant) {
5639         ptr = NotNull;
5640         res_xk = false;
5641         return NOT_SUBTYPE;
5642       }
5643     }
5644   } else {// Non integral arrays.
5645     // Must fall to bottom if exact klasses in upper lattice
5646     // are not equal or super klass is exact.
5647     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5648         // meet with top[] and bottom[] are processed further down:
5649         !this_top_or_bottom && !other_top_or_bottom &&
5650         // both are exact and not equal:

5652          // 'tap'  is exact and super or unrelated:
5653          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5654          // 'this' is exact and super or unrelated:
5655          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5656       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5657         elem = Type::BOTTOM;
5658       }
5659       ptr = NotNull;
5660       res_xk = false;
5661       return NOT_SUBTYPE;
5662     }
5663   }
5664 
5665   res_xk = false;
5666   switch (other_ptr) {
5667     case AnyNull:
5668     case TopPTR:
5669       // Compute new klass on demand, do not use tap->_klass
5670       if (below_centerline(this_ptr)) {
5671         res_xk = this_xk;
5672         if (this_ary->is_flat()) {
5673           elem = this_ary->elem();
5674         }
5675       } else {
5676         res_xk = (other_xk || this_xk);
5677       }
5678       break;
5679     case Constant: {
5680       if (this_ptr == Constant) {
5681         res_xk = true;
5682       } else if (above_centerline(this_ptr)) {
5683         res_xk = true;
5684       } else {
5685         // Only precise for identical arrays
5686         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5687         // Even though MyValue is final, [LMyValue is only exact if the array
5688         // is null-free due to null-free [LMyValue <: null-able [LMyValue.
5689         if (res_xk && !res_not_null_free) {
5690           res_xk = false;
5691         }
5692       }
5693       break;
5694     }
5695     case NotNull:
5696     case BotPTR:
5697       // Compute new klass on demand, do not use tap->_klass
5698       if (above_centerline(this_ptr)) {
5699         res_xk = other_xk;
5700         if (other_ary->is_flat()) {
5701           elem = other_ary->elem();
5702         }
5703       } else {
5704         res_xk = (other_xk && this_xk) &&
5705                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5706         // Even though MyValue is final, [LMyValue is only exact if the array
5707         // is null-free due to null-free [LMyValue <: null-able [LMyValue.
5708         if (res_xk && !res_not_null_free) {
5709           res_xk = false;
5710         }
5711       }
5712       break;
5713     default:  {
5714       ShouldNotReachHere();
5715       return result;
5716     }
5717   }
5718   return result;
5719 }
5720 
5721 
5722 //------------------------------xdual------------------------------------------
5723 // Dual: compute field-by-field dual
5724 const Type *TypeAryPtr::xdual() const {
5725   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());
5726 }
5727 
5728 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5729   return _field_offset.meet(offset);
5730 }
5731 
5732 //------------------------------dual_offset------------------------------------
5733 Type::Offset TypeAryPtr::dual_field_offset() const {
5734   return _field_offset.dual();
5735 }
5736 
5737 //------------------------------dump2------------------------------------------
5738 #ifndef PRODUCT
5739 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5740   _ary->dump2(d,depth,st);
5741   _interfaces->dump(st);
5742 
5743   switch( _ptr ) {
5744   case Constant:
5745     const_oop()->print(st);
5746     break;
5747   case BotPTR:
5748     if (!WizardMode && !Verbose) {
5749       if( _klass_is_exact ) st->print(":exact");
5750       break;
5751     }
5752   case TopPTR:
5753   case AnyNull:
5754   case NotNull:
5755     st->print(":%s", ptr_msg[_ptr]);
5756     if( _klass_is_exact ) st->print(":exact");
5757     break;
5758   default:
5759     break;
5760   }
5761 
5762   if (is_flat()) {
5763     st->print(":flat");
5764     st->print("(");
5765     _field_offset.dump2(st);
5766     st->print(")");
5767   }
5768   if (is_null_free()) {
5769     st->print(":null_free");
5770   }
5771   if (offset() != 0) {
5772     BasicType basic_elem_type = elem()->basic_type();
5773     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5774     if( _offset == Offset::top )       st->print("+undefined");
5775     else if( _offset == Offset::bottom )  st->print("+any");
5776     else if( offset() < header_size ) st->print("+%d", offset());
5777     else {
5778       if (basic_elem_type == T_ILLEGAL) {
5779         st->print("+any");
5780       } else {
5781         int elem_size = type2aelembytes(basic_elem_type);
5782         st->print("[%d]", (offset() - header_size)/elem_size);
5783       }
5784     }
5785   }
5786   st->print(" *");
5787   if (_instance_id == InstanceTop)
5788     st->print(",iid=top");
5789   else if (_instance_id != InstanceBot)
5790     st->print(",iid=%d",_instance_id);
5791 
5792   dump_inline_depth(st);
5793   dump_speculative(st);
5794 }
5795 #endif
5796 
5797 bool TypeAryPtr::empty(void) const {
5798   if (_ary->empty())       return true;
5799   // FIXME: Does this belong here? Or in the meet code itself?
5800   if (is_flat() && is_not_flat()) {
5801     return true;
5802   }
5803   return TypeOopPtr::empty();
5804 }
5805 
5806 //------------------------------add_offset-------------------------------------
5807 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5808   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);
5809 }
5810 
5811 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5812   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);
5813 }
5814 
5815 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5816   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5817 }
5818 
5819 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5820   if (_speculative == nullptr) {
5821     return this;
5822   }
5823   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5824   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);
5825 }
5826 
5827 const Type* TypeAryPtr::cleanup_speculative() const {
5828   if (speculative() == nullptr) {
5829     return this;
5830   }
5831   // Keep speculative part if it contains information about flat-/nullability
5832   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5833   if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5834       (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5835     return this;
5836   }
5837   return TypeOopPtr::cleanup_speculative();
5838 }
5839 
5840 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5841   if (!UseInlineDepthForSpeculativeTypes) {
5842     return this;
5843   }
5844   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5845 }
5846 
5847 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5848   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);
5849 }
5850 
5851 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5852   int adj = 0;
5853   if (is_flat() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5854     if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5855       adj = _offset.get();
5856       offset += _offset.get();
5857     }
5858     uint header = arrayOopDesc::base_offset_in_bytes(T_OBJECT);
5859     if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5860       offset += _field_offset.get();
5861       if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5862         offset += header;
5863       }
5864     }
5865     if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5866       // Try to get the field of the inline type array element we are pointing to
5867       ciInlineKlass* vk = elem()->inline_klass();
5868       int shift = flat_log_elem_size();
5869       int mask = (1 << shift) - 1;
5870       intptr_t field_offset = ((offset - header) & mask);
5871       ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5872       if (field != nullptr) {
5873         return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5874       }
5875     }
5876   }
5877   return add_offset(offset - adj);
5878 }
5879 
5880 // Return offset incremented by field_offset for flat inline type arrays
5881 int TypeAryPtr::flat_offset() const {
5882   int offset = _offset.get();
5883   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5884       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5885     offset += _field_offset.get();
5886   }
5887   return offset;
5888 }
5889 
5890 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5891   assert(is_known_instance(), "should be known");
5892   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5893 }
5894 
5895 //=============================================================================
5896 
5897 
5898 //------------------------------hash-------------------------------------------
5899 // Type-specific hashing function.
5900 uint TypeNarrowPtr::hash(void) const {
5901   return _ptrtype->hash() + 7;
5902 }
5903 
5904 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5905   return _ptrtype->singleton();
5906 }
5907 
5908 bool TypeNarrowPtr::empty(void) const {
5909   return _ptrtype->empty();
5910 }
5911 
5912 intptr_t TypeNarrowPtr::get_con() const {
5913   return _ptrtype->get_con();
5914 }
5915 
5916 bool TypeNarrowPtr::eq( const Type *t ) const {
5917   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5971   case HalfFloatTop:
5972   case HalfFloatCon:
5973   case HalfFloatBot:
5974   case FloatTop:
5975   case FloatCon:
5976   case FloatBot:
5977   case DoubleTop:
5978   case DoubleCon:
5979   case DoubleBot:
5980   case AnyPtr:
5981   case RawPtr:
5982   case OopPtr:
5983   case InstPtr:
5984   case AryPtr:
5985   case MetadataPtr:
5986   case KlassPtr:
5987   case InstKlassPtr:
5988   case AryKlassPtr:
5989   case NarrowOop:
5990   case NarrowKlass:

5991   case Bottom:                  // Ye Olde Default
5992     return Type::BOTTOM;
5993   case Top:
5994     return this;
5995 
5996   default:                      // All else is a mistake
5997     typerr(t);
5998 
5999   } // End of switch
6000 
6001   return this;
6002 }
6003 
6004 #ifndef PRODUCT
6005 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6006   _ptrtype->dump2(d, depth, st);
6007 }
6008 #endif
6009 
6010 const TypeNarrowOop *TypeNarrowOop::BOTTOM;

6054     return (one == two) && TypePtr::eq(t);
6055   } else {
6056     return one->equals(two) && TypePtr::eq(t);
6057   }
6058 }
6059 
6060 //------------------------------hash-------------------------------------------
6061 // Type-specific hashing function.
6062 uint TypeMetadataPtr::hash(void) const {
6063   return
6064     (metadata() ? metadata()->hash() : 0) +
6065     TypePtr::hash();
6066 }
6067 
6068 //------------------------------singleton--------------------------------------
6069 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6070 // constants
6071 bool TypeMetadataPtr::singleton(void) const {
6072   // detune optimizer to not generate constant metadata + constant offset as a constant!
6073   // TopPTR, Null, AnyNull, Constant are all singletons
6074   return (offset() == 0) && !below_centerline(_ptr);
6075 }
6076 
6077 //------------------------------add_offset-------------------------------------
6078 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
6079   return make( _ptr, _metadata, xadd_offset(offset));
6080 }
6081 
6082 //-----------------------------filter------------------------------------------
6083 // Do not allow interface-vs.-noninterface joins to collapse to top.
6084 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
6085   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
6086   if (ft == nullptr || ft->empty())
6087     return Type::TOP;           // Canonical empty value
6088   return ft;
6089 }
6090 
6091  //------------------------------get_con----------------------------------------
6092 intptr_t TypeMetadataPtr::get_con() const {
6093   assert( _ptr == Null || _ptr == Constant, "" );
6094   assert(offset() >= 0, "");
6095 
6096   if (offset() != 0) {
6097     // After being ported to the compiler interface, the compiler no longer
6098     // directly manipulates the addresses of oops.  Rather, it only has a pointer
6099     // to a handle at compile time.  This handle is embedded in the generated
6100     // code and dereferenced at the time the nmethod is made.  Until that time,
6101     // it is not reasonable to do arithmetic with the addresses of oops (we don't
6102     // have access to the addresses!).  This does not seem to currently happen,
6103     // but this assertion here is to help prevent its occurrence.
6104     tty->print_cr("Found oop constant with non-zero offset");
6105     ShouldNotReachHere();
6106   }
6107 
6108   return (intptr_t)metadata()->constant_encoding();
6109 }
6110 
6111 //------------------------------cast_to_ptr_type-------------------------------
6112 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
6113   if( ptr == _ptr ) return this;
6114   return make(ptr, metadata(), _offset);
6115 }
6116 

6130   case HalfFloatBot:
6131   case FloatTop:
6132   case FloatCon:
6133   case FloatBot:
6134   case DoubleTop:
6135   case DoubleCon:
6136   case DoubleBot:
6137   case NarrowOop:
6138   case NarrowKlass:
6139   case Bottom:                  // Ye Olde Default
6140     return Type::BOTTOM;
6141   case Top:
6142     return this;
6143 
6144   default:                      // All else is a mistake
6145     typerr(t);
6146 
6147   case AnyPtr: {
6148     // Found an AnyPtr type vs self-OopPtr type
6149     const TypePtr *tp = t->is_ptr();
6150     Offset offset = meet_offset(tp->offset());
6151     PTR ptr = meet_ptr(tp->ptr());
6152     switch (tp->ptr()) {
6153     case Null:
6154       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6155       // else fall through:
6156     case TopPTR:
6157     case AnyNull: {
6158       return make(ptr, _metadata, offset);
6159     }
6160     case BotPTR:
6161     case NotNull:
6162       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6163     default: typerr(t);
6164     }
6165   }
6166 
6167   case RawPtr:
6168   case KlassPtr:
6169   case InstKlassPtr:
6170   case AryKlassPtr:
6171   case OopPtr:
6172   case InstPtr:
6173   case AryPtr:
6174     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
6175 
6176   case MetadataPtr: {
6177     const TypeMetadataPtr *tp = t->is_metadataptr();
6178     Offset offset = meet_offset(tp->offset());
6179     PTR tptr = tp->ptr();
6180     PTR ptr = meet_ptr(tptr);
6181     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6182     if (tptr == TopPTR || _ptr == TopPTR ||
6183         metadata()->equals(tp->metadata())) {
6184       return make(ptr, md, offset);
6185     }
6186     // metadata is different
6187     if( ptr == Constant ) {  // Cannot be equal constants, so...
6188       if( tptr == Constant && _ptr != Constant)  return t;
6189       if( _ptr == Constant && tptr != Constant)  return this;
6190       ptr = NotNull;            // Fall down in lattice
6191     }
6192     return make(ptr, nullptr, offset);
6193     break;
6194   }
6195   } // End of switch
6196   return this;                  // Return the double constant
6197 }
6198 
6199 
6200 //------------------------------xdual------------------------------------------
6201 // Dual of a pure metadata pointer.
6202 const Type *TypeMetadataPtr::xdual() const {
6203   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6204 }
6205 
6206 //------------------------------dump2------------------------------------------
6207 #ifndef PRODUCT
6208 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6209   st->print("metadataptr:%s", ptr_msg[_ptr]);
6210   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
6211   switch (offset()) {
6212   case OffsetTop: st->print("+top"); break;
6213   case OffsetBot: st->print("+any"); break;
6214   case         0: break;
6215   default:        st->print("+%d",offset()); break;
6216   }
6217 }
6218 #endif
6219 
6220 
6221 //=============================================================================
6222 // Convenience common pre-built type.
6223 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6224 
6225 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6226   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
6227 }
6228 
6229 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6230   return make(Constant, m, Offset(0));
6231 }
6232 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6233   return make(Constant, m, Offset(0));
6234 }
6235 
6236 //------------------------------make-------------------------------------------
6237 // Create a meta data constant
6238 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6239   assert(m == nullptr || !m->is_klass(), "wrong type");
6240   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6241 }
6242 
6243 
6244 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6245   const Type* elem = _ary->_elem;
6246   bool xk = klass_is_exact();
6247   if (elem->make_oopptr() != nullptr) {
6248     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6249     if (elem->is_klassptr()->klass_is_exact() &&
6250         // Even though MyValue is final, [LMyValue is only exact if the array
6251         // is null-free due to null-free [LMyValue <: null-able [LMyValue.
6252         (is_null_free() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
6253       xk = true;
6254     }
6255   }
6256   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_null_free());
6257 }
6258 
6259 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6260   if (klass->is_instance_klass()) {
6261     return TypeInstKlassPtr::make(klass, interface_handling);
6262   }
6263   return TypeAryKlassPtr::make(klass, interface_handling);
6264 }
6265 
6266 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling) {
6267   if (klass->is_instance_klass()) {
6268     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
6269     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
6270   }
6271   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
6272 }
6273 
6274 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)


6275   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
6276   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6277          klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6278 }
6279 
6280 // Is there a single ciKlass* that can represent that type?
6281 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6282   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6283   if (_interfaces->empty()) {
6284     return _klass;
6285   }
6286   if (_klass != ciEnv::current()->Object_klass()) {
6287     if (_interfaces->eq(_klass->as_instance_klass())) {
6288       return _klass;
6289     }
6290     return nullptr;
6291   }
6292   return _interfaces->exact_klass();
6293 }
6294 
6295 //------------------------------eq---------------------------------------------
6296 // Structural equality check for Type representations
6297 bool TypeKlassPtr::eq(const Type *t) const {
6298   const TypeKlassPtr *p = t->is_klassptr();
6299   return
6300     _interfaces->eq(p->_interfaces) &&
6301     TypePtr::eq(p);
6302 }
6303 
6304 //------------------------------hash-------------------------------------------
6305 // Type-specific hashing function.
6306 uint TypeKlassPtr::hash(void) const {
6307   return TypePtr::hash() + _interfaces->hash();
6308 }
6309 
6310 //------------------------------singleton--------------------------------------
6311 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6312 // constants
6313 bool TypeKlassPtr::singleton(void) const {
6314   // detune optimizer to not generate constant klass + constant offset as a constant!
6315   // TopPTR, Null, AnyNull, Constant are all singletons
6316   return (offset() == 0) && !below_centerline(_ptr);
6317 }
6318 
6319 // Do not allow interface-vs.-noninterface joins to collapse to top.
6320 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6321   // logic here mirrors the one from TypeOopPtr::filter. See comments
6322   // there.
6323   const Type* ft = join_helper(kills, include_speculative);
6324 
6325   if (ft->empty()) {
6326     return Type::TOP;           // Canonical empty value
6327   }
6328 
6329   return ft;
6330 }
6331 
6332 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6333   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6334     return _interfaces->union_with(other->_interfaces);
6335   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6336     return other->_interfaces;
6337   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6338     return _interfaces;
6339   }
6340   return _interfaces->intersection_with(other->_interfaces);
6341 }
6342 
6343 //------------------------------get_con----------------------------------------
6344 intptr_t TypeKlassPtr::get_con() const {
6345   assert( _ptr == Null || _ptr == Constant, "" );
6346   assert( offset() >= 0, "" );
6347 
6348   if (offset() != 0) {
6349     // After being ported to the compiler interface, the compiler no longer
6350     // directly manipulates the addresses of oops.  Rather, it only has a pointer
6351     // to a handle at compile time.  This handle is embedded in the generated
6352     // code and dereferenced at the time the nmethod is made.  Until that time,
6353     // it is not reasonable to do arithmetic with the addresses of oops (we don't
6354     // have access to the addresses!).  This does not seem to currently happen,
6355     // but this assertion here is to help prevent its occurrence.
6356     tty->print_cr("Found oop constant with non-zero offset");
6357     ShouldNotReachHere();
6358   }
6359 
6360   ciKlass* k = exact_klass();
6361 
6362   return (intptr_t)k->constant_encoding();
6363 }
6364 
6365 //------------------------------dump2------------------------------------------
6366 // Dump Klass Type
6367 #ifndef PRODUCT
6368 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {

6372   case NotNull:
6373     {
6374       const char *name = klass()->name()->as_utf8();
6375       if (name) {
6376         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
6377       } else {
6378         ShouldNotReachHere();
6379       }
6380       _interfaces->dump(st);
6381     }
6382   case BotPTR:
6383     if (!WizardMode && !Verbose && _ptr != Constant) break;
6384   case TopPTR:
6385   case AnyNull:
6386     st->print(":%s", ptr_msg[_ptr]);
6387     if (_ptr == Constant) st->print(":exact");
6388     break;
6389   default:
6390     break;
6391   }
6392   if (Verbose) {
6393     if (isa_instklassptr() && is_instklassptr()->flat_in_array()) st->print(":flat in array");



6394   }
6395   _offset.dump2(st);
6396   st->print(" *");
6397 
6398   if (flat_in_array() && !klass()->is_inlinetype()) {
6399     st->print(" (flat in array)");
6400   }
6401 }
6402 #endif
6403 
6404 //=============================================================================
6405 // Convenience common pre-built types.
6406 
6407 // Not-null object klass or below
6408 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6409 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6410 
6411 bool TypeInstKlassPtr::eq(const Type *t) const {
6412   const TypeKlassPtr *p = t->is_klassptr();
6413   return
6414     klass()->equals(p->klass()) &&
6415     flat_in_array() == p->flat_in_array() &&
6416     TypeKlassPtr::eq(p);
6417 }
6418 
6419 uint TypeInstKlassPtr::hash(void) const {
6420   return klass()->hash() + TypeKlassPtr::hash() + (uint)flat_in_array();
6421 }
6422 
6423 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array) {
6424   flat_in_array = flat_in_array || k->flat_in_array();
6425 
6426   TypeInstKlassPtr *r =
6427     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6428 
6429   return r;
6430 }
6431 
6432 //------------------------------add_offset-------------------------------------
6433 // Access internals of klass object
6434 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6435   return make(_ptr, klass(), _interfaces, xadd_offset(offset), flat_in_array());
6436 }
6437 
6438 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6439   return make(_ptr, klass(), _interfaces, Offset(offset), flat_in_array());
6440 }
6441 
6442 //------------------------------cast_to_ptr_type-------------------------------
6443 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6444   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6445   if( ptr == _ptr ) return this;
6446   return make(ptr, _klass, _interfaces, _offset, flat_in_array());
6447 }
6448 
6449 
6450 bool TypeInstKlassPtr::must_be_exact() const {
6451   if (!_klass->is_loaded())  return false;
6452   ciInstanceKlass* ik = _klass->as_instance_klass();
6453   if (ik->is_final())  return true;  // cannot clear xk
6454   return false;
6455 }
6456 
6457 //-----------------------------cast_to_exactness-------------------------------
6458 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6459   if (klass_is_exact == (_ptr == Constant)) return this;
6460   if (must_be_exact()) return this;
6461   ciKlass* k = klass();
6462   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array());
6463 }
6464 
6465 
6466 //-----------------------------as_instance_type--------------------------------
6467 // Corresponding type for an instance of the given class.
6468 // It will be NotNull, and exact if and only if the klass type is exact.
6469 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6470   ciKlass* k = klass();
6471   bool xk = klass_is_exact();
6472   Compile* C = Compile::current();
6473   Dependencies* deps = C->dependencies();
6474   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6475   // Element is an instance
6476   bool klass_is_exact = false;
6477   const TypeInterfaces* interfaces = _interfaces;
6478   if (k->is_loaded()) {
6479     // Try to set klass_is_exact.
6480     ciInstanceKlass* ik = k->as_instance_klass();
6481     klass_is_exact = ik->is_final();
6482     if (!klass_is_exact && klass_change
6483         && deps != nullptr && UseUniqueSubclasses) {
6484       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6485       if (sub != nullptr) {
6486         if (_interfaces->eq(sub)) {
6487           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6488           k = ik = sub;
6489           xk = sub->is_final();
6490         }
6491       }
6492     }
6493   }
6494   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array() && !klass()->is_inlinetype());
6495 }
6496 
6497 //------------------------------xmeet------------------------------------------
6498 // Compute the MEET of two types, return a new Type object.
6499 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6500   // Perform a fast test for common case; meeting the same types together.
6501   if( this == t ) return this;  // Meeting same type-rep?
6502 
6503   // Current "this->_base" is Pointer
6504   switch (t->base()) {          // switch on original type
6505 
6506   case Int:                     // Mixing ints & oops happens when javac
6507   case Long:                    // reuses local variables
6508   case HalfFloatTop:
6509   case HalfFloatCon:
6510   case HalfFloatBot:
6511   case FloatTop:
6512   case FloatCon:
6513   case FloatBot:
6514   case DoubleTop:
6515   case DoubleCon:
6516   case DoubleBot:
6517   case NarrowOop:
6518   case NarrowKlass:
6519   case Bottom:                  // Ye Olde Default
6520     return Type::BOTTOM;
6521   case Top:
6522     return this;
6523 
6524   default:                      // All else is a mistake
6525     typerr(t);
6526 
6527   case AnyPtr: {                // Meeting to AnyPtrs
6528     // Found an AnyPtr type vs self-KlassPtr type
6529     const TypePtr *tp = t->is_ptr();
6530     Offset offset = meet_offset(tp->offset());
6531     PTR ptr = meet_ptr(tp->ptr());
6532     switch (tp->ptr()) {
6533     case TopPTR:
6534       return this;
6535     case Null:
6536       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6537     case AnyNull:
6538       return make(ptr, klass(), _interfaces, offset, flat_in_array());
6539     case BotPTR:
6540     case NotNull:
6541       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6542     default: typerr(t);
6543     }
6544   }
6545 
6546   case RawPtr:
6547   case MetadataPtr:
6548   case OopPtr:
6549   case AryPtr:                  // Meet with AryPtr
6550   case InstPtr:                 // Meet with InstPtr
6551       return TypePtr::BOTTOM;
6552 
6553   //
6554   //             A-top         }
6555   //           /   |   \       }  Tops
6556   //       B-top A-any C-top   }
6557   //          | /  |  \ |      }  Any-nulls
6558   //       B-any   |   C-any   }
6559   //          |    |    |
6560   //       B-con A-con C-con   } constants; not comparable across classes
6561   //          |    |    |
6562   //       B-not   |   C-not   }
6563   //          | \  |  / |      }  not-nulls
6564   //       B-bot A-not C-bot   }
6565   //           \   |   /       }  Bottoms
6566   //             A-bot         }
6567   //
6568 
6569   case InstKlassPtr: {  // Meet two KlassPtr types
6570     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6571     Offset  off     = meet_offset(tkls->offset());
6572     PTR  ptr     = meet_ptr(tkls->ptr());
6573     const TypeInterfaces* interfaces = meet_interfaces(tkls);
6574 
6575     ciKlass* res_klass = nullptr;
6576     bool res_xk = false;
6577     bool res_flat_in_array = false;
6578     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk, res_flat_in_array)) {
6579       case UNLOADED:
6580         ShouldNotReachHere();
6581       case SUBTYPE:
6582       case NOT_SUBTYPE:
6583       case LCA:
6584       case QUICK: {
6585         assert(res_xk == (ptr == Constant), "");
6586         const Type* res = make(ptr, res_klass, interfaces, off, res_flat_in_array);
6587         return res;
6588       }
6589       default:
6590         ShouldNotReachHere();
6591     }
6592   } // End of case KlassPtr
6593   case AryKlassPtr: {                // All arrays inherit from Object class
6594     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6595     Offset offset = meet_offset(tp->offset());
6596     PTR ptr = meet_ptr(tp->ptr());
6597     const TypeInterfaces* interfaces = meet_interfaces(tp);
6598     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6599     const TypeInterfaces* this_interfaces = _interfaces;
6600 
6601     switch (ptr) {
6602     case TopPTR:
6603     case AnyNull:                // Fall 'down' to dual of object klass
6604       // For instances when a subclass meets a superclass we fall
6605       // below the centerline when the superclass is exact. We need to
6606       // do the same here.
6607       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6608         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());
6609       } else {
6610         // cannot subclass, so the meet has to fall badly below the centerline
6611         ptr = NotNull;
6612         interfaces = _interfaces->intersection_with(tp->_interfaces);
6613         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6614       }
6615     case Constant:
6616     case NotNull:
6617     case BotPTR:                // Fall down to object klass
6618       // LCA is object_klass, but if we subclass from the top we can do better
6619       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6620         // If 'this' (InstPtr) is above the centerline and it is Object class
6621         // then we can subclass in the Java class hierarchy.
6622         // For instances when a subclass meets a superclass we fall
6623         // below the centerline when the superclass is exact. We need
6624         // to do the same here.
6625         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6626           // that is, tp's array type is a subtype of my klass
6627           return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset, tp->is_not_flat(), tp->is_not_null_free(), tp->is_null_free());

6628         }
6629       }
6630       // The other case cannot happen, since I cannot be a subtype of an array.
6631       // The meet falls down to Object class below centerline.
6632       if( ptr == Constant )
6633          ptr = NotNull;
6634       interfaces = this_interfaces->intersection_with(tp_interfaces);
6635       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6636     default: typerr(t);
6637     }
6638   }
6639 
6640   } // End of switch
6641   return this;                  // Return the double constant
6642 }
6643 
6644 //------------------------------xdual------------------------------------------
6645 // Dual: compute field-by-field dual
6646 const Type    *TypeInstKlassPtr::xdual() const {
6647   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flat_in_array());
6648 }
6649 
6650 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) {
6651   static_assert(std::is_base_of<T2, T1>::value, "");
6652   if (!this_one->is_loaded() || !other->is_loaded()) {
6653     return false;
6654   }
6655   if (!this_one->is_instance_type(other)) {
6656     return false;
6657   }
6658 
6659   if (!other_exact) {
6660     return false;
6661   }
6662 
6663   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6664     return true;
6665   }
6666 
6667   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);

6728   const TypeInterfaces* interfaces = _interfaces;
6729   if (k->is_loaded()) {
6730     ciInstanceKlass* ik = k->as_instance_klass();
6731     bool klass_is_exact = ik->is_final();
6732     if (!klass_is_exact &&
6733         deps != nullptr) {
6734       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6735       if (sub != nullptr) {
6736         if (_interfaces->eq(sub)) {
6737           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6738           k = ik = sub;
6739           klass_is_exact = sub->is_final();
6740           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6741         }
6742       }
6743     }
6744   }
6745   return this;
6746 }
6747 
6748 bool TypeInstKlassPtr::can_be_inline_array() const {
6749   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6750 }
6751 
6752 bool TypeAryKlassPtr::can_be_inline_array() const {
6753   return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6754 }
6755 
6756 bool TypeInstPtr::can_be_inline_array() const {
6757   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6758 }
6759 
6760 bool TypeAryPtr::can_be_inline_array() const {
6761   return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6762 }
6763 
6764 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free) {
6765   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, null_free))->hashcons();
6766 }
6767 
6768 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool null_free) {
6769   if (k->is_obj_array_klass()) {
6770     // Element is an object array. Recursively call ourself.
6771     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6772     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6773     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset, not_flat, not_null_free, null_free);
6774   } else if (k->is_type_array_klass()) {
6775     // Element is an typeArray
6776     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6777     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6778   } else if (k->is_flat_array_klass()) {
6779     ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6780     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass);
6781     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, null_free);
6782   } else {
6783     ShouldNotReachHere();
6784     return nullptr;
6785   }
6786 }
6787 
6788 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling) {
6789   bool null_free = k->as_array_klass()->is_elem_null_free();
6790   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));
6791 
6792   bool not_flat = !UseArrayFlattening || not_null_free || (k->as_array_klass()->element_klass() != nullptr &&
6793                                                      k->as_array_klass()->element_klass()->is_inlinetype() &&
6794                                                      !k->as_array_klass()->element_klass()->flat_in_array());
6795 
6796   return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, null_free);
6797 }
6798 
6799 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6800   return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling);
6801 }
6802 
6803 //------------------------------eq---------------------------------------------
6804 // Structural equality check for Type representations
6805 bool TypeAryKlassPtr::eq(const Type *t) const {
6806   const TypeAryKlassPtr *p = t->is_aryklassptr();
6807   return
6808     _elem == p->_elem &&  // Check array
6809     _not_flat == p->_not_flat &&
6810     _not_null_free == p->_not_null_free &&
6811     _null_free == p->_null_free &&
6812     TypeKlassPtr::eq(p);  // Check sub-parts
6813 }
6814 
6815 //------------------------------hash-------------------------------------------
6816 // Type-specific hashing function.
6817 uint TypeAryKlassPtr::hash(void) const {
6818   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6819       (uint)(_not_null_free ? 44 : 0) + (uint)(_null_free ? 45 : 0);
6820 }
6821 
6822 //----------------------compute_klass------------------------------------------
6823 // Compute the defining klass for this class
6824 ciKlass* TypeAryPtr::compute_klass() const {
6825   // Compute _klass based on element type.
6826   ciKlass* k_ary = nullptr;
6827   const TypeInstPtr *tinst;
6828   const TypeAryPtr *tary;
6829   const Type* el = elem();
6830   if (el->isa_narrowoop()) {
6831     el = el->make_ptr();
6832   }
6833 
6834   // Get element klass
6835   if (is_flat() && el->is_inlinetypeptr()) {
6836     // Klass is required by TypeAryPtr::flat_layout_helper() and others
6837     if (el->inline_klass() != nullptr) {
6838       k_ary = ciArrayKlass::make(el->inline_klass(), /* null_free */ true);
6839     }
6840   } else if ((tinst = el->isa_instptr()) != nullptr) {
6841     // Leave k_ary at nullptr.
6842   } else if ((tary = el->isa_aryptr()) != nullptr) {
6843     // Leave k_ary at nullptr.
6844   } else if ((el->base() == Type::Top) ||
6845              (el->base() == Type::Bottom)) {
6846     // element type of Bottom occurs from meet of basic type
6847     // and object; Top occurs when doing join on Bottom.
6848     // Leave k_ary at null.
6849   } else {
6850     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6851     // Compute array klass directly from basic type
6852     k_ary = ciTypeArrayKlass::make(el->basic_type());
6853   }
6854   return k_ary;
6855 }
6856 
6857 //------------------------------klass------------------------------------------
6858 // Return the defining klass for this class
6859 ciKlass* TypeAryPtr::klass() const {
6860   if( _klass ) return _klass;   // Return cached value, if possible
6861 
6862   // Oops, need to compute _klass and cache it
6863   ciKlass* k_ary = compute_klass();

6871     // type TypeAryPtr::OOPS.  This Type is shared between all
6872     // active compilations.  However, the ciKlass which represents
6873     // this Type is *not* shared between compilations, so caching
6874     // this value would result in fetching a dangling pointer.
6875     //
6876     // Recomputing the underlying ciKlass for each request is
6877     // a bit less efficient than caching, but calls to
6878     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6879     ((TypeAryPtr*)this)->_klass = k_ary;
6880   }
6881   return k_ary;
6882 }
6883 
6884 // Is there a single ciKlass* that can represent that type?
6885 ciKlass* TypeAryPtr::exact_klass_helper() const {
6886   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6887     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6888     if (k == nullptr) {
6889       return nullptr;
6890     }
6891     k = ciArrayKlass::make(k, is_null_free());
6892     return k;
6893   }
6894 
6895   return klass();
6896 }
6897 
6898 const Type* TypeAryPtr::base_element_type(int& dims) const {
6899   const Type* elem = this->elem();
6900   dims = 1;
6901   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6902     elem = elem->make_ptr()->is_aryptr()->elem();
6903     dims++;
6904   }
6905   return elem;
6906 }
6907 
6908 //------------------------------add_offset-------------------------------------
6909 // Access internals of klass object
6910 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6911   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6912 }
6913 
6914 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6915   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _null_free);
6916 }
6917 
6918 //------------------------------cast_to_ptr_type-------------------------------
6919 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6920   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6921   if (ptr == _ptr) return this;
6922   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _null_free);
6923 }
6924 
6925 bool TypeAryKlassPtr::must_be_exact() const {
6926   if (_elem == Type::BOTTOM) return false;
6927   if (_elem == Type::TOP   ) return false;
6928   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6929   if (!tk)             return true;   // a primitive type, like int
6930   // Even though MyValue is final, [LMyValue is only exact if the array
6931   // is null-free due to null-free [LMyValue <: null-able [LMyValue.
6932   if (tk->isa_instklassptr() && tk->klass()->is_inlinetype() && !is_null_free()) {
6933     return false;
6934   }
6935   return tk->must_be_exact();
6936 }
6937 
6938 
6939 //-----------------------------cast_to_exactness-------------------------------
6940 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6941   if (must_be_exact() && !klass_is_exact) return this;  // cannot clear xk
6942   if (klass_is_exact == this->klass_is_exact()) {
6943     return this;
6944   }
6945   ciKlass* k = _klass;
6946   const Type* elem = this->elem();
6947   if (elem->isa_klassptr() && !klass_is_exact) {
6948     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6949   }
6950   bool not_flat = is_not_flat();
6951   bool not_null_free = is_not_null_free();
6952   if (_elem->isa_klassptr()) {
6953     if (klass_is_exact || _elem->isa_aryklassptr()) {
6954       assert((!is_null_free() && !is_flat()) ||
6955              _elem->is_klassptr()->klass()->is_abstract() || _elem->is_klassptr()->klass()->is_java_lang_Object(),
6956              "null-free (or flat) concrete inline type arrays should always be exact");
6957       // An array can't be null-free (or flat) if the klass is exact
6958       not_null_free = true;
6959       not_flat = true;
6960     } else {
6961       // Klass is not exact (anymore), re-compute null-free/flat properties
6962       const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(_elem->is_instklassptr()->instance_klass());
6963       not_null_free = !exact_etype->can_be_inline_type();
6964       not_flat = !UseArrayFlattening || not_null_free || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->flat_in_array());
6965     }
6966   }
6967   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _null_free);
6968 }
6969 
6970 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_null_free() const {
6971   return make(_ptr, elem(), klass(), _offset, is_not_flat(), false, true);
6972 }
6973 
6974 //-----------------------------as_instance_type--------------------------------
6975 // Corresponding type for an instance of the given class.
6976 // It will be NotNull, and exact if and only if the klass type is exact.
6977 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6978   ciKlass* k = klass();
6979   bool    xk = klass_is_exact();
6980   const Type* el = nullptr;
6981   if (elem()->isa_klassptr()) {
6982     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6983     k = nullptr;
6984   } else {
6985     el = elem();
6986   }
6987   bool null_free = _null_free;
6988   if (null_free && el->isa_ptr()) {
6989     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6990   }
6991   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free()), k, xk, Offset(0));
6992 }
6993 
6994 
6995 //------------------------------xmeet------------------------------------------
6996 // Compute the MEET of two types, return a new Type object.
6997 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6998   // Perform a fast test for common case; meeting the same types together.
6999   if( this == t ) return this;  // Meeting same type-rep?
7000 
7001   // Current "this->_base" is Pointer
7002   switch (t->base()) {          // switch on original type
7003 
7004   case Int:                     // Mixing ints & oops happens when javac
7005   case Long:                    // reuses local variables
7006   case HalfFloatTop:
7007   case HalfFloatCon:
7008   case HalfFloatBot:
7009   case FloatTop:
7010   case FloatCon:
7011   case FloatBot:
7012   case DoubleTop:
7013   case DoubleCon:
7014   case DoubleBot:
7015   case NarrowOop:
7016   case NarrowKlass:
7017   case Bottom:                  // Ye Olde Default
7018     return Type::BOTTOM;
7019   case Top:
7020     return this;
7021 
7022   default:                      // All else is a mistake
7023     typerr(t);
7024 
7025   case AnyPtr: {                // Meeting to AnyPtrs
7026     // Found an AnyPtr type vs self-KlassPtr type
7027     const TypePtr *tp = t->is_ptr();
7028     Offset offset = meet_offset(tp->offset());
7029     PTR ptr = meet_ptr(tp->ptr());
7030     switch (tp->ptr()) {
7031     case TopPTR:
7032       return this;
7033     case Null:
7034       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
7035     case AnyNull:
7036       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_null_free());
7037     case BotPTR:
7038     case NotNull:
7039       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
7040     default: typerr(t);
7041     }
7042   }
7043 
7044   case RawPtr:
7045   case MetadataPtr:
7046   case OopPtr:
7047   case AryPtr:                  // Meet with AryPtr
7048   case InstPtr:                 // Meet with InstPtr
7049     return TypePtr::BOTTOM;
7050 
7051   //
7052   //             A-top         }
7053   //           /   |   \       }  Tops
7054   //       B-top A-any C-top   }
7055   //          | /  |  \ |      }  Any-nulls
7056   //       B-any   |   C-any   }
7057   //          |    |    |
7058   //       B-con A-con C-con   } constants; not comparable across classes
7059   //          |    |    |
7060   //       B-not   |   C-not   }
7061   //          | \  |  / |      }  not-nulls
7062   //       B-bot A-not C-bot   }
7063   //           \   |   /       }  Bottoms
7064   //             A-bot         }
7065   //
7066 
7067   case AryKlassPtr: {  // Meet two KlassPtr types
7068     const TypeAryKlassPtr *tap = t->is_aryklassptr();
7069     Offset off = meet_offset(tap->offset());
7070     const Type* elem = _elem->meet(tap->_elem);

7071     PTR ptr = meet_ptr(tap->ptr());
7072     ciKlass* res_klass = nullptr;
7073     bool res_xk = false;
7074     bool res_flat = false;
7075     bool res_not_flat = false;
7076     bool res_not_null_free = false;
7077     MeetResult res = meet_aryptr(ptr, elem, this, tap,
7078                                  res_klass, res_xk, res_flat, res_not_flat, res_not_null_free);
7079     assert(res_xk == (ptr == Constant), "");
7080     bool null_free = meet_null_free(tap->_null_free);
7081     if (res == NOT_SUBTYPE) {
7082       null_free = false;
7083     } else if (res == SUBTYPE) {
7084       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
7085         null_free = _null_free;
7086       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
7087         null_free = tap->_null_free;
7088       } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
7089         null_free = _null_free || tap->_null_free;
7090       }
7091     }
7092     return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, null_free);
7093   } // End of case KlassPtr
7094   case InstKlassPtr: {
7095     const TypeInstKlassPtr *tp = t->is_instklassptr();
7096     Offset offset = meet_offset(tp->offset());
7097     PTR ptr = meet_ptr(tp->ptr());
7098     const TypeInterfaces* interfaces = meet_interfaces(tp);
7099     const TypeInterfaces* tp_interfaces = tp->_interfaces;
7100     const TypeInterfaces* this_interfaces = _interfaces;
7101 
7102     switch (ptr) {
7103     case TopPTR:
7104     case AnyNull:                // Fall 'down' to dual of object klass
7105       // For instances when a subclass meets a superclass we fall
7106       // below the centerline when the superclass is exact. We need to
7107       // do the same here.
7108       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7109           !tp->klass_is_exact()) {
7110         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
7111       } else {
7112         // cannot subclass, so the meet has to fall badly below the centerline
7113         ptr = NotNull;
7114         interfaces = this_interfaces->intersection_with(tp->_interfaces);
7115         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
7116       }
7117     case Constant:
7118     case NotNull:
7119     case BotPTR:                // Fall down to object klass
7120       // LCA is object_klass, but if we subclass from the top we can do better
7121       if (above_centerline(tp->ptr())) {
7122         // If 'tp'  is above the centerline and it is Object class
7123         // then we can subclass in the Java class hierarchy.
7124         // For instances when a subclass meets a superclass we fall
7125         // below the centerline when the superclass is exact. We need
7126         // to do the same here.
7127         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7128             !tp->klass_is_exact()) {
7129           // that is, my array type is a subtype of 'tp' klass
7130           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_null_free());
7131         }
7132       }
7133       // The other case cannot happen, since t cannot be a subtype of an array.
7134       // The meet falls down to Object class below centerline.
7135       if (ptr == Constant)
7136          ptr = NotNull;
7137       interfaces = this_interfaces->intersection_with(tp_interfaces);
7138       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
7139     default: typerr(t);
7140     }
7141   }
7142 
7143   } // End of switch
7144   return this;                  // Return the double constant
7145 }
7146 
7147 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) {
7148   static_assert(std::is_base_of<T2, T1>::value, "");
7149 
7150   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7151     return true;
7152   }
7153 
7154   int dummy;
7155   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7156 
7157   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7158     return false;
7159   }
7160 
7161   if (this_one->is_instance_type(other)) {
7162     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7163            other_exact;
7164   }
7165 
7166   assert(this_one->is_array_type(other), "");
7167   const T1* other_ary = this_one->is_array_type(other);
7168   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7169   if (other_top_or_bottom) {
7170     return false;
7171   }
7172 
7173   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7174   const TypePtr* this_elem = this_one->elem()->make_ptr();
7175   if (this_elem != nullptr && other_elem != nullptr) {
7176     if (other->is_null_free() && !this_one->is_null_free()) {
7177       return false; // A nullable array can't be a subtype of a null-free array
7178     }
7179     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7180   }
7181   if (this_elem == nullptr && other_elem == nullptr) {
7182     return this_one->klass()->is_subtype_of(other->klass());
7183   }
7184   return false;
7185 }
7186 
7187 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7188   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7189 }
7190 
7191 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7192   static_assert(std::is_base_of<T2, T1>::value, "");
7193 
7194   int dummy;
7195   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7196 
7197   if (!this_one->is_array_type(other) ||
7198       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

7251   }
7252 
7253   const TypePtr* this_elem = this_one->elem()->make_ptr();
7254   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7255   if (other_elem != nullptr && this_elem != nullptr) {
7256     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7257   }
7258   if (other_elem == nullptr && this_elem == nullptr) {
7259     return this_one->klass()->is_subtype_of(other->klass());
7260   }
7261   return false;
7262 }
7263 
7264 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7265   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7266 }
7267 
7268 //------------------------------xdual------------------------------------------
7269 // Dual: compute field-by-field dual
7270 const Type    *TypeAryKlassPtr::xdual() const {
7271   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_null_free());
7272 }
7273 
7274 // Is there a single ciKlass* that can represent that type?
7275 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7276   if (elem()->isa_klassptr()) {
7277     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7278     if (k == nullptr) {
7279       return nullptr;
7280     }
7281     k = ciArrayKlass::make(k, _null_free);
7282     return k;
7283   }
7284 
7285   return klass();
7286 }
7287 
7288 ciKlass* TypeAryKlassPtr::klass() const {
7289   if (_klass != nullptr) {
7290     return _klass;
7291   }
7292   ciKlass* k = nullptr;
7293   if (elem()->isa_klassptr()) {
7294     // leave null
7295   } else if ((elem()->base() == Type::Top) ||
7296              (elem()->base() == Type::Bottom)) {
7297   } else {
7298     k = ciTypeArrayKlass::make(elem()->basic_type());
7299     ((TypeAryKlassPtr*)this)->_klass = k;
7300   }
7301   return k;

7308   switch( _ptr ) {
7309   case Constant:
7310     st->print("precise ");
7311   case NotNull:
7312     {
7313       st->print("[");
7314       _elem->dump2(d, depth, st);
7315       _interfaces->dump(st);
7316       st->print(": ");
7317     }
7318   case BotPTR:
7319     if( !WizardMode && !Verbose && _ptr != Constant ) break;
7320   case TopPTR:
7321   case AnyNull:
7322     st->print(":%s", ptr_msg[_ptr]);
7323     if( _ptr == Constant ) st->print(":exact");
7324     break;
7325   default:
7326     break;
7327   }
7328   if (is_flat()) st->print(":flat");
7329   if (_null_free) st->print(":null free");
7330   if (Verbose) {
7331     if (_not_flat) st->print(":not flat");
7332     if (_not_null_free) st->print(":not null free");
7333   }
7334 
7335   _offset.dump2(st);
7336 
7337   st->print(" *");
7338 }
7339 #endif
7340 
7341 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7342   const Type* elem = this->elem();
7343   dims = 1;
7344   while (elem->isa_aryklassptr()) {
7345     elem = elem->is_aryklassptr()->elem();
7346     dims++;
7347   }
7348   return elem;
7349 }
7350 
7351 //=============================================================================
7352 // Convenience common pre-built types.
7353 
7354 //------------------------------make-------------------------------------------
7355 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7356                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
7357   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7358 }
7359 
7360 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7361   return make(domain, domain, range, range);
7362 }
7363 
7364 //------------------------------osr_domain-----------------------------
7365 const TypeTuple* osr_domain() {
7366   const Type **fields = TypeTuple::fields(2);
7367   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
7368   return TypeTuple::make(TypeFunc::Parms+1, fields);
7369 }
7370 
7371 //------------------------------make-------------------------------------------
7372 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7373   Compile* C = Compile::current();
7374   const TypeFunc* tf = nullptr;
7375   if (!is_osr_compilation) {
7376     tf = C->last_tf(method); // check cache
7377     if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
7378   }
7379   // Inline types are not passed/returned by reference, instead each field of
7380   // the inline type is passed/returned as an argument. We maintain two views of
7381   // the argument/return list here: one based on the signature (with an inline
7382   // type argument/return as a single slot), one based on the actual calling
7383   // convention (with an inline type argument/return as a list of its fields).
7384   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7385   // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7386   if (method != C->method() && method->get_Method()->mismatch()) {
7387     has_scalar_args = false;
7388   }
7389   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7390   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7391   ciSignature* sig = method->signature();
7392   bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7393   const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7394   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7395   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7396   if (!is_osr_compilation) {
7397     C->set_last_tf(method, tf);  // fill cache
7398   }



7399   return tf;
7400 }
7401 
7402 //------------------------------meet-------------------------------------------
7403 // Compute the MEET of two types.  It returns a new Type object.
7404 const Type *TypeFunc::xmeet( const Type *t ) const {
7405   // Perform a fast test for common case; meeting the same types together.
7406   if( this == t ) return this;  // Meeting same type-rep?
7407 
7408   // Current "this->_base" is Func
7409   switch (t->base()) {          // switch on original type
7410 
7411   case Bottom:                  // Ye Olde Default
7412     return t;
7413 
7414   default:                      // All else is a mistake
7415     typerr(t);
7416 
7417   case Top:
7418     break;
7419   }
7420   return this;                  // Return the double constant
7421 }
7422 
7423 //------------------------------xdual------------------------------------------
7424 // Dual: compute field-by-field dual
7425 const Type *TypeFunc::xdual() const {
7426   return this;
7427 }
7428 
7429 //------------------------------eq---------------------------------------------
7430 // Structural equality check for Type representations
7431 bool TypeFunc::eq( const Type *t ) const {
7432   const TypeFunc *a = (const TypeFunc*)t;
7433   return _domain_sig == a->_domain_sig &&
7434     _domain_cc == a->_domain_cc &&
7435     _range_sig == a->_range_sig &&
7436     _range_cc == a->_range_cc;
7437 }
7438 
7439 //------------------------------hash-------------------------------------------
7440 // Type-specific hashing function.
7441 uint TypeFunc::hash(void) const {
7442   return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7443 }
7444 
7445 //------------------------------dump2------------------------------------------
7446 // Dump Function Type
7447 #ifndef PRODUCT
7448 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7449   if( _range_sig->cnt() <= Parms )
7450     st->print("void");
7451   else {
7452     uint i;
7453     for (i = Parms; i < _range_sig->cnt()-1; i++) {
7454       _range_sig->field_at(i)->dump2(d,depth,st);
7455       st->print("/");
7456     }
7457     _range_sig->field_at(i)->dump2(d,depth,st);
7458   }
7459   st->print(" ");
7460   st->print("( ");
7461   if( !depth || d[this] ) {     // Check for recursive dump
7462     st->print("...)");
7463     return;
7464   }
7465   d.Insert((void*)this,(void*)this);    // Stop recursion
7466   if (Parms < _domain_sig->cnt())
7467     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7468   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7469     st->print(", ");
7470     _domain_sig->field_at(i)->dump2(d,depth-1,st);
7471   }
7472   st->print(" )");
7473 }
7474 #endif
7475 
7476 //------------------------------singleton--------------------------------------
7477 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
7478 // constants (Ldi nodes).  Singletons are integer, float or double constants
7479 // or a single symbol.
7480 bool TypeFunc::singleton(void) const {
7481   return false;                 // Never a singleton
7482 }
7483 
7484 bool TypeFunc::empty(void) const {
7485   return false;                 // Never empty
7486 }
7487 
7488 
7489 BasicType TypeFunc::return_type() const{
7490   if (range_sig()->cnt() == TypeFunc::Parms) {
7491     return T_VOID;
7492   }
7493   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7494 }
< prev index next >