< 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 
1014 #ifdef ASSERT
1015   Compile* C = Compile::current();
1016   VerifyMeet verify(C);
1017 #endif
1018 
1019   const Type *this_t = maybe_remove_speculative(include_speculative);
1020   t = t->maybe_remove_speculative(include_speculative);
1021 
1022   const Type *mt = this_t->xmeet(t);
1023 #ifdef ASSERT
1024   verify.add(this_t, t, mt);
1025   if (isa_narrowoop() || t->isa_narrowoop()) {
1026     return mt;
1027   }
1028   if (isa_narrowklass() || t->isa_narrowklass()) {
1029     return mt;
1030   }



1031   this_t->check_symmetrical(t, mt, verify);
1032   const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1033   this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1034 #endif
1035   return mt;
1036 }
1037 
1038 //------------------------------xmeet------------------------------------------
1039 // Compute the MEET of two types.  It returns a new Type object.
1040 const Type *Type::xmeet( const Type *t ) const {
1041   // Perform a fast test for common case; meeting the same types together.
1042   if( this == t ) return this;  // Meeting same type-rep?
1043 
1044   // Meeting TOP with anything?
1045   if( _base == Top ) return t;
1046 
1047   // Meeting BOTTOM with anything?
1048   if( _base == Bottom ) return BOTTOM;
1049 
1050   // Current "this->_base" is one of: Bad, Multi, Control, Top,

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





















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





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












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








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

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








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

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

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

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



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




2580 }
2581 
2582 //------------------------------hash-------------------------------------------
2583 // Type-specific hashing function.
2584 uint TypeAry::hash(void) const {
2585   return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);

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





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











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

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

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

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

3675 #endif
3676 
3677 // Can't be implemented because there's no way to know if the type is above or below the center line.
3678 const Type* TypeInterfaces::xmeet(const Type* t) const {
3679   ShouldNotReachHere();
3680   return Type::xmeet(t);
3681 }
3682 
3683 bool TypeInterfaces::singleton(void) const {
3684   ShouldNotReachHere();
3685   return Type::singleton();
3686 }
3687 
3688 bool TypeInterfaces::has_non_array_interface() const {
3689   assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3690 
3691   return !TypeAryPtr::_array_interfaces->contains(this);
3692 }
3693 
3694 //------------------------------TypeOopPtr-------------------------------------
3695 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3696                        int instance_id, const TypePtr* speculative, int inline_depth)
3697   : TypePtr(t, ptr, offset, speculative, inline_depth),
3698     _const_oop(o), _klass(k),
3699     _interfaces(interfaces),
3700     _klass_is_exact(xk),
3701     _is_ptr_to_narrowoop(false),
3702     _is_ptr_to_narrowklass(false),
3703     _is_ptr_to_boxed_value(false),
3704     _instance_id(instance_id) {
3705 #ifdef ASSERT
3706   if (klass() != nullptr && klass()->is_loaded()) {
3707     interfaces->verify_is_loaded();
3708   }
3709 #endif
3710   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3711       (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3712     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3713   }
3714 #ifdef _LP64
3715   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3716     if (_offset == oopDesc::klass_offset_in_bytes()) {
3717       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3718     } else if (klass() == nullptr) {
3719       // Array with unknown body type
3720       assert(this->isa_aryptr(), "only arrays without klass");
3721       _is_ptr_to_narrowoop = UseCompressedOops;
3722     } else if (this->isa_aryptr()) {
3723       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3724                              _offset != arrayOopDesc::length_offset_in_bytes());









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

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

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

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









3941     // We used to pass NotNull in here, asserting that the sub-arrays
3942     // are all not-null.  This is not true in generally, as code can
3943     // slam nulls down in the subarrays.
3944     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3945     return arr;
3946   } else if (klass->is_type_array_klass()) {
3947     // Element is an typeArray
3948     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3949     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

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








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





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
















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

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

4194 const TypeInstPtr *TypeInstPtr::BOTTOM;
4195 const TypeInstPtr *TypeInstPtr::MIRROR;
4196 const TypeInstPtr *TypeInstPtr::MARK;
4197 const TypeInstPtr *TypeInstPtr::KLASS;
4198 
4199 // Is there a single ciKlass* that can represent that type?
4200 ciKlass* TypeInstPtr::exact_klass_helper() const {
4201   if (_interfaces->empty()) {
4202     return _klass;
4203   }
4204   if (_klass != ciEnv::current()->Object_klass()) {
4205     if (_interfaces->eq(_klass->as_instance_klass())) {
4206       return _klass;
4207     }
4208     return nullptr;
4209   }
4210   return _interfaces->exact_klass();
4211 }
4212 
4213 //------------------------------TypeInstPtr-------------------------------------
4214 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
4215                          int instance_id, const TypePtr* speculative, int inline_depth)
4216   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {

4217   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4218   assert(k != nullptr &&
4219          (k->is_loaded() || o == nullptr),
4220          "cannot have constants with non-loaded klass");


4221 };
4222 
4223 //------------------------------make-------------------------------------------
4224 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4225                                      ciKlass* k,
4226                                      const TypeInterfaces* interfaces,
4227                                      bool xk,
4228                                      ciObject* o,
4229                                      int offset,

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



4251   // Now hash this baby
4252   TypeInstPtr *result =
4253     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4254 
4255   return result;
4256 }
4257 
4258 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4259   if (k->is_instance_klass()) {
4260     if (k->is_loaded()) {
4261       if (k->is_interface() && interface_handling == ignore_interfaces) {
4262         assert(interface, "no interface expected");
4263         k = ciEnv::current()->Object_klass();
4264         const TypeInterfaces* interfaces = TypeInterfaces::make();
4265         return interfaces;
4266       }
4267       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4268       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4269       if (k->is_interface()) {
4270         assert(interface, "no interface expected");
4271         k = ciEnv::current()->Object_klass();
4272       } else {
4273         assert(klass, "no instance klass expected");

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

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

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





4566   bool this_xk = this_type->klass_is_exact();
4567   bool other_xk = other_type->klass_is_exact();
4568   PTR this_ptr = this_type->ptr();
4569   PTR other_ptr = other_type->ptr();
4570   const TypeInterfaces* this_interfaces = this_type->interfaces();
4571   const TypeInterfaces* other_interfaces = other_type->interfaces();
4572   // Check for easy case; klasses are equal (and perhaps not loaded!)
4573   // If we have constants, then we created oops so classes are loaded
4574   // and we can handle the constants further down.  This case handles
4575   // both-not-loaded or both-loaded classes
4576   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4577     res_klass = this_klass;
4578     res_xk = this_xk;

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
























































4612   const T* subtype = nullptr;
4613   bool subtype_exact = false;


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

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





4618     subtype = this_type;     // Pick subtyping class
4619     subtype_exact = this_xk;
4620   } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {








4621     subtype = other_type;    // Pick subtyping class
4622     subtype_exact = other_xk;








4623   }
4624 
4625   if (subtype) {
4626     if (above_centerline(ptr)) { // both are up?


4627       this_type = other_type = subtype;
4628       this_xk = other_xk = subtype_exact;





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

4631       this_xk = other_xk;

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

4633       other_type = this_type; // this is down; keep down man
4634       other_xk = this_xk;
4635     } else {

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



4637     }
4638   }
4639 
4640   // Check for classes now being equal
4641   if (this_type->is_same_java_type_as(other_type)) {
4642     // If the klasses are equal, the constants may still differ.  Fall to
4643     // NotNull if they do (neither constant is null; that is a special case
4644     // handled elsewhere).
4645     res_klass = this_type->klass();
4646     res_xk = this_xk;

4647     return SUBTYPE;
4648   } // Else classes are not equal
4649 
4650   // Since klasses are different, we require a LCA in the Java
4651   // class hierarchy - which means we have to fall to at least NotNull.
4652   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4653     ptr = NotNull;
4654   }
4655 
4656   interfaces = this_interfaces->intersection_with(other_interfaces);
4657 
4658   // Now we find the LCA of Java classes
4659   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4660 
4661   res_klass = k;
4662   res_xk = false;

4663 
4664   return LCA;
4665 }
4666 




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

