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

3669 void TypeInterfaces::verify_is_loaded() const {
3670   for (int i = 0; i < _interfaces.length(); i++) {
3671     ciKlass* interface = _interfaces.at(i);
3672     assert(interface->is_loaded(), "Interface not loaded");
3673   }
3674 }
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 //------------------------------TypeOopPtr-------------------------------------
3689 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3690                        int instance_id, const TypePtr* speculative, int inline_depth)
3691   : TypePtr(t, ptr, offset, speculative, inline_depth),
3692     _const_oop(o), _klass(k),
3693     _interfaces(interfaces),
3694     _klass_is_exact(xk),
3695     _is_ptr_to_narrowoop(false),
3696     _is_ptr_to_narrowklass(false),
3697     _is_ptr_to_boxed_value(false),
3698     _instance_id(instance_id) {
3699 #ifdef ASSERT
3700   if (klass() != nullptr && klass()->is_loaded()) {
3701     interfaces->verify_is_loaded();
3702   }
3703 #endif
3704   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3705       (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3706     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);
3707   }
3708 #ifdef _LP64
3709   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3710     if (_offset == oopDesc::klass_offset_in_bytes()) {
3711       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3712     } else if (klass() == nullptr) {
3713       // Array with unknown body type
3714       assert(this->isa_aryptr(), "only arrays without klass");
3715       _is_ptr_to_narrowoop = UseCompressedOops;
3716     } else if (this->isa_aryptr()) {
3717       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3718                              _offset != arrayOopDesc::length_offset_in_bytes());









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

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

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

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









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

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








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





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
















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

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

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

4211   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4212   assert(k != nullptr &&
4213          (k->is_loaded() || o == nullptr),
4214          "cannot have constants with non-loaded klass");


4215 };
4216 
4217 //------------------------------make-------------------------------------------
4218 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4219                                      ciKlass* k,
4220                                      const TypeInterfaces* interfaces,
4221                                      bool xk,
4222                                      ciObject* o,
4223                                      int offset,

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



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

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

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

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





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

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
























































4606   const T* subtype = nullptr;
4607   bool subtype_exact = false;


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

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





4612     subtype = this_type;     // Pick subtyping class
4613     subtype_exact = this_xk;
4614   } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {








4615     subtype = other_type;    // Pick subtyping class
4616     subtype_exact = other_xk;








4617   }
4618 
4619   if (subtype) {
4620     if (above_centerline(ptr)) { // both are up?


4621       this_type = other_type = subtype;
4622       this_xk = other_xk = subtype_exact;





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

4625       this_xk = other_xk;

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

4627       other_type = this_type; // this is down; keep down man
4628       other_xk = this_xk;
4629     } else {

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



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

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

4657 
4658   return LCA;
4659 }
4660 




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

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

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





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




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

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

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



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



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

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































































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

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

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

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



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














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






5252   res_klass = nullptr;
5253   MeetResult result = SUBTYPE;





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

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



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





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



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







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










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









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




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













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











































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

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

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

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

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





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

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




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

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


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

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

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







6278 
6279 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6280   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6281 }
6282 
6283 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {








6284   if (k->is_obj_array_klass()) {
6285     // Element is an object array. Recursively call ourself.
6286     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6287     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6288     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6289   } else if (k->is_type_array_klass()) {
6290     // Element is an typeArray
6291     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6292     return TypeAryKlassPtr::make(ptr, etype, k, offset);




6293   } else {
6294     ShouldNotReachHere();
6295     return nullptr;
6296   }
6297 }
6298 














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