4692     _interfaces->eq(p->_interfaces) &&
4693     TypeOopPtr::eq(p);          // Check sub-type stuff
4694 }
4695 
4696 //------------------------------hash-------------------------------------------
4697 // Type-specific hashing function.
4698 uint TypeInstPtr::hash(void) const {
4699   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4700 }
4701 
4702 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4703   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4704 }
4705 
4706 
4707 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4708   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4709 }
4710 
4711 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4712   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4713 }
4714 
4715 
4716 //------------------------------dump2------------------------------------------
4717 // Dump oop Type
4718 #ifndef PRODUCT
4719 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {

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





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




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

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

4895 
4896 //------------------------------make-------------------------------------------
4897 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4898                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4899   assert(!(k == nullptr && ary->_elem->isa_int()),
4900          "integral arrays must be pre-equipped with a class");
4901   if (!xk)  xk = ary->ary_must_be_exact();
4902   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4903   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4904       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4905     k = nullptr;
4906   }
4907   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4908 }
4909 
4910 //------------------------------make-------------------------------------------
4911 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4912                                    int instance_id, const TypePtr* speculative, int inline_depth,
4913                                    bool is_autobox_cache) {
4914   assert(!(k == nullptr && ary->_elem->isa_int()),
4915          "integral arrays must be pre-equipped with a class");
4916   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4917   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
4918   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4919   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4920       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4921     k = nullptr;
4922   }
4923   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4924 }
4925 
4926 //------------------------------cast_to_ptr_type-------------------------------
4927 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4928   if( ptr == _ptr ) return this;
4929   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4930 }
4931 
4932 
4933 //-----------------------------cast_to_exactness-------------------------------
4934 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4935   if( klass_is_exact == _klass_is_exact ) return this;
4936   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4937   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4938 }
4939 
4940 //-----------------------------cast_to_instance_id----------------------------
4941 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4942   if( instance_id == _instance_id ) return this;
4943   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4944 }
4945 
4946 
4947 //-----------------------------max_array_length-------------------------------
4948 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4949 jint TypeAryPtr::max_array_length(BasicType etype) {
4950   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4951     if (etype == T_NARROWOOP) {
4952       etype = T_OBJECT;
4953     } else if (etype == T_ILLEGAL) { // bottom[]
4954       etype = T_BYTE; // will produce conservatively high value
4955     } else {
4956       fatal("not an element type: %s", type2name(etype));
4957     }
4958   }
4959   return arrayOopDesc::max_array_length(etype);
4960 }
4961 
4962 //-----------------------------narrow_size_type-------------------------------
4963 // Narrow the given size type to the index range for the given array base type.

4979   if (hi > max_hi) {
4980     hi = max_hi;
4981     if (size->is_con()) {
4982       lo = hi;
4983     }
4984     chg = true;
4985   }
4986   // Negative length arrays will produce weird intermediate dead fast-path code
4987   if (lo > hi)
4988     return TypeInt::ZERO;
4989   if (!chg)
4990     return size;
4991   return TypeInt::make(lo, hi, Type::WidenMin);
4992 }
4993 
4994 //-------------------------------cast_to_size----------------------------------
4995 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4996   assert(new_size != nullptr, "");
4997   new_size = narrow_size_type(new_size);
4998   if (new_size == size())  return this;
4999   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
5000   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);































































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

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

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

5155     const TypeAry *tary = _ary->meet_speculative(tap->_ary)->is_ary();
5156     PTR ptr = meet_ptr(tap->ptr());
5157     int instance_id = meet_instance_id(tap->instance_id());
5158     const TypePtr* speculative = xmeet_speculative(tap);
5159     int depth = meet_inline_depth(tap->inline_depth());
5160 
5161     ciKlass* res_klass = nullptr;
5162     bool res_xk = false;



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














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






5258   res_klass = nullptr;
5259   MeetResult result = SUBTYPE;





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

5287          // 'tap'  is exact and super or unrelated:
5288          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5289          // 'this' is exact and super or unrelated:
5290          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5291       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5292         elem = Type::BOTTOM;
5293       }
5294       ptr = NotNull;
5295       res_xk = false;
5296       return NOT_SUBTYPE;
5297     }
5298   }
5299 
5300   res_xk = false;
5301   switch (other_ptr) {
5302     case AnyNull:
5303     case TopPTR:
5304       // Compute new klass on demand, do not use tap->_klass
5305       if (below_centerline(this_ptr)) {
5306         res_xk = this_xk;



5307       } else {
5308         res_xk = (other_xk || this_xk);
5309       }
5310       return result;
5311     case Constant: {
5312       if (this_ptr == Constant) {
5313         res_xk = true;
5314       } else if(above_centerline(this_ptr)) {
5315         res_xk = true;
5316       } else {
5317         // Only precise for identical arrays
5318         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));





5319       }
5320       return result;
5321     }
5322     case NotNull:
5323     case BotPTR:
5324       // Compute new klass on demand, do not use tap->_klass
5325       if (above_centerline(this_ptr)) {
5326         res_xk = other_xk;



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







5330       }
5331       return result;
5332     default:  {
5333       ShouldNotReachHere();
5334       return result;
5335     }
5336   }
5337   return result;
5338 }
5339 
5340 
5341 //------------------------------xdual------------------------------------------
5342 // Dual: compute field-by-field dual
5343 const Type *TypeAryPtr::xdual() const {
5344   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());










5345 }
5346 
5347 //------------------------------dump2------------------------------------------
5348 #ifndef PRODUCT
5349 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5350   _ary->dump2(d,depth,st);
5351   _interfaces->dump(st);
5352 
5353   switch( _ptr ) {
5354   case Constant:
5355     const_oop()->print(st);
5356     break;
5357   case BotPTR:
5358     if (!WizardMode && !Verbose) {
5359       if( _klass_is_exact ) st->print(":exact");
5360       break;
5361     }
5362   case TopPTR:
5363   case AnyNull:
5364   case NotNull:
5365     st->print(":%s", ptr_msg[_ptr]);
5366     if( _klass_is_exact ) st->print(":exact");
5367     break;
5368   default:
5369     break;
5370   }
5371 
5372   if( _offset != 0 ) {









5373     BasicType basic_elem_type = elem()->basic_type();
5374     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5375     if( _offset == OffsetTop )       st->print("+undefined");
5376     else if( _offset == OffsetBot )  st->print("+any");
5377     else if( _offset < header_size ) st->print("+%d", _offset);
5378     else {
5379       if (basic_elem_type == T_ILLEGAL) {
5380         st->print("+any");
5381       } else {
5382         int elem_size = type2aelembytes(basic_elem_type);
5383         st->print("[%d]", (_offset - header_size)/elem_size);
5384       }
5385     }
5386   }
5387   st->print(" *");
5388   if (_instance_id == InstanceTop)
5389     st->print(",iid=top");
5390   else if (_instance_id != InstanceBot)
5391     st->print(",iid=%d",_instance_id);
5392 
5393   dump_inline_depth(st);
5394   dump_speculative(st);
5395 }
5396 #endif
5397 
5398 bool TypeAryPtr::empty(void) const {
5399   if (_ary->empty())       return true;




5400   return TypeOopPtr::empty();
5401 }
5402 
5403 //------------------------------add_offset-------------------------------------
5404 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5405   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5406 }
5407 
5408 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5409   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5410 }
5411 
5412 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5413   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5414 }
5415 
5416 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5417   if (_speculative == nullptr) {
5418     return this;
5419   }
5420   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5421   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);













5422 }
5423 
5424 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5425   if (!UseInlineDepthForSpeculativeTypes) {
5426     return this;
5427   }
5428   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);











































5429 }
5430 
5431 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5432   assert(is_known_instance(), "should be known");
5433   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5434 }
5435 
5436 //=============================================================================
5437 

5438 //------------------------------hash-------------------------------------------
5439 // Type-specific hashing function.
5440 uint TypeNarrowPtr::hash(void) const {
5441   return _ptrtype->hash() + 7;
5442 }
5443 
5444 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5445   return _ptrtype->singleton();
5446 }
5447 
5448 bool TypeNarrowPtr::empty(void) const {
5449   return _ptrtype->empty();
5450 }
5451 
5452 intptr_t TypeNarrowPtr::get_con() const {
5453   return _ptrtype->get_con();
5454 }
5455 
5456 bool TypeNarrowPtr::eq( const Type *t ) const {
5457   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

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

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

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





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

5912   case NotNull:
5913     {
5914       const char *name = klass()->name()->as_utf8();
5915       if (name) {
5916         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5917       } else {
5918         ShouldNotReachHere();
5919       }
5920       _interfaces->dump(st);
5921     }
5922   case BotPTR:
5923     if (!WizardMode && !Verbose && _ptr != Constant) break;
5924   case TopPTR:
5925   case AnyNull:
5926     st->print(":%s", ptr_msg[_ptr]);
5927     if (_ptr == Constant) st->print(":exact");
5928     break;
5929   default:
5930     break;
5931   }
5932 
5933   if (_offset) {               // Dump offset, if any
5934     if (_offset == OffsetBot)      { st->print("+any"); }
5935     else if (_offset == OffsetTop) { st->print("+unknown"); }
5936     else                            { st->print("+%d", _offset); }
5937   }
5938 
5939   st->print(" *");




5940 }
5941 #endif
5942 
5943 //=============================================================================
5944 // Convenience common pre-built types.
5945 
5946 // Not-null object klass or below
5947 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5948 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5949 
5950 bool TypeInstKlassPtr::eq(const Type *t) const {
5951   const TypeKlassPtr *p = t->is_klassptr();
5952   return
5953     klass()->equals(p->klass()) &&

5954     TypeKlassPtr::eq(p);
5955 }
5956 
5957 uint TypeInstKlassPtr::hash(void) const {
5958   return klass()->hash() + TypeKlassPtr::hash();
5959 }
5960 
5961 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {


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

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

6277   const TypeInterfaces* interfaces = _interfaces;
6278   if (k->is_loaded()) {
6279     ciInstanceKlass* ik = k->as_instance_klass();
6280     bool klass_is_exact = ik->is_final();
6281     if (!klass_is_exact &&
6282         deps != nullptr) {
6283       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6284       if (sub != nullptr) {
6285         if (_interfaces->eq(sub)) {
6286           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6287           k = ik = sub;
6288           klass_is_exact = sub->is_final();
6289           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6290         }
6291       }
6292     }
6293   }
6294   return this;
6295 }
6296 











6297 
6298 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6299   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6300 }
6301 
6302 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {




6303   if (k->is_obj_array_klass()) {
6304     // Element is an object array. Recursively call ourself.
6305     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6306     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6307     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6308   } else if (k->is_type_array_klass()) {
6309     // Element is an typeArray
6310     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6311     return TypeAryKlassPtr::make(ptr, etype, k, offset);




6312   } else {
6313     ShouldNotReachHere();
6314     return nullptr;
6315   }
6316 }
6317 














6318 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6319   return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);
6320 }
6321 
6322 //------------------------------eq---------------------------------------------
6323 // Structural equality check for Type representations
6324 bool TypeAryKlassPtr::eq(const Type *t) const {
6325   const TypeAryKlassPtr *p = t->is_aryklassptr();
6326   return
6327     _elem == p->_elem &&  // Check array




6328     TypeKlassPtr::eq(p);  // Check sub-parts
6329 }
6330 
6331 //------------------------------hash-------------------------------------------
6332 // Type-specific hashing function.
6333 uint TypeAryKlassPtr::hash(void) const {
6334   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();

6335 }
6336 
6337 //----------------------compute_klass------------------------------------------
6338 // Compute the defining klass for this class
6339 ciKlass* TypeAryPtr::compute_klass() const {
6340   // Compute _klass based on element type.
6341   ciKlass* k_ary = nullptr;
6342   const TypeInstPtr *tinst;
6343   const TypeAryPtr *tary;
6344   const Type* el = elem();
6345   if (el->isa_narrowoop()) {
6346     el = el->make_ptr();
6347   }
6348 
6349   // Get element klass
6350   if ((tinst = el->isa_instptr()) != nullptr) {
6351     // Leave k_ary at null.







6352   } else if ((tary = el->isa_aryptr()) != nullptr) {
6353     // Leave k_ary at null.
6354   } else if ((el->base() == Type::Top) ||
6355              (el->base() == Type::Bottom)) {
6356     // element type of Bottom occurs from meet of basic type
6357     // and object; Top occurs when doing join on Bottom.
6358     // Leave k_ary at null.
6359   } else {
6360     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6361     // Compute array klass directly from basic type
6362     k_ary = ciTypeArrayKlass::make(el->basic_type());
6363   }
6364   return k_ary;
6365 }
6366 
6367 //------------------------------klass------------------------------------------
6368 // Return the defining klass for this class
6369 ciKlass* TypeAryPtr::klass() const {
6370   if( _klass ) return _klass;   // Return cached value, if possible
6371 
6372   // Oops, need to compute _klass and cache it
6373   ciKlass* k_ary = compute_klass();

6381     // type TypeAryPtr::OOPS.  This Type is shared between all
6382     // active compilations.  However, the ciKlass which represents
6383     // this Type is *not* shared between compilations, so caching
6384     // this value would result in fetching a dangling pointer.
6385     //
6386     // Recomputing the underlying ciKlass for each request is
6387     // a bit less efficient than caching, but calls to
6388     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6389     ((TypeAryPtr*)this)->_klass = k_ary;
6390   }
6391   return k_ary;
6392 }
6393 
6394 // Is there a single ciKlass* that can represent that type?
6395 ciKlass* TypeAryPtr::exact_klass_helper() const {
6396   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6397     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6398     if (k == nullptr) {
6399       return nullptr;
6400     }
6401     k = ciObjArrayKlass::make(k);
6402     return k;
6403   }
6404 
6405   return klass();
6406 }
6407 
6408 const Type* TypeAryPtr::base_element_type(int& dims) const {
6409   const Type* elem = this->elem();
6410   dims = 1;
6411   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6412     elem = elem->make_ptr()->is_aryptr()->elem();
6413     dims++;
6414   }
6415   return elem;
6416 }
6417 
6418 //------------------------------add_offset-------------------------------------
6419 // Access internals of klass object
6420 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6421   return make(_ptr, elem(), klass(), xadd_offset(offset));
6422 }
6423 
6424 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6425   return make(_ptr, elem(), klass(), offset);
6426 }
6427 
6428 //------------------------------cast_to_ptr_type-------------------------------
6429 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6430   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6431   if (ptr == _ptr) return this;
6432   return make(ptr, elem(), _klass, _offset);
6433 }
6434 
6435 bool TypeAryKlassPtr::must_be_exact() const {
6436   if (_elem == Type::BOTTOM) return false;
6437   if (_elem == Type::TOP   ) return false;
6438   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6439   if (!tk)             return true;   // a primitive type, like int







6440   return tk->must_be_exact();
6441 }
6442 
6443 
6444 //-----------------------------cast_to_exactness-------------------------------
6445 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6446   if (must_be_exact()) return this;  // cannot clear xk



6447   ciKlass* k = _klass;
6448   const Type* elem = this->elem();
6449   if (elem->isa_klassptr() && !klass_is_exact) {
6450     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6451   }
6452   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);


















6453 }
6454 