6309     TypeKlassPtr::eq(p);  // Check sub-parts
6310 }
6311 
6312 //------------------------------hash-------------------------------------------
6313 // Type-specific hashing function.
6314 uint TypeAryKlassPtr::hash(void) const {
6315   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();

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







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

6362     // type TypeAryPtr::OOPS.  This Type is shared between all
6363     // active compilations.  However, the ciKlass which represents
6364     // this Type is *not* shared between compilations, so caching
6365     // this value would result in fetching a dangling pointer.
6366     //
6367     // Recomputing the underlying ciKlass for each request is
6368     // a bit less efficient than caching, but calls to
6369     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6370     ((TypeAryPtr*)this)->_klass = k_ary;
6371   }
6372   return k_ary;
6373 }
6374 
6375 // Is there a single ciKlass* that can represent that type?
6376 ciKlass* TypeAryPtr::exact_klass_helper() const {
6377   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6378     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6379     if (k == nullptr) {
6380       return nullptr;
6381     }
6382     k = ciObjArrayKlass::make(k);


6383     return k;
6384   }
6385 
6386   return klass();
6387 }
6388 
6389 const Type* TypeAryPtr::base_element_type(int& dims) const {
6390   const Type* elem = this->elem();
6391   dims = 1;
6392   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6393     elem = elem->make_ptr()->is_aryptr()->elem();
6394     dims++;
6395   }
6396   return elem;
6397 }
6398 
6399 //------------------------------add_offset-------------------------------------
6400 // Access internals of klass object
6401 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6402   return make(_ptr, elem(), klass(), xadd_offset(offset));
6403 }
6404 
6405 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6406   return make(_ptr, elem(), klass(), offset);
6407 }
6408 
6409 //------------------------------cast_to_ptr_type-------------------------------
6410 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6411   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6412   if (ptr == _ptr) return this;
6413   return make(ptr, elem(), _klass, _offset);
6414 }
6415 
6416 bool TypeAryKlassPtr::must_be_exact() const {
6417   if (_elem == Type::BOTTOM) return false;
6418   if (_elem == Type::TOP   ) return false;
6419   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6420   if (!tk)             return true;   // a primitive type, like int







6421   return tk->must_be_exact();
6422 }
6423 
6424 
6425 //-----------------------------cast_to_exactness-------------------------------
6426 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6427   if (must_be_exact()) return this;  // cannot clear xk



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


















6434 }
6435 



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




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




6535     assert(res_xk == (ptr == Constant), "");
6536     return make(ptr, elem, res_klass, off);

















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



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

6692   }
6693 
6694   const TypePtr* this_elem = this_one->elem()->make_ptr();
6695   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6696   if (other_elem != nullptr && this_elem != nullptr) {
6697     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6698   }
6699   if (other_elem == nullptr && this_elem == nullptr) {
6700     return this_one->klass()->is_subtype_of(other->klass());
6701   }
6702   return false;
6703 }
6704 
6705 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6706   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6707 }
6708 
6709 //------------------------------xdual------------------------------------------
6710 // Dual: compute field-by-field dual
6711 const Type    *TypeAryKlassPtr::xdual() const {
6712   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6713 }
6714 
6715 // Is there a single ciKlass* that can represent that type?
6716 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6717   if (elem()->isa_klassptr()) {
6718     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6719     if (k == nullptr) {
6720       return nullptr;
6721     }
6722     k = ciObjArrayKlass::make(k);


6723     return k;
6724   }
6725 
6726   return klass();
6727 }
6728 
6729 ciKlass* TypeAryKlassPtr::klass() const {
6730   if (_klass != nullptr) {
6731     return _klass;
6732   }
6733   ciKlass* k = nullptr;
6734   if (elem()->isa_klassptr()) {
6735     // leave null
6736   } else if ((elem()->base() == Type::Top) ||
6737              (elem()->base() == Type::Bottom)) {
6738   } else {
6739     k = ciTypeArrayKlass::make(elem()->basic_type());
6740     ((TypeAryKlassPtr*)this)->_klass = k;
6741   }
6742   return k;

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


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












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

















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


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

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

3802 void TypeInterfaces::verify_is_loaded() const {
3803   for (int i = 0; i < _interfaces.length(); i++) {
3804     ciKlass* interface = _interfaces.at(i);
3805     assert(interface->is_loaded(), "Interface not loaded");
3806   }
3807 }
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 //------------------------------TypeOopPtr-------------------------------------
3822 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3823                        int instance_id, const TypePtr* speculative, int inline_depth)
3824   : TypePtr(t, ptr, offset, speculative, inline_depth),
3825     _const_oop(o), _klass(k),
3826     _interfaces(interfaces),
3827     _klass_is_exact(xk),
3828     _is_ptr_to_narrowoop(false),
3829     _is_ptr_to_narrowklass(false),
3830     _is_ptr_to_boxed_value(false),
3831     _instance_id(instance_id) {
3832 #ifdef ASSERT
3833   if (klass() != nullptr && klass()->is_loaded()) {
3834     interfaces->verify_is_loaded();
3835   }
3836 #endif
3837   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3838       (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3839     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3840   }
3841 #ifdef _LP64
3842   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3843     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3844       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3845     } else if (klass() == nullptr) {
3846       // Array with unknown body type
3847       assert(this->isa_aryptr(), "only arrays without klass");
3848       _is_ptr_to_narrowoop = UseCompressedOops;
3849     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3850       if (klass()->is_obj_array_klass()) {
3851         _is_ptr_to_narrowoop = true;
3852       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3853         // Check if the field of the inline type array element contains oops
3854         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3855         int foffset = field_offset.get() + vk->payload_offset();
3856         ciField* field = vk->get_field_by_offset(foffset, false);
3857         assert(field != nullptr, "missing field");
3858         BasicType bt = field->layout_type();
3859         _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(bt);
3860       }
3861     } else if (klass()->is_instance_klass()) {

3862       if (this->isa_klassptr()) {
3863         // Perm objects don't use compressed references
3864       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3865         // unsafe access
3866         _is_ptr_to_narrowoop = UseCompressedOops;
3867       } else {
3868         assert(this->isa_instptr(), "must be an instance ptr.");

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

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

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

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

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





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

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

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

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

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

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




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

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

5149   if (other_elem == nullptr && this_elem == nullptr) {
5150     return this_one->klass()->is_subtype_of(other->klass());
5151   }
5152 
5153   return false;
5154 }
5155 
5156 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
5157   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5158 }
5159 
5160 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5161   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
5162 }
5163 
5164 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5165   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5166 }
5167 
5168 //=============================================================================
5169 // Convenience common pre-built types.
5170 const TypeAryPtr* TypeAryPtr::BOTTOM;
5171 const TypeAryPtr *TypeAryPtr::RANGE;
5172 const TypeAryPtr *TypeAryPtr::OOPS;
5173 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
5174 const TypeAryPtr *TypeAryPtr::BYTES;
5175 const TypeAryPtr *TypeAryPtr::SHORTS;
5176 const TypeAryPtr *TypeAryPtr::CHARS;
5177 const TypeAryPtr *TypeAryPtr::INTS;
5178 const TypeAryPtr *TypeAryPtr::LONGS;
5179 const TypeAryPtr *TypeAryPtr::FLOATS;
5180 const TypeAryPtr *TypeAryPtr::DOUBLES;
5181 const TypeAryPtr *TypeAryPtr::INLINES;
5182 
5183 //------------------------------make-------------------------------------------
5184 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5185                                    int instance_id, const TypePtr* speculative, int inline_depth) {
5186   assert(!(k == nullptr && ary->_elem->isa_int()),
5187          "integral arrays must be pre-equipped with a class");
5188   if (!xk)  xk = ary->ary_must_be_exact();
5189   assert(instance_id <= 0 || xk, "instances are always exactly typed");
5190   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5191       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5192     k = nullptr;
5193   }
5194   if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
5195     k = nullptr;
5196   }
5197   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
5198 }
5199 
5200 //------------------------------make-------------------------------------------
5201 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5202                                    int instance_id, const TypePtr* speculative, int inline_depth,
5203                                    bool is_autobox_cache) {
5204   assert(!(k == nullptr && ary->_elem->isa_int()),
5205          "integral arrays must be pre-equipped with a class");
5206   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
5207   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
5208   assert(instance_id <= 0 || xk, "instances are always exactly typed");
5209   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5210       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5211     k = nullptr;
5212   }
5213   if (k != nullptr && k->is_flat_array_klass() && !ary->_flat) {
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->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);

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

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

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