6455 
6456 //-----------------------------as_instance_type--------------------------------
6457 // Corresponding type for an instance of the given class.
6458 // It will be NotNull, and exact if and only if the klass type is exact.
6459 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6460   ciKlass* k = klass();
6461   bool    xk = klass_is_exact();
6462   const Type* el = nullptr;
6463   if (elem()->isa_klassptr()) {
6464     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6465     k = nullptr;
6466   } else {
6467     el = elem();
6468   }
6469   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);




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




6554     assert(res_xk == (ptr == Constant), "");
6555     return make(ptr, elem, res_klass, off);

















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



6639     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6640   }
6641   if (this_elem == nullptr && other_elem == nullptr) {
6642     return this_one->klass()->is_subtype_of(other->klass());
6643   }
6644   return false;
6645 }
6646 
6647 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6648   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6649 }
6650 
6651 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6652   static_assert(std::is_base_of<T2, T1>::value, "");
6653 
6654   int dummy;
6655   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6656 
6657   if (!this_one->is_array_type(other) ||
6658       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

6711   }
6712 
6713   const TypePtr* this_elem = this_one->elem()->make_ptr();
6714   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6715   if (other_elem != nullptr && this_elem != nullptr) {
6716     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6717   }
6718   if (other_elem == nullptr && this_elem == nullptr) {
6719     return this_one->klass()->is_subtype_of(other->klass());
6720   }
6721   return false;
6722 }
6723 
6724 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6725   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6726 }
6727 
6728 //------------------------------xdual------------------------------------------
6729 // Dual: compute field-by-field dual
6730 const Type    *TypeAryKlassPtr::xdual() const {
6731   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6732 }
6733 
6734 // Is there a single ciKlass* that can represent that type?
6735 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6736   if (elem()->isa_klassptr()) {
6737     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6738     if (k == nullptr) {
6739       return nullptr;
6740     }
6741     k = ciObjArrayKlass::make(k);





6742     return k;
6743   }
6744 
6745   return klass();
6746 }
6747 
6748 ciKlass* TypeAryKlassPtr::klass() const {
6749   if (_klass != nullptr) {
6750     return _klass;
6751   }
6752   ciKlass* k = nullptr;
6753   if (elem()->isa_klassptr()) {
6754     // leave null
6755   } else if ((elem()->base() == Type::Top) ||
6756              (elem()->base() == Type::Bottom)) {
6757   } else {
6758     k = ciTypeArrayKlass::make(elem()->basic_type());
6759     ((TypeAryKlassPtr*)this)->_klass = k;
6760   }
6761   return k;

6768   switch( _ptr ) {
6769   case Constant:
6770     st->print("precise ");
6771   case NotNull:
6772     {
6773       st->print("[");
6774       _elem->dump2(d, depth, st);
6775       _interfaces->dump(st);
6776       st->print(": ");
6777     }
6778   case BotPTR:
6779     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6780   case TopPTR:
6781   case AnyNull:
6782     st->print(":%s", ptr_msg[_ptr]);
6783     if( _ptr == Constant ) st->print(":exact");
6784     break;
6785   default:
6786     break;
6787   }
6788 
6789   if( _offset ) {               // Dump offset, if any
6790     if( _offset == OffsetBot )      { st->print("+any"); }
6791     else if( _offset == OffsetTop ) { st->print("+unknown"); }
6792     else                            { st->print("+%d", _offset); }
6793   }
6794 


6795   st->print(" *");
6796 }
6797 #endif
6798 
6799 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6800   const Type* elem = this->elem();
6801   dims = 1;
6802   while (elem->isa_aryklassptr()) {
6803     elem = elem->is_aryklassptr()->elem();
6804     dims++;
6805   }
6806   return elem;
6807 }
6808 
6809 //=============================================================================
6810 // Convenience common pre-built types.
6811 
6812 //------------------------------make-------------------------------------------
6813 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6814   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();












6815 }
6816 
6817 //------------------------------make-------------------------------------------
6818 const TypeFunc *TypeFunc::make(ciMethod* method) {
6819   Compile* C = Compile::current();
6820   const TypeFunc* tf = C->last_tf(method); // check cache
6821   if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
6822   const TypeTuple *domain;
6823   if (method->is_static()) {
6824     domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6825   } else {
6826     domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);

















6827   }
6828   const TypeTuple *range  = TypeTuple::make_range(method->signature(), ignore_interfaces);
6829   tf = TypeFunc::make(domain, range);
6830   C->set_last_tf(method, tf);  // fill cache
6831   return tf;
6832 }
6833 
6834 //------------------------------meet-------------------------------------------
6835 // Compute the MEET of two types.  It returns a new Type object.
6836 const Type *TypeFunc::xmeet( const Type *t ) const {
6837   // Perform a fast test for common case; meeting the same types together.
6838   if( this == t ) return this;  // Meeting same type-rep?
6839 
6840   // Current "this->_base" is Func
6841   switch (t->base()) {          // switch on original type
6842 
6843   case Bottom:                  // Ye Olde Default
6844     return t;
6845 
6846   default:                      // All else is a mistake
6847     typerr(t);
6848 
6849   case Top:
6850     break;
6851   }
6852   return this;                  // Return the double constant
6853 }
6854 
6855 //------------------------------xdual------------------------------------------
6856 // Dual: compute field-by-field dual
6857 const Type *TypeFunc::xdual() const {
6858   return this;
6859 }
6860 
6861 //------------------------------eq---------------------------------------------
6862 // Structural equality check for Type representations
6863 bool TypeFunc::eq( const Type *t ) const {
6864   const TypeFunc *a = (const TypeFunc*)t;
6865   return _domain == a->_domain &&
6866     _range == a->_range;


6867 }
6868 
6869 //------------------------------hash-------------------------------------------
6870 // Type-specific hashing function.
6871 uint TypeFunc::hash(void) const {
6872   return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6873 }
6874 
6875 //------------------------------dump2------------------------------------------
6876 // Dump Function Type
6877 #ifndef PRODUCT
6878 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6879   if( _range->cnt() <= Parms )
6880     st->print("void");
6881   else {
6882     uint i;
6883     for (i = Parms; i < _range->cnt()-1; i++) {
6884       _range->field_at(i)->dump2(d,depth,st);
6885       st->print("/");
6886     }
6887     _range->field_at(i)->dump2(d,depth,st);
6888   }
6889   st->print(" ");
6890   st->print("( ");
6891   if( !depth || d[this] ) {     // Check for recursive dump
6892     st->print("...)");
6893     return;
6894   }
6895   d.Insert((void*)this,(void*)this);    // Stop recursion
6896   if (Parms < _domain->cnt())
6897     _domain->field_at(Parms)->dump2(d,depth-1,st);
6898   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6899     st->print(", ");
6900     _domain->field_at(i)->dump2(d,depth-1,st);
6901   }
6902   st->print(" )");
6903 }
6904 #endif
6905 
6906 //------------------------------singleton--------------------------------------
6907 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6908 // constants (Ldi nodes).  Singletons are integer, float or double constants
6909 // or a single symbol.
6910 bool TypeFunc::singleton(void) const {
6911   return false;                 // Never a singleton
6912 }
6913 
6914 bool TypeFunc::empty(void) const {
6915   return false;                 // Never empty
6916 }
6917 
6918 
6919 BasicType TypeFunc::return_type() const{
6920   if (range()->cnt() == TypeFunc::Parms) {
6921     return T_VOID;
6922   }
6923   return range()->field_at(TypeFunc::Parms)->basic_type();
6924 }

   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 
1083 #ifdef ASSERT
1084   Compile* C = Compile::current();
1085   VerifyMeet verify(C);
1086 #endif
1087 
1088   const Type *this_t = maybe_remove_speculative(include_speculative);
1089   t = t->maybe_remove_speculative(include_speculative);
1090 
1091   const Type *mt = this_t->xmeet(t);
1092 #ifdef ASSERT
1093   verify.add(this_t, t, mt);
1094   if (isa_narrowoop() || t->isa_narrowoop()) {
1095     return mt;
1096   }
1097   if (isa_narrowklass() || t->isa_narrowklass()) {
1098     return mt;
1099   }
1100   // TODO 8350865 This currently triggers a verification failure, the code around "// Even though MyValue is final" needs adjustments
1101   if ((this_t->isa_ptr() && this_t->is_ptr()->is_not_flat()) ||
1102       (this_t->_dual->isa_ptr() && this_t->_dual->is_ptr()->is_not_flat())) return mt;
1103   this_t->check_symmetrical(t, mt, verify);
1104   const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1105   this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1106 #endif
1107   return mt;
1108 }
1109 
1110 //------------------------------xmeet------------------------------------------
1111 // Compute the MEET of two types.  It returns a new Type object.
1112 const Type *Type::xmeet( const Type *t ) const {
1113   // Perform a fast test for common case; meeting the same types together.
1114   if( this == t ) return this;  // Meeting same type-rep?
1115 
1116   // Meeting TOP with anything?
1117   if( _base == Top ) return t;
1118 
1119   // Meeting BOTTOM with anything?
1120   if( _base == Bottom ) return BOTTOM;
1121 
1122   // Current "this->_base" is one of: Bad, Multi, Control, Top,

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

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

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

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





3076 }
3077 
3078 //------------------------------dual_offset------------------------------------
3079 Type::Offset TypePtr::dual_offset() const {
3080   return _offset.dual();


3081 }
3082 
3083 //------------------------------xdual------------------------------------------
3084 // Dual: compute field-by-field dual
3085 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
3086   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
3087 };
3088 const Type *TypePtr::xdual() const {
3089   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
3090 }
3091 
3092 //------------------------------xadd_offset------------------------------------
3093 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
3094   return _offset.add(offset);











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

3362   }
3363   // We already know the speculative type is always null
3364   if (speculative_always_null()) {
3365     return false;
3366   }
3367   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3368     return false;
3369   }
3370   return true;
3371 }
3372 
3373 //------------------------------dump2------------------------------------------
3374 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3375   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3376 };
3377 
3378 #ifndef PRODUCT
3379 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3380   if( _ptr == Null ) st->print("null");
3381   else st->print("%s *", ptr_msg[_ptr]);
3382   _offset.dump2(st);


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

3808 #endif
3809 
3810 // Can't be implemented because there's no way to know if the type is above or below the center line.
3811 const Type* TypeInterfaces::xmeet(const Type* t) const {
3812   ShouldNotReachHere();
3813   return Type::xmeet(t);
3814 }
3815 
3816 bool TypeInterfaces::singleton(void) const {
3817   ShouldNotReachHere();
3818   return Type::singleton();
3819 }
3820 
3821 bool TypeInterfaces::has_non_array_interface() const {
3822   assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3823 
3824   return !TypeAryPtr::_array_interfaces->contains(this);
3825 }
3826 
3827 //------------------------------TypeOopPtr-------------------------------------
3828 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3829                        int instance_id, const TypePtr* speculative, int inline_depth)
3830   : TypePtr(t, ptr, offset, speculative, inline_depth),
3831     _const_oop(o), _klass(k),
3832     _interfaces(interfaces),
3833     _klass_is_exact(xk),
3834     _is_ptr_to_narrowoop(false),
3835     _is_ptr_to_narrowklass(false),
3836     _is_ptr_to_boxed_value(false),
3837     _instance_id(instance_id) {
3838 #ifdef ASSERT
3839   if (klass() != nullptr && klass()->is_loaded()) {
3840     interfaces->verify_is_loaded();
3841   }
3842 #endif
3843   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3844       (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3845     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3846   }
3847 #ifdef _LP64
3848   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3849     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3850       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3851     } else if (klass() == nullptr) {
3852       // Array with unknown body type
3853       assert(this->isa_aryptr(), "only arrays without klass");
3854       _is_ptr_to_narrowoop = UseCompressedOops;
3855     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3856       if (klass()->is_obj_array_klass()) {
3857         _is_ptr_to_narrowoop = true;
3858       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3859         // Check if the field of the inline type array element contains oops
3860         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3861         int foffset = field_offset.get() + vk->payload_offset();
3862         ciField* field = vk->get_field_by_offset(foffset, false);
3863         assert(field != nullptr, "missing field");
3864         BasicType bt = field->layout_type();
3865         _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(bt);
3866       }
3867     } else if (klass()->is_instance_klass()) {

3868       if (this->isa_klassptr()) {
3869         // Perm objects don't use compressed references
3870       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3871         // unsafe access
3872         _is_ptr_to_narrowoop = UseCompressedOops;
3873       } else {
3874         assert(this->isa_instptr(), "must be an instance ptr.");

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

3951 //------------------------------as_klass_type----------------------------------
3952 // Return the klass type corresponding to this instance or array type.
3953 // It is the type that is loaded from an object of this type.
3954 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3955   ShouldNotReachHere();
3956   return nullptr;
3957 }
3958 
3959 //------------------------------meet-------------------------------------------
3960 // Compute the MEET of two types.  It returns a new Type object.
3961 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3962   // Perform a fast test for common case; meeting the same types together.
3963   if( this == t ) return this;  // Meeting same type-rep?
3964 
3965   // Current "this->_base" is OopPtr
3966   switch (t->base()) {          // switch on original type
3967 
3968   case Int:                     // Mixing ints & oops happens when javac
3969   case Long:                    // reuses local variables
3970   case HalfFloatTop:

3979   case NarrowOop:
3980   case NarrowKlass:
3981   case Bottom:                  // Ye Olde Default
3982     return Type::BOTTOM;
3983   case Top:
3984     return this;
3985 
3986   default:                      // All else is a mistake
3987     typerr(t);
3988 
3989   case RawPtr:
3990   case MetadataPtr:
3991   case KlassPtr:
3992   case InstKlassPtr:
3993   case AryKlassPtr:
3994     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3995 
3996   case AnyPtr: {
3997     // Found an AnyPtr type vs self-OopPtr type
3998     const TypePtr *tp = t->is_ptr();
3999     Offset offset = meet_offset(tp->offset());
4000     PTR ptr = meet_ptr(tp->ptr());
4001     const TypePtr* speculative = xmeet_speculative(tp);
4002     int depth = meet_inline_depth(tp->inline_depth());
4003     switch (tp->ptr()) {
4004     case Null:
4005       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4006       // else fall through:
4007     case TopPTR:
4008     case AnyNull: {
4009       int instance_id = meet_instance_id(InstanceTop);
4010       return make(ptr, offset, instance_id, speculative, depth);
4011     }
4012     case BotPTR:
4013     case NotNull:
4014       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4015     default: typerr(t);
4016     }
4017   }
4018 
4019   case OopPtr: {                 // Meeting to other OopPtrs

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

4229   } else {
4230     return one->equals(two) && TypePtr::eq(t);
4231   }
4232 }
4233 
4234 //------------------------------hash-------------------------------------------
4235 // Type-specific hashing function.
4236 uint TypeOopPtr::hash(void) const {
4237   return
4238     (uint)(const_oop() ? const_oop()->hash() : 0) +
4239     (uint)_klass_is_exact +
4240     (uint)_instance_id + TypePtr::hash();
4241 }
4242 
4243 //------------------------------dump2------------------------------------------
4244 #ifndef PRODUCT
4245 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4246   st->print("oopptr:%s", ptr_msg[_ptr]);
4247   if( _klass_is_exact ) st->print(":exact");
4248   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4249   _offset.dump2(st);





4250   if (_instance_id == InstanceTop)
4251     st->print(",iid=top");
4252   else if (_instance_id != InstanceBot)
4253     st->print(",iid=%d",_instance_id);
4254 
4255   dump_inline_depth(st);
4256   dump_speculative(st);
4257 }
4258 #endif
4259 
4260 //------------------------------singleton--------------------------------------
4261 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4262 // constants
4263 bool TypeOopPtr::singleton(void) const {
4264   // detune optimizer to not generate constant oop + constant offset as a constant!
4265   // TopPTR, Null, AnyNull, Constant are all singletons
4266   return (offset() == 0) && !below_centerline(_ptr);
4267 }
4268 
4269 //------------------------------add_offset-------------------------------------
4270 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4271   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4272 }
4273 
4274 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4275   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4276 }
4277 
4278 /**
4279  * Return same type without a speculative part
4280  */
4281 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4282   if (_speculative == nullptr) {
4283     return this;
4284   }
4285   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4286   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4287 }
4288 
4289 /**
4290  * Return same type but drop speculative part if we know we won't use
4291  * it
4292  */
4293 const Type* TypeOopPtr::cleanup_speculative() const {
4294   // If the klass is exact and the ptr is not null then there's
4295   // nothing that the speculative type can help us with

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

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

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

4963 }
4964 
4965 
4966 //------------------------------xdual------------------------------------------
4967 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4968 // inheritance mechanism.
4969 const Type *TypeInstPtr::xdual() const {
4970   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());
4971 }
4972 
4973 //------------------------------eq---------------------------------------------
4974 // Structural equality check for Type representations
4975 bool TypeInstPtr::eq( const Type *t ) const {
4976   const TypeInstPtr *p = t->is_instptr();
4977   return
4978     klass()->equals(p->klass()) &&
4979     flat_in_array() == p->flat_in_array() &&
4980     _interfaces->eq(p->_interfaces) &&
4981     TypeOopPtr::eq(p);          // Check sub-type stuff
4982 }
4983 
4984 //------------------------------hash-------------------------------------------
4985 // Type-specific hashing function.
4986 uint TypeInstPtr::hash(void) const {
4987   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + (uint)flat_in_array();
4988 }
4989 
4990 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4991   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4992 }
4993 
4994 
4995 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4996   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4997 }
4998 
4999 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5000   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5001 }
5002 
5003 
5004 //------------------------------dump2------------------------------------------
5005 // Dump oop Type
5006 #ifndef PRODUCT
5007 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {

5021       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
5022       char* buf = ss.as_string(/* c_heap= */false);
5023       StringUtils::replace_no_expand(buf, "\n", "");
5024       st->print_raw(buf);
5025     }
5026   case BotPTR:
5027     if (!WizardMode && !Verbose) {
5028       if( _klass_is_exact ) st->print(":exact");
5029       break;
5030     }
5031   case TopPTR:
5032   case AnyNull:
5033   case NotNull:
5034     st->print(":%s", ptr_msg[_ptr]);
5035     if( _klass_is_exact ) st->print(":exact");
5036     break;
5037   default:
5038     break;
5039   }
5040 
5041   _offset.dump2(st);




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