7293   }
7294 
7295   const TypePtr* this_elem = this_one->elem()->make_ptr();
7296   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7297   if (other_elem != nullptr && this_elem != nullptr) {
7298     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7299   }
7300   if (other_elem == nullptr && this_elem == nullptr) {
7301     return this_one->klass()->is_subtype_of(other->klass());
7302   }
7303   return false;
7304 }
7305 
7306 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7307   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7308 }
7309 
7310 //------------------------------xdual------------------------------------------
7311 // Dual: compute field-by-field dual
7312 const Type    *TypeAryKlassPtr::xdual() const {
7313   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_flat(), dual_null_free());
7314 }
7315 
7316 // Is there a single ciKlass* that can represent that type?
7317 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7318   if (elem()->isa_klassptr()) {
7319     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7320     if (k == nullptr) {
7321       return nullptr;
7322     }
7323     // TODO 8350865 We assume atomic if the atomic layout is available
7324     bool atomic = k->is_inlinetype() && (is_null_free() ? k->as_inline_klass()->has_atomic_layout() : k->as_inline_klass()->has_nullable_atomic_layout());
7325     k = ciArrayKlass::make(k, is_flat(), is_null_free(), atomic);
7326     return k;
7327   }
7328 
7329   return klass();
7330 }
7331 
7332 ciKlass* TypeAryKlassPtr::klass() const {
7333   if (_klass != nullptr) {
7334     return _klass;
7335   }
7336   ciKlass* k = nullptr;
7337   if (elem()->isa_klassptr()) {
7338     // leave null
7339   } else if ((elem()->base() == Type::Top) ||
7340              (elem()->base() == Type::Bottom)) {
7341   } else {
7342     k = ciTypeArrayKlass::make(elem()->basic_type());
7343     ((TypeAryKlassPtr*)this)->_klass = k;
7344   }
7345   return k;

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



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