5135   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
5136     return true;
5137   }
5138 
5139   if (this_one->is_instance_type(other)) {
5140     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
5141   }
5142 
5143   int dummy;
5144   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
5145   if (this_top_or_bottom) {
5146     return false;
5147   }
5148 
5149   const T1* other_ary = this_one->is_array_type(other);
5150   const TypePtr* other_elem = other_ary->elem()->make_ptr();
5151   const TypePtr* this_elem = this_one->elem()->make_ptr();
5152   if (other_elem != nullptr && this_elem != nullptr) {
5153     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
5154   }

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

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

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

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

5995   case HalfFloatTop:
5996   case HalfFloatCon:
5997   case HalfFloatBot:
5998   case FloatTop:
5999   case FloatCon:
6000   case FloatBot:
6001   case DoubleTop:
6002   case DoubleCon:
6003   case DoubleBot:
6004   case AnyPtr:
6005   case RawPtr:
6006   case OopPtr:
6007   case InstPtr:
6008   case AryPtr:
6009   case MetadataPtr:
6010   case KlassPtr:
6011   case InstKlassPtr:
6012   case AryKlassPtr:
6013   case NarrowOop:
6014   case NarrowKlass:

6015   case Bottom:                  // Ye Olde Default
6016     return Type::BOTTOM;
6017   case Top:
6018     return this;
6019 
6020   default:                      // All else is a mistake
6021     typerr(t);
6022 
6023   } // End of switch
6024 
6025   return this;
6026 }
6027 
6028 #ifndef PRODUCT
6029 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6030   _ptrtype->dump2(d, depth, st);
6031 }
6032 #endif
6033 
6034 const TypeNarrowOop *TypeNarrowOop::BOTTOM;

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

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


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

6398   case NotNull:
6399     {
6400       const char *name = klass()->name()->as_utf8();
6401       if (name) {
6402         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
6403       } else {
6404         ShouldNotReachHere();
6405       }
6406       _interfaces->dump(st);
6407     }
6408   case BotPTR:
6409     if (!WizardMode && !Verbose && _ptr != Constant) break;
6410   case TopPTR:
6411   case AnyNull:
6412     st->print(":%s", ptr_msg[_ptr]);
6413     if (_ptr == Constant) st->print(":exact");
6414     break;
6415   default:
6416     break;
6417   }
6418   if (Verbose) {
6419     if (isa_instklassptr() && is_instklassptr()->flat_in_array()) st->print(":flat in array");



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

6654         }
6655       }
6656       // The other case cannot happen, since I cannot be a subtype of an array.
6657       // The meet falls down to Object class below centerline.
6658       if( ptr == Constant )
6659          ptr = NotNull;
6660       interfaces = this_interfaces->intersection_with(tp_interfaces);
6661       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6662     default: typerr(t);
6663     }
6664   }
6665 
6666   } // End of switch
6667   return this;                  // Return the double constant
6668 }
6669 
6670 //------------------------------xdual------------------------------------------
6671 // Dual: compute field-by-field dual
6672 const Type    *TypeInstKlassPtr::xdual() const {
6673   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flat_in_array());
6674 }
6675 
6676 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) {
6677   static_assert(std::is_base_of<T2, T1>::value, "");
6678   if (!this_one->is_loaded() || !other->is_loaded()) {
6679     return false;
6680   }
6681   if (!this_one->is_instance_type(other)) {
6682     return false;
6683   }
6684 
6685   if (!other_exact) {
6686     return false;
6687   }
6688 
6689   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6690     return true;
6691   }
6692 
6693   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);

6767   const TypeInterfaces* interfaces = _interfaces;
6768   if (k->is_loaded()) {
6769     ciInstanceKlass* ik = k->as_instance_klass();
6770     bool klass_is_exact = ik->is_final();
6771     if (!klass_is_exact &&
6772         deps != nullptr) {
6773       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6774       if (sub != nullptr) {
6775         if (_interfaces->eq(sub)) {
6776           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6777           k = ik = sub;
6778           klass_is_exact = sub->is_final();
6779           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6780         }
6781       }
6782     }
6783   }
6784   return this;
6785 }
6786 
6787 bool TypeInstKlassPtr::can_be_inline_array() const {
6788   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6789 }
6790 
6791 bool TypeAryKlassPtr::can_be_inline_array() const {
6792   return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6793 }
6794 
6795 bool TypeInstPtr::can_be_inline_array() const {
6796   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6797 }
6798 
6799 bool TypeAryPtr::can_be_inline_array() const {
6800   return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6801 }
6802 
6803 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool flat, bool null_free) {
6804   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free))->hashcons();
6805 }
6806 
6807 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool not_flat, bool not_null_free, bool flat, bool null_free) {
6808   if (k->is_obj_array_klass()) {
6809     // Element is an object array. Recursively call ourself.
6810     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6811     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6812     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset, not_flat, not_null_free, flat, null_free);
6813   } else if (k->is_type_array_klass()) {
6814     // Element is an typeArray
6815     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6816     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free);
6817   } else if (k->is_flat_array_klass()) {
6818     ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6819     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6820     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free);
6821   } else {
6822     ShouldNotReachHere();
6823     return nullptr;
6824   }
6825 }
6826 
6827 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling) {
6828   bool null_free = k->as_array_klass()->is_elem_null_free();
6829   bool flat = k->is_flat_array_klass();
6830 
6831   bool not_inline = k->is_type_array_klass() || !k->as_array_klass()->element_klass()->can_be_inline_klass(false);
6832   bool not_null_free = (ptr == Constant) ? !null_free : not_inline;
6833   bool not_flat = (ptr == Constant) ? !flat : (!UseArrayFlattening || not_inline ||
6834                    (k->as_array_klass()->element_klass() != nullptr &&
6835                     k->as_array_klass()->element_klass()->is_inlinetype() &&
6836                    !k->as_array_klass()->element_klass()->maybe_flat_in_array()));
6837 
6838   return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, flat, null_free);
6839 }
6840 
6841 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6842   return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling);
6843 }
6844 
6845 //------------------------------eq---------------------------------------------
6846 // Structural equality check for Type representations
6847 bool TypeAryKlassPtr::eq(const Type *t) const {
6848   const TypeAryKlassPtr *p = t->is_aryklassptr();
6849   return
6850     _elem == p->_elem &&  // Check array
6851     _not_flat == p->_not_flat &&
6852     _not_null_free == p->_not_null_free &&
6853     _null_free == p->_null_free &&
6854     _flat == p->_flat &&
6855     TypeKlassPtr::eq(p);  // Check sub-parts
6856 }
6857 
6858 //------------------------------hash-------------------------------------------
6859 // Type-specific hashing function.
6860 uint TypeAryKlassPtr::hash(void) const {
6861   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6862       (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0);
6863 }
6864 
6865 //----------------------compute_klass------------------------------------------
6866 // Compute the defining klass for this class
6867 ciKlass* TypeAryPtr::compute_klass() const {
6868   // Compute _klass based on element type.
6869   ciKlass* k_ary = nullptr;
6870   const TypeInstPtr *tinst;
6871   const TypeAryPtr *tary;
6872   const Type* el = elem();
6873   if (el->isa_narrowoop()) {
6874     el = el->make_ptr();
6875   }
6876 
6877   // Get element klass
6878   if (is_flat() && el->is_inlinetypeptr()) {
6879     // Klass is required by TypeAryPtr::flat_layout_helper() and others
6880     if (el->inline_klass() != nullptr) {
6881       // TODO 8350865 We assume atomic if the atomic layout is available
6882       bool atomic = is_null_free() ? el->inline_klass()->has_atomic_layout() : el->inline_klass()->has_nullable_atomic_layout();
6883       k_ary = ciArrayKlass::make(el->inline_klass(), /* flat */ true, is_null_free(), atomic);
6884     }
6885   } else if ((tinst = el->isa_instptr()) != nullptr) {
6886     // Leave k_ary at nullptr.
6887   } else if ((tary = el->isa_aryptr()) != nullptr) {
6888     // Leave k_ary at nullptr.
6889   } else if ((el->base() == Type::Top) ||
6890              (el->base() == Type::Bottom)) {
6891     // element type of Bottom occurs from meet of basic type
6892     // and object; Top occurs when doing join on Bottom.
6893     // Leave k_ary at null.
6894   } else {
6895     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6896     // Compute array klass directly from basic type
6897     k_ary = ciTypeArrayKlass::make(el->basic_type());
6898   }
6899   return k_ary;
6900 }
6901 
6902 //------------------------------klass------------------------------------------
6903 // Return the defining klass for this class
6904 ciKlass* TypeAryPtr::klass() const {
6905   if( _klass ) return _klass;   // Return cached value, if possible
6906 
6907   // Oops, need to compute _klass and cache it
6908   ciKlass* k_ary = compute_klass();

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

7119     PTR ptr = meet_ptr(tap->ptr());
7120     ciKlass* res_klass = nullptr;
7121     bool res_xk = false;
7122     bool res_flat = false;
7123     bool res_not_flat = false;
7124     bool res_not_null_free = false;
7125     MeetResult res = meet_aryptr(ptr, elem, this, tap,
7126                                  res_klass, res_xk, res_flat, res_not_flat, res_not_null_free);
7127     assert(res_xk == (ptr == Constant), "");
7128     bool flat = meet_flat(tap->_flat);
7129     bool null_free = meet_null_free(tap->_null_free);
7130     if (res == NOT_SUBTYPE) {
7131       flat = false;
7132       null_free = false;
7133     } else if (res == SUBTYPE) {
7134       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
7135         flat = _flat;
7136         null_free = _null_free;
7137       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
7138         flat = tap->_flat;
7139         null_free = tap->_null_free;
7140       } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
7141         null_free = _null_free || tap->_null_free;
7142         flat = _flat || tap->_flat;
7143       }
7144     }
7145     return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free);
7146   } // End of case KlassPtr
7147   case InstKlassPtr: {
7148     const TypeInstKlassPtr *tp = t->is_instklassptr();
7149     Offset offset = meet_offset(tp->offset());
7150     PTR ptr = meet_ptr(tp->ptr());
7151     const TypeInterfaces* interfaces = meet_interfaces(tp);
7152     const TypeInterfaces* tp_interfaces = tp->_interfaces;
7153     const TypeInterfaces* this_interfaces = _interfaces;
7154 
7155     switch (ptr) {
7156     case TopPTR:
7157     case AnyNull:                // Fall 'down' to dual of object klass
7158       // For instances when a subclass meets a superclass we fall
7159       // below the centerline when the superclass is exact. We need to
7160       // do the same here.
7161       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7162           !tp->klass_is_exact()) {
7163         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free());
7164       } else {
7165         // cannot subclass, so the meet has to fall badly below the centerline
7166         ptr = NotNull;
7167         interfaces = this_interfaces->intersection_with(tp->_interfaces);
7168         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
7169       }
7170     case Constant:
7171     case NotNull:
7172     case BotPTR:                // Fall down to object klass
7173       // LCA is object_klass, but if we subclass from the top we can do better
7174       if (above_centerline(tp->ptr())) {
7175         // If 'tp'  is above the centerline and it is Object class
7176         // then we can subclass in the Java class hierarchy.
7177         // For instances when a subclass meets a superclass we fall
7178         // below the centerline when the superclass is exact. We need
7179         // to do the same here.
7180         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7181             !tp->klass_is_exact()) {
7182           // that is, my array type is a subtype of 'tp' klass
7183           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free());
7184         }
7185       }
7186       // The other case cannot happen, since t cannot be a subtype of an array.
7187       // The meet falls down to Object class below centerline.
7188       if (ptr == Constant)
7189          ptr = NotNull;
7190       interfaces = this_interfaces->intersection_with(tp_interfaces);
7191       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
7192     default: typerr(t);
7193     }
7194   }
7195 
7196   } // End of switch
7197   return this;                  // Return the double constant
7198 }
7199 
7200 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) {
7201   static_assert(std::is_base_of<T2, T1>::value, "");
7202 
7203   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7204     return true;
7205   }
7206 
7207   int dummy;
7208   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7209 
7210   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7211     return false;
7212   }
7213 
7214   if (this_one->is_instance_type(other)) {
7215     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7216            other_exact;
7217   }
7218 
7219   assert(this_one->is_array_type(other), "");
7220   const T1* other_ary = this_one->is_array_type(other);
7221   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7222   if (other_top_or_bottom) {
7223     return false;
7224   }
7225 
7226   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7227   const TypePtr* this_elem = this_one->elem()->make_ptr();
7228   if (this_elem != nullptr && other_elem != nullptr) {
7229     if (other->is_null_free() && !this_one->is_null_free()) {
7230       return false; // A nullable array can't be a subtype of a null-free array
7231     }
7232     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7233   }
7234   if (this_elem == nullptr && other_elem == nullptr) {
7235     return this_one->klass()->is_subtype_of(other->klass());
7236   }
7237   return false;
7238 }
7239 
7240 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7241   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7242 }
7243 
7244 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7245   static_assert(std::is_base_of<T2, T1>::value, "");
7246 
7247   int dummy;
7248   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7249 
7250   if (!this_one->is_array_type(other) ||
7251       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

7304   }
7305 
7306   const TypePtr* this_elem = this_one->elem()->make_ptr();
7307   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7308   if (other_elem != nullptr && this_elem != nullptr) {
7309     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7310   }
7311   if (other_elem == nullptr && this_elem == nullptr) {
7312     return this_one->klass()->is_subtype_of(other->klass());
7313   }
7314   return false;
7315 }
7316 
7317 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7318   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7319 }
7320 
7321 //------------------------------xdual------------------------------------------
7322 // Dual: compute field-by-field dual
7323 const Type    *TypeAryKlassPtr::xdual() const {
7324   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_flat(), dual_null_free());
7325 }
7326 
7327 // Is there a single ciKlass* that can represent that type?
7328 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7329   if (elem()->isa_klassptr()) {
7330     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7331     if (k == nullptr) {
7332       return nullptr;
7333     }
7334     // TODO 8350865 LibraryCallKit::inline_newArray passes a constant TypeAryKlassPtr to GraphKit::new_array
7335     // As long as atomicity is not tracked by TypeAryKlassPtr, don't re-compute it here to avoid loosing atomicity information
7336     if (k->is_inlinetype() && _klass != nullptr) {
7337       return _klass;
7338     }
7339     k = ciArrayKlass::make(k, is_flat(), is_null_free());
7340     return k;
7341   }
7342 
7343   return klass();
7344 }
7345 
7346 ciKlass* TypeAryKlassPtr::klass() const {
7347   if (_klass != nullptr) {
7348     return _klass;
7349   }
7350   ciKlass* k = nullptr;
7351   if (elem()->isa_klassptr()) {
7352     // leave null
7353   } else if ((elem()->base() == Type::Top) ||
7354              (elem()->base() == Type::Bottom)) {
7355   } else {
7356     k = ciTypeArrayKlass::make(elem()->basic_type());
7357     ((TypeAryKlassPtr*)this)->_klass = k;
7358   }
7359   return k;

7366   switch( _ptr ) {
7367   case Constant:
7368     st->print("precise ");
7369   case NotNull:
7370     {
7371       st->print("[");
7372       _elem->dump2(d, depth, st);
7373       _interfaces->dump(st);
7374       st->print(": ");
7375     }
7376   case BotPTR:
7377     if( !WizardMode && !Verbose && _ptr != Constant ) break;
7378   case TopPTR:
7379   case AnyNull:
7380     st->print(":%s", ptr_msg[_ptr]);
7381     if( _ptr == Constant ) st->print(":exact");
7382     break;
7383   default:
7384     break;
7385   }
7386   if (_flat) st->print(":flat");
7387   if (_null_free) st->print(":null free");
7388   if (Verbose) {
7389     if (_not_flat) st->print(":not flat");
7390     if (_not_null_free) st->print(":not null free");
7391   }
7392 
7393   _offset.dump2(st);
7394 
7395   st->print(" *");
7396 }
7397 #endif
7398 
7399 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7400   const Type* elem = this->elem();
7401   dims = 1;
7402   while (elem->isa_aryklassptr()) {
7403     elem = elem->is_aryklassptr()->elem();
7404     dims++;
7405   }
7406   return elem;
7407 }
7408 
7409 //=============================================================================
7410 // Convenience common pre-built types.
7411 
7412 //------------------------------make-------------------------------------------
7413 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7414                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
7415   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7416 }
7417 
7418 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7419   return make(domain, domain, range, range);
7420 }
7421 
7422 //------------------------------osr_domain-----------------------------
7423 const TypeTuple* osr_domain() {
7424   const Type **fields = TypeTuple::fields(2);
7425   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
7426   return TypeTuple::make(TypeFunc::Parms+1, fields);
7427 }
7428 
7429 //------------------------------make-------------------------------------------
7430 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7431   Compile* C = Compile::current();
7432   const TypeFunc* tf = nullptr;
7433   if (!is_osr_compilation) {
7434     tf = C->last_tf(method); // check cache
7435     if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
7436   }
7437   // Inline types are not passed/returned by reference, instead each field of
7438   // the inline type is passed/returned as an argument. We maintain two views of
7439   // the argument/return list here: one based on the signature (with an inline
7440   // type argument/return as a single slot), one based on the actual calling
7441   // convention (with an inline type argument/return as a list of its fields).
7442   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7443   // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7444   if (method != C->method() && method->get_Method()->mismatch()) {
7445     has_scalar_args = false;
7446   }
7447   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7448   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7449   ciSignature* sig = method->signature();
7450   bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7451   const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7452   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7453   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7454   if (!is_osr_compilation) {
7455     C->set_last_tf(method, tf);  // fill cache
7456   }



7457   return tf;
7458 }
7459 
7460 //------------------------------meet-------------------------------------------
7461 // Compute the MEET of two types.  It returns a new Type object.
7462 const Type *TypeFunc::xmeet( const Type *t ) const {
7463   // Perform a fast test for common case; meeting the same types together.
7464   if( this == t ) return this;  // Meeting same type-rep?
7465 
7466   // Current "this->_base" is Func
7467   switch (t->base()) {          // switch on original type
7468 
7469   case Bottom:                  // Ye Olde Default
7470     return t;
7471 
7472   default:                      // All else is a mistake
7473     typerr(t);
7474 
7475   case Top:
7476     break;
7477   }
7478   return this;                  // Return the double constant
7479 }
7480 
7481 //------------------------------xdual------------------------------------------
7482 // Dual: compute field-by-field dual
7483 const Type *TypeFunc::xdual() const {
7484   return this;
7485 }
7486 
7487 //------------------------------eq---------------------------------------------
7488 // Structural equality check for Type representations
7489 bool TypeFunc::eq( const Type *t ) const {
7490   const TypeFunc *a = (const TypeFunc*)t;
7491   return _domain_sig == a->_domain_sig &&
7492     _domain_cc == a->_domain_cc &&
7493     _range_sig == a->_range_sig &&
7494     _range_cc == a->_range_cc;
7495 }
7496 
7497 //------------------------------hash-------------------------------------------
7498 // Type-specific hashing function.
7499 uint TypeFunc::hash(void) const {
7500   return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7501 }
7502 
7503 //------------------------------dump2------------------------------------------
7504 // Dump Function Type
7505 #ifndef PRODUCT
7506 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7507   if( _range_sig->cnt() <= Parms )
7508     st->print("void");
7509   else {
7510     uint i;
7511     for (i = Parms; i < _range_sig->cnt()-1; i++) {
7512       _range_sig->field_at(i)->dump2(d,depth,st);
7513       st->print("/");
7514     }
7515     _range_sig->field_at(i)->dump2(d,depth,st);
7516   }
7517   st->print(" ");
7518   st->print("( ");
7519   if( !depth || d[this] ) {     // Check for recursive dump
7520     st->print("...)");
7521     return;
7522   }
7523   d.Insert((void*)this,(void*)this);    // Stop recursion
7524   if (Parms < _domain_sig->cnt())
7525     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7526   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7527     st->print(", ");
7528     _domain_sig->field_at(i)->dump2(d,depth-1,st);
7529   }
7530   st->print(" )");
7531 }
7532 #endif
7533 
7534 //------------------------------singleton--------------------------------------
7535 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
7536 // constants (Ldi nodes).  Singletons are integer, float or double constants
7537 // or a single symbol.
7538 bool TypeFunc::singleton(void) const {
7539   return false;                 // Never a singleton
7540 }
7541 
7542 bool TypeFunc::empty(void) const {
7543   return false;                 // Never empty
7544 }
7545 
7546 
7547 BasicType TypeFunc::return_type() const{
7548   if (range_sig()->cnt() == TypeFunc::Parms) {
7549     return T_VOID;
7550   }
7551   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7552 }
< prev index next >