< 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/arraycopynode.hpp"
  39 #include "opto/callnode.hpp"
  40 #include "opto/matcher.hpp"
  41 #include "opto/node.hpp"
  42 #include "opto/opcodes.hpp"
  43 #include "opto/rangeinference.hpp"
  44 #include "opto/runtime.hpp"
  45 #include "opto/type.hpp"
  46 #include "runtime/stubRoutines.hpp"
  47 #include "utilities/checkedCast.hpp"

  48 #include "utilities/powerOfTwo.hpp"
  49 #include "utilities/stringUtils.hpp"
  50 
  51 // Portions of code courtesy of Clifford Click
  52 
  53 // Optimization - Graph Style
  54 
  55 // Dictionary of types shared among compilations.
  56 Dict* Type::_shared_type_dict = nullptr;













































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

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



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

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

 626 
 627   // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
 628   TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
 629   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;

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

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

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

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



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














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

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

 997     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
 998 
 999     fatal("meet not symmetric");
1000   }
1001 }
1002 #endif
1003 
1004 //------------------------------meet-------------------------------------------
1005 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
1006 // commutative and the lattice is symmetric.
1007 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1008   if (isa_narrowoop() && t->isa_narrowoop()) {
1009     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1010     return result->make_narrowoop();
1011   }
1012   if (isa_narrowklass() && t->isa_narrowklass()) {
1013     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1014     return result->make_narrowklass();
1015   }
1016 
1017 #ifdef ASSERT
1018   Compile* C = Compile::current();
1019   VerifyMeet verify(C);
1020 #endif
1021 
1022   const Type *this_t = maybe_remove_speculative(include_speculative);
1023   t = t->maybe_remove_speculative(include_speculative);
1024 
1025   const Type *mt = this_t->xmeet(t);
1026 #ifdef ASSERT
1027   verify.add(this_t, t, mt);
1028   if (isa_narrowoop() || t->isa_narrowoop()) {
1029     return mt;
1030   }
1031   if (isa_narrowklass() || t->isa_narrowklass()) {
1032     return mt;
1033   }



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

2030 void TypeLong::dump_verbose() const {
2031   TypeIntHelper::int_type_dump(this, tty, true);
2032 }
2033 #endif
2034 
2035 //=============================================================================
2036 // Convenience common pre-built types.
2037 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2038 const TypeTuple *TypeTuple::IFFALSE;
2039 const TypeTuple *TypeTuple::IFTRUE;
2040 const TypeTuple *TypeTuple::IFNEITHER;
2041 const TypeTuple *TypeTuple::LOOPBODY;
2042 const TypeTuple *TypeTuple::MEMBAR;
2043 const TypeTuple *TypeTuple::STORECONDITIONAL;
2044 const TypeTuple *TypeTuple::START_I2C;
2045 const TypeTuple *TypeTuple::INT_PAIR;
2046 const TypeTuple *TypeTuple::LONG_PAIR;
2047 const TypeTuple *TypeTuple::INT_CC_PAIR;
2048 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2049 





















2050 //------------------------------make-------------------------------------------
2051 // Make a TypeTuple from the range of a method signature
2052 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
2053   ciType* return_type = sig->return_type();
2054   uint arg_cnt = return_type->size();





2055   const Type **field_array = fields(arg_cnt);
2056   switch (return_type->basic_type()) {
2057   case T_LONG:
2058     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2059     field_array[TypeFunc::Parms+1] = Type::HALF;
2060     break;
2061   case T_DOUBLE:
2062     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2063     field_array[TypeFunc::Parms+1] = Type::HALF;
2064     break;
2065   case T_OBJECT:












2066   case T_ARRAY:
2067   case T_BOOLEAN:
2068   case T_CHAR:
2069   case T_FLOAT:
2070   case T_BYTE:
2071   case T_SHORT:
2072   case T_INT:
2073     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2074     break;
2075   case T_VOID:
2076     break;
2077   default:
2078     ShouldNotReachHere();
2079   }
2080   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2081 }
2082 
2083 // Make a TypeTuple from the domain of a method signature
2084 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2085   uint arg_cnt = sig->size();








2086 
2087   uint pos = TypeFunc::Parms;
2088   const Type **field_array;
2089   if (recv != nullptr) {
2090     arg_cnt++;
2091     field_array = fields(arg_cnt);
2092     // Use get_const_type here because it respects UseUniqueSubclasses:
2093     field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2094   } else {
2095     field_array = fields(arg_cnt);
2096   }
2097 
2098   int i = 0;
2099   while (pos < TypeFunc::Parms + arg_cnt) {
2100     ciType* type = sig->type_at(i);

2101 
2102     switch (type->basic_type()) {
2103     case T_LONG:
2104       field_array[pos++] = TypeLong::LONG;
2105       field_array[pos++] = Type::HALF;
2106       break;
2107     case T_DOUBLE:
2108       field_array[pos++] = Type::DOUBLE;
2109       field_array[pos++] = Type::HALF;
2110       break;
2111     case T_OBJECT:








2112     case T_ARRAY:
2113     case T_FLOAT:
2114     case T_INT:
2115       field_array[pos++] = get_const_type(type, interface_handling);
2116       break;
2117     case T_BOOLEAN:
2118     case T_CHAR:
2119     case T_BYTE:
2120     case T_SHORT:
2121       field_array[pos++] = TypeInt::INT;
2122       break;
2123     default:
2124       ShouldNotReachHere();
2125     }
2126     i++;
2127   }

2128 
2129   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2130 }
2131 
2132 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2133   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2134 }
2135 
2136 //------------------------------fields-----------------------------------------
2137 // Subroutine call type with space allocated for argument types
2138 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2139 const Type **TypeTuple::fields( uint arg_cnt ) {
2140   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2141   flds[TypeFunc::Control  ] = Type::CONTROL;
2142   flds[TypeFunc::I_O      ] = Type::ABIO;
2143   flds[TypeFunc::Memory   ] = Type::MEMORY;
2144   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2145   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2146 
2147   return flds;

2242     if (_fields[i]->empty())  return true;
2243   }
2244   return false;
2245 }
2246 
2247 //=============================================================================
2248 // Convenience common pre-built types.
2249 
2250 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2251   // Certain normalizations keep us sane when comparing types.
2252   // We do not want arrayOop variables to differ only by the wideness
2253   // of their index types.  Pick minimum wideness, since that is the
2254   // forced wideness of small ranges anyway.
2255   if (size->_widen != Type::WidenMin)
2256     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2257   else
2258     return size;
2259 }
2260 
2261 //------------------------------make-------------------------------------------
2262 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {

2263   if (UseCompressedOops && elem->isa_oopptr()) {
2264     elem = elem->make_narrowoop();
2265   }
2266   size = normalize_array_size(size);
2267   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2268 }
2269 
2270 //------------------------------meet-------------------------------------------
2271 // Compute the MEET of two types.  It returns a new Type object.
2272 const Type *TypeAry::xmeet( const Type *t ) const {
2273   // Perform a fast test for common case; meeting the same types together.
2274   if( this == t ) return this;  // Meeting same type-rep?
2275 
2276   // Current "this->_base" is Ary
2277   switch (t->base()) {          // switch on original type
2278 
2279   case Bottom:                  // Ye Olde Default
2280     return t;
2281 
2282   default:                      // All else is a mistake
2283     typerr(t);
2284 
2285   case Array: {                 // Meeting 2 arrays?
2286     const TypeAry* a = t->is_ary();
2287     const Type* size = _size->xmeet(a->_size);
2288     const TypeInt* isize = size->isa_int();
2289     if (isize == nullptr) {
2290       assert(size == Type::TOP || size == Type::BOTTOM, "");
2291       return size;
2292     }
2293     return TypeAry::make(_elem->meet_speculative(a->_elem),
2294                          isize, _stable && a->_stable);




2295   }
2296   case Top:
2297     break;
2298   }
2299   return this;                  // Return the double constant
2300 }
2301 
2302 //------------------------------xdual------------------------------------------
2303 // Dual: compute field-by-field dual
2304 const Type *TypeAry::xdual() const {
2305   const TypeInt* size_dual = _size->dual()->is_int();
2306   size_dual = normalize_array_size(size_dual);
2307   return new TypeAry(_elem->dual(), size_dual, !_stable);
2308 }
2309 
2310 //------------------------------eq---------------------------------------------
2311 // Structural equality check for Type representations
2312 bool TypeAry::eq( const Type *t ) const {
2313   const TypeAry *a = (const TypeAry*)t;
2314   return _elem == a->_elem &&
2315     _stable == a->_stable &&
2316     _size == a->_size;





2317 }
2318 
2319 //------------------------------hash-------------------------------------------
2320 // Type-specific hashing function.
2321 uint TypeAry::hash(void) const {
2322   return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);

2323 }
2324 
2325 /**
2326  * Return same type without a speculative part in the element
2327  */
2328 const TypeAry* TypeAry::remove_speculative() const {
2329   return make(_elem->remove_speculative(), _size, _stable);
2330 }
2331 
2332 /**
2333  * Return same type with cleaned up speculative part of element
2334  */
2335 const Type* TypeAry::cleanup_speculative() const {
2336   return make(_elem->cleanup_speculative(), _size, _stable);
2337 }
2338 
2339 /**
2340  * Return same type but with a different inline depth (used for speculation)
2341  *
2342  * @param depth  depth to meet with
2343  */
2344 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2345   if (!UseInlineDepthForSpeculativeTypes) {
2346     return this;
2347   }
2348   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2349 }
2350 
2351 //------------------------------dump2------------------------------------------
2352 #ifndef PRODUCT
2353 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2354   if (_stable)  st->print("stable:");






2355   _elem->dump2(d, depth, st);
2356   st->print("[");
2357   _size->dump2(d, depth, st);
2358   st->print("]");
2359 }
2360 #endif
2361 
2362 //------------------------------singleton--------------------------------------
2363 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2364 // constants (Ldi nodes).  Singletons are integer, float or double constants
2365 // or a single symbol.
2366 bool TypeAry::singleton(void) const {
2367   return false;                 // Never a singleton
2368 }
2369 
2370 bool TypeAry::empty(void) const {
2371   return _elem->empty() || _size->empty();
2372 }
2373 
2374 //--------------------------ary_must_be_exact----------------------------------
2375 bool TypeAry::ary_must_be_exact() const {
2376   // This logic looks at the element type of an array, and returns true
2377   // if the element type is either a primitive or a final instance class.
2378   // In such cases, an array built on this ary must have no subclasses.
2379   if (_elem == BOTTOM)      return false;  // general array not exact
2380   if (_elem == TOP   )      return false;  // inverted general array not exact
2381   const TypeOopPtr*  toop = nullptr;
2382   if (UseCompressedOops && _elem->isa_narrowoop()) {
2383     toop = _elem->make_ptr()->isa_oopptr();
2384   } else {
2385     toop = _elem->isa_oopptr();
2386   }
2387   if (!toop)                return true;   // a primitive type, like int
2388   if (!toop->is_loaded())   return false;  // unloaded class
2389   const TypeInstPtr* tinst;
2390   if (_elem->isa_narrowoop())
2391     tinst = _elem->make_ptr()->isa_instptr();
2392   else
2393     tinst = _elem->isa_instptr();
2394   if (tinst)
2395     return tinst->instance_klass()->is_final();











2396   const TypeAryPtr*  tap;
2397   if (_elem->isa_narrowoop())
2398     tap = _elem->make_ptr()->isa_aryptr();
2399   else
2400     tap = _elem->isa_aryptr();
2401   if (tap)
2402     return tap->ary()->ary_must_be_exact();
2403   return false;
2404 }
2405 
2406 //==============================TypeVect=======================================
2407 // Convenience common pre-built types.
2408 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2409 const TypeVect* TypeVect::VECTS = nullptr; //  32-bit vectors
2410 const TypeVect* TypeVect::VECTD = nullptr; //  64-bit vectors
2411 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2412 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2413 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2414 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2415 

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

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

2964   }
2965   // We already know the speculative type is always null
2966   if (speculative_always_null()) {
2967     return false;
2968   }
2969   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
2970     return false;
2971   }
2972   return true;
2973 }
2974 
2975 //------------------------------dump2------------------------------------------
2976 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
2977   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
2978 };
2979 
2980 #ifndef PRODUCT
2981 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
2982   if( _ptr == Null ) st->print("null");
2983   else st->print("%s *", ptr_msg[_ptr]);
2984   if( _offset == OffsetTop ) st->print("+top");
2985   else if( _offset == OffsetBot ) st->print("+bot");
2986   else if( _offset ) st->print("+%d", _offset);
2987   dump_inline_depth(st);
2988   dump_speculative(st);
2989 }
2990 
2991 /**
2992  *dump the speculative part of the type
2993  */
2994 void TypePtr::dump_speculative(outputStream *st) const {
2995   if (_speculative != nullptr) {
2996     st->print(" (speculative=");
2997     _speculative->dump_on(st);
2998     st->print(")");
2999   }
3000 }
3001 
3002 /**
3003  *dump the inline depth of the type
3004  */
3005 void TypePtr::dump_inline_depth(outputStream *st) const {
3006   if (_inline_depth != InlineDepthBottom) {
3007     if (_inline_depth == InlineDepthTop) {
3008       st->print(" (inline_depth=InlineDepthTop)");
3009     } else {
3010       st->print(" (inline_depth=%d)", _inline_depth);
3011     }
3012   }
3013 }
3014 #endif
3015 
3016 //------------------------------singleton--------------------------------------
3017 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3018 // constants
3019 bool TypePtr::singleton(void) const {
3020   // TopPTR, Null, AnyNull, Constant are all singletons
3021   return (_offset != OffsetBot) && !below_centerline(_ptr);
3022 }
3023 
3024 bool TypePtr::empty(void) const {
3025   return (_offset == OffsetTop) || above_centerline(_ptr);
3026 }
3027 
3028 //=============================================================================
3029 // Convenience common pre-built types.
3030 const TypeRawPtr *TypeRawPtr::BOTTOM;
3031 const TypeRawPtr *TypeRawPtr::NOTNULL;
3032 
3033 //------------------------------make-------------------------------------------
3034 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3035   assert( ptr != Constant, "what is the constant?" );
3036   assert( ptr != Null, "Use TypePtr for null" );
3037   return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3038 }
3039 
3040 const TypeRawPtr *TypeRawPtr::make(address bits) {
3041   assert(bits != nullptr, "Use TypePtr for null");
3042   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3043 }
3044 
3045 //------------------------------cast_to_ptr_type-------------------------------

3412 #endif
3413 
3414 // Can't be implemented because there's no way to know if the type is above or below the center line.
3415 const Type* TypeInterfaces::xmeet(const Type* t) const {
3416   ShouldNotReachHere();
3417   return Type::xmeet(t);
3418 }
3419 
3420 bool TypeInterfaces::singleton(void) const {
3421   ShouldNotReachHere();
3422   return Type::singleton();
3423 }
3424 
3425 bool TypeInterfaces::has_non_array_interface() const {
3426   assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3427 
3428   return !TypeAryPtr::_array_interfaces->contains(this);
3429 }
3430 
3431 //------------------------------TypeOopPtr-------------------------------------
3432 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3433                        int instance_id, const TypePtr* speculative, int inline_depth)
3434   : TypePtr(t, ptr, offset, speculative, inline_depth),
3435     _const_oop(o), _klass(k),
3436     _interfaces(interfaces),
3437     _klass_is_exact(xk),
3438     _is_ptr_to_narrowoop(false),
3439     _is_ptr_to_narrowklass(false),
3440     _is_ptr_to_boxed_value(false),

3441     _instance_id(instance_id) {
3442 #ifdef ASSERT
3443   if (klass() != nullptr && klass()->is_loaded()) {
3444     interfaces->verify_is_loaded();
3445   }
3446 #endif
3447   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3448       (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3449     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);









3450   }

3451 #ifdef _LP64
3452   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3453     if (_offset == oopDesc::klass_offset_in_bytes()) {
3454       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3455     } else if (klass() == nullptr) {
3456       // Array with unknown body type
3457       assert(this->isa_aryptr(), "only arrays without klass");
3458       _is_ptr_to_narrowoop = UseCompressedOops;
3459     } else if (this->isa_aryptr()) {
3460       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3461                              _offset != arrayOopDesc::length_offset_in_bytes());














3462     } else if (klass()->is_instance_klass()) {
3463       ciInstanceKlass* ik = klass()->as_instance_klass();
3464       if (this->isa_klassptr()) {
3465         // Perm objects don't use compressed references
3466       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3467         // unsafe access
3468         _is_ptr_to_narrowoop = UseCompressedOops;
3469       } else {
3470         assert(this->isa_instptr(), "must be an instance ptr.");
3471 
3472         if (klass() == ciEnv::current()->Class_klass() &&
3473             (_offset == java_lang_Class::klass_offset() ||
3474              _offset == java_lang_Class::array_klass_offset())) {
3475           // Special hidden fields from the Class.
3476           assert(this->isa_instptr(), "must be an instance ptr.");
3477           _is_ptr_to_narrowoop = false;
3478         } else if (klass() == ciEnv::current()->Class_klass() &&
3479                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3480           // Static fields
3481           ciField* field = nullptr;
3482           if (const_oop() != nullptr) {
3483             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3484             field = k->get_field_by_offset(_offset, true);
3485           }
3486           if (field != nullptr) {
3487             BasicType basic_elem_type = field->layout_type();
3488             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3489           } else {
3490             // unsafe access
3491             _is_ptr_to_narrowoop = UseCompressedOops;
3492           }
3493         } else {
3494           // Instance fields which contains a compressed oop references.
3495           ciField* field = ik->get_field_by_offset(_offset, false);

3496           if (field != nullptr) {
3497             BasicType basic_elem_type = field->layout_type();
3498             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3499           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3500             // Compile::find_alias_type() cast exactness on all types to verify
3501             // that it does not affect alias type.
3502             _is_ptr_to_narrowoop = UseCompressedOops;
3503           } else {
3504             // Type for the copy start in LibraryCallKit::inline_native_clone().
3505             _is_ptr_to_narrowoop = UseCompressedOops;
3506           }
3507         }
3508       }
3509     }
3510   }
3511 #endif
3512 }
3513 
3514 //------------------------------make-------------------------------------------
3515 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3516                                      const TypePtr* speculative, int inline_depth) {
3517   assert(ptr != Constant, "no constant generic pointers");
3518   ciKlass*  k = Compile::current()->env()->Object_klass();
3519   bool      xk = false;
3520   ciObject* o = nullptr;
3521   const TypeInterfaces* interfaces = TypeInterfaces::make();
3522   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3523 }
3524 
3525 
3526 //------------------------------cast_to_ptr_type-------------------------------
3527 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3528   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3529   if( ptr == _ptr ) return this;
3530   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3531 }
3532 
3533 //-----------------------------cast_to_instance_id----------------------------
3534 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3535   // There are no instances of a general oop.
3536   // Return self unchanged.
3537   return this;
3538 }
3539 
3540 //-----------------------------cast_to_exactness-------------------------------
3541 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3542   // There is no such thing as an exact general oop.
3543   // Return self unchanged.
3544   return this;
3545 }
3546 
3547 
3548 //------------------------------as_klass_type----------------------------------
3549 // Return the klass type corresponding to this instance or array type.
3550 // It is the type that is loaded from an object of this type.
3551 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3552   ShouldNotReachHere();
3553   return nullptr;
3554 }
3555 
3556 //------------------------------meet-------------------------------------------
3557 // Compute the MEET of two types.  It returns a new Type object.
3558 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3559   // Perform a fast test for common case; meeting the same types together.
3560   if( this == t ) return this;  // Meeting same type-rep?
3561 
3562   // Current "this->_base" is OopPtr
3563   switch (t->base()) {          // switch on original type
3564 
3565   case Int:                     // Mixing ints & oops happens when javac
3566   case Long:                    // reuses local variables
3567   case HalfFloatTop:

3576   case NarrowOop:
3577   case NarrowKlass:
3578   case Bottom:                  // Ye Olde Default
3579     return Type::BOTTOM;
3580   case Top:
3581     return this;
3582 
3583   default:                      // All else is a mistake
3584     typerr(t);
3585 
3586   case RawPtr:
3587   case MetadataPtr:
3588   case KlassPtr:
3589   case InstKlassPtr:
3590   case AryKlassPtr:
3591     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3592 
3593   case AnyPtr: {
3594     // Found an AnyPtr type vs self-OopPtr type
3595     const TypePtr *tp = t->is_ptr();
3596     int offset = meet_offset(tp->offset());
3597     PTR ptr = meet_ptr(tp->ptr());
3598     const TypePtr* speculative = xmeet_speculative(tp);
3599     int depth = meet_inline_depth(tp->inline_depth());
3600     switch (tp->ptr()) {
3601     case Null:
3602       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3603       // else fall through:
3604     case TopPTR:
3605     case AnyNull: {
3606       int instance_id = meet_instance_id(InstanceTop);
3607       return make(ptr, offset, instance_id, speculative, depth);
3608     }
3609     case BotPTR:
3610     case NotNull:
3611       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3612     default: typerr(t);
3613     }
3614   }
3615 
3616   case OopPtr: {                 // Meeting to other OopPtrs

3618     int instance_id = meet_instance_id(tp->instance_id());
3619     const TypePtr* speculative = xmeet_speculative(tp);
3620     int depth = meet_inline_depth(tp->inline_depth());
3621     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3622   }
3623 
3624   case InstPtr:                  // For these, flip the call around to cut down
3625   case AryPtr:
3626     return t->xmeet(this);      // Call in reverse direction
3627 
3628   } // End of switch
3629   return this;                  // Return the double constant
3630 }
3631 
3632 
3633 //------------------------------xdual------------------------------------------
3634 // Dual of a pure heap pointer.  No relevant klass or oop information.
3635 const Type *TypeOopPtr::xdual() const {
3636   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3637   assert(const_oop() == nullptr,             "no constants here");
3638   return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3639 }
3640 
3641 //--------------------------make_from_klass_common-----------------------------
3642 // Computes the element-type given a klass.
3643 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3644   if (klass->is_instance_klass()) {
3645     Compile* C = Compile::current();
3646     Dependencies* deps = C->dependencies();
3647     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3648     // Element is an instance
3649     bool klass_is_exact = false;
3650     if (klass->is_loaded()) {
3651       // Try to set klass_is_exact.
3652       ciInstanceKlass* ik = klass->as_instance_klass();
3653       klass_is_exact = ik->is_final();
3654       if (!klass_is_exact && klass_change
3655           && deps != nullptr && UseUniqueSubclasses) {
3656         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3657         if (sub != nullptr) {
3658           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3659           klass = ik = sub;
3660           klass_is_exact = sub->is_final();
3661         }
3662       }
3663       if (!klass_is_exact && try_for_exact && deps != nullptr &&
3664           !ik->is_interface() && !ik->has_subklass()) {
3665         // Add a dependence; if concrete subclass added we need to recompile
3666         deps->assert_leaf_type(ik);
3667         klass_is_exact = true;
3668       }
3669     }
3670     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3671     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3672   } else if (klass->is_obj_array_klass()) {
3673     // Element is an object array. Recursively call ourself.
3674     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3675     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3676     bool xk = etype->klass_is_exact();
3677     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);














3678     // We used to pass NotNull in here, asserting that the sub-arrays
3679     // are all not-null.  This is not true in generally, as code can
3680     // slam nulls down in the subarrays.
3681     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3682     return arr;
3683   } else if (klass->is_type_array_klass()) {
3684     // Element is an typeArray
3685     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3686     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

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











3690     return arr;
3691   } else {
3692     ShouldNotReachHere();
3693     return nullptr;
3694   }
3695 }
3696 
3697 //------------------------------make_from_constant-----------------------------
3698 // Make a java pointer from an oop constant
3699 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3700   assert(!o->is_null_object(), "null object not yet handled here.");
3701 
3702   const bool make_constant = require_constant || o->should_be_constant();
3703 
3704   ciKlass* klass = o->klass();
3705   if (klass->is_instance_klass()) {
3706     // Element is an instance
3707     if (make_constant) {
3708       return TypeInstPtr::make(o);
3709     } else {
3710       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3711     }
3712   } else if (klass->is_obj_array_klass()) {
3713     // Element is an object array. Recursively call ourself.
3714     const TypeOopPtr *etype =
3715       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3716     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));






3717     // We used to pass NotNull in here, asserting that the sub-arrays
3718     // are all not-null.  This is not true in generally, as code can
3719     // slam nulls down in the subarrays.
3720     if (make_constant) {
3721       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3722     } else {
3723       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3724     }
3725   } else if (klass->is_type_array_klass()) {
3726     // Element is an typeArray
3727     const Type* etype =
3728       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3729     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3730     // We used to pass NotNull in here, asserting that the array pointer
3731     // is not-null. That was not true in general.
3732     if (make_constant) {
3733       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3734     } else {
3735       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);

















3736     }
3737   }
3738 
3739   fatal("unhandled object type");
3740   return nullptr;
3741 }
3742 
3743 //------------------------------get_con----------------------------------------
3744 intptr_t TypeOopPtr::get_con() const {
3745   assert( _ptr == Null || _ptr == Constant, "" );
3746   assert( _offset >= 0, "" );
3747 
3748   if (_offset != 0) {
3749     // After being ported to the compiler interface, the compiler no longer
3750     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3751     // to a handle at compile time.  This handle is embedded in the generated
3752     // code and dereferenced at the time the nmethod is made.  Until that time,
3753     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3754     // have access to the addresses!).  This does not seem to currently happen,
3755     // but this assertion here is to help prevent its occurrence.
3756     tty->print_cr("Found oop constant with non-zero offset");
3757     ShouldNotReachHere();
3758   }
3759 
3760   return (intptr_t)const_oop()->constant_encoding();
3761 }
3762 
3763 
3764 //-----------------------------filter------------------------------------------
3765 // Do not allow interface-vs.-noninterface joins to collapse to top.
3766 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3767 
3768   const Type* ft = join_helper(kills, include_speculative);

3787   } else {
3788     return one->equals(two) && TypePtr::eq(t);
3789   }
3790 }
3791 
3792 //------------------------------hash-------------------------------------------
3793 // Type-specific hashing function.
3794 uint TypeOopPtr::hash(void) const {
3795   return
3796     (uint)(const_oop() ? const_oop()->hash() : 0) +
3797     (uint)_klass_is_exact +
3798     (uint)_instance_id + TypePtr::hash();
3799 }
3800 
3801 //------------------------------dump2------------------------------------------
3802 #ifndef PRODUCT
3803 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3804   st->print("oopptr:%s", ptr_msg[_ptr]);
3805   if( _klass_is_exact ) st->print(":exact");
3806   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
3807   switch( _offset ) {
3808   case OffsetTop: st->print("+top"); break;
3809   case OffsetBot: st->print("+any"); break;
3810   case         0: break;
3811   default:        st->print("+%d",_offset); break;
3812   }
3813   if (_instance_id == InstanceTop)
3814     st->print(",iid=top");
3815   else if (_instance_id != InstanceBot)
3816     st->print(",iid=%d",_instance_id);
3817 
3818   dump_inline_depth(st);
3819   dump_speculative(st);
3820 }
3821 #endif
3822 
3823 //------------------------------singleton--------------------------------------
3824 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3825 // constants
3826 bool TypeOopPtr::singleton(void) const {
3827   // detune optimizer to not generate constant oop + constant offset as a constant!
3828   // TopPTR, Null, AnyNull, Constant are all singletons
3829   return (_offset == 0) && !below_centerline(_ptr);
3830 }
3831 
3832 //------------------------------add_offset-------------------------------------
3833 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3834   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3835 }
3836 
3837 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3838   return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3839 }
3840 
3841 /**
3842  * Return same type without a speculative part
3843  */
3844 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3845   if (_speculative == nullptr) {
3846     return this;
3847   }
3848   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3849   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
3850 }
3851 
3852 /**
3853  * Return same type but drop speculative part if we know we won't use
3854  * it
3855  */
3856 const Type* TypeOopPtr::cleanup_speculative() const {
3857   // If the klass is exact and the ptr is not null then there's
3858   // nothing that the speculative type can help us with

3931 const TypeInstPtr *TypeInstPtr::BOTTOM;
3932 const TypeInstPtr *TypeInstPtr::MIRROR;
3933 const TypeInstPtr *TypeInstPtr::MARK;
3934 const TypeInstPtr *TypeInstPtr::KLASS;
3935 
3936 // Is there a single ciKlass* that can represent that type?
3937 ciKlass* TypeInstPtr::exact_klass_helper() const {
3938   if (_interfaces->empty()) {
3939     return _klass;
3940   }
3941   if (_klass != ciEnv::current()->Object_klass()) {
3942     if (_interfaces->eq(_klass->as_instance_klass())) {
3943       return _klass;
3944     }
3945     return nullptr;
3946   }
3947   return _interfaces->exact_klass();
3948 }
3949 
3950 //------------------------------TypeInstPtr-------------------------------------
3951 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
3952                          int instance_id, const TypePtr* speculative, int inline_depth)
3953   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {

3954   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
3955   assert(k != nullptr &&
3956          (k->is_loaded() || o == nullptr),
3957          "cannot have constants with non-loaded klass");


3958 };
3959 
3960 //------------------------------make-------------------------------------------
3961 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
3962                                      ciKlass* k,
3963                                      const TypeInterfaces* interfaces,
3964                                      bool xk,
3965                                      ciObject* o,
3966                                      int offset,

3967                                      int instance_id,
3968                                      const TypePtr* speculative,
3969                                      int inline_depth) {
3970   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
3971   // Either const_oop() is null or else ptr is Constant
3972   assert( (!o && ptr != Constant) || (o && ptr == Constant),
3973           "constant pointers must have a value supplied" );
3974   // Ptr is never Null
3975   assert( ptr != Null, "null pointers are not typed" );
3976 
3977   assert(instance_id <= 0 || xk, "instances are always exactly typed");
3978   if (ptr == Constant) {
3979     // Note:  This case includes meta-object constants, such as methods.
3980     xk = true;
3981   } else if (k->is_loaded()) {
3982     ciInstanceKlass* ik = k->as_instance_klass();
3983     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
3984     assert(!ik->is_interface(), "no interface here");
3985     if (xk && ik->is_interface())  xk = false;  // no exact interface
3986   }
3987 



3988   // Now hash this baby
3989   TypeInstPtr *result =
3990     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
3991 
3992   return result;
3993 }
3994 
3995 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
3996   if (k->is_instance_klass()) {
3997     if (k->is_loaded()) {
3998       if (k->is_interface() && interface_handling == ignore_interfaces) {
3999         assert(interface, "no interface expected");
4000         k = ciEnv::current()->Object_klass();
4001         const TypeInterfaces* interfaces = TypeInterfaces::make();
4002         return interfaces;
4003       }
4004       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4005       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4006       if (k->is_interface()) {
4007         assert(interface, "no interface expected");
4008         k = ciEnv::current()->Object_klass();
4009       } else {
4010         assert(klass, "no instance klass expected");

4036   switch (bt) {
4037     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4038     case T_INT:      return TypeInt::make(constant.as_int());
4039     case T_CHAR:     return TypeInt::make(constant.as_char());
4040     case T_BYTE:     return TypeInt::make(constant.as_byte());
4041     case T_SHORT:    return TypeInt::make(constant.as_short());
4042     case T_FLOAT:    return TypeF::make(constant.as_float());
4043     case T_DOUBLE:   return TypeD::make(constant.as_double());
4044     case T_LONG:     return TypeLong::make(constant.as_long());
4045     default:         break;
4046   }
4047   fatal("Invalid boxed value type '%s'", type2name(bt));
4048   return nullptr;
4049 }
4050 
4051 //------------------------------cast_to_ptr_type-------------------------------
4052 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4053   if( ptr == _ptr ) return this;
4054   // Reconstruct _sig info here since not a problem with later lazy
4055   // construction, _sig will show up on demand.
4056   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4057 }
4058 
4059 
4060 //-----------------------------cast_to_exactness-------------------------------
4061 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4062   if( klass_is_exact == _klass_is_exact ) return this;
4063   if (!_klass->is_loaded())  return this;
4064   ciInstanceKlass* ik = _klass->as_instance_klass();
4065   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4066   assert(!ik->is_interface(), "no interface here");
4067   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);
4068 }
4069 
4070 //-----------------------------cast_to_instance_id----------------------------
4071 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4072   if( instance_id == _instance_id ) return this;
4073   return make(_ptr, klass(),  _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4074 }
4075 
4076 //------------------------------xmeet_unloaded---------------------------------
4077 // Compute the MEET of two InstPtrs when at least one is unloaded.
4078 // Assume classes are different since called after check for same name/class-loader
4079 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4080   int off = meet_offset(tinst->offset());
4081   PTR ptr = meet_ptr(tinst->ptr());
4082   int instance_id = meet_instance_id(tinst->instance_id());
4083   const TypePtr* speculative = xmeet_speculative(tinst);
4084   int depth = meet_inline_depth(tinst->inline_depth());
4085 
4086   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4087   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4088   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4089     //
4090     // Meet unloaded class with java/lang/Object
4091     //
4092     // Meet
4093     //          |                     Unloaded Class
4094     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4095     //  ===================================================================
4096     //   TOP    | ..........................Unloaded......................|
4097     //  AnyNull |  U-AN    |................Unloaded......................|
4098     // Constant | ... O-NN .................................. |   O-BOT   |
4099     //  NotNull | ... O-NN .................................. |   O-BOT   |
4100     //  BOTTOM  | ........................Object-BOTTOM ..................|
4101     //
4102     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4103     //
4104     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded->with_speculative(speculative); }
4105     else if (loaded->ptr() == TypePtr::AnyNull)  { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }
4106     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4107     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4108       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM->with_speculative(speculative);  }
4109       else                                       { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4110     }
4111     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4112 
4113     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4114   }
4115 
4116   // Both are unloaded, not the same class, not Object
4117   // Or meet unloaded with a different loaded class, not java/lang/Object
4118   if (ptr != TypePtr::BotPTR) {
4119     return TypeInstPtr::NOTNULL->with_speculative(speculative);
4120   }
4121   return TypeInstPtr::BOTTOM->with_speculative(speculative);
4122 }
4123 
4124 
4125 //------------------------------meet-------------------------------------------

4149   case Top:
4150     return this;
4151 
4152   default:                      // All else is a mistake
4153     typerr(t);
4154 
4155   case MetadataPtr:
4156   case KlassPtr:
4157   case InstKlassPtr:
4158   case AryKlassPtr:
4159   case RawPtr: return TypePtr::BOTTOM;
4160 
4161   case AryPtr: {                // All arrays inherit from Object class
4162     // Call in reverse direction to avoid duplication
4163     return t->is_aryptr()->xmeet_helper(this);
4164   }
4165 
4166   case OopPtr: {                // Meeting to OopPtrs
4167     // Found a OopPtr type vs self-InstPtr type
4168     const TypeOopPtr *tp = t->is_oopptr();
4169     int offset = meet_offset(tp->offset());
4170     PTR ptr = meet_ptr(tp->ptr());
4171     switch (tp->ptr()) {
4172     case TopPTR:
4173     case AnyNull: {
4174       int instance_id = meet_instance_id(InstanceTop);
4175       const TypePtr* speculative = xmeet_speculative(tp);
4176       int depth = meet_inline_depth(tp->inline_depth());
4177       return make(ptr, klass(), _interfaces, klass_is_exact(),
4178                   (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4179     }
4180     case NotNull:
4181     case BotPTR: {
4182       int instance_id = meet_instance_id(tp->instance_id());
4183       const TypePtr* speculative = xmeet_speculative(tp);
4184       int depth = meet_inline_depth(tp->inline_depth());
4185       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4186     }
4187     default: typerr(t);
4188     }
4189   }
4190 
4191   case AnyPtr: {                // Meeting to AnyPtrs
4192     // Found an AnyPtr type vs self-InstPtr type
4193     const TypePtr *tp = t->is_ptr();
4194     int offset = meet_offset(tp->offset());
4195     PTR ptr = meet_ptr(tp->ptr());
4196     int instance_id = meet_instance_id(InstanceTop);
4197     const TypePtr* speculative = xmeet_speculative(tp);
4198     int depth = meet_inline_depth(tp->inline_depth());
4199     switch (tp->ptr()) {
4200     case Null:
4201       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4202       // else fall through to AnyNull
4203     case TopPTR:
4204     case AnyNull: {
4205       return make(ptr, klass(), _interfaces, klass_is_exact(),
4206                   (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4207     }
4208     case NotNull:
4209     case BotPTR:
4210       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4211     default: typerr(t);
4212     }
4213   }
4214 
4215   /*
4216                  A-top         }
4217                /   |   \       }  Tops
4218            B-top A-any C-top   }
4219               | /  |  \ |      }  Any-nulls
4220            B-any   |   C-any   }
4221               |    |    |
4222            B-con A-con C-con   } constants; not comparable across classes
4223               |    |    |
4224            B-not   |   C-not   }
4225               | \  |  / |      }  not-nulls
4226            B-bot A-not C-bot   }
4227                \   |   /       }  Bottoms
4228                  A-bot         }
4229   */
4230 
4231   case InstPtr: {                // Meeting 2 Oops?
4232     // Found an InstPtr sub-type vs self-InstPtr type
4233     const TypeInstPtr *tinst = t->is_instptr();
4234     int off = meet_offset(tinst->offset());
4235     PTR ptr = meet_ptr(tinst->ptr());
4236     int instance_id = meet_instance_id(tinst->instance_id());
4237     const TypePtr* speculative = xmeet_speculative(tinst);
4238     int depth = meet_inline_depth(tinst->inline_depth());
4239     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4240 
4241     ciKlass* tinst_klass = tinst->klass();
4242     ciKlass* this_klass  = klass();
4243 
4244     ciKlass* res_klass = nullptr;
4245     bool res_xk = false;

4246     const Type* res;
4247     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4248 
4249     if (kind == UNLOADED) {
4250       // One of these classes has not been loaded
4251       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4252 #ifndef PRODUCT
4253       if (PrintOpto && Verbose) {
4254         tty->print("meet of unloaded classes resulted in: ");
4255         unloaded_meet->dump();
4256         tty->cr();
4257         tty->print("  this == ");
4258         dump();
4259         tty->cr();
4260         tty->print(" tinst == ");
4261         tinst->dump();
4262         tty->cr();
4263       }
4264 #endif
4265       res = unloaded_meet;
4266     } else {
4267       if (kind == NOT_SUBTYPE && instance_id > 0) {
4268         instance_id = InstanceBot;
4269       } else if (kind == LCA) {
4270         instance_id = InstanceBot;
4271       }
4272       ciObject* o = nullptr;             // Assume not constant when done
4273       ciObject* this_oop = const_oop();
4274       ciObject* tinst_oop = tinst->const_oop();
4275       if (ptr == Constant) {
4276         if (this_oop != nullptr && tinst_oop != nullptr &&
4277             this_oop->equals(tinst_oop))
4278           o = this_oop;
4279         else if (above_centerline(_ptr)) {
4280           assert(!tinst_klass->is_interface(), "");
4281           o = tinst_oop;
4282         } else if (above_centerline(tinst->_ptr)) {
4283           assert(!this_klass->is_interface(), "");
4284           o = this_oop;
4285         } else
4286           ptr = NotNull;
4287       }
4288       res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4289     }
4290 
4291     return res;
4292 
4293   } // End of case InstPtr
4294 
4295   } // End of switch
4296   return this;                  // Return the double constant
4297 }
4298 
4299 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4300                                                             ciKlass*& res_klass, bool& res_xk) {
4301   ciKlass* this_klass = this_type->klass();
4302   ciKlass* other_klass = other_type->klass();





4303   bool this_xk = this_type->klass_is_exact();
4304   bool other_xk = other_type->klass_is_exact();
4305   PTR this_ptr = this_type->ptr();
4306   PTR other_ptr = other_type->ptr();
4307   const TypeInterfaces* this_interfaces = this_type->interfaces();
4308   const TypeInterfaces* other_interfaces = other_type->interfaces();
4309   // Check for easy case; klasses are equal (and perhaps not loaded!)
4310   // If we have constants, then we created oops so classes are loaded
4311   // and we can handle the constants further down.  This case handles
4312   // both-not-loaded or both-loaded classes
4313   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4314     res_klass = this_klass;
4315     res_xk = this_xk;

4316     return QUICK;
4317   }
4318 
4319   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4320   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4321     return UNLOADED;
4322   }
4323 
4324   // !!! Here's how the symmetry requirement breaks down into invariants:
4325   // If we split one up & one down AND they subtype, take the down man.
4326   // If we split one up & one down AND they do NOT subtype, "fall hard".
4327   // If both are up and they subtype, take the subtype class.
4328   // If both are up and they do NOT subtype, "fall hard".
4329   // If both are down and they subtype, take the supertype class.
4330   // If both are down and they do NOT subtype, "fall hard".
4331   // Constants treated as down.
4332 
4333   // Now, reorder the above list; observe that both-down+subtype is also
4334   // "fall hard"; "fall hard" becomes the default case:
4335   // If we split one up & one down AND they subtype, take the down man.
4336   // If both are up and they subtype, take the subtype class.
4337 
4338   // If both are down and they subtype, "fall hard".
4339   // If both are down and they do NOT subtype, "fall hard".
4340   // If both are up and they do NOT subtype, "fall hard".
4341   // If we split one up & one down AND they do NOT subtype, "fall hard".
4342 
4343   // If a proper subtype is exact, and we return it, we return it exactly.
4344   // If a proper supertype is exact, there can be no subtyping relationship!
4345   // If both types are equal to the subtype, exactness is and-ed below the
4346   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4347 
4348   // Check for subtyping:
























































4349   const T* subtype = nullptr;
4350   bool subtype_exact = false;


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

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





4355     subtype = this_type;     // Pick subtyping class
4356     subtype_exact = this_xk;
4357   } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {








4358     subtype = other_type;    // Pick subtyping class
4359     subtype_exact = other_xk;








4360   }
4361 
4362   if (subtype) {
4363     if (above_centerline(ptr)) { // both are up?


4364       this_type = other_type = subtype;
4365       this_xk = other_xk = subtype_exact;





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

4368       this_xk = other_xk;

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

4370       other_type = this_type; // this is down; keep down man
4371       other_xk = this_xk;
4372     } else {

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



4374     }
4375   }
4376 
4377   // Check for classes now being equal
4378   if (this_type->is_same_java_type_as(other_type)) {
4379     // If the klasses are equal, the constants may still differ.  Fall to
4380     // NotNull if they do (neither constant is null; that is a special case
4381     // handled elsewhere).
4382     res_klass = this_type->klass();
4383     res_xk = this_xk;

4384     return SUBTYPE;
4385   } // Else classes are not equal
4386 
4387   // Since klasses are different, we require a LCA in the Java
4388   // class hierarchy - which means we have to fall to at least NotNull.
4389   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4390     ptr = NotNull;
4391   }
4392 
4393   interfaces = this_interfaces->intersection_with(other_interfaces);
4394 
4395   // Now we find the LCA of Java classes
4396   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4397 
4398   res_klass = k;
4399   res_xk = false;

4400 
4401   return LCA;
4402 }
4403 




4404 //------------------------java_mirror_type--------------------------------------
4405 ciType* TypeInstPtr::java_mirror_type() const {
4406   // must be a singleton type
4407   if( const_oop() == nullptr )  return nullptr;
4408 
4409   // must be of type java.lang.Class
4410   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;
4411 
4412   return const_oop()->as_instance()->java_mirror_type();
4413 }
4414 
4415 
4416 //------------------------------xdual------------------------------------------
4417 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4418 // inheritance mechanism.
4419 const Type *TypeInstPtr::xdual() const {
4420   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4421 }
4422 
4423 //------------------------------eq---------------------------------------------
4424 // Structural equality check for Type representations
4425 bool TypeInstPtr::eq( const Type *t ) const {
4426   const TypeInstPtr *p = t->is_instptr();
4427   return
4428     klass()->equals(p->klass()) &&

4429     _interfaces->eq(p->_interfaces) &&
4430     TypeOopPtr::eq(p);          // Check sub-type stuff
4431 }
4432 
4433 //------------------------------hash-------------------------------------------
4434 // Type-specific hashing function.
4435 uint TypeInstPtr::hash(void) const {
4436   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4437 }
4438 
4439 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4440   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4441 }
4442 
4443 
4444 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4445   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4446 }
4447 
4448 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4449   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4450 }
4451 
4452 
4453 //------------------------------dump2------------------------------------------
4454 // Dump oop Type
4455 #ifndef PRODUCT
4456 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {

4470       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4471       char* buf = ss.as_string(/* c_heap= */false);
4472       StringUtils::replace_no_expand(buf, "\n", "");
4473       st->print_raw(buf);
4474     }
4475   case BotPTR:
4476     if (!WizardMode && !Verbose) {
4477       if( _klass_is_exact ) st->print(":exact");
4478       break;
4479     }
4480   case TopPTR:
4481   case AnyNull:
4482   case NotNull:
4483     st->print(":%s", ptr_msg[_ptr]);
4484     if( _klass_is_exact ) st->print(":exact");
4485     break;
4486   default:
4487     break;
4488   }
4489 
4490   if( _offset ) {               // Dump offset, if any
4491     if( _offset == OffsetBot )      st->print("+any");
4492     else if( _offset == OffsetTop ) st->print("+unknown");
4493     else st->print("+%d", _offset);
4494   }
4495 
4496   st->print(" *");





4497   if (_instance_id == InstanceTop)
4498     st->print(",iid=top");
4499   else if (_instance_id != InstanceBot)
4500     st->print(",iid=%d",_instance_id);
4501 
4502   dump_inline_depth(st);
4503   dump_speculative(st);
4504 }
4505 #endif
4506 
4507 //------------------------------add_offset-------------------------------------
4508 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4509   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4510               _instance_id, add_offset_speculative(offset), _inline_depth);
4511 }
4512 
4513 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4514   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4515               _instance_id, with_offset_speculative(offset), _inline_depth);
4516 }
4517 
4518 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4519   if (_speculative == nullptr) {
4520     return this;
4521   }
4522   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4523   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4524               _instance_id, nullptr, _inline_depth);
4525 }
4526 
4527 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4528   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4529 }
4530 
4531 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4532   if (!UseInlineDepthForSpeculativeTypes) {
4533     return this;
4534   }
4535   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4536 }
4537 
4538 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4539   assert(is_known_instance(), "should be known");
4540   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);




4541 }
4542 
4543 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4544   bool xk = klass_is_exact();
4545   ciInstanceKlass* ik = klass()->as_instance_klass();
4546   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4547     if (_interfaces->eq(ik)) {
4548       Compile* C = Compile::current();
4549       Dependencies* deps = C->dependencies();
4550       deps->assert_leaf_type(ik);
4551       xk = true;
4552     }
4553   }
4554   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);
4555 }
4556 
4557 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) {
4558   static_assert(std::is_base_of<T2, T1>::value, "");
4559 
4560   if (!this_one->is_instance_type(other)) {
4561     return false;
4562   }
4563 
4564   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4565     return true;
4566   }
4567 
4568   return this_one->klass()->is_subtype_of(other->klass()) &&
4569          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4570 }
4571 
4572 
4573 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4574   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);

4579   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4580     return true;
4581   }
4582 
4583   if (this_one->is_instance_type(other)) {
4584     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4585   }
4586 
4587   int dummy;
4588   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4589   if (this_top_or_bottom) {
4590     return false;
4591   }
4592 
4593   const T1* other_ary = this_one->is_array_type(other);
4594   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4595   const TypePtr* this_elem = this_one->elem()->make_ptr();
4596   if (other_elem != nullptr && this_elem != nullptr) {
4597     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4598   }
4599 
4600   if (other_elem == nullptr && this_elem == nullptr) {
4601     return this_one->klass()->is_subtype_of(other->klass());
4602   }
4603 
4604   return false;
4605 }
4606 
4607 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4608   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4609 }
4610 
4611 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4612   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4613 }
4614 
4615 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4616   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4617 }
4618 
4619 //=============================================================================
4620 // Convenience common pre-built types.
4621 const TypeAryPtr* TypeAryPtr::BOTTOM;
4622 const TypeAryPtr* TypeAryPtr::RANGE;
4623 const TypeAryPtr* TypeAryPtr::OOPS;
4624 const TypeAryPtr* TypeAryPtr::NARROWOOPS;
4625 const TypeAryPtr* TypeAryPtr::BYTES;
4626 const TypeAryPtr* TypeAryPtr::SHORTS;
4627 const TypeAryPtr* TypeAryPtr::CHARS;
4628 const TypeAryPtr* TypeAryPtr::INTS;
4629 const TypeAryPtr* TypeAryPtr::LONGS;
4630 const TypeAryPtr* TypeAryPtr::FLOATS;
4631 const TypeAryPtr* TypeAryPtr::DOUBLES;

4632 
4633 //------------------------------make-------------------------------------------
4634 const TypeAryPtr *TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4635                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4636   assert(!(k == nullptr && ary->_elem->isa_int()),
4637          "integral arrays must be pre-equipped with a class");
4638   if (!xk)  xk = ary->ary_must_be_exact();
4639   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4640   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4641       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4642     k = nullptr;
4643   }
4644   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, instance_id, false, speculative, inline_depth))->hashcons();
4645 }
4646 
4647 //------------------------------make-------------------------------------------
4648 const TypeAryPtr *TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,
4649                                    int instance_id, const TypePtr* speculative, int inline_depth,
4650                                    bool is_autobox_cache) {
4651   assert(!(k == nullptr && ary->_elem->isa_int()),
4652          "integral arrays must be pre-equipped with a class");
4653   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4654   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
4655   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4656   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4657       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4658     k = nullptr;
4659   }
4660   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4661 }
4662 
4663 //------------------------------cast_to_ptr_type-------------------------------
4664 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4665   if( ptr == _ptr ) return this;
4666   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4667 }
4668 
4669 
4670 //-----------------------------cast_to_exactness-------------------------------
4671 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
4672   if( klass_is_exact == _klass_is_exact ) return this;
4673   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
4674   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
4675 }
4676 
4677 //-----------------------------cast_to_instance_id----------------------------
4678 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
4679   if( instance_id == _instance_id ) return this;
4680   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
4681 }
4682 
4683 
4684 //-----------------------------max_array_length-------------------------------
4685 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
4686 jint TypeAryPtr::max_array_length(BasicType etype) {
4687   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
4688     if (etype == T_NARROWOOP) {
4689       etype = T_OBJECT;
4690     } else if (etype == T_ILLEGAL) { // bottom[]
4691       etype = T_BYTE; // will produce conservatively high value
4692     } else {
4693       fatal("not an element type: %s", type2name(etype));
4694     }
4695   }
4696   return arrayOopDesc::max_array_length(etype);
4697 }
4698 
4699 //-----------------------------narrow_size_type-------------------------------
4700 // Narrow the given size type to the index range for the given array base type.

4718     if (size->is_con()) {
4719       lo = hi;
4720     }
4721     chg = true;
4722   }
4723   // Negative length arrays will produce weird intermediate dead fast-path code
4724   if (lo > hi) {
4725     return TypeInt::ZERO;
4726   }
4727   if (!chg) {
4728     return size;
4729   }
4730   return TypeInt::make(lo, hi, Type::WidenMin);
4731 }
4732 
4733 //-------------------------------cast_to_size----------------------------------
4734 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4735   assert(new_size != nullptr, "");
4736   new_size = narrow_size_type(new_size);
4737   if (new_size == size())  return this;
4738   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4739   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);































































4740 }
4741 
4742 //------------------------------cast_to_stable---------------------------------
4743 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4744   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4745     return this;
4746 
4747   const Type* elem = this->elem();
4748   const TypePtr* elem_ptr = elem->make_ptr();
4749 
4750   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4751     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4752     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4753   }
4754 
4755   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4756 
4757   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4758 }
4759 
4760 //-----------------------------stable_dimension--------------------------------
4761 int TypeAryPtr::stable_dimension() const {
4762   if (!is_stable())  return 0;
4763   int dim = 1;
4764   const TypePtr* elem_ptr = elem()->make_ptr();
4765   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4766     dim += elem_ptr->is_aryptr()->stable_dimension();
4767   return dim;
4768 }
4769 
4770 //----------------------cast_to_autobox_cache-----------------------------------
4771 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4772   if (is_autobox_cache())  return this;
4773   const TypeOopPtr* etype = elem()->make_oopptr();
4774   if (etype == nullptr)  return this;
4775   // The pointers in the autobox arrays are always non-null.
4776   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4777   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4778   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4779 }
4780 
4781 //------------------------------eq---------------------------------------------
4782 // Structural equality check for Type representations
4783 bool TypeAryPtr::eq( const Type *t ) const {
4784   const TypeAryPtr *p = t->is_aryptr();
4785   return
4786     _ary == p->_ary &&  // Check array
4787     TypeOopPtr::eq(p);  // Check sub-parts

4788 }
4789 
4790 //------------------------------hash-------------------------------------------
4791 // Type-specific hashing function.
4792 uint TypeAryPtr::hash(void) const {
4793   return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4794 }
4795 
4796 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4797   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4798 }
4799 
4800 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4801   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4802 }
4803 
4804 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4805   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4806 }
4807 //------------------------------meet-------------------------------------------
4808 // Compute the MEET of two types.  It returns a new Type object.
4809 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4810   // Perform a fast test for common case; meeting the same types together.
4811   if( this == t ) return this;  // Meeting same type-rep?
4812   // Current "this->_base" is Pointer
4813   switch (t->base()) {          // switch on original type

4820   case HalfFloatBot:
4821   case FloatTop:
4822   case FloatCon:
4823   case FloatBot:
4824   case DoubleTop:
4825   case DoubleCon:
4826   case DoubleBot:
4827   case NarrowOop:
4828   case NarrowKlass:
4829   case Bottom:                  // Ye Olde Default
4830     return Type::BOTTOM;
4831   case Top:
4832     return this;
4833 
4834   default:                      // All else is a mistake
4835     typerr(t);
4836 
4837   case OopPtr: {                // Meeting to OopPtrs
4838     // Found a OopPtr type vs self-AryPtr type
4839     const TypeOopPtr *tp = t->is_oopptr();
4840     int offset = meet_offset(tp->offset());
4841     PTR ptr = meet_ptr(tp->ptr());
4842     int depth = meet_inline_depth(tp->inline_depth());
4843     const TypePtr* speculative = xmeet_speculative(tp);
4844     switch (tp->ptr()) {
4845     case TopPTR:
4846     case AnyNull: {
4847       int instance_id = meet_instance_id(InstanceTop);
4848       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4849                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4850     }
4851     case BotPTR:
4852     case NotNull: {
4853       int instance_id = meet_instance_id(tp->instance_id());
4854       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4855     }
4856     default: ShouldNotReachHere();
4857     }
4858   }
4859 
4860   case AnyPtr: {                // Meeting two AnyPtrs
4861     // Found an AnyPtr type vs self-AryPtr type
4862     const TypePtr *tp = t->is_ptr();
4863     int offset = meet_offset(tp->offset());
4864     PTR ptr = meet_ptr(tp->ptr());
4865     const TypePtr* speculative = xmeet_speculative(tp);
4866     int depth = meet_inline_depth(tp->inline_depth());
4867     switch (tp->ptr()) {
4868     case TopPTR:
4869       return this;
4870     case BotPTR:
4871     case NotNull:
4872       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4873     case Null:
4874       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4875       // else fall through to AnyNull
4876     case AnyNull: {
4877       int instance_id = meet_instance_id(InstanceTop);
4878       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4879                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4880     }
4881     default: ShouldNotReachHere();
4882     }
4883   }
4884 
4885   case MetadataPtr:
4886   case KlassPtr:
4887   case InstKlassPtr:
4888   case AryKlassPtr:
4889   case RawPtr: return TypePtr::BOTTOM;
4890 
4891   case AryPtr: {                // Meeting 2 references?
4892     const TypeAryPtr *tap = t->is_aryptr();
4893     int off = meet_offset(tap->offset());

4894     const Type* tm = _ary->meet_speculative(tap->_ary);
4895     const TypeAry* tary = tm->isa_ary();
4896     if (tary == nullptr) {
4897       assert(tm == Type::TOP || tm == Type::BOTTOM, "");
4898       return tm;
4899     }
4900     PTR ptr = meet_ptr(tap->ptr());
4901     int instance_id = meet_instance_id(tap->instance_id());
4902     const TypePtr* speculative = xmeet_speculative(tap);
4903     int depth = meet_inline_depth(tap->inline_depth());
4904 
4905     ciKlass* res_klass = nullptr;
4906     bool res_xk = false;




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














4910     }
4911 
4912     ciObject* o = nullptr;             // Assume not constant when done
4913     ciObject* this_oop = const_oop();
4914     ciObject* tap_oop = tap->const_oop();
4915     if (ptr == Constant) {
4916       if (this_oop != nullptr && tap_oop != nullptr &&
4917           this_oop->equals(tap_oop)) {
4918         o = tap_oop;
4919       } else if (above_centerline(_ptr)) {
4920         o = tap_oop;
4921       } else if (above_centerline(tap->_ptr)) {
4922         o = this_oop;
4923       } else {
4924         ptr = NotNull;
4925       }
4926     }
4927     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4928   }
4929 
4930   // All arrays inherit from Object class
4931   case InstPtr: {
4932     const TypeInstPtr *tp = t->is_instptr();
4933     int offset = meet_offset(tp->offset());
4934     PTR ptr = meet_ptr(tp->ptr());
4935     int instance_id = meet_instance_id(tp->instance_id());
4936     const TypePtr* speculative = xmeet_speculative(tp);
4937     int depth = meet_inline_depth(tp->inline_depth());
4938     const TypeInterfaces* interfaces = meet_interfaces(tp);
4939     const TypeInterfaces* tp_interfaces = tp->_interfaces;
4940     const TypeInterfaces* this_interfaces = _interfaces;
4941 
4942     switch (ptr) {
4943     case TopPTR:
4944     case AnyNull:                // Fall 'down' to dual of object klass
4945       // For instances when a subclass meets a superclass we fall
4946       // below the centerline when the superclass is exact. We need to
4947       // do the same here.
4948       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
4949         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4950       } else {
4951         // cannot subclass, so the meet has to fall badly below the centerline
4952         ptr = NotNull;
4953         instance_id = InstanceBot;
4954         interfaces = this_interfaces->intersection_with(tp_interfaces);
4955         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);
4956       }
4957     case Constant:
4958     case NotNull:
4959     case BotPTR:                // Fall down to object klass
4960       // LCA is object_klass, but if we subclass from the top we can do better
4961       if (above_centerline(tp->ptr())) {
4962         // If 'tp'  is above the centerline and it is Object class
4963         // then we can subclass in the Java class hierarchy.
4964         // For instances when a subclass meets a superclass we fall
4965         // below the centerline when the superclass is exact. We need
4966         // to do the same here.
4967         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
4968           // that is, my array type is a subtype of 'tp' klass
4969           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4970                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4971         }
4972       }
4973       // The other case cannot happen, since t cannot be a subtype of an array.
4974       // The meet falls down to Object class below centerline.
4975       if (ptr == Constant) {
4976          ptr = NotNull;
4977       }
4978       if (instance_id > 0) {
4979         instance_id = InstanceBot;
4980       }
4981       interfaces = this_interfaces->intersection_with(tp_interfaces);
4982       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);
4983     default: typerr(t);
4984     }
4985   }
4986   }
4987   return this;                  // Lint noise
4988 }
4989 
4990 
4991 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
4992                                                            const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
4993   int dummy;
4994   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
4995   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
4996   ciKlass* this_klass = this_ary->klass();
4997   ciKlass* other_klass = other_ary->klass();
4998   bool this_xk = this_ary->klass_is_exact();
4999   bool other_xk = other_ary->klass_is_exact();
5000   PTR this_ptr = this_ary->ptr();
5001   PTR other_ptr = other_ary->ptr();









5002   res_klass = nullptr;
5003   MeetResult result = SUBTYPE;






5004   if (elem->isa_int()) {
5005     // Integral array element types have irrelevant lattice relations.
5006     // It is the klass that determines array layout, not the element type.
5007     if (this_top_or_bottom)
5008       res_klass = other_klass;
5009     else if (other_top_or_bottom || other_klass == this_klass) {
5010       res_klass = this_klass;
5011     } else {
5012       // Something like byte[int+] meets char[int+].
5013       // This must fall to bottom, not (int[-128..65535])[int+].
5014       // instance_id = InstanceBot;
5015       elem = Type::BOTTOM;
5016       result = NOT_SUBTYPE;
5017       if (above_centerline(ptr) || ptr == Constant) {
5018         ptr = NotNull;
5019         res_xk = false;
5020         return NOT_SUBTYPE;
5021       }
5022     }
5023   } else {// Non integral arrays.
5024     // Must fall to bottom if exact klasses in upper lattice
5025     // are not equal or super klass is exact.
5026     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5027         // meet with top[] and bottom[] are processed further down:
5028         !this_top_or_bottom && !other_top_or_bottom &&
5029         // both are exact and not equal:

5031          // 'tap'  is exact and super or unrelated:
5032          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5033          // 'this' is exact and super or unrelated:
5034          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5035       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5036         elem = Type::BOTTOM;
5037       }
5038       ptr = NotNull;
5039       res_xk = false;
5040       return NOT_SUBTYPE;
5041     }
5042   }
5043 
5044   res_xk = false;
5045   switch (other_ptr) {
5046     case AnyNull:
5047     case TopPTR:
5048       // Compute new klass on demand, do not use tap->_klass
5049       if (below_centerline(this_ptr)) {
5050         res_xk = this_xk;



5051       } else {
5052         res_xk = (other_xk || this_xk);
5053       }
5054       return result;
5055     case Constant: {
5056       if (this_ptr == Constant) {


5057         res_xk = true;
5058       } else if(above_centerline(this_ptr)) {
5059         res_xk = true;
5060       } else {
5061         // Only precise for identical arrays
5062         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));






5063       }
5064       return result;
5065     }
5066     case NotNull:
5067     case BotPTR:
5068       // Compute new klass on demand, do not use tap->_klass
5069       if (above_centerline(this_ptr)) {
5070         res_xk = other_xk;



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






5074       }
5075       return result;
5076     default:  {
5077       ShouldNotReachHere();
5078       return result;
5079     }
5080   }
5081   return result;
5082 }
5083 
5084 
5085 //------------------------------xdual------------------------------------------
5086 // Dual: compute field-by-field dual
5087 const Type *TypeAryPtr::xdual() const {
5088   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());










5089 }
5090 
5091 //------------------------------dump2------------------------------------------
5092 #ifndef PRODUCT
5093 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5094   _ary->dump2(d,depth,st);
5095   _interfaces->dump(st);
5096 
5097   switch( _ptr ) {
5098   case Constant:
5099     const_oop()->print(st);
5100     break;
5101   case BotPTR:
5102     if (!WizardMode && !Verbose) {
5103       if( _klass_is_exact ) st->print(":exact");
5104       break;
5105     }
5106   case TopPTR:
5107   case AnyNull:
5108   case NotNull:
5109     st->print(":%s", ptr_msg[_ptr]);
5110     if( _klass_is_exact ) st->print(":exact");
5111     break;
5112   default:
5113     break;
5114   }
5115 
5116   if( _offset != 0 ) {






















5117     BasicType basic_elem_type = elem()->basic_type();
5118     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5119     if( _offset == OffsetTop )       st->print("+undefined");
5120     else if( _offset == OffsetBot )  st->print("+any");
5121     else if( _offset < header_size ) st->print("+%d", _offset);
5122     else {
5123       if (basic_elem_type == T_ILLEGAL) {
5124         st->print("+any");
5125       } else {
5126         int elem_size = type2aelembytes(basic_elem_type);
5127         st->print("[%d]", (_offset - header_size)/elem_size);
5128       }
5129     }
5130   }
5131   st->print(" *");
5132   if (_instance_id == InstanceTop)
5133     st->print(",iid=top");
5134   else if (_instance_id != InstanceBot)
5135     st->print(",iid=%d",_instance_id);
5136 
5137   dump_inline_depth(st);
5138   dump_speculative(st);
5139 }
5140 #endif
5141 
5142 bool TypeAryPtr::empty(void) const {
5143   if (_ary->empty())       return true;




5144   return TypeOopPtr::empty();
5145 }
5146 
5147 //------------------------------add_offset-------------------------------------
5148 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5149   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
5150 }
5151 
5152 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5153   return make(_ptr, _const_oop, _ary, _klass, _klass_is_exact, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
5154 }
5155 
5156 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5157   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _instance_id, _speculative, _inline_depth);
5158 }
5159 
5160 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5161   if (_speculative == nullptr) {
5162     return this;
5163   }
5164   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5165   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, nullptr, _inline_depth);













5166 }
5167 
5168 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5169   if (!UseInlineDepthForSpeculativeTypes) {
5170     return this;
5171   }
5172   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);











































5173 }
5174 
5175 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5176   assert(is_known_instance(), "should be known");
5177   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5178 }
5179 
5180 //=============================================================================
5181 

5182 //------------------------------hash-------------------------------------------
5183 // Type-specific hashing function.
5184 uint TypeNarrowPtr::hash(void) const {
5185   return _ptrtype->hash() + 7;
5186 }
5187 
5188 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5189   return _ptrtype->singleton();
5190 }
5191 
5192 bool TypeNarrowPtr::empty(void) const {
5193   return _ptrtype->empty();
5194 }
5195 
5196 intptr_t TypeNarrowPtr::get_con() const {
5197   return _ptrtype->get_con();
5198 }
5199 
5200 bool TypeNarrowPtr::eq( const Type *t ) const {
5201   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5255   case HalfFloatTop:
5256   case HalfFloatCon:
5257   case HalfFloatBot:
5258   case FloatTop:
5259   case FloatCon:
5260   case FloatBot:
5261   case DoubleTop:
5262   case DoubleCon:
5263   case DoubleBot:
5264   case AnyPtr:
5265   case RawPtr:
5266   case OopPtr:
5267   case InstPtr:
5268   case AryPtr:
5269   case MetadataPtr:
5270   case KlassPtr:
5271   case InstKlassPtr:
5272   case AryKlassPtr:
5273   case NarrowOop:
5274   case NarrowKlass:
5275 
5276   case Bottom:                  // Ye Olde Default
5277     return Type::BOTTOM;
5278   case Top:
5279     return this;
5280 
5281   default:                      // All else is a mistake
5282     typerr(t);
5283 
5284   } // End of switch
5285 
5286   return this;
5287 }
5288 
5289 #ifndef PRODUCT
5290 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5291   _ptrtype->dump2(d, depth, st);
5292 }
5293 #endif
5294 
5295 const TypeNarrowOop *TypeNarrowOop::BOTTOM;

5339     return (one == two) && TypePtr::eq(t);
5340   } else {
5341     return one->equals(two) && TypePtr::eq(t);
5342   }
5343 }
5344 
5345 //------------------------------hash-------------------------------------------
5346 // Type-specific hashing function.
5347 uint TypeMetadataPtr::hash(void) const {
5348   return
5349     (metadata() ? metadata()->hash() : 0) +
5350     TypePtr::hash();
5351 }
5352 
5353 //------------------------------singleton--------------------------------------
5354 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5355 // constants
5356 bool TypeMetadataPtr::singleton(void) const {
5357   // detune optimizer to not generate constant metadata + constant offset as a constant!
5358   // TopPTR, Null, AnyNull, Constant are all singletons
5359   return (_offset == 0) && !below_centerline(_ptr);
5360 }
5361 
5362 //------------------------------add_offset-------------------------------------
5363 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5364   return make( _ptr, _metadata, xadd_offset(offset));
5365 }
5366 
5367 //-----------------------------filter------------------------------------------
5368 // Do not allow interface-vs.-noninterface joins to collapse to top.
5369 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5370   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5371   if (ft == nullptr || ft->empty())
5372     return Type::TOP;           // Canonical empty value
5373   return ft;
5374 }
5375 
5376  //------------------------------get_con----------------------------------------
5377 intptr_t TypeMetadataPtr::get_con() const {
5378   assert( _ptr == Null || _ptr == Constant, "" );
5379   assert( _offset >= 0, "" );
5380 
5381   if (_offset != 0) {
5382     // After being ported to the compiler interface, the compiler no longer
5383     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5384     // to a handle at compile time.  This handle is embedded in the generated
5385     // code and dereferenced at the time the nmethod is made.  Until that time,
5386     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5387     // have access to the addresses!).  This does not seem to currently happen,
5388     // but this assertion here is to help prevent its occurrence.
5389     tty->print_cr("Found oop constant with non-zero offset");
5390     ShouldNotReachHere();
5391   }
5392 
5393   return (intptr_t)metadata()->constant_encoding();
5394 }
5395 
5396 //------------------------------cast_to_ptr_type-------------------------------
5397 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5398   if( ptr == _ptr ) return this;
5399   return make(ptr, metadata(), _offset);
5400 }
5401 

5415   case HalfFloatBot:
5416   case FloatTop:
5417   case FloatCon:
5418   case FloatBot:
5419   case DoubleTop:
5420   case DoubleCon:
5421   case DoubleBot:
5422   case NarrowOop:
5423   case NarrowKlass:
5424   case Bottom:                  // Ye Olde Default
5425     return Type::BOTTOM;
5426   case Top:
5427     return this;
5428 
5429   default:                      // All else is a mistake
5430     typerr(t);
5431 
5432   case AnyPtr: {
5433     // Found an AnyPtr type vs self-OopPtr type
5434     const TypePtr *tp = t->is_ptr();
5435     int offset = meet_offset(tp->offset());
5436     PTR ptr = meet_ptr(tp->ptr());
5437     switch (tp->ptr()) {
5438     case Null:
5439       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5440       // else fall through:
5441     case TopPTR:
5442     case AnyNull: {
5443       return make(ptr, _metadata, offset);
5444     }
5445     case BotPTR:
5446     case NotNull:
5447       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5448     default: typerr(t);
5449     }
5450   }
5451 
5452   case RawPtr:
5453   case KlassPtr:
5454   case InstKlassPtr:
5455   case AryKlassPtr:
5456   case OopPtr:
5457   case InstPtr:
5458   case AryPtr:
5459     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5460 
5461   case MetadataPtr: {
5462     const TypeMetadataPtr *tp = t->is_metadataptr();
5463     int offset = meet_offset(tp->offset());
5464     PTR tptr = tp->ptr();
5465     PTR ptr = meet_ptr(tptr);
5466     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5467     if (tptr == TopPTR || _ptr == TopPTR ||
5468         metadata()->equals(tp->metadata())) {
5469       return make(ptr, md, offset);
5470     }
5471     // metadata is different
5472     if( ptr == Constant ) {  // Cannot be equal constants, so...
5473       if( tptr == Constant && _ptr != Constant)  return t;
5474       if( _ptr == Constant && tptr != Constant)  return this;
5475       ptr = NotNull;            // Fall down in lattice
5476     }
5477     return make(ptr, nullptr, offset);
5478     break;
5479   }
5480   } // End of switch
5481   return this;                  // Return the double constant
5482 }
5483 
5484 
5485 //------------------------------xdual------------------------------------------
5486 // Dual of a pure metadata pointer.
5487 const Type *TypeMetadataPtr::xdual() const {
5488   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5489 }
5490 
5491 //------------------------------dump2------------------------------------------
5492 #ifndef PRODUCT
5493 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5494   st->print("metadataptr:%s", ptr_msg[_ptr]);
5495   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
5496   switch( _offset ) {
5497   case OffsetTop: st->print("+top"); break;
5498   case OffsetBot: st->print("+any"); break;
5499   case         0: break;
5500   default:        st->print("+%d",_offset); break;
5501   }
5502 }
5503 #endif
5504 
5505 
5506 //=============================================================================
5507 // Convenience common pre-built type.
5508 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5509 
5510 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5511   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5512 }
5513 
5514 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5515   return make(Constant, m, 0);
5516 }
5517 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5518   return make(Constant, m, 0);
5519 }
5520 
5521 //------------------------------make-------------------------------------------
5522 // Create a meta data constant
5523 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5524   assert(m == nullptr || !m->is_klass(), "wrong type");
5525   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5526 }
5527 
5528 
5529 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5530   const Type* elem = _ary->_elem;
5531   bool xk = klass_is_exact();
5532   if (elem->make_oopptr() != nullptr) {
5533     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5534     if (elem->is_klassptr()->klass_is_exact()) {





5535       xk = true;
5536     }
5537   }
5538   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), 0);
5539 }
5540 
5541 const TypeKlassPtr* TypeKlassPtr::make(ciKlass *klass, InterfaceHandling interface_handling) {
5542   if (klass->is_instance_klass()) {
5543     return TypeInstKlassPtr::make(klass, interface_handling);
5544   }
5545   return TypeAryKlassPtr::make(klass, interface_handling);
5546 }
5547 
5548 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling) {
5549   if (klass->is_instance_klass()) {
5550     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
5551     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
5552   }
5553   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
5554 }
5555 
5556 
5557 //------------------------------TypeKlassPtr-----------------------------------
5558 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
5559   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
5560   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
5561          klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
5562 }
5563 
5564 // Is there a single ciKlass* that can represent that type?
5565 ciKlass* TypeKlassPtr::exact_klass_helper() const {
5566   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
5567   if (_interfaces->empty()) {
5568     return _klass;
5569   }
5570   if (_klass != ciEnv::current()->Object_klass()) {
5571     if (_interfaces->eq(_klass->as_instance_klass())) {
5572       return _klass;
5573     }
5574     return nullptr;
5575   }
5576   return _interfaces->exact_klass();
5577 }
5578 
5579 //------------------------------eq---------------------------------------------
5580 // Structural equality check for Type representations
5581 bool TypeKlassPtr::eq(const Type *t) const {
5582   const TypeKlassPtr *p = t->is_klassptr();
5583   return
5584     _interfaces->eq(p->_interfaces) &&
5585     TypePtr::eq(p);
5586 }
5587 
5588 //------------------------------hash-------------------------------------------
5589 // Type-specific hashing function.
5590 uint TypeKlassPtr::hash(void) const {
5591   return TypePtr::hash() + _interfaces->hash();
5592 }
5593 
5594 //------------------------------singleton--------------------------------------
5595 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5596 // constants
5597 bool TypeKlassPtr::singleton(void) const {
5598   // detune optimizer to not generate constant klass + constant offset as a constant!
5599   // TopPTR, Null, AnyNull, Constant are all singletons
5600   return (_offset == 0) && !below_centerline(_ptr);
5601 }
5602 
5603 // Do not allow interface-vs.-noninterface joins to collapse to top.
5604 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
5605   // logic here mirrors the one from TypeOopPtr::filter. See comments
5606   // there.
5607   const Type* ft = join_helper(kills, include_speculative);
5608 
5609   if (ft->empty()) {
5610     return Type::TOP;           // Canonical empty value
5611   }
5612 
5613   return ft;
5614 }
5615 
5616 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
5617   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
5618     return _interfaces->union_with(other->_interfaces);
5619   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
5620     return other->_interfaces;
5621   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
5622     return _interfaces;
5623   }
5624   return _interfaces->intersection_with(other->_interfaces);
5625 }
5626 
5627 //------------------------------get_con----------------------------------------
5628 intptr_t TypeKlassPtr::get_con() const {
5629   assert( _ptr == Null || _ptr == Constant, "" );
5630   assert( _offset >= 0, "" );
5631 
5632   if (_offset != 0) {
5633     // After being ported to the compiler interface, the compiler no longer
5634     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5635     // to a handle at compile time.  This handle is embedded in the generated
5636     // code and dereferenced at the time the nmethod is made.  Until that time,
5637     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5638     // have access to the addresses!).  This does not seem to currently happen,
5639     // but this assertion here is to help prevent its occurrence.
5640     tty->print_cr("Found oop constant with non-zero offset");
5641     ShouldNotReachHere();
5642   }
5643 
5644   ciKlass* k = exact_klass();
5645 
5646   return (intptr_t)k->constant_encoding();
5647 }
5648 
5649 //------------------------------dump2------------------------------------------
5650 // Dump Klass Type
5651 #ifndef PRODUCT
5652 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {

5656   case NotNull:
5657     {
5658       const char *name = klass()->name()->as_utf8();
5659       if (name) {
5660         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
5661       } else {
5662         ShouldNotReachHere();
5663       }
5664       _interfaces->dump(st);
5665     }
5666   case BotPTR:
5667     if (!WizardMode && !Verbose && _ptr != Constant) break;
5668   case TopPTR:
5669   case AnyNull:
5670     st->print(":%s", ptr_msg[_ptr]);
5671     if (_ptr == Constant) st->print(":exact");
5672     break;
5673   default:
5674     break;
5675   }
5676 
5677   if (_offset) {               // Dump offset, if any
5678     if (_offset == OffsetBot)      { st->print("+any"); }
5679     else if (_offset == OffsetTop) { st->print("+unknown"); }
5680     else                            { st->print("+%d", _offset); }
5681   }
5682 
5683   st->print(" *");




5684 }
5685 #endif
5686 
5687 //=============================================================================
5688 // Convenience common pre-built types.
5689 
5690 // Not-null object klass or below
5691 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
5692 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
5693 
5694 bool TypeInstKlassPtr::eq(const Type *t) const {
5695   const TypeKlassPtr *p = t->is_klassptr();
5696   return
5697     klass()->equals(p->klass()) &&

5698     TypeKlassPtr::eq(p);
5699 }
5700 
5701 uint TypeInstKlassPtr::hash(void) const {
5702   return klass()->hash() + TypeKlassPtr::hash();
5703 }
5704 
5705 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {


5706   TypeInstKlassPtr *r =
5707     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5708 
5709   return r;
5710 }
5711 
5712 //------------------------------add_offset-------------------------------------
5713 // Access internals of klass object
5714 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5715   return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5716 }
5717 
5718 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5719   return make(_ptr, klass(), _interfaces, offset);
5720 }
5721 
5722 //------------------------------cast_to_ptr_type-------------------------------
5723 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5724   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5725   if( ptr == _ptr ) return this;
5726   return make(ptr, _klass, _interfaces, _offset);
5727 }
5728 
5729 
5730 bool TypeInstKlassPtr::must_be_exact() const {
5731   if (!_klass->is_loaded())  return false;
5732   ciInstanceKlass* ik = _klass->as_instance_klass();
5733   if (ik->is_final())  return true;  // cannot clear xk
5734   return false;
5735 }
5736 
5737 //-----------------------------cast_to_exactness-------------------------------
5738 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5739   if (klass_is_exact == (_ptr == Constant)) return this;
5740   if (must_be_exact()) return this;
5741   ciKlass* k = klass();
5742   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);
5743 }
5744 
5745 
5746 //-----------------------------as_instance_type--------------------------------
5747 // Corresponding type for an instance of the given class.
5748 // It will be NotNull, and exact if and only if the klass type is exact.
5749 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5750   ciKlass* k = klass();
5751   bool xk = klass_is_exact();
5752   Compile* C = Compile::current();
5753   Dependencies* deps = C->dependencies();
5754   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5755   // Element is an instance
5756   bool klass_is_exact = false;
5757   const TypeInterfaces* interfaces = _interfaces;
5758   if (k->is_loaded()) {
5759     // Try to set klass_is_exact.
5760     ciInstanceKlass* ik = k->as_instance_klass();
5761     klass_is_exact = ik->is_final();
5762     if (!klass_is_exact && klass_change
5763         && deps != nullptr && UseUniqueSubclasses) {
5764       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5765       if (sub != nullptr) {
5766         if (_interfaces->eq(sub)) {
5767           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5768           k = ik = sub;
5769           xk = sub->is_final();
5770         }
5771       }
5772     }
5773   }
5774   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);
5775 }
5776 
5777 //------------------------------xmeet------------------------------------------
5778 // Compute the MEET of two types, return a new Type object.
5779 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5780   // Perform a fast test for common case; meeting the same types together.
5781   if( this == t ) return this;  // Meeting same type-rep?
5782 
5783   // Current "this->_base" is Pointer
5784   switch (t->base()) {          // switch on original type
5785 
5786   case Int:                     // Mixing ints & oops happens when javac
5787   case Long:                    // reuses local variables
5788   case HalfFloatTop:
5789   case HalfFloatCon:
5790   case HalfFloatBot:
5791   case FloatTop:
5792   case FloatCon:
5793   case FloatBot:
5794   case DoubleTop:
5795   case DoubleCon:
5796   case DoubleBot:
5797   case NarrowOop:
5798   case NarrowKlass:
5799   case Bottom:                  // Ye Olde Default
5800     return Type::BOTTOM;
5801   case Top:
5802     return this;
5803 
5804   default:                      // All else is a mistake
5805     typerr(t);
5806 
5807   case AnyPtr: {                // Meeting to AnyPtrs
5808     // Found an AnyPtr type vs self-KlassPtr type
5809     const TypePtr *tp = t->is_ptr();
5810     int offset = meet_offset(tp->offset());
5811     PTR ptr = meet_ptr(tp->ptr());
5812     switch (tp->ptr()) {
5813     case TopPTR:
5814       return this;
5815     case Null:
5816       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5817     case AnyNull:
5818       return make( ptr, klass(), _interfaces, offset );
5819     case BotPTR:
5820     case NotNull:
5821       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5822     default: typerr(t);
5823     }
5824   }
5825 
5826   case RawPtr:
5827   case MetadataPtr:
5828   case OopPtr:
5829   case AryPtr:                  // Meet with AryPtr
5830   case InstPtr:                 // Meet with InstPtr
5831     return TypePtr::BOTTOM;
5832 
5833   //
5834   //             A-top         }
5835   //           /   |   \       }  Tops
5836   //       B-top A-any C-top   }
5837   //          | /  |  \ |      }  Any-nulls
5838   //       B-any   |   C-any   }
5839   //          |    |    |
5840   //       B-con A-con C-con   } constants; not comparable across classes
5841   //          |    |    |
5842   //       B-not   |   C-not   }
5843   //          | \  |  / |      }  not-nulls
5844   //       B-bot A-not C-bot   }
5845   //           \   |   /       }  Bottoms
5846   //             A-bot         }
5847   //
5848 
5849   case InstKlassPtr: {  // Meet two KlassPtr types
5850     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5851     int  off     = meet_offset(tkls->offset());
5852     PTR  ptr     = meet_ptr(tkls->ptr());
5853     const TypeInterfaces* interfaces = meet_interfaces(tkls);
5854 
5855     ciKlass* res_klass = nullptr;
5856     bool res_xk = false;
5857     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {

5858       case UNLOADED:
5859         ShouldNotReachHere();
5860       case SUBTYPE:
5861       case NOT_SUBTYPE:
5862       case LCA:
5863       case QUICK: {
5864         assert(res_xk == (ptr == Constant), "");
5865         const Type* res = make(ptr, res_klass, interfaces, off);
5866         return res;
5867       }
5868       default:
5869         ShouldNotReachHere();
5870     }
5871   } // End of case KlassPtr
5872   case AryKlassPtr: {                // All arrays inherit from Object class
5873     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5874     int offset = meet_offset(tp->offset());
5875     PTR ptr = meet_ptr(tp->ptr());
5876     const TypeInterfaces* interfaces = meet_interfaces(tp);
5877     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5878     const TypeInterfaces* this_interfaces = _interfaces;
5879 
5880     switch (ptr) {
5881     case TopPTR:
5882     case AnyNull:                // Fall 'down' to dual of object klass
5883       // For instances when a subclass meets a superclass we fall
5884       // below the centerline when the superclass is exact. We need to
5885       // do the same here.
5886       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5887         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);
5888       } else {
5889         // cannot subclass, so the meet has to fall badly below the centerline
5890         ptr = NotNull;
5891         interfaces = _interfaces->intersection_with(tp->_interfaces);
5892         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5893       }
5894     case Constant:
5895     case NotNull:
5896     case BotPTR:                // Fall down to object klass
5897       // LCA is object_klass, but if we subclass from the top we can do better
5898       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5899         // If 'this' (InstPtr) is above the centerline and it is Object class
5900         // then we can subclass in the Java class hierarchy.
5901         // For instances when a subclass meets a superclass we fall
5902         // below the centerline when the superclass is exact. We need
5903         // to do the same here.
5904         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5905           // that is, tp's array type is a subtype of my klass
5906           return TypeAryKlassPtr::make(ptr,
5907                                        tp->elem(), tp->klass(), offset);
5908         }
5909       }
5910       // The other case cannot happen, since I cannot be a subtype of an array.
5911       // The meet falls down to Object class below centerline.
5912       if( ptr == Constant )
5913          ptr = NotNull;
5914       interfaces = this_interfaces->intersection_with(tp_interfaces);
5915       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
5916     default: typerr(t);
5917     }
5918   }
5919 
5920   } // End of switch
5921   return this;                  // Return the double constant
5922 }
5923 
5924 //------------------------------xdual------------------------------------------
5925 // Dual: compute field-by-field dual
5926 const Type    *TypeInstKlassPtr::xdual() const {
5927   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5928 }
5929 
5930 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) {
5931   static_assert(std::is_base_of<T2, T1>::value, "");
5932   if (!this_one->is_loaded() || !other->is_loaded()) {
5933     return false;
5934   }
5935   if (!this_one->is_instance_type(other)) {
5936     return false;
5937   }
5938 
5939   if (!other_exact) {
5940     return false;
5941   }
5942 
5943   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
5944     return true;
5945   }
5946 
5947   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);

6021   const TypeInterfaces* interfaces = _interfaces;
6022   if (k->is_loaded()) {
6023     ciInstanceKlass* ik = k->as_instance_klass();
6024     bool klass_is_exact = ik->is_final();
6025     if (!klass_is_exact &&
6026         deps != nullptr) {
6027       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6028       if (sub != nullptr) {
6029         if (_interfaces->eq(sub)) {
6030           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6031           k = ik = sub;
6032           klass_is_exact = sub->is_final();
6033           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6034         }
6035       }
6036     }
6037   }
6038   return this;
6039 }
6040 



6041 
6042 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6043   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6044 }
6045 
6046 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {












6047   if (k->is_obj_array_klass()) {
6048     // Element is an object array. Recursively call ourself.
6049     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6050     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6051     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6052   } else if (k->is_type_array_klass()) {
6053     // Element is an typeArray
6054     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6055     return TypeAryKlassPtr::make(ptr, etype, k, offset);




6056   } else {
6057     ShouldNotReachHere();
6058     return nullptr;
6059   }
6060 }
6061 
6062 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6063   return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);




























6064 }
6065 
6066 //------------------------------eq---------------------------------------------
6067 // Structural equality check for Type representations
6068 bool TypeAryKlassPtr::eq(const Type *t) const {
6069   const TypeAryKlassPtr *p = t->is_aryklassptr();
6070   return
6071     _elem == p->_elem &&  // Check array






6072     TypeKlassPtr::eq(p);  // Check sub-parts
6073 }
6074 
6075 //------------------------------hash-------------------------------------------
6076 // Type-specific hashing function.
6077 uint TypeAryKlassPtr::hash(void) const {
6078   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();

6079 }
6080 
6081 //----------------------compute_klass------------------------------------------
6082 // Compute the defining klass for this class
6083 ciKlass* TypeAryPtr::compute_klass() const {
6084   // Compute _klass based on element type.
6085   ciKlass* k_ary = nullptr;
6086   const TypeInstPtr *tinst;
6087   const TypeAryPtr *tary;
6088   const Type* el = elem();
6089   if (el->isa_narrowoop()) {
6090     el = el->make_ptr();
6091   }
6092 
6093   // Get element klass
6094   if ((tinst = el->isa_instptr()) != nullptr) {
6095     // Leave k_ary at null.
6096   } else if ((tary = el->isa_aryptr()) != nullptr) {
6097     // Leave k_ary at null.
6098   } else if ((el->base() == Type::Top) ||
6099              (el->base() == Type::Bottom)) {
6100     // element type of Bottom occurs from meet of basic type
6101     // and object; Top occurs when doing join on Bottom.
6102     // Leave k_ary at null.
6103   } else {
6104     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6105     // Compute array klass directly from basic type
6106     k_ary = ciTypeArrayKlass::make(el->basic_type());
6107   }
6108   return k_ary;
6109 }
6110 
6111 //------------------------------klass------------------------------------------
6112 // Return the defining klass for this class
6113 ciKlass* TypeAryPtr::klass() const {
6114   if( _klass ) return _klass;   // Return cached value, if possible
6115 
6116   // Oops, need to compute _klass and cache it
6117   ciKlass* k_ary = compute_klass();

6125     // type TypeAryPtr::OOPS.  This Type is shared between all
6126     // active compilations.  However, the ciKlass which represents
6127     // this Type is *not* shared between compilations, so caching
6128     // this value would result in fetching a dangling pointer.
6129     //
6130     // Recomputing the underlying ciKlass for each request is
6131     // a bit less efficient than caching, but calls to
6132     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6133     ((TypeAryPtr*)this)->_klass = k_ary;
6134   }
6135   return k_ary;
6136 }
6137 
6138 // Is there a single ciKlass* that can represent that type?
6139 ciKlass* TypeAryPtr::exact_klass_helper() const {
6140   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6141     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6142     if (k == nullptr) {
6143       return nullptr;
6144     }
6145     k = ciObjArrayKlass::make(k);
6146     return k;
6147   }
6148 
6149   return klass();
6150 }
6151 
6152 const Type* TypeAryPtr::base_element_type(int& dims) const {
6153   const Type* elem = this->elem();
6154   dims = 1;
6155   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6156     elem = elem->make_ptr()->is_aryptr()->elem();
6157     dims++;
6158   }
6159   return elem;
6160 }
6161 
6162 //------------------------------add_offset-------------------------------------
6163 // Access internals of klass object
6164 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6165   return make(_ptr, elem(), klass(), xadd_offset(offset));
6166 }
6167 
6168 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6169   return make(_ptr, elem(), klass(), offset);
6170 }
6171 
6172 //------------------------------cast_to_ptr_type-------------------------------
6173 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6174   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6175   if (ptr == _ptr) return this;
6176   return make(ptr, elem(), _klass, _offset);
6177 }
6178 
6179 bool TypeAryKlassPtr::must_be_exact() const {
6180   if (_elem == Type::BOTTOM) return false;
6181   if (_elem == Type::TOP   ) return false;
6182   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6183   if (!tk)             return true;   // a primitive type, like int







6184   return tk->must_be_exact();
6185 }
6186 
6187 
6188 //-----------------------------cast_to_exactness-------------------------------
6189 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6190   if (must_be_exact()) return this;  // cannot clear xk



6191   ciKlass* k = _klass;
6192   const Type* elem = this->elem();
6193   if (elem->isa_klassptr() && !klass_is_exact) {
6194     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6195   }
6196   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);


















6197 }
6198 
6199 
6200 //-----------------------------as_instance_type--------------------------------
6201 // Corresponding type for an instance of the given class.
6202 // It will be NotNull, and exact if and only if the klass type is exact.
6203 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6204   ciKlass* k = klass();
6205   bool    xk = klass_is_exact();
6206   const Type* el = nullptr;
6207   if (elem()->isa_klassptr()) {
6208     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6209     k = nullptr;
6210   } else {
6211     el = elem();
6212   }
6213   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);




6214 }
6215 
6216 
6217 //------------------------------xmeet------------------------------------------
6218 // Compute the MEET of two types, return a new Type object.
6219 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6220   // Perform a fast test for common case; meeting the same types together.
6221   if( this == t ) return this;  // Meeting same type-rep?
6222 
6223   // Current "this->_base" is Pointer
6224   switch (t->base()) {          // switch on original type
6225 
6226   case Int:                     // Mixing ints & oops happens when javac
6227   case Long:                    // reuses local variables
6228   case HalfFloatTop:
6229   case HalfFloatCon:
6230   case HalfFloatBot:
6231   case FloatTop:
6232   case FloatCon:
6233   case FloatBot:
6234   case DoubleTop:
6235   case DoubleCon:
6236   case DoubleBot:
6237   case NarrowOop:
6238   case NarrowKlass:
6239   case Bottom:                  // Ye Olde Default
6240     return Type::BOTTOM;
6241   case Top:
6242     return this;
6243 
6244   default:                      // All else is a mistake
6245     typerr(t);
6246 
6247   case AnyPtr: {                // Meeting to AnyPtrs
6248     // Found an AnyPtr type vs self-KlassPtr type
6249     const TypePtr *tp = t->is_ptr();
6250     int offset = meet_offset(tp->offset());
6251     PTR ptr = meet_ptr(tp->ptr());
6252     switch (tp->ptr()) {
6253     case TopPTR:
6254       return this;
6255     case Null:
6256       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6257     case AnyNull:
6258       return make( ptr, _elem, klass(), offset );
6259     case BotPTR:
6260     case NotNull:
6261       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6262     default: typerr(t);
6263     }
6264   }
6265 
6266   case RawPtr:
6267   case MetadataPtr:
6268   case OopPtr:
6269   case AryPtr:                  // Meet with AryPtr
6270   case InstPtr:                 // Meet with InstPtr
6271     return TypePtr::BOTTOM;
6272 
6273   //
6274   //             A-top         }
6275   //           /   |   \       }  Tops
6276   //       B-top A-any C-top   }
6277   //          | /  |  \ |      }  Any-nulls
6278   //       B-any   |   C-any   }
6279   //          |    |    |
6280   //       B-con A-con C-con   } constants; not comparable across classes
6281   //          |    |    |
6282   //       B-not   |   C-not   }
6283   //          | \  |  / |      }  not-nulls
6284   //       B-bot A-not C-bot   }
6285   //           \   |   /       }  Bottoms
6286   //             A-bot         }
6287   //
6288 
6289   case AryKlassPtr: {  // Meet two KlassPtr types
6290     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6291     int off = meet_offset(tap->offset());
6292     const Type* elem = _elem->meet(tap->_elem);
6293 
6294     PTR ptr = meet_ptr(tap->ptr());
6295     ciKlass* res_klass = nullptr;
6296     bool res_xk = false;
6297     meet_aryptr(ptr, elem, this, tap, res_klass, res_xk);





6298     assert(res_xk == (ptr == Constant), "");
6299     return make(ptr, elem, res_klass, off);
































6300   } // End of case KlassPtr
6301   case InstKlassPtr: {
6302     const TypeInstKlassPtr *tp = t->is_instklassptr();
6303     int offset = meet_offset(tp->offset());
6304     PTR ptr = meet_ptr(tp->ptr());
6305     const TypeInterfaces* interfaces = meet_interfaces(tp);
6306     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6307     const TypeInterfaces* this_interfaces = _interfaces;
6308 
6309     switch (ptr) {
6310     case TopPTR:
6311     case AnyNull:                // Fall 'down' to dual of object klass
6312       // For instances when a subclass meets a superclass we fall
6313       // below the centerline when the superclass is exact. We need to
6314       // do the same here.
6315       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6316           !tp->klass_is_exact()) {
6317         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6318       } else {
6319         // cannot subclass, so the meet has to fall badly below the centerline
6320         ptr = NotNull;
6321         interfaces = this_interfaces->intersection_with(tp->_interfaces);
6322         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6323       }
6324     case Constant:
6325     case NotNull:
6326     case BotPTR:                // Fall down to object klass
6327       // LCA is object_klass, but if we subclass from the top we can do better
6328       if (above_centerline(tp->ptr())) {
6329         // If 'tp'  is above the centerline and it is Object class
6330         // then we can subclass in the Java class hierarchy.
6331         // For instances when a subclass meets a superclass we fall
6332         // below the centerline when the superclass is exact. We need
6333         // to do the same here.
6334         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6335             !tp->klass_is_exact()) {
6336           // that is, my array type is a subtype of 'tp' klass
6337           return make(ptr, _elem, _klass, offset);
6338         }
6339       }
6340       // The other case cannot happen, since t cannot be a subtype of an array.
6341       // The meet falls down to Object class below centerline.
6342       if (ptr == Constant)
6343          ptr = NotNull;
6344       interfaces = this_interfaces->intersection_with(tp_interfaces);
6345       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);
6346     default: typerr(t);
6347     }
6348   }
6349 
6350   } // End of switch
6351   return this;                  // Return the double constant
6352 }
6353 
6354 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) {
6355   static_assert(std::is_base_of<T2, T1>::value, "");
6356 
6357   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6358     return true;
6359   }
6360 
6361   int dummy;
6362   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6363 
6364   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6365     return false;
6366   }
6367 
6368   if (this_one->is_instance_type(other)) {
6369     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6370            other_exact;
6371   }
6372 
6373   assert(this_one->is_array_type(other), "");
6374   const T1* other_ary = this_one->is_array_type(other);
6375   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6376   if (other_top_or_bottom) {
6377     return false;
6378   }
6379 
6380   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6381   const TypePtr* this_elem = this_one->elem()->make_ptr();
6382   if (this_elem != nullptr && other_elem != nullptr) {



6383     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6384   }
6385   if (this_elem == nullptr && other_elem == nullptr) {
6386     return this_one->klass()->is_subtype_of(other->klass());
6387   }
6388   return false;
6389 }
6390 
6391 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6392   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6393 }
6394 
6395 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6396   static_assert(std::is_base_of<T2, T1>::value, "");
6397 
6398   int dummy;
6399   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6400 
6401   if (!this_one->is_array_type(other) ||
6402       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

6455   }
6456 
6457   const TypePtr* this_elem = this_one->elem()->make_ptr();
6458   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6459   if (other_elem != nullptr && this_elem != nullptr) {
6460     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6461   }
6462   if (other_elem == nullptr && this_elem == nullptr) {
6463     return this_one->klass()->is_subtype_of(other->klass());
6464   }
6465   return false;
6466 }
6467 
6468 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6469   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6470 }
6471 
6472 //------------------------------xdual------------------------------------------
6473 // Dual: compute field-by-field dual
6474 const Type    *TypeAryKlassPtr::xdual() const {
6475   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6476 }
6477 
6478 // Is there a single ciKlass* that can represent that type?
6479 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6480   if (elem()->isa_klassptr()) {
6481     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6482     if (k == nullptr) {
6483       return nullptr;
6484     }
6485     k = ciObjArrayKlass::make(k);
6486     return k;
6487   }
6488 
6489   return klass();
6490 }
6491 
6492 ciKlass* TypeAryKlassPtr::klass() const {
6493   if (_klass != nullptr) {
6494     return _klass;
6495   }
6496   ciKlass* k = nullptr;
6497   if (elem()->isa_klassptr()) {
6498     // leave null
6499   } else if ((elem()->base() == Type::Top) ||
6500              (elem()->base() == Type::Bottom)) {
6501   } else {
6502     k = ciTypeArrayKlass::make(elem()->basic_type());
6503     ((TypeAryKlassPtr*)this)->_klass = k;
6504   }
6505   return k;

6512   switch( _ptr ) {
6513   case Constant:
6514     st->print("precise ");
6515   case NotNull:
6516     {
6517       st->print("[");
6518       _elem->dump2(d, depth, st);
6519       _interfaces->dump(st);
6520       st->print(": ");
6521     }
6522   case BotPTR:
6523     if( !WizardMode && !Verbose && _ptr != Constant ) break;
6524   case TopPTR:
6525   case AnyNull:
6526     st->print(":%s", ptr_msg[_ptr]);
6527     if( _ptr == Constant ) st->print(":exact");
6528     break;
6529   default:
6530     break;
6531   }
6532 
6533   if( _offset ) {               // Dump offset, if any
6534     if( _offset == OffsetBot )      { st->print("+any"); }
6535     else if( _offset == OffsetTop ) { st->print("+unknown"); }
6536     else                            { st->print("+%d", _offset); }


6537   }
6538 


6539   st->print(" *");
6540 }
6541 #endif
6542 
6543 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6544   const Type* elem = this->elem();
6545   dims = 1;
6546   while (elem->isa_aryklassptr()) {
6547     elem = elem->is_aryklassptr()->elem();
6548     dims++;
6549   }
6550   return elem;
6551 }
6552 
6553 //=============================================================================
6554 // Convenience common pre-built types.
6555 
6556 //------------------------------make-------------------------------------------
6557 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6558   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();












6559 }
6560 
6561 //------------------------------make-------------------------------------------
6562 const TypeFunc *TypeFunc::make(ciMethod* method) {
6563   Compile* C = Compile::current();
6564   const TypeFunc* tf = C->last_tf(method); // check cache
6565   if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
6566   const TypeTuple *domain;
6567   if (method->is_static()) {
6568     domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6569   } else {
6570     domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);

















6571   }
6572   const TypeTuple *range  = TypeTuple::make_range(method->signature(), ignore_interfaces);
6573   tf = TypeFunc::make(domain, range);
6574   C->set_last_tf(method, tf);  // fill cache
6575   return tf;
6576 }
6577 
6578 //------------------------------meet-------------------------------------------
6579 // Compute the MEET of two types.  It returns a new Type object.
6580 const Type *TypeFunc::xmeet( const Type *t ) const {
6581   // Perform a fast test for common case; meeting the same types together.
6582   if( this == t ) return this;  // Meeting same type-rep?
6583 
6584   // Current "this->_base" is Func
6585   switch (t->base()) {          // switch on original type
6586 
6587   case Bottom:                  // Ye Olde Default
6588     return t;
6589 
6590   default:                      // All else is a mistake
6591     typerr(t);
6592 
6593   case Top:
6594     break;
6595   }
6596   return this;                  // Return the double constant
6597 }
6598 
6599 //------------------------------xdual------------------------------------------
6600 // Dual: compute field-by-field dual
6601 const Type *TypeFunc::xdual() const {
6602   return this;
6603 }
6604 
6605 //------------------------------eq---------------------------------------------
6606 // Structural equality check for Type representations
6607 bool TypeFunc::eq( const Type *t ) const {
6608   const TypeFunc *a = (const TypeFunc*)t;
6609   return _domain == a->_domain &&
6610     _range == a->_range;


6611 }
6612 
6613 //------------------------------hash-------------------------------------------
6614 // Type-specific hashing function.
6615 uint TypeFunc::hash(void) const {
6616   return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6617 }
6618 
6619 //------------------------------dump2------------------------------------------
6620 // Dump Function Type
6621 #ifndef PRODUCT
6622 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6623   if( _range->cnt() <= Parms )
6624     st->print("void");
6625   else {
6626     uint i;
6627     for (i = Parms; i < _range->cnt()-1; i++) {
6628       _range->field_at(i)->dump2(d,depth,st);
6629       st->print("/");
6630     }
6631     _range->field_at(i)->dump2(d,depth,st);
6632   }
6633   st->print(" ");
6634   st->print("( ");
6635   if( !depth || d[this] ) {     // Check for recursive dump
6636     st->print("...)");
6637     return;
6638   }
6639   d.Insert((void*)this,(void*)this);    // Stop recursion
6640   if (Parms < _domain->cnt())
6641     _domain->field_at(Parms)->dump2(d,depth-1,st);
6642   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6643     st->print(", ");
6644     _domain->field_at(i)->dump2(d,depth-1,st);
6645   }
6646   st->print(" )");
6647 }
6648 #endif
6649 
6650 //------------------------------singleton--------------------------------------
6651 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6652 // constants (Ldi nodes).  Singletons are integer, float or double constants
6653 // or a single symbol.
6654 bool TypeFunc::singleton(void) const {
6655   return false;                 // Never a singleton
6656 }
6657 
6658 bool TypeFunc::empty(void) const {
6659   return false;                 // Never empty
6660 }
6661 
6662 
6663 BasicType TypeFunc::return_type() const{
6664   if (range()->cnt() == TypeFunc::Parms) {
6665     return T_VOID;
6666   }
6667   return range()->field_at(TypeFunc::Parms)->basic_type();
6668 }

   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/ciField.hpp"
  26 #include "ci/ciFlatArrayKlass.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/arraycopynode.hpp"
  42 #include "opto/callnode.hpp"
  43 #include "opto/matcher.hpp"
  44 #include "opto/node.hpp"
  45 #include "opto/opcodes.hpp"
  46 #include "opto/rangeinference.hpp"
  47 #include "opto/runtime.hpp"
  48 #include "opto/type.hpp"
  49 #include "runtime/stubRoutines.hpp"
  50 #include "utilities/checkedCast.hpp"
  51 #include "utilities/globalDefinitions.hpp"
  52 #include "utilities/powerOfTwo.hpp"
  53 #include "utilities/stringUtils.hpp"
  54 
  55 // Portions of code courtesy of Clifford Click
  56 
  57 // Optimization - Graph Style
  58 
  59 // Dictionary of types shared among compilations.
  60 Dict* Type::_shared_type_dict = nullptr;
  61 const Type::Offset Type::Offset::top(Type::OffsetTop);
  62 const Type::Offset Type::Offset::bottom(Type::OffsetBot);
  63 
  64 const Type::Offset Type::Offset::meet(const Type::Offset other) const {
  65   // Either is 'TOP' offset?  Return the other offset!
  66   if (_offset == OffsetTop) return other;
  67   if (other._offset == OffsetTop) return *this;
  68   // If either is different, return 'BOTTOM' offset
  69   if (_offset != other._offset) return bottom;
  70   return Offset(_offset);
  71 }
  72 
  73 const Type::Offset Type::Offset::dual() const {
  74   if (_offset == OffsetTop) return bottom;// Map 'TOP' into 'BOTTOM'
  75   if (_offset == OffsetBot) return top;// Map 'BOTTOM' into 'TOP'
  76   return Offset(_offset);               // Map everything else into self
  77 }
  78 
  79 const Type::Offset Type::Offset::add(intptr_t offset) const {
  80   // Adding to 'TOP' offset?  Return 'TOP'!
  81   if (_offset == OffsetTop || offset == OffsetTop) return top;
  82   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
  83   if (_offset == OffsetBot || offset == OffsetBot) return bottom;
  84   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
  85   offset += (intptr_t)_offset;
  86   if (offset != (int)offset || offset == OffsetTop) return bottom;
  87 
  88   // assert( _offset >= 0 && _offset+offset >= 0, "" );
  89   // It is possible to construct a negative offset during PhaseCCP
  90 
  91   return Offset((int)offset);        // Sum valid offsets
  92 }
  93 
  94 void Type::Offset::dump2(outputStream *st) const {
  95   if (_offset == 0) {
  96     return;
  97   } else if (_offset == OffsetTop) {
  98     st->print("+top");
  99   }
 100   else if (_offset == OffsetBot) {
 101     st->print("+bot");
 102   } else if (_offset) {
 103     st->print("+%d", _offset);
 104   }
 105 }
 106 
 107 // Array which maps compiler types to Basic Types
 108 const Type::TypeInfo Type::_type_info[Type::lastype] = {
 109   { Bad,             T_ILLEGAL,    "bad",           false, Node::NotAMachineReg, relocInfo::none          },  // Bad
 110   { Control,         T_ILLEGAL,    "control",       false, 0,                    relocInfo::none          },  // Control
 111   { Bottom,          T_VOID,       "top",           false, 0,                    relocInfo::none          },  // Top
 112   { Bad,             T_INT,        "int:",          false, Op_RegI,              relocInfo::none          },  // Int
 113   { Bad,             T_LONG,       "long:",         false, Op_RegL,              relocInfo::none          },  // Long
 114   { Half,            T_VOID,       "half",          false, 0,                    relocInfo::none          },  // Half
 115   { Bad,             T_NARROWOOP,  "narrowoop:",    false, Op_RegN,              relocInfo::none          },  // NarrowOop
 116   { Bad,             T_NARROWKLASS,"narrowklass:",  false, Op_RegN,              relocInfo::none          },  // NarrowKlass
 117   { Bad,             T_ILLEGAL,    "tuple:",        false, Node::NotAMachineReg, relocInfo::none          },  // Tuple
 118   { Bad,             T_ARRAY,      "array:",        false, Node::NotAMachineReg, relocInfo::none          },  // Array
 119   { Bad,             T_ARRAY,      "interfaces:",   false, Node::NotAMachineReg, relocInfo::none          },  // Interfaces
 120 
 121 #if defined(PPC64)
 122   { Bad,             T_ILLEGAL,    "vectormask:",   false, Op_RegVectMask,       relocInfo::none          },  // VectorMask.
 123   { Bad,             T_ILLEGAL,    "vectora:",      false, Op_VecA,              relocInfo::none          },  // VectorA.
 124   { Bad,             T_ILLEGAL,    "vectors:",      false, 0,                    relocInfo::none          },  // VectorS
 125   { Bad,             T_ILLEGAL,    "vectord:",      false, Op_RegL,              relocInfo::none          },  // VectorD

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

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

1006   ~VerifyMeet() {
1007     assert(_C->_type_verify->_depth != 0, "");
1008     _C->_type_verify->_depth--;
1009     if (_C->_type_verify->_depth == 0) {
1010       _C->_type_verify->_cache.trunc_to(0);
1011     }
1012   }
1013 
1014   const Type* meet(const Type* t1, const Type* t2) const {
1015     return _C->_type_verify->meet(t1, t2);
1016   }
1017 
1018   void add(const Type* t1, const Type* t2, const Type* res) const {
1019     _C->_type_verify->add(t1, t2, res);
1020   }
1021 };
1022 
1023 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
1024   Compile* C = Compile::current();
1025   const Type* mt2 = verify.meet(t, this);
1026 
1027   // Verify that:
1028   //      this meet t == t meet this
1029   if (mt != mt2) {
1030     tty->print_cr("=== Meet Not Commutative ===");
1031     tty->print("t           = ");   t->dump(); tty->cr();
1032     tty->print("this        = ");      dump(); tty->cr();
1033     tty->print("t meet this = "); mt2->dump(); tty->cr();
1034     tty->print("this meet t = ");  mt->dump(); tty->cr();
1035     fatal("meet not commutative");
1036   }
1037   const Type* dual_join = mt->_dual;
1038   const Type* t2t    = verify.meet(dual_join,t->_dual);
1039   const Type* t2this = verify.meet(dual_join,this->_dual);
1040 
1041   // Interface meet Oop is Not Symmetric:
1042   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
1043   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
1044 
1045   // Verify that:
1046   // 1)     mt_dual meet t_dual    == t_dual
1047   //    which corresponds to
1048   //       !(t meet this)  meet !t ==
1049   //       (!t join !this) meet !t == !t
1050   // 2)    mt_dual meet this_dual     == this_dual
1051   //    which corresponds to
1052   //       !(t meet this)  meet !this ==
1053   //       (!t join !this) meet !this == !this
1054   // TODO 8332406 Fix this
1055   if ((   isa_instptr() != nullptr &&    is_instptr()->flat_in_array()) ||
1056       (t->isa_instptr() != nullptr && t->is_instptr()->flat_in_array())) {
1057     return;
1058   }
1059   if (t2t != t->_dual || t2this != this->_dual) {
1060     tty->print_cr("=== Meet Not Symmetric ===");
1061     tty->print("t   =                   ");              t->dump(); tty->cr();
1062     tty->print("this=                   ");                 dump(); tty->cr();
1063     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
1064 
1065     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
1066     tty->print("this_dual=              ");          _dual->dump(); tty->cr();
1067     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
1068 
1069     // 1)
1070     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
1071     // 2)
1072     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
1073 
1074     fatal("meet not symmetric");
1075   }
1076 }
1077 #endif
1078 
1079 //------------------------------meet-------------------------------------------
1080 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
1081 // commutative and the lattice is symmetric.
1082 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1083   if (isa_narrowoop() && t->isa_narrowoop()) {
1084     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1085     return result->make_narrowoop();
1086   }
1087   if (isa_narrowklass() && t->isa_narrowklass()) {
1088     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1089     return result->make_narrowklass();
1090   }
1091 
1092 #ifdef ASSERT
1093   Compile* C = Compile::current();
1094   VerifyMeet verify(C);
1095 #endif
1096 
1097   const Type *this_t = maybe_remove_speculative(include_speculative);
1098   t = t->maybe_remove_speculative(include_speculative);
1099 
1100   const Type *mt = this_t->xmeet(t);
1101 #ifdef ASSERT
1102   verify.add(this_t, t, mt);
1103   if (isa_narrowoop() || t->isa_narrowoop()) {
1104     return mt;
1105   }
1106   if (isa_narrowklass() || t->isa_narrowklass()) {
1107     return mt;
1108   }
1109   // TODO 8350865 This currently triggers a verification failure, the code around "// Even though MyValue is final" needs adjustments
1110   if ((this_t->isa_ptr() && this_t->is_ptr()->is_not_flat()) ||
1111       (this_t->_dual->isa_ptr() && this_t->_dual->is_ptr()->is_not_flat())) return mt;
1112   this_t->check_symmetrical(t, mt, verify);
1113   const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1114   this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1115 #endif
1116   return mt;
1117 }
1118 
1119 //------------------------------xmeet------------------------------------------
1120 // Compute the MEET of two types.  It returns a new Type object.
1121 const Type *Type::xmeet( const Type *t ) const {
1122   // Perform a fast test for common case; meeting the same types together.
1123   if( this == t ) return this;  // Meeting same type-rep?
1124 
1125   // Meeting TOP with anything?
1126   if( _base == Top ) return t;
1127 
1128   // Meeting BOTTOM with anything?
1129   if( _base == Bottom ) return BOTTOM;
1130 
1131   // Current "this->_base" is one of: Bad, Multi, Control, Top,

2108 void TypeLong::dump_verbose() const {
2109   TypeIntHelper::int_type_dump(this, tty, true);
2110 }
2111 #endif
2112 
2113 //=============================================================================
2114 // Convenience common pre-built types.
2115 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2116 const TypeTuple *TypeTuple::IFFALSE;
2117 const TypeTuple *TypeTuple::IFTRUE;
2118 const TypeTuple *TypeTuple::IFNEITHER;
2119 const TypeTuple *TypeTuple::LOOPBODY;
2120 const TypeTuple *TypeTuple::MEMBAR;
2121 const TypeTuple *TypeTuple::STORECONDITIONAL;
2122 const TypeTuple *TypeTuple::START_I2C;
2123 const TypeTuple *TypeTuple::INT_PAIR;
2124 const TypeTuple *TypeTuple::LONG_PAIR;
2125 const TypeTuple *TypeTuple::INT_CC_PAIR;
2126 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2127 
2128 static void collect_inline_fields(ciInlineKlass* vk, const Type** field_array, uint& pos) {
2129   for (int i = 0; i < vk->nof_declared_nonstatic_fields(); i++) {
2130     ciField* field = vk->declared_nonstatic_field_at(i);
2131     if (field->is_flat()) {
2132       collect_inline_fields(field->type()->as_inline_klass(), field_array, pos);
2133       if (!field->is_null_free()) {
2134         // Use T_INT instead of T_BOOLEAN here because the upper bits can contain garbage if the holder
2135         // is null and C2 will only zero them for T_INT assuming that T_BOOLEAN is already canonicalized.
2136         field_array[pos++] = Type::get_const_basic_type(T_INT);
2137       }
2138     } else {
2139       BasicType bt = field->type()->basic_type();
2140       const Type* ft = Type::get_const_type(field->type());
2141       field_array[pos++] = ft;
2142       if (type2size[bt] == 2) {
2143         field_array[pos++] = Type::HALF;
2144       }
2145     }
2146   }
2147 }
2148 
2149 //------------------------------make-------------------------------------------
2150 // Make a TypeTuple from the range of a method signature
2151 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling, bool ret_vt_fields) {
2152   ciType* return_type = sig->return_type();
2153   uint arg_cnt = return_type->size();
2154   if (ret_vt_fields) {
2155     arg_cnt = return_type->as_inline_klass()->inline_arg_slots() + 1;
2156     // InlineTypeNode::NullMarker field used for null checking
2157     arg_cnt++;
2158   }
2159   const Type **field_array = fields(arg_cnt);
2160   switch (return_type->basic_type()) {
2161   case T_LONG:
2162     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2163     field_array[TypeFunc::Parms+1] = Type::HALF;
2164     break;
2165   case T_DOUBLE:
2166     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2167     field_array[TypeFunc::Parms+1] = Type::HALF;
2168     break;
2169   case T_OBJECT:
2170     if (return_type->is_inlinetype() && ret_vt_fields) {
2171       uint pos = TypeFunc::Parms;
2172       field_array[pos++] = get_const_type(return_type); // Oop might be null when returning as fields
2173       collect_inline_fields(return_type->as_inline_klass(), field_array, pos);
2174       // InlineTypeNode::NullMarker field used for null checking
2175       field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2176       assert(pos == (TypeFunc::Parms + arg_cnt), "out of bounds");
2177       break;
2178     } else {
2179       field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling)->join_speculative(TypePtr::BOTTOM);
2180     }
2181     break;
2182   case T_ARRAY:
2183   case T_BOOLEAN:
2184   case T_CHAR:
2185   case T_FLOAT:
2186   case T_BYTE:
2187   case T_SHORT:
2188   case T_INT:
2189     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2190     break;
2191   case T_VOID:
2192     break;
2193   default:
2194     ShouldNotReachHere();
2195   }
2196   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2197 }
2198 
2199 // Make a TypeTuple from the domain of a method signature
2200 const TypeTuple *TypeTuple::make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args) {
2201   ciSignature* sig = method->signature();
2202   uint arg_cnt = sig->size() + (method->is_static() ? 0 : 1);
2203   if (vt_fields_as_args) {
2204     arg_cnt = 0;
2205     assert(method->get_sig_cc() != nullptr, "Should have scalarized signature");
2206     for (ExtendedSignature sig_cc = ExtendedSignature(method->get_sig_cc(), SigEntryFilter()); !sig_cc.at_end(); ++sig_cc) {
2207       arg_cnt += type2size[(*sig_cc)._bt];
2208     }
2209   }
2210 
2211   uint pos = TypeFunc::Parms;
2212   const Type** field_array = fields(arg_cnt);
2213   if (!method->is_static()) {
2214     ciInstanceKlass* recv = method->holder();
2215     if (vt_fields_as_args && recv->is_inlinetype() && recv->as_inline_klass()->can_be_passed_as_fields() && method->is_scalarized_arg(0)) {
2216       collect_inline_fields(recv->as_inline_klass(), field_array, pos);
2217     } else {
2218       field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2219     }
2220   }
2221 
2222   int i = 0;
2223   while (pos < TypeFunc::Parms + arg_cnt) {
2224     ciType* type = sig->type_at(i);
2225     BasicType bt = type->basic_type();
2226 
2227     switch (bt) {
2228     case T_LONG:
2229       field_array[pos++] = TypeLong::LONG;
2230       field_array[pos++] = Type::HALF;
2231       break;
2232     case T_DOUBLE:
2233       field_array[pos++] = Type::DOUBLE;
2234       field_array[pos++] = Type::HALF;
2235       break;
2236     case T_OBJECT:
2237       if (type->is_inlinetype() && vt_fields_as_args && method->is_scalarized_arg(i + (method->is_static() ? 0 : 1))) {
2238         // InlineTypeNode::NullMarker field used for null checking
2239         field_array[pos++] = get_const_basic_type(T_BOOLEAN);
2240         collect_inline_fields(type->as_inline_klass(), field_array, pos);
2241       } else {
2242         field_array[pos++] = get_const_type(type, interface_handling);
2243       }
2244       break;
2245     case T_ARRAY:
2246     case T_FLOAT:
2247     case T_INT:
2248       field_array[pos++] = get_const_type(type, interface_handling);
2249       break;
2250     case T_BOOLEAN:
2251     case T_CHAR:
2252     case T_BYTE:
2253     case T_SHORT:
2254       field_array[pos++] = TypeInt::INT;
2255       break;
2256     default:
2257       ShouldNotReachHere();
2258     }
2259     i++;
2260   }
2261   assert(pos == TypeFunc::Parms + arg_cnt, "wrong number of arguments");
2262 
2263   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2264 }
2265 
2266 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2267   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2268 }
2269 
2270 //------------------------------fields-----------------------------------------
2271 // Subroutine call type with space allocated for argument types
2272 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2273 const Type **TypeTuple::fields( uint arg_cnt ) {
2274   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2275   flds[TypeFunc::Control  ] = Type::CONTROL;
2276   flds[TypeFunc::I_O      ] = Type::ABIO;
2277   flds[TypeFunc::Memory   ] = Type::MEMORY;
2278   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2279   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2280 
2281   return flds;

2376     if (_fields[i]->empty())  return true;
2377   }
2378   return false;
2379 }
2380 
2381 //=============================================================================
2382 // Convenience common pre-built types.
2383 
2384 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2385   // Certain normalizations keep us sane when comparing types.
2386   // We do not want arrayOop variables to differ only by the wideness
2387   // of their index types.  Pick minimum wideness, since that is the
2388   // forced wideness of small ranges anyway.
2389   if (size->_widen != Type::WidenMin)
2390     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2391   else
2392     return size;
2393 }
2394 
2395 //------------------------------make-------------------------------------------
2396 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable,
2397                              bool flat, bool not_flat, bool not_null_free, bool atomic) {
2398   if (UseCompressedOops && elem->isa_oopptr()) {
2399     elem = elem->make_narrowoop();
2400   }
2401   size = normalize_array_size(size);
2402   return (TypeAry*)(new TypeAry(elem, size, stable, flat, not_flat, not_null_free, atomic))->hashcons();
2403 }
2404 
2405 //------------------------------meet-------------------------------------------
2406 // Compute the MEET of two types.  It returns a new Type object.
2407 const Type *TypeAry::xmeet( const Type *t ) const {
2408   // Perform a fast test for common case; meeting the same types together.
2409   if( this == t ) return this;  // Meeting same type-rep?
2410 
2411   // Current "this->_base" is Ary
2412   switch (t->base()) {          // switch on original type
2413 
2414   case Bottom:                  // Ye Olde Default
2415     return t;
2416 
2417   default:                      // All else is a mistake
2418     typerr(t);
2419 
2420   case Array: {                 // Meeting 2 arrays?
2421     const TypeAry* a = t->is_ary();
2422     const Type* size = _size->xmeet(a->_size);
2423     const TypeInt* isize = size->isa_int();
2424     if (isize == nullptr) {
2425       assert(size == Type::TOP || size == Type::BOTTOM, "");
2426       return size;
2427     }
2428     return TypeAry::make(_elem->meet_speculative(a->_elem),
2429                          isize, _stable && a->_stable,
2430                          _flat && a->_flat,
2431                          _not_flat && a->_not_flat,
2432                          _not_null_free && a->_not_null_free,
2433                          _atomic && a->_atomic);
2434   }
2435   case Top:
2436     break;
2437   }
2438   return this;                  // Return the double constant
2439 }
2440 
2441 //------------------------------xdual------------------------------------------
2442 // Dual: compute field-by-field dual
2443 const Type *TypeAry::xdual() const {
2444   const TypeInt* size_dual = _size->dual()->is_int();
2445   size_dual = normalize_array_size(size_dual);
2446   return new TypeAry(_elem->dual(), size_dual, !_stable, !_flat, !_not_flat, !_not_null_free, !_atomic);
2447 }
2448 
2449 //------------------------------eq---------------------------------------------
2450 // Structural equality check for Type representations
2451 bool TypeAry::eq( const Type *t ) const {
2452   const TypeAry *a = (const TypeAry*)t;
2453   return _elem == a->_elem &&
2454     _stable == a->_stable &&
2455     _size == a->_size &&
2456     _flat == a->_flat &&
2457     _not_flat == a->_not_flat &&
2458     _not_null_free == a->_not_null_free &&
2459     _atomic == a->_atomic;
2460 
2461 }
2462 
2463 //------------------------------hash-------------------------------------------
2464 // Type-specific hashing function.
2465 uint TypeAry::hash(void) const {
2466   return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0) +
2467       (uint)(_flat ? 44 : 0) + (uint)(_not_flat ? 45 : 0) + (uint)(_not_null_free ? 46 : 0) + (uint)(_atomic ? 47 : 0);
2468 }
2469 
2470 /**
2471  * Return same type without a speculative part in the element
2472  */
2473 const TypeAry* TypeAry::remove_speculative() const {
2474   return make(_elem->remove_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2475 }
2476 
2477 /**
2478  * Return same type with cleaned up speculative part of element
2479  */
2480 const Type* TypeAry::cleanup_speculative() const {
2481   return make(_elem->cleanup_speculative(), _size, _stable, _flat, _not_flat, _not_null_free, _atomic);
2482 }
2483 
2484 /**
2485  * Return same type but with a different inline depth (used for speculation)
2486  *
2487  * @param depth  depth to meet with
2488  */
2489 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2490   if (!UseInlineDepthForSpeculativeTypes) {
2491     return this;
2492   }
2493   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2494 }
2495 
2496 //------------------------------dump2------------------------------------------
2497 #ifndef PRODUCT
2498 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2499   if (_stable)  st->print("stable:");
2500   if (_flat) st->print("flat:");
2501   if (Verbose) {
2502     if (_not_flat) st->print("not flat:");
2503     if (_not_null_free) st->print("not null free:");
2504   }
2505   if (_atomic) st->print("atomic:");
2506   _elem->dump2(d, depth, st);
2507   st->print("[");
2508   _size->dump2(d, depth, st);
2509   st->print("]");
2510 }
2511 #endif
2512 
2513 //------------------------------singleton--------------------------------------
2514 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2515 // constants (Ldi nodes).  Singletons are integer, float or double constants
2516 // or a single symbol.
2517 bool TypeAry::singleton(void) const {
2518   return false;                 // Never a singleton
2519 }
2520 
2521 bool TypeAry::empty(void) const {
2522   return _elem->empty() || _size->empty();
2523 }
2524 
2525 //--------------------------ary_must_be_exact----------------------------------
2526 bool TypeAry::ary_must_be_exact() const {
2527   // This logic looks at the element type of an array, and returns true
2528   // if the element type is either a primitive or a final instance class.
2529   // In such cases, an array built on this ary must have no subclasses.
2530   if (_elem == BOTTOM)      return false;  // general array not exact
2531   if (_elem == TOP   )      return false;  // inverted general array not exact
2532   const TypeOopPtr*  toop = nullptr;
2533   if (UseCompressedOops && _elem->isa_narrowoop()) {
2534     toop = _elem->make_ptr()->isa_oopptr();
2535   } else {
2536     toop = _elem->isa_oopptr();
2537   }
2538   if (!toop)                return true;   // a primitive type, like int
2539   if (!toop->is_loaded())   return false;  // unloaded class
2540   const TypeInstPtr* tinst;
2541   if (_elem->isa_narrowoop())
2542     tinst = _elem->make_ptr()->isa_instptr();
2543   else
2544     tinst = _elem->isa_instptr();
2545   if (tinst) {
2546     if (tinst->instance_klass()->is_final()) {
2547       // Even though MyValue is final, [LMyValue is only exact if the array
2548       // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
2549       // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
2550       // If so, we should add '&& !_not_null_free'
2551       if (tinst->is_inlinetypeptr() && (tinst->ptr() != TypePtr::NotNull)) {
2552         return false;
2553       }
2554       return true;
2555     }
2556     return false;
2557   }
2558   const TypeAryPtr*  tap;
2559   if (_elem->isa_narrowoop())
2560     tap = _elem->make_ptr()->isa_aryptr();
2561   else
2562     tap = _elem->isa_aryptr();
2563   if (tap)
2564     return tap->ary()->ary_must_be_exact();
2565   return false;
2566 }
2567 
2568 //==============================TypeVect=======================================
2569 // Convenience common pre-built types.
2570 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2571 const TypeVect* TypeVect::VECTS = nullptr; //  32-bit vectors
2572 const TypeVect* TypeVect::VECTD = nullptr; //  64-bit vectors
2573 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2574 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2575 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2576 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2577 

2712 
2713 //=============================================================================
2714 // Convenience common pre-built types.
2715 const TypePtr *TypePtr::NULL_PTR;
2716 const TypePtr *TypePtr::NOTNULL;
2717 const TypePtr *TypePtr::BOTTOM;
2718 
2719 //------------------------------meet-------------------------------------------
2720 // Meet over the PTR enum
2721 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2722   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2723   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2724   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2725   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2726   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2727   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2728   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2729 };
2730 
2731 //------------------------------make-------------------------------------------
2732 const TypePtr* TypePtr::make(TYPES t, enum PTR ptr, Offset offset, const TypePtr* speculative, int inline_depth) {
2733   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2734 }
2735 
2736 //------------------------------cast_to_ptr_type-------------------------------
2737 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2738   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2739   if( ptr == _ptr ) return this;
2740   return make(_base, ptr, _offset, _speculative, _inline_depth);
2741 }
2742 
2743 //------------------------------get_con----------------------------------------
2744 intptr_t TypePtr::get_con() const {
2745   assert( _ptr == Null, "" );
2746   return offset();
2747 }
2748 
2749 //------------------------------meet-------------------------------------------
2750 // Compute the MEET of two types.  It returns a new Type object.
2751 const Type *TypePtr::xmeet(const Type *t) const {
2752   const Type* res = xmeet_helper(t);
2753   if (res->isa_ptr() == nullptr) {
2754     return res;
2755   }
2756 
2757   const TypePtr* res_ptr = res->is_ptr();
2758   if (res_ptr->speculative() != nullptr) {
2759     // type->speculative() is null means that speculation is no better
2760     // than type, i.e. type->speculative() == type. So there are 2
2761     // ways to represent the fact that we have no useful speculative
2762     // data and we should use a single one to be able to test for
2763     // equality between types. Check whether type->speculative() ==
2764     // type and set speculative to null if it is the case.
2765     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2766       return res_ptr->remove_speculative();

2800     int depth = meet_inline_depth(tp->inline_depth());
2801     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2802   }
2803   case RawPtr:                  // For these, flip the call around to cut down
2804   case OopPtr:
2805   case InstPtr:                 // on the cases I have to handle.
2806   case AryPtr:
2807   case MetadataPtr:
2808   case KlassPtr:
2809   case InstKlassPtr:
2810   case AryKlassPtr:
2811     return t->xmeet(this);      // Call in reverse direction
2812   default:                      // All else is a mistake
2813     typerr(t);
2814 
2815   }
2816   return this;
2817 }
2818 
2819 //------------------------------meet_offset------------------------------------
2820 Type::Offset TypePtr::meet_offset(int offset) const {
2821   return _offset.meet(Offset(offset));





2822 }
2823 
2824 //------------------------------dual_offset------------------------------------
2825 Type::Offset TypePtr::dual_offset() const {
2826   return _offset.dual();


2827 }
2828 
2829 //------------------------------xdual------------------------------------------
2830 // Dual: compute field-by-field dual
2831 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2832   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2833 };
2834 const Type *TypePtr::xdual() const {
2835   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2836 }
2837 
2838 //------------------------------xadd_offset------------------------------------
2839 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2840   return _offset.add(offset);











2841 }
2842 
2843 //------------------------------add_offset-------------------------------------
2844 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2845   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2846 }
2847 
2848 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2849   return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2850 }
2851 
2852 //------------------------------eq---------------------------------------------
2853 // Structural equality check for Type representations
2854 bool TypePtr::eq( const Type *t ) const {
2855   const TypePtr *a = (const TypePtr*)t;
2856   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2857 }
2858 
2859 //------------------------------hash-------------------------------------------
2860 // Type-specific hashing function.
2861 uint TypePtr::hash(void) const {
2862   return (uint)_ptr + (uint)offset() + (uint)hash_speculative() + (uint)_inline_depth;
2863 }
2864 
2865 /**
2866  * Return same type without a speculative part
2867  */
2868 const TypePtr* TypePtr::remove_speculative() const {
2869   if (_speculative == nullptr) {
2870     return this;
2871   }
2872   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2873   return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2874 }
2875 
2876 /**
2877  * Return same type but drop speculative part if we know we won't use
2878  * it
2879  */
2880 const Type* TypePtr::cleanup_speculative() const {
2881   if (speculative() == nullptr) {
2882     return this;

3108   }
3109   // We already know the speculative type is always null
3110   if (speculative_always_null()) {
3111     return false;
3112   }
3113   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3114     return false;
3115   }
3116   return true;
3117 }
3118 
3119 //------------------------------dump2------------------------------------------
3120 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3121   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3122 };
3123 
3124 #ifndef PRODUCT
3125 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3126   if( _ptr == Null ) st->print("null");
3127   else st->print("%s *", ptr_msg[_ptr]);
3128   _offset.dump2(st);


3129   dump_inline_depth(st);
3130   dump_speculative(st);
3131 }
3132 
3133 /**
3134  *dump the speculative part of the type
3135  */
3136 void TypePtr::dump_speculative(outputStream *st) const {
3137   if (_speculative != nullptr) {
3138     st->print(" (speculative=");
3139     _speculative->dump_on(st);
3140     st->print(")");
3141   }
3142 }
3143 
3144 /**
3145  *dump the inline depth of the type
3146  */
3147 void TypePtr::dump_inline_depth(outputStream *st) const {
3148   if (_inline_depth != InlineDepthBottom) {
3149     if (_inline_depth == InlineDepthTop) {
3150       st->print(" (inline_depth=InlineDepthTop)");
3151     } else {
3152       st->print(" (inline_depth=%d)", _inline_depth);
3153     }
3154   }
3155 }
3156 #endif
3157 
3158 //------------------------------singleton--------------------------------------
3159 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3160 // constants
3161 bool TypePtr::singleton(void) const {
3162   // TopPTR, Null, AnyNull, Constant are all singletons
3163   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3164 }
3165 
3166 bool TypePtr::empty(void) const {
3167   return (_offset == Offset::top) || above_centerline(_ptr);
3168 }
3169 
3170 //=============================================================================
3171 // Convenience common pre-built types.
3172 const TypeRawPtr *TypeRawPtr::BOTTOM;
3173 const TypeRawPtr *TypeRawPtr::NOTNULL;
3174 
3175 //------------------------------make-------------------------------------------
3176 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3177   assert( ptr != Constant, "what is the constant?" );
3178   assert( ptr != Null, "Use TypePtr for null" );
3179   return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3180 }
3181 
3182 const TypeRawPtr *TypeRawPtr::make(address bits) {
3183   assert(bits != nullptr, "Use TypePtr for null");
3184   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3185 }
3186 
3187 //------------------------------cast_to_ptr_type-------------------------------

3554 #endif
3555 
3556 // Can't be implemented because there's no way to know if the type is above or below the center line.
3557 const Type* TypeInterfaces::xmeet(const Type* t) const {
3558   ShouldNotReachHere();
3559   return Type::xmeet(t);
3560 }
3561 
3562 bool TypeInterfaces::singleton(void) const {
3563   ShouldNotReachHere();
3564   return Type::singleton();
3565 }
3566 
3567 bool TypeInterfaces::has_non_array_interface() const {
3568   assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3569 
3570   return !TypeAryPtr::_array_interfaces->contains(this);
3571 }
3572 
3573 //------------------------------TypeOopPtr-------------------------------------
3574 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3575                        int instance_id, const TypePtr* speculative, int inline_depth)
3576   : TypePtr(t, ptr, offset, speculative, inline_depth),
3577     _const_oop(o), _klass(k),
3578     _interfaces(interfaces),
3579     _klass_is_exact(xk),
3580     _is_ptr_to_narrowoop(false),
3581     _is_ptr_to_narrowklass(false),
3582     _is_ptr_to_boxed_value(false),
3583     _is_ptr_to_strict_final_field(false),
3584     _instance_id(instance_id) {
3585 #ifdef ASSERT
3586   if (klass() != nullptr && klass()->is_loaded()) {
3587     interfaces->verify_is_loaded();
3588   }
3589 #endif
3590   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3591       (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3592     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3593     _is_ptr_to_strict_final_field = _is_ptr_to_boxed_value;
3594   }
3595 
3596   if (klass() != nullptr && klass()->is_instance_klass() && klass()->is_loaded() &&
3597       this->offset() != Type::OffsetBot && this->offset() != Type::OffsetTop) {
3598     ciField* field = klass()->as_instance_klass()->get_field_by_offset(this->offset(), false);
3599     if (field != nullptr && field->is_strict() && field->is_final()) {
3600       _is_ptr_to_strict_final_field = true;
3601     }
3602   }
3603 
3604 #ifdef _LP64
3605   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3606     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3607       _is_ptr_to_narrowklass = UseCompressedClassPointers;
3608     } else if (klass() == nullptr) {
3609       // Array with unknown body type
3610       assert(this->isa_aryptr(), "only arrays without klass");
3611       _is_ptr_to_narrowoop = UseCompressedOops;
3612     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3613       if (klass()->is_obj_array_klass()) {
3614         _is_ptr_to_narrowoop = true;
3615       } else if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3616         // Check if the field of the inline type array element contains oops
3617         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3618         int foffset = field_offset.get() + vk->payload_offset();
3619         BasicType field_bt;
3620         ciField* field = vk->get_field_by_offset(foffset, false);
3621         if (field != nullptr) {
3622           field_bt = field->layout_type();
3623         } else {
3624           assert(field_offset.get() == vk->null_marker_offset_in_payload(), "no field or null marker of %s at offset %d", vk->name()->as_utf8(), foffset);
3625           field_bt = T_BOOLEAN;
3626         }
3627         _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(field_bt);
3628       }
3629     } else if (klass()->is_instance_klass()) {

3630       if (this->isa_klassptr()) {
3631         // Perm objects don't use compressed references
3632       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3633         // unsafe access
3634         _is_ptr_to_narrowoop = UseCompressedOops;
3635       } else {
3636         assert(this->isa_instptr(), "must be an instance ptr.");

3637         if (klass() == ciEnv::current()->Class_klass() &&
3638             (this->offset() == java_lang_Class::klass_offset() ||
3639              this->offset() == java_lang_Class::array_klass_offset())) {
3640           // Special hidden fields from the Class.
3641           assert(this->isa_instptr(), "must be an instance ptr.");
3642           _is_ptr_to_narrowoop = false;
3643         } else if (klass() == ciEnv::current()->Class_klass() &&
3644                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3645           // Static fields
3646           ciField* field = nullptr;
3647           if (const_oop() != nullptr) {
3648             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3649             field = k->get_field_by_offset(this->offset(), true);
3650           }
3651           if (field != nullptr) {
3652             BasicType basic_elem_type = field->layout_type();
3653             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3654           } else {
3655             // unsafe access
3656             _is_ptr_to_narrowoop = UseCompressedOops;
3657           }
3658         } else {
3659           // Instance fields which contains a compressed oop references.
3660           ciInstanceKlass* ik = klass()->as_instance_klass();
3661           ciField* field = ik->get_field_by_offset(this->offset(), false);
3662           if (field != nullptr) {
3663             BasicType basic_elem_type = field->layout_type();
3664             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3665           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3666             // Compile::find_alias_type() cast exactness on all types to verify
3667             // that it does not affect alias type.
3668             _is_ptr_to_narrowoop = UseCompressedOops;
3669           } else {
3670             // Type for the copy start in LibraryCallKit::inline_native_clone().
3671             _is_ptr_to_narrowoop = UseCompressedOops;
3672           }
3673         }
3674       }
3675     }
3676   }
3677 #endif // _LP64
3678 }
3679 
3680 //------------------------------make-------------------------------------------
3681 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3682                                    const TypePtr* speculative, int inline_depth) {
3683   assert(ptr != Constant, "no constant generic pointers");
3684   ciKlass*  k = Compile::current()->env()->Object_klass();
3685   bool      xk = false;
3686   ciObject* o = nullptr;
3687   const TypeInterfaces* interfaces = TypeInterfaces::make();
3688   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3689 }
3690 
3691 
3692 //------------------------------cast_to_ptr_type-------------------------------
3693 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3694   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3695   if( ptr == _ptr ) return this;
3696   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3697 }
3698 
3699 //-----------------------------cast_to_instance_id----------------------------
3700 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3701   // There are no instances of a general oop.
3702   // Return self unchanged.
3703   return this;
3704 }
3705 
3706 //-----------------------------cast_to_exactness-------------------------------
3707 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3708   // There is no such thing as an exact general oop.
3709   // Return self unchanged.
3710   return this;
3711 }
3712 

3713 //------------------------------as_klass_type----------------------------------
3714 // Return the klass type corresponding to this instance or array type.
3715 // It is the type that is loaded from an object of this type.
3716 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3717   ShouldNotReachHere();
3718   return nullptr;
3719 }
3720 
3721 //------------------------------meet-------------------------------------------
3722 // Compute the MEET of two types.  It returns a new Type object.
3723 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3724   // Perform a fast test for common case; meeting the same types together.
3725   if( this == t ) return this;  // Meeting same type-rep?
3726 
3727   // Current "this->_base" is OopPtr
3728   switch (t->base()) {          // switch on original type
3729 
3730   case Int:                     // Mixing ints & oops happens when javac
3731   case Long:                    // reuses local variables
3732   case HalfFloatTop:

3741   case NarrowOop:
3742   case NarrowKlass:
3743   case Bottom:                  // Ye Olde Default
3744     return Type::BOTTOM;
3745   case Top:
3746     return this;
3747 
3748   default:                      // All else is a mistake
3749     typerr(t);
3750 
3751   case RawPtr:
3752   case MetadataPtr:
3753   case KlassPtr:
3754   case InstKlassPtr:
3755   case AryKlassPtr:
3756     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3757 
3758   case AnyPtr: {
3759     // Found an AnyPtr type vs self-OopPtr type
3760     const TypePtr *tp = t->is_ptr();
3761     Offset offset = meet_offset(tp->offset());
3762     PTR ptr = meet_ptr(tp->ptr());
3763     const TypePtr* speculative = xmeet_speculative(tp);
3764     int depth = meet_inline_depth(tp->inline_depth());
3765     switch (tp->ptr()) {
3766     case Null:
3767       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3768       // else fall through:
3769     case TopPTR:
3770     case AnyNull: {
3771       int instance_id = meet_instance_id(InstanceTop);
3772       return make(ptr, offset, instance_id, speculative, depth);
3773     }
3774     case BotPTR:
3775     case NotNull:
3776       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3777     default: typerr(t);
3778     }
3779   }
3780 
3781   case OopPtr: {                 // Meeting to other OopPtrs

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

4001   } else {
4002     return one->equals(two) && TypePtr::eq(t);
4003   }
4004 }
4005 
4006 //------------------------------hash-------------------------------------------
4007 // Type-specific hashing function.
4008 uint TypeOopPtr::hash(void) const {
4009   return
4010     (uint)(const_oop() ? const_oop()->hash() : 0) +
4011     (uint)_klass_is_exact +
4012     (uint)_instance_id + TypePtr::hash();
4013 }
4014 
4015 //------------------------------dump2------------------------------------------
4016 #ifndef PRODUCT
4017 void TypeOopPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
4018   st->print("oopptr:%s", ptr_msg[_ptr]);
4019   if( _klass_is_exact ) st->print(":exact");
4020   if( const_oop() ) st->print(INTPTR_FORMAT, p2i(const_oop()));
4021   _offset.dump2(st);





4022   if (_instance_id == InstanceTop)
4023     st->print(",iid=top");
4024   else if (_instance_id != InstanceBot)
4025     st->print(",iid=%d",_instance_id);
4026 
4027   dump_inline_depth(st);
4028   dump_speculative(st);
4029 }
4030 #endif
4031 
4032 //------------------------------singleton--------------------------------------
4033 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4034 // constants
4035 bool TypeOopPtr::singleton(void) const {
4036   // detune optimizer to not generate constant oop + constant offset as a constant!
4037   // TopPTR, Null, AnyNull, Constant are all singletons
4038   return (offset() == 0) && !below_centerline(_ptr);
4039 }
4040 
4041 //------------------------------add_offset-------------------------------------
4042 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4043   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4044 }
4045 
4046 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4047   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4048 }
4049 
4050 /**
4051  * Return same type without a speculative part
4052  */
4053 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4054   if (_speculative == nullptr) {
4055     return this;
4056   }
4057   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4058   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4059 }
4060 
4061 /**
4062  * Return same type but drop speculative part if we know we won't use
4063  * it
4064  */
4065 const Type* TypeOopPtr::cleanup_speculative() const {
4066   // If the klass is exact and the ptr is not null then there's
4067   // nothing that the speculative type can help us with

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

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

4365   case Top:
4366     return this;
4367 
4368   default:                      // All else is a mistake
4369     typerr(t);
4370 
4371   case MetadataPtr:
4372   case KlassPtr:
4373   case InstKlassPtr:
4374   case AryKlassPtr:
4375   case RawPtr: return TypePtr::BOTTOM;
4376 
4377   case AryPtr: {                // All arrays inherit from Object class
4378     // Call in reverse direction to avoid duplication
4379     return t->is_aryptr()->xmeet_helper(this);
4380   }
4381 
4382   case OopPtr: {                // Meeting to OopPtrs
4383     // Found a OopPtr type vs self-InstPtr type
4384     const TypeOopPtr *tp = t->is_oopptr();
4385     Offset offset = meet_offset(tp->offset());
4386     PTR ptr = meet_ptr(tp->ptr());
4387     switch (tp->ptr()) {
4388     case TopPTR:
4389     case AnyNull: {
4390       int instance_id = meet_instance_id(InstanceTop);
4391       const TypePtr* speculative = xmeet_speculative(tp);
4392       int depth = meet_inline_depth(tp->inline_depth());
4393       return make(ptr, klass(), _interfaces, klass_is_exact(),
4394                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4395     }
4396     case NotNull:
4397     case BotPTR: {
4398       int instance_id = meet_instance_id(tp->instance_id());
4399       const TypePtr* speculative = xmeet_speculative(tp);
4400       int depth = meet_inline_depth(tp->inline_depth());
4401       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4402     }
4403     default: typerr(t);
4404     }
4405   }
4406 
4407   case AnyPtr: {                // Meeting to AnyPtrs
4408     // Found an AnyPtr type vs self-InstPtr type
4409     const TypePtr *tp = t->is_ptr();
4410     Offset offset = meet_offset(tp->offset());
4411     PTR ptr = meet_ptr(tp->ptr());
4412     int instance_id = meet_instance_id(InstanceTop);
4413     const TypePtr* speculative = xmeet_speculative(tp);
4414     int depth = meet_inline_depth(tp->inline_depth());
4415     switch (tp->ptr()) {
4416     case Null:
4417       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4418       // else fall through to AnyNull
4419     case TopPTR:
4420     case AnyNull: {
4421       return make(ptr, klass(), _interfaces, klass_is_exact(),
4422                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4423     }
4424     case NotNull:
4425     case BotPTR:
4426       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4427     default: typerr(t);
4428     }
4429   }
4430 
4431   /*
4432                  A-top         }
4433                /   |   \       }  Tops
4434            B-top A-any C-top   }
4435               | /  |  \ |      }  Any-nulls
4436            B-any   |   C-any   }
4437               |    |    |
4438            B-con A-con C-con   } constants; not comparable across classes
4439               |    |    |
4440            B-not   |   C-not   }
4441               | \  |  / |      }  not-nulls
4442            B-bot A-not C-bot   }
4443                \   |   /       }  Bottoms
4444                  A-bot         }
4445   */
4446 
4447   case InstPtr: {                // Meeting 2 Oops?
4448     // Found an InstPtr sub-type vs self-InstPtr type
4449     const TypeInstPtr *tinst = t->is_instptr();
4450     Offset off = meet_offset(tinst->offset());
4451     PTR ptr = meet_ptr(tinst->ptr());
4452     int instance_id = meet_instance_id(tinst->instance_id());
4453     const TypePtr* speculative = xmeet_speculative(tinst);
4454     int depth = meet_inline_depth(tinst->inline_depth());
4455     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4456 
4457     ciKlass* tinst_klass = tinst->klass();
4458     ciKlass* this_klass  = klass();
4459 
4460     ciKlass* res_klass = nullptr;
4461     bool res_xk = false;
4462     bool res_flat_in_array = false;
4463     const Type* res;
4464     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk, res_flat_in_array);
4465 
4466     if (kind == UNLOADED) {
4467       // One of these classes has not been loaded
4468       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4469 #ifndef PRODUCT
4470       if (PrintOpto && Verbose) {
4471         tty->print("meet of unloaded classes resulted in: ");
4472         unloaded_meet->dump();
4473         tty->cr();
4474         tty->print("  this == ");
4475         dump();
4476         tty->cr();
4477         tty->print(" tinst == ");
4478         tinst->dump();
4479         tty->cr();
4480       }
4481 #endif
4482       res = unloaded_meet;
4483     } else {
4484       if (kind == NOT_SUBTYPE && instance_id > 0) {
4485         instance_id = InstanceBot;
4486       } else if (kind == LCA) {
4487         instance_id = InstanceBot;
4488       }
4489       ciObject* o = nullptr;             // Assume not constant when done
4490       ciObject* this_oop = const_oop();
4491       ciObject* tinst_oop = tinst->const_oop();
4492       if (ptr == Constant) {
4493         if (this_oop != nullptr && tinst_oop != nullptr &&
4494             this_oop->equals(tinst_oop))
4495           o = this_oop;
4496         else if (above_centerline(_ptr)) {
4497           assert(!tinst_klass->is_interface(), "");
4498           o = tinst_oop;
4499         } else if (above_centerline(tinst->_ptr)) {
4500           assert(!this_klass->is_interface(), "");
4501           o = this_oop;
4502         } else
4503           ptr = NotNull;
4504       }
4505       res = make(ptr, res_klass, interfaces, res_xk, o, off, res_flat_in_array, instance_id, speculative, depth);
4506     }
4507 
4508     return res;
4509 
4510   } // End of case InstPtr
4511 
4512   } // End of switch
4513   return this;                  // Return the double constant
4514 }
4515 
4516 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4517                                                             ciKlass*& res_klass, bool& res_xk, bool& res_flat_in_array) {
4518   ciKlass* this_klass = this_type->klass();
4519   ciKlass* other_klass = other_type->klass();
4520   const bool this_flat_in_array = this_type->flat_in_array();
4521   const bool other_flat_in_array = other_type->flat_in_array();
4522   const bool this_not_flat_in_array = this_type->not_flat_in_array();
4523   const bool other_not_flat_in_array = other_type->not_flat_in_array();
4524 
4525   bool this_xk = this_type->klass_is_exact();
4526   bool other_xk = other_type->klass_is_exact();
4527   PTR this_ptr = this_type->ptr();
4528   PTR other_ptr = other_type->ptr();
4529   const TypeInterfaces* this_interfaces = this_type->interfaces();
4530   const TypeInterfaces* other_interfaces = other_type->interfaces();
4531   // Check for easy case; klasses are equal (and perhaps not loaded!)
4532   // If we have constants, then we created oops so classes are loaded
4533   // and we can handle the constants further down.  This case handles
4534   // both-not-loaded or both-loaded classes
4535   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk && this_flat_in_array == other_flat_in_array) {
4536     res_klass = this_klass;
4537     res_xk = this_xk;
4538     res_flat_in_array = this_flat_in_array;
4539     return QUICK;
4540   }
4541 
4542   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4543   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4544     return UNLOADED;
4545   }
4546 
4547   // !!! Here's how the symmetry requirement breaks down into invariants:
4548   // If we split one up & one down AND they subtype, take the down man.
4549   // If we split one up & one down AND they do NOT subtype, "fall hard".
4550   // If both are up and they subtype, take the subtype class.
4551   // If both are up and they do NOT subtype, "fall hard".
4552   // If both are down and they subtype, take the supertype class.
4553   // If both are down and they do NOT subtype, "fall hard".
4554   // Constants treated as down.
4555 
4556   // Now, reorder the above list; observe that both-down+subtype is also
4557   // "fall hard"; "fall hard" becomes the default case:
4558   // If we split one up & one down AND they subtype, take the down man.
4559   // If both are up and they subtype, take the subtype class.
4560 
4561   // If both are down and they subtype, "fall hard".
4562   // If both are down and they do NOT subtype, "fall hard".
4563   // If both are up and they do NOT subtype, "fall hard".
4564   // If we split one up & one down AND they do NOT subtype, "fall hard".
4565 
4566   // If a proper subtype is exact, and we return it, we return it exactly.
4567   // If a proper supertype is exact, there can be no subtyping relationship!
4568   // If both types are equal to the subtype, exactness is and-ed below the
4569   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4570 
4571   // Flat in Array property _flat_in_array.
4572   // For simplicity, _flat_in_array is a boolean but we actually have a tri state:
4573   // - Flat in array       -> flat_in_array()
4574   // - Not flat in array   -> not_flat_in_array()
4575   // - Maybe flat in array -> !not_flat_in_array()
4576   //
4577   // Maybe we should convert _flat_in_array to a proper lattice with four elements at some point:
4578   //
4579   //                  Top
4580   //    Flat in Array     Not Flat in Array
4581   //          Maybe Flat in Array
4582   //
4583   // where
4584   //     Top = dual(maybe Flat In Array) = "Flat in Array AND Not Flat in Array"
4585   //
4586   // But for now we stick with the current model with _flat_in_array as a boolean.
4587   //
4588   // When meeting two InstPtr types, we want to have the following behavior:
4589   //
4590   // (FiA-M) Meet(this, other):
4591   //     'this' and 'other' are either the same klass OR sub klasses:
4592   //
4593   //                yes maybe no
4594   //           yes   y    m    m                      y = Flat in Array
4595   //         maybe   m    m    m                      n = Not Flat in Array
4596   //            no   m    m    n                      m = Maybe Flat in Array
4597   //
4598   //  Join(this, other):
4599   //     (FiA-J-Same) 'this' and 'other' are the SAME klass:
4600   //
4601   //                yes maybe no                      E = Empty set
4602   //           yes   y    y    E                      y = Flat in Array
4603   //         maybe   y    m    m                      n = Not Flat in Array
4604   //            no   E    m    n                      m = Maybe Flat in Array
4605   //
4606   //     (FiA-J-Sub) 'this' and 'other' are SUB klasses:
4607   //
4608   //               yes maybe no   -> Super Klass      E = Empty set
4609   //          yes   y    y    y                       y = Flat in Array
4610   //        maybe   y    m    m                       n = Not Flat in Array
4611   //           no   E    m    n                       m = Maybe Flat in Array
4612   //           |
4613   //           v
4614   //       Sub Klass
4615   //
4616   //     Note the difference when joining a super klass that is not flat in array with a sub klass that is compared to
4617   //     the same klass case. We will take over the flat in array property of the sub klass. This can be done because
4618   //     the super klass could be Object (i.e. not an inline type and thus not flat in array) while the sub klass is a
4619   //     value class which can be flat in array.
4620   //
4621   //     The empty set is only a possible result when matching 'ptr' above the center line (i.e. joining). In this case,
4622   //     we can "fall hard" by setting 'ptr' to NotNull such that when we take the dual of that meet above the center
4623   //     line, we get an empty set again.
4624   //
4625   //     Note: When changing to a separate lattice with _flat_in_array we may want to add TypeInst(Klass)Ptr::empty()
4626   //           that returns true when the meet result is FlatInArray::Top (i.e. dual(maybe flat in array)).
4627 
4628   const T* subtype = nullptr;
4629   bool subtype_exact = false;
4630   bool flat_in_array = false;
4631   bool is_empty = false;
4632   if (this_type->is_same_java_type_as(other_type)) {
4633     // Same klass
4634     subtype = this_type;
4635     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4636     if (above_centerline(ptr)) {
4637       // Case (FiA-J-Same)
4638       // One is flat in array and the other not? Result is empty/"fall hard".
4639       is_empty = (this_flat_in_array && other_not_flat_in_array) || (this_not_flat_in_array && other_flat_in_array);
4640     }
4641   } else if (!other_xk && is_meet_subtype_of(this_type, other_type)) {
4642     subtype = this_type;     // Pick subtyping class
4643     subtype_exact = this_xk;
4644     if (above_centerline(ptr)) {
4645       // Case (FiA-J-Sub)
4646       is_empty = this_not_flat_in_array && other_flat_in_array;
4647       if (!is_empty) {
4648         bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4649         flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4650       }
4651     }
4652   } else if (!this_xk && is_meet_subtype_of(other_type, this_type)) {
4653     subtype = other_type;    // Pick subtyping class
4654     subtype_exact = other_xk;
4655     if (above_centerline(ptr)) {
4656       // Case (FiA-J-Sub)
4657       is_empty = this_flat_in_array && other_not_flat_in_array;
4658       if (!is_empty) {
4659         bool this_flat_other_maybe_flat = this_flat_in_array && (!other_flat_in_array && !other_not_flat_in_array);
4660         flat_in_array = other_flat_in_array || this_flat_other_maybe_flat;
4661       }
4662     }
4663   }
4664 
4665 
4666   if (subtype && !is_empty) {
4667     if (above_centerline(ptr)) {
4668       // Both types are empty.
4669       this_type = other_type = subtype;
4670       this_xk = other_xk = subtype_exact;
4671       // Case (FiA-J-Sub)
4672       bool other_flat_this_maybe_flat = other_flat_in_array && (!this_flat_in_array && !this_not_flat_in_array);
4673       flat_in_array = this_flat_in_array || other_flat_this_maybe_flat;
4674       // One is flat in array and the other not? Result is empty/"fall hard".
4675       is_empty = (this_flat_in_array && other_not_flat_in_array) || (this_not_flat_in_array && other_flat_in_array);
4676     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4677       // this_type is empty while other_type is not. Take other_type.
4678       this_type = other_type;
4679       this_xk = other_xk;
4680       flat_in_array = other_flat_in_array;
4681     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4682       // other_type is empty while this_type is not. Take this_type.
4683       other_type = this_type; // this is down; keep down man
4684       flat_in_array = this_flat_in_array;
4685     } else {
4686       // this_type and other_type are both non-empty.
4687       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4688       // Case (FiA-M)
4689       // Meeting two types below the center line: Only flat in array if both are.
4690       flat_in_array = this_flat_in_array && other_flat_in_array;
4691     }
4692   }
4693 
4694   // Check for classes now being equal
4695   if (this_type->is_same_java_type_as(other_type) && !is_empty) {
4696     // If the klasses are equal, the constants may still differ.  Fall to
4697     // NotNull if they do (neither constant is null; that is a special case
4698     // handled elsewhere).
4699     res_klass = this_type->klass();
4700     res_xk = this_xk;
4701     res_flat_in_array = flat_in_array;
4702     return SUBTYPE;
4703   } // Else classes are not equal
4704 
4705   // Since klasses are different, we require a LCA in the Java
4706   // class hierarchy - which means we have to fall to at least NotNull.
4707   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4708     ptr = NotNull;
4709   }
4710 
4711   interfaces = this_interfaces->intersection_with(other_interfaces);
4712 
4713   // Now we find the LCA of Java classes
4714   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4715 
4716   res_klass = k;
4717   res_xk = false;
4718   res_flat_in_array = this_flat_in_array && other_flat_in_array;
4719 
4720   return LCA;
4721 }
4722 
4723 template<class T> bool TypePtr::is_meet_subtype_of(const T* sub_type, const T* super_type) {
4724   return sub_type->is_meet_subtype_of(super_type) && !(super_type->flat_in_array() && sub_type->not_flat_in_array());
4725 }
4726 
4727 //------------------------java_mirror_type--------------------------------------
4728 ciType* TypeInstPtr::java_mirror_type() const {
4729   // must be a singleton type
4730   if( const_oop() == nullptr )  return nullptr;
4731 
4732   // must be of type java.lang.Class
4733   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;

4734   return const_oop()->as_instance()->java_mirror_type();
4735 }
4736 
4737 
4738 //------------------------------xdual------------------------------------------
4739 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4740 // inheritance mechanism.
4741 const Type *TypeInstPtr::xdual() const {
4742   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());
4743 }
4744 
4745 //------------------------------eq---------------------------------------------
4746 // Structural equality check for Type representations
4747 bool TypeInstPtr::eq( const Type *t ) const {
4748   const TypeInstPtr *p = t->is_instptr();
4749   return
4750     klass()->equals(p->klass()) &&
4751     flat_in_array() == p->flat_in_array() &&
4752     _interfaces->eq(p->_interfaces) &&
4753     TypeOopPtr::eq(p);          // Check sub-type stuff
4754 }
4755 
4756 //------------------------------hash-------------------------------------------
4757 // Type-specific hashing function.
4758 uint TypeInstPtr::hash(void) const {
4759   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + (uint)flat_in_array();
4760 }
4761 
4762 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4763   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4764 }
4765 
4766 
4767 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4768   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4769 }
4770 
4771 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4772   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4773 }
4774 
4775 
4776 //------------------------------dump2------------------------------------------
4777 // Dump oop Type
4778 #ifndef PRODUCT
4779 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {

4793       // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4794       char* buf = ss.as_string(/* c_heap= */false);
4795       StringUtils::replace_no_expand(buf, "\n", "");
4796       st->print_raw(buf);
4797     }
4798   case BotPTR:
4799     if (!WizardMode && !Verbose) {
4800       if( _klass_is_exact ) st->print(":exact");
4801       break;
4802     }
4803   case TopPTR:
4804   case AnyNull:
4805   case NotNull:
4806     st->print(":%s", ptr_msg[_ptr]);
4807     if( _klass_is_exact ) st->print(":exact");
4808     break;
4809   default:
4810     break;
4811   }
4812 
4813   _offset.dump2(st);




4814 
4815   st->print(" *");
4816 
4817   if (flat_in_array() && !klass()->is_inlinetype()) {
4818     st->print(" (flat in array)");
4819   }
4820 
4821   if (_instance_id == InstanceTop)
4822     st->print(",iid=top");
4823   else if (_instance_id != InstanceBot)
4824     st->print(",iid=%d",_instance_id);
4825 
4826   dump_inline_depth(st);
4827   dump_speculative(st);
4828 }
4829 #endif
4830 
4831 //------------------------------add_offset-------------------------------------
4832 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4833   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), flat_in_array(),
4834               _instance_id, add_offset_speculative(offset), _inline_depth);
4835 }
4836 
4837 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4838   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), flat_in_array(),
4839               _instance_id, with_offset_speculative(offset), _inline_depth);
4840 }
4841 
4842 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4843   if (_speculative == nullptr) {
4844     return this;
4845   }
4846   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4847   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(),
4848               _instance_id, nullptr, _inline_depth);
4849 }
4850 
4851 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4852   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, speculative, _inline_depth);
4853 }
4854 
4855 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4856   if (!UseInlineDepthForSpeculativeTypes) {
4857     return this;
4858   }
4859   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), _instance_id, _speculative, depth);
4860 }
4861 
4862 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4863   assert(is_known_instance(), "should be known");
4864   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, flat_in_array(), instance_id, _speculative, _inline_depth);
4865 }
4866 
4867 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4868   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, true, _instance_id, _speculative, _inline_depth);
4869 }
4870 
4871 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4872   bool xk = klass_is_exact();
4873   ciInstanceKlass* ik = klass()->as_instance_klass();
4874   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4875     if (_interfaces->eq(ik)) {
4876       Compile* C = Compile::current();
4877       Dependencies* deps = C->dependencies();
4878       deps->assert_leaf_type(ik);
4879       xk = true;
4880     }
4881   }
4882   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array());
4883 }
4884 
4885 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) {
4886   static_assert(std::is_base_of<T2, T1>::value, "");
4887 
4888   if (!this_one->is_instance_type(other)) {
4889     return false;
4890   }
4891 
4892   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4893     return true;
4894   }
4895 
4896   return this_one->klass()->is_subtype_of(other->klass()) &&
4897          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4898 }
4899 
4900 
4901 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4902   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);

4907   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4908     return true;
4909   }
4910 
4911   if (this_one->is_instance_type(other)) {
4912     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4913   }
4914 
4915   int dummy;
4916   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4917   if (this_top_or_bottom) {
4918     return false;
4919   }
4920 
4921   const T1* other_ary = this_one->is_array_type(other);
4922   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4923   const TypePtr* this_elem = this_one->elem()->make_ptr();
4924   if (other_elem != nullptr && this_elem != nullptr) {
4925     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4926   }

4927   if (other_elem == nullptr && this_elem == nullptr) {
4928     return this_one->klass()->is_subtype_of(other->klass());
4929   }
4930 
4931   return false;
4932 }
4933 
4934 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4935   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4936 }
4937 
4938 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4939   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4940 }
4941 
4942 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4943   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4944 }
4945 
4946 //=============================================================================
4947 // Convenience common pre-built types.
4948 const TypeAryPtr* TypeAryPtr::BOTTOM;
4949 const TypeAryPtr *TypeAryPtr::RANGE;
4950 const TypeAryPtr *TypeAryPtr::OOPS;
4951 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
4952 const TypeAryPtr *TypeAryPtr::BYTES;
4953 const TypeAryPtr *TypeAryPtr::SHORTS;
4954 const TypeAryPtr *TypeAryPtr::CHARS;
4955 const TypeAryPtr *TypeAryPtr::INTS;
4956 const TypeAryPtr *TypeAryPtr::LONGS;
4957 const TypeAryPtr *TypeAryPtr::FLOATS;
4958 const TypeAryPtr *TypeAryPtr::DOUBLES;
4959 const TypeAryPtr *TypeAryPtr::INLINES;
4960 
4961 //------------------------------make-------------------------------------------
4962 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4963                                    int instance_id, const TypePtr* speculative, int inline_depth) {
4964   assert(!(k == nullptr && ary->_elem->isa_int()),
4965          "integral arrays must be pre-equipped with a class");
4966   if (!xk)  xk = ary->ary_must_be_exact();
4967   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4968   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4969       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4970     k = nullptr;
4971   }
4972   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
4973 }
4974 
4975 //------------------------------make-------------------------------------------
4976 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
4977                                    int instance_id, const TypePtr* speculative, int inline_depth,
4978                                    bool is_autobox_cache) {
4979   assert(!(k == nullptr && ary->_elem->isa_int()),
4980          "integral arrays must be pre-equipped with a class");
4981   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
4982   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
4983   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4984   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
4985       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
4986     k = nullptr;
4987   }
4988   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
4989 }
4990 
4991 //------------------------------cast_to_ptr_type-------------------------------
4992 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
4993   if( ptr == _ptr ) return this;
4994   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
4995 }
4996 
4997 
4998 //-----------------------------cast_to_exactness-------------------------------
4999 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
5000   if( klass_is_exact == _klass_is_exact ) return this;
5001   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
5002   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5003 }
5004 
5005 //-----------------------------cast_to_instance_id----------------------------
5006 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
5007   if( instance_id == _instance_id ) return this;
5008   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
5009 }
5010 
5011 
5012 //-----------------------------max_array_length-------------------------------
5013 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
5014 jint TypeAryPtr::max_array_length(BasicType etype) {
5015   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5016     if (etype == T_NARROWOOP) {
5017       etype = T_OBJECT;
5018     } else if (etype == T_ILLEGAL) { // bottom[]
5019       etype = T_BYTE; // will produce conservatively high value
5020     } else {
5021       fatal("not an element type: %s", type2name(etype));
5022     }
5023   }
5024   return arrayOopDesc::max_array_length(etype);
5025 }
5026 
5027 //-----------------------------narrow_size_type-------------------------------
5028 // Narrow the given size type to the index range for the given array base type.

5046     if (size->is_con()) {
5047       lo = hi;
5048     }
5049     chg = true;
5050   }
5051   // Negative length arrays will produce weird intermediate dead fast-path code
5052   if (lo > hi) {
5053     return TypeInt::ZERO;
5054   }
5055   if (!chg) {
5056     return size;
5057   }
5058   return TypeInt::make(lo, hi, Type::WidenMin);
5059 }
5060 
5061 //-------------------------------cast_to_size----------------------------------
5062 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5063   assert(new_size != nullptr, "");
5064   new_size = narrow_size_type(new_size);
5065   if (new_size == size())  return this;
5066   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5067   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5068 }
5069 
5070 //-------------------------------cast_to_not_flat------------------------------
5071 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5072   if (not_flat == is_not_flat()) {
5073     return this;
5074   }
5075   assert(!not_flat || !is_flat(), "inconsistency");
5076   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free(), is_atomic());
5077   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5078   // We keep the speculative part if it contains information about flat-/nullability.
5079   // Make sure it's removed if it's not better than the non-speculative type anymore.
5080   if (res->speculative() == res->remove_speculative()) {
5081     return res->remove_speculative();
5082   }
5083   return res;
5084 }
5085 
5086 //-------------------------------cast_to_not_null_free-------------------------
5087 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5088   if (not_null_free == is_not_null_free()) {
5089     return this;
5090   }
5091   assert(!not_null_free || !is_null_free(), "inconsistency");
5092   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), is_not_flat(), not_null_free, is_atomic());
5093   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5094                                _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5095   // We keep the speculative part if it contains information about flat-/nullability.
5096   // Make sure it's removed if it's not better than the non-speculative type anymore.
5097   if (res->speculative() == res->remove_speculative()) {
5098     return res->remove_speculative();
5099   }
5100   return res;
5101 }
5102 
5103 //---------------------------------update_properties---------------------------
5104 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5105   if ((from->is_flat()          && is_not_flat()) ||
5106       (from->is_not_flat()      && is_flat()) ||
5107       (from->is_null_free()     && is_not_null_free()) ||
5108       (from->is_not_null_free() && is_null_free())) {
5109     return nullptr; // Inconsistent properties
5110   }
5111   const TypeAryPtr* res = this;
5112   if (from->is_not_null_free()) {
5113     res = res->cast_to_not_null_free();
5114   }
5115   if (from->is_not_flat()) {
5116     res = res->cast_to_not_flat();
5117   }
5118   return res;
5119 }
5120 
5121 jint TypeAryPtr::flat_layout_helper() const {
5122   return exact_klass()->as_flat_array_klass()->layout_helper();
5123 }
5124 
5125 int TypeAryPtr::flat_elem_size() const {
5126   return exact_klass()->as_flat_array_klass()->element_byte_size();
5127 }
5128 
5129 int TypeAryPtr::flat_log_elem_size() const {
5130   return exact_klass()->as_flat_array_klass()->log2_element_size();
5131 }
5132 
5133 //------------------------------cast_to_stable---------------------------------
5134 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5135   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5136     return this;
5137 
5138   const Type* elem = this->elem();
5139   const TypePtr* elem_ptr = elem->make_ptr();
5140 
5141   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5142     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5143     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5144   }
5145 
5146   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5147 
5148   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5149 }
5150 
5151 //-----------------------------stable_dimension--------------------------------
5152 int TypeAryPtr::stable_dimension() const {
5153   if (!is_stable())  return 0;
5154   int dim = 1;
5155   const TypePtr* elem_ptr = elem()->make_ptr();
5156   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5157     dim += elem_ptr->is_aryptr()->stable_dimension();
5158   return dim;
5159 }
5160 
5161 //----------------------cast_to_autobox_cache-----------------------------------
5162 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5163   if (is_autobox_cache())  return this;
5164   const TypeOopPtr* etype = elem()->make_oopptr();
5165   if (etype == nullptr)  return this;
5166   // The pointers in the autobox arrays are always non-null.
5167   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5168   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5169   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5170 }
5171 
5172 //------------------------------eq---------------------------------------------
5173 // Structural equality check for Type representations
5174 bool TypeAryPtr::eq( const Type *t ) const {
5175   const TypeAryPtr *p = t->is_aryptr();
5176   return
5177     _ary == p->_ary &&  // Check array
5178     TypeOopPtr::eq(p) &&// Check sub-parts
5179     _field_offset == p->_field_offset;
5180 }
5181 
5182 //------------------------------hash-------------------------------------------
5183 // Type-specific hashing function.
5184 uint TypeAryPtr::hash(void) const {
5185   return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5186 }
5187 
5188 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5189   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5190 }
5191 
5192 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5193   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5194 }
5195 
5196 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5197   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5198 }
5199 //------------------------------meet-------------------------------------------
5200 // Compute the MEET of two types.  It returns a new Type object.
5201 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5202   // Perform a fast test for common case; meeting the same types together.
5203   if( this == t ) return this;  // Meeting same type-rep?
5204   // Current "this->_base" is Pointer
5205   switch (t->base()) {          // switch on original type

5212   case HalfFloatBot:
5213   case FloatTop:
5214   case FloatCon:
5215   case FloatBot:
5216   case DoubleTop:
5217   case DoubleCon:
5218   case DoubleBot:
5219   case NarrowOop:
5220   case NarrowKlass:
5221   case Bottom:                  // Ye Olde Default
5222     return Type::BOTTOM;
5223   case Top:
5224     return this;
5225 
5226   default:                      // All else is a mistake
5227     typerr(t);
5228 
5229   case OopPtr: {                // Meeting to OopPtrs
5230     // Found a OopPtr type vs self-AryPtr type
5231     const TypeOopPtr *tp = t->is_oopptr();
5232     Offset offset = meet_offset(tp->offset());
5233     PTR ptr = meet_ptr(tp->ptr());
5234     int depth = meet_inline_depth(tp->inline_depth());
5235     const TypePtr* speculative = xmeet_speculative(tp);
5236     switch (tp->ptr()) {
5237     case TopPTR:
5238     case AnyNull: {
5239       int instance_id = meet_instance_id(InstanceTop);
5240       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5241                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5242     }
5243     case BotPTR:
5244     case NotNull: {
5245       int instance_id = meet_instance_id(tp->instance_id());
5246       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5247     }
5248     default: ShouldNotReachHere();
5249     }
5250   }
5251 
5252   case AnyPtr: {                // Meeting two AnyPtrs
5253     // Found an AnyPtr type vs self-AryPtr type
5254     const TypePtr *tp = t->is_ptr();
5255     Offset offset = meet_offset(tp->offset());
5256     PTR ptr = meet_ptr(tp->ptr());
5257     const TypePtr* speculative = xmeet_speculative(tp);
5258     int depth = meet_inline_depth(tp->inline_depth());
5259     switch (tp->ptr()) {
5260     case TopPTR:
5261       return this;
5262     case BotPTR:
5263     case NotNull:
5264       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5265     case Null:
5266       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5267       // else fall through to AnyNull
5268     case AnyNull: {
5269       int instance_id = meet_instance_id(InstanceTop);
5270       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5271                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5272     }
5273     default: ShouldNotReachHere();
5274     }
5275   }
5276 
5277   case MetadataPtr:
5278   case KlassPtr:
5279   case InstKlassPtr:
5280   case AryKlassPtr:
5281   case RawPtr: return TypePtr::BOTTOM;
5282 
5283   case AryPtr: {                // Meeting 2 references?
5284     const TypeAryPtr *tap = t->is_aryptr();
5285     Offset off = meet_offset(tap->offset());
5286     Offset field_off = meet_field_offset(tap->field_offset());
5287     const Type* tm = _ary->meet_speculative(tap->_ary);
5288     const TypeAry* tary = tm->isa_ary();
5289     if (tary == nullptr) {
5290       assert(tm == Type::TOP || tm == Type::BOTTOM, "");
5291       return tm;
5292     }
5293     PTR ptr = meet_ptr(tap->ptr());
5294     int instance_id = meet_instance_id(tap->instance_id());
5295     const TypePtr* speculative = xmeet_speculative(tap);
5296     int depth = meet_inline_depth(tap->inline_depth());
5297 
5298     ciKlass* res_klass = nullptr;
5299     bool res_xk = false;
5300     bool res_flat = false;
5301     bool res_not_flat = false;
5302     bool res_not_null_free = false;
5303     bool res_atomic = false;
5304     const Type* elem = tary->_elem;
5305     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic) == NOT_SUBTYPE) {
5306       instance_id = InstanceBot;
5307     } else if (this->is_flat() != tap->is_flat()) {
5308       // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5309       if (tary->_flat) {
5310         // Result is in a flat representation
5311         off = Offset(is_flat() ? offset() : tap->offset());
5312         field_off = is_flat() ? field_offset() : tap->field_offset();
5313       } else if (below_centerline(ptr)) {
5314         // Result is in a non-flat representation
5315         off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5316         field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5317       } else if (flat_offset() == tap->flat_offset()) {
5318         off = Offset(!is_flat() ? offset() : tap->offset());
5319         field_off = !is_flat() ? field_offset() : tap->field_offset();
5320       }
5321     }
5322 
5323     ciObject* o = nullptr;             // Assume not constant when done
5324     ciObject* this_oop = const_oop();
5325     ciObject* tap_oop = tap->const_oop();
5326     if (ptr == Constant) {
5327       if (this_oop != nullptr && tap_oop != nullptr &&
5328           this_oop->equals(tap_oop)) {
5329         o = tap_oop;
5330       } else if (above_centerline(_ptr)) {
5331         o = tap_oop;
5332       } else if (above_centerline(tap->_ptr)) {
5333         o = this_oop;
5334       } else {
5335         ptr = NotNull;
5336       }
5337     }
5338     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable, res_flat, res_not_flat, res_not_null_free, res_atomic), res_klass, res_xk, off, field_off, instance_id, speculative, depth);
5339   }
5340 
5341   // All arrays inherit from Object class
5342   case InstPtr: {
5343     const TypeInstPtr *tp = t->is_instptr();
5344     Offset offset = meet_offset(tp->offset());
5345     PTR ptr = meet_ptr(tp->ptr());
5346     int instance_id = meet_instance_id(tp->instance_id());
5347     const TypePtr* speculative = xmeet_speculative(tp);
5348     int depth = meet_inline_depth(tp->inline_depth());
5349     const TypeInterfaces* interfaces = meet_interfaces(tp);
5350     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5351     const TypeInterfaces* this_interfaces = _interfaces;
5352 
5353     switch (ptr) {
5354     case TopPTR:
5355     case AnyNull:                // Fall 'down' to dual of object klass
5356       // For instances when a subclass meets a superclass we fall
5357       // below the centerline when the superclass is exact. We need to
5358       // do the same here.
5359       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5360         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5361       } else {
5362         // cannot subclass, so the meet has to fall badly below the centerline
5363         ptr = NotNull;
5364         instance_id = InstanceBot;
5365         interfaces = this_interfaces->intersection_with(tp_interfaces);
5366         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5367       }
5368     case Constant:
5369     case NotNull:
5370     case BotPTR:                // Fall down to object klass
5371       // LCA is object_klass, but if we subclass from the top we can do better
5372       if (above_centerline(tp->ptr())) {
5373         // If 'tp'  is above the centerline and it is Object class
5374         // then we can subclass in the Java class hierarchy.
5375         // For instances when a subclass meets a superclass we fall
5376         // below the centerline when the superclass is exact. We need
5377         // to do the same here.
5378         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact() && !tp->flat_in_array()) {
5379           // that is, my array type is a subtype of 'tp' klass
5380           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5381                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5382         }
5383       }
5384       // The other case cannot happen, since t cannot be a subtype of an array.
5385       // The meet falls down to Object class below centerline.
5386       if (ptr == Constant) {
5387          ptr = NotNull;
5388       }
5389       if (instance_id > 0) {
5390         instance_id = InstanceBot;
5391       }
5392       interfaces = this_interfaces->intersection_with(tp_interfaces);
5393       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, false, instance_id, speculative, depth);
5394     default: typerr(t);
5395     }
5396   }
5397   }
5398   return this;                  // Lint noise
5399 }
5400 
5401 
5402 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5403                                                            ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free, bool &res_atomic) {
5404   int dummy;
5405   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5406   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5407   ciKlass* this_klass = this_ary->klass();
5408   ciKlass* other_klass = other_ary->klass();
5409   bool this_xk = this_ary->klass_is_exact();
5410   bool other_xk = other_ary->klass_is_exact();
5411   PTR this_ptr = this_ary->ptr();
5412   PTR other_ptr = other_ary->ptr();
5413   bool this_flat = this_ary->is_flat();
5414   bool this_not_flat = this_ary->is_not_flat();
5415   bool other_flat = other_ary->is_flat();
5416   bool other_not_flat = other_ary->is_not_flat();
5417   bool this_not_null_free = this_ary->is_not_null_free();
5418   bool other_not_null_free = other_ary->is_not_null_free();
5419   bool this_atomic = this_ary->is_atomic();
5420   bool other_atomic = other_ary->is_atomic();
5421   const bool same_nullness = this_ary->is_null_free() == other_ary->is_null_free();
5422   res_klass = nullptr;
5423   MeetResult result = SUBTYPE;
5424   res_flat = this_flat && other_flat;
5425   bool res_null_free = this_ary->is_null_free() && other_ary->is_null_free();
5426   res_not_flat = this_not_flat && other_not_flat;
5427   res_not_null_free = this_not_null_free && other_not_null_free;
5428   res_atomic = this_atomic && other_atomic;
5429 
5430   if (elem->isa_int()) {
5431     // Integral array element types have irrelevant lattice relations.
5432     // It is the klass that determines array layout, not the element type.
5433       if (this_top_or_bottom) {
5434         res_klass = other_klass;
5435       } else if (other_top_or_bottom || other_klass == this_klass) {
5436       res_klass = this_klass;
5437     } else {
5438       // Something like byte[int+] meets char[int+].
5439       // This must fall to bottom, not (int[-128..65535])[int+].
5440       // instance_id = InstanceBot;
5441       elem = Type::BOTTOM;
5442       result = NOT_SUBTYPE;
5443       if (above_centerline(ptr) || ptr == Constant) {
5444         ptr = NotNull;
5445         res_xk = false;
5446         return NOT_SUBTYPE;
5447       }
5448     }
5449   } else {// Non integral arrays.
5450     // Must fall to bottom if exact klasses in upper lattice
5451     // are not equal or super klass is exact.
5452     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5453         // meet with top[] and bottom[] are processed further down:
5454         !this_top_or_bottom && !other_top_or_bottom &&
5455         // both are exact and not equal:

5457          // 'tap'  is exact and super or unrelated:
5458          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5459          // 'this' is exact and super or unrelated:
5460          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5461       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5462         elem = Type::BOTTOM;
5463       }
5464       ptr = NotNull;
5465       res_xk = false;
5466       return NOT_SUBTYPE;
5467     }
5468   }
5469 
5470   res_xk = false;
5471   switch (other_ptr) {
5472     case AnyNull:
5473     case TopPTR:
5474       // Compute new klass on demand, do not use tap->_klass
5475       if (below_centerline(this_ptr)) {
5476         res_xk = this_xk;
5477         if (this_ary->is_flat()) {
5478           elem = this_ary->elem();
5479         }
5480       } else {
5481         res_xk = (other_xk || this_xk);
5482       }
5483       break;
5484     case Constant: {
5485       if (this_ptr == Constant && same_nullness) {
5486         // Only exact if same nullness since:
5487         //     null-free [LMyValue <: nullable [LMyValue.
5488         res_xk = true;
5489       } else if (above_centerline(this_ptr)) {
5490         res_xk = true;
5491       } else {
5492         // Only precise for identical arrays
5493         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5494         // Even though MyValue is final, [LMyValue is only exact if the array
5495         // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5496         if (res_xk && !res_null_free && !res_not_null_free) {
5497           ptr = NotNull;
5498           res_xk = false;
5499         }
5500       }
5501       break;
5502     }
5503     case NotNull:
5504     case BotPTR:
5505       // Compute new klass on demand, do not use tap->_klass
5506       if (above_centerline(this_ptr)) {
5507         res_xk = other_xk;
5508         if (other_ary->is_flat()) {
5509           elem = other_ary->elem();
5510         }
5511       } else {
5512         res_xk = (other_xk && this_xk) &&
5513                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5514         // Even though MyValue is final, [LMyValue is only exact if the array
5515         // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5516         if (res_xk && !res_null_free && !res_not_null_free) {
5517           ptr = NotNull;
5518           res_xk = false;
5519         }
5520       }
5521       break;
5522     default:  {
5523       ShouldNotReachHere();
5524       return result;
5525     }
5526   }
5527   return result;
5528 }
5529 
5530 
5531 //------------------------------xdual------------------------------------------
5532 // Dual: compute field-by-field dual
5533 const Type *TypeAryPtr::xdual() const {
5534   bool xk = _klass_is_exact;
5535   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());
5536 }
5537 
5538 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5539   return _field_offset.meet(offset);
5540 }
5541 
5542 //------------------------------dual_offset------------------------------------
5543 Type::Offset TypeAryPtr::dual_field_offset() const {
5544   return _field_offset.dual();
5545 }
5546 
5547 //------------------------------dump2------------------------------------------
5548 #ifndef PRODUCT
5549 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5550   _ary->dump2(d,depth,st);
5551   _interfaces->dump(st);
5552 
5553   switch( _ptr ) {
5554   case Constant:
5555     const_oop()->print(st);
5556     break;
5557   case BotPTR:
5558     if (!WizardMode && !Verbose) {
5559       if( _klass_is_exact ) st->print(":exact");
5560       break;
5561     }
5562   case TopPTR:
5563   case AnyNull:
5564   case NotNull:
5565     st->print(":%s", ptr_msg[_ptr]);
5566     if( _klass_is_exact ) st->print(":exact");
5567     break;
5568   default:
5569     break;
5570   }
5571 
5572   if (is_flat()) {
5573     st->print(":flat");
5574     st->print("(");
5575     _field_offset.dump2(st);
5576     st->print(")");
5577   } else if (is_not_flat()) {
5578     st->print(":not_flat");
5579   }
5580   if (is_null_free()) {
5581     st->print(":null free");
5582   }
5583   if (is_atomic()) {
5584     st->print(":atomic");
5585   }
5586   if (Verbose) {
5587     if (is_not_flat()) {
5588       st->print(":not flat");
5589     }
5590     if (is_not_null_free()) {
5591       st->print(":nullable");
5592     }
5593   }
5594   if (offset() != 0) {
5595     BasicType basic_elem_type = elem()->basic_type();
5596     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5597     if( _offset == Offset::top )       st->print("+undefined");
5598     else if( _offset == Offset::bottom )  st->print("+any");
5599     else if( offset() < header_size ) st->print("+%d", offset());
5600     else {
5601       if (basic_elem_type == T_ILLEGAL) {
5602         st->print("+any");
5603       } else {
5604         int elem_size = type2aelembytes(basic_elem_type);
5605         st->print("[%d]", (offset() - header_size)/elem_size);
5606       }
5607     }
5608   }
5609   st->print(" *");
5610   if (_instance_id == InstanceTop)
5611     st->print(",iid=top");
5612   else if (_instance_id != InstanceBot)
5613     st->print(",iid=%d",_instance_id);
5614 
5615   dump_inline_depth(st);
5616   dump_speculative(st);
5617 }
5618 #endif
5619 
5620 bool TypeAryPtr::empty(void) const {
5621   if (_ary->empty())       return true;
5622   // FIXME: Does this belong here? Or in the meet code itself?
5623   if (is_flat() && is_not_flat()) {
5624     return true;
5625   }
5626   return TypeOopPtr::empty();
5627 }
5628 
5629 //------------------------------add_offset-------------------------------------
5630 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5631   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);
5632 }
5633 
5634 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5635   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);
5636 }
5637 
5638 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5639   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5640 }
5641 
5642 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5643   if (_speculative == nullptr) {
5644     return this;
5645   }
5646   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5647   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);
5648 }
5649 
5650 const Type* TypeAryPtr::cleanup_speculative() const {
5651   if (speculative() == nullptr) {
5652     return this;
5653   }
5654   // Keep speculative part if it contains information about flat-/nullability
5655   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5656   if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5657       (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5658     return this;
5659   }
5660   return TypeOopPtr::cleanup_speculative();
5661 }
5662 
5663 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5664   if (!UseInlineDepthForSpeculativeTypes) {
5665     return this;
5666   }
5667   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5668 }
5669 
5670 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5671   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);
5672 }
5673 
5674 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5675   int adj = 0;
5676   if (is_flat() && klass_is_exact() && offset != Type::OffsetBot && offset != Type::OffsetTop) {
5677     if (_offset.get() != OffsetBot && _offset.get() != OffsetTop) {
5678       adj = _offset.get();
5679       offset += _offset.get();
5680     }
5681     uint header = arrayOopDesc::base_offset_in_bytes(T_FLAT_ELEMENT);
5682     if (_field_offset.get() != OffsetBot && _field_offset.get() != OffsetTop) {
5683       offset += _field_offset.get();
5684       if (_offset.get() == OffsetBot || _offset.get() == OffsetTop) {
5685         offset += header;
5686       }
5687     }
5688     if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5689       // Try to get the field of the inline type array element we are pointing to
5690       ciInlineKlass* vk = elem()->inline_klass();
5691       int shift = flat_log_elem_size();
5692       int mask = (1 << shift) - 1;
5693       intptr_t field_offset = ((offset - header) & mask);
5694       ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5695       if (field != nullptr || field_offset == vk->null_marker_offset_in_payload()) {
5696         return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5697       }
5698     }
5699   }
5700   return add_offset(offset - adj);
5701 }
5702 
5703 // Return offset incremented by field_offset for flat inline type arrays
5704 int TypeAryPtr::flat_offset() const {
5705   int offset = _offset.get();
5706   if (offset != Type::OffsetBot && offset != Type::OffsetTop &&
5707       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5708     offset += _field_offset.get();
5709   }
5710   return offset;
5711 }
5712 
5713 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5714   assert(is_known_instance(), "should be known");
5715   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5716 }
5717 
5718 //=============================================================================
5719 
5720 
5721 //------------------------------hash-------------------------------------------
5722 // Type-specific hashing function.
5723 uint TypeNarrowPtr::hash(void) const {
5724   return _ptrtype->hash() + 7;
5725 }
5726 
5727 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5728   return _ptrtype->singleton();
5729 }
5730 
5731 bool TypeNarrowPtr::empty(void) const {
5732   return _ptrtype->empty();
5733 }
5734 
5735 intptr_t TypeNarrowPtr::get_con() const {
5736   return _ptrtype->get_con();
5737 }
5738 
5739 bool TypeNarrowPtr::eq( const Type *t ) const {
5740   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5794   case HalfFloatTop:
5795   case HalfFloatCon:
5796   case HalfFloatBot:
5797   case FloatTop:
5798   case FloatCon:
5799   case FloatBot:
5800   case DoubleTop:
5801   case DoubleCon:
5802   case DoubleBot:
5803   case AnyPtr:
5804   case RawPtr:
5805   case OopPtr:
5806   case InstPtr:
5807   case AryPtr:
5808   case MetadataPtr:
5809   case KlassPtr:
5810   case InstKlassPtr:
5811   case AryKlassPtr:
5812   case NarrowOop:
5813   case NarrowKlass:

5814   case Bottom:                  // Ye Olde Default
5815     return Type::BOTTOM;
5816   case Top:
5817     return this;
5818 
5819   default:                      // All else is a mistake
5820     typerr(t);
5821 
5822   } // End of switch
5823 
5824   return this;
5825 }
5826 
5827 #ifndef PRODUCT
5828 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5829   _ptrtype->dump2(d, depth, st);
5830 }
5831 #endif
5832 
5833 const TypeNarrowOop *TypeNarrowOop::BOTTOM;

5877     return (one == two) && TypePtr::eq(t);
5878   } else {
5879     return one->equals(two) && TypePtr::eq(t);
5880   }
5881 }
5882 
5883 //------------------------------hash-------------------------------------------
5884 // Type-specific hashing function.
5885 uint TypeMetadataPtr::hash(void) const {
5886   return
5887     (metadata() ? metadata()->hash() : 0) +
5888     TypePtr::hash();
5889 }
5890 
5891 //------------------------------singleton--------------------------------------
5892 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
5893 // constants
5894 bool TypeMetadataPtr::singleton(void) const {
5895   // detune optimizer to not generate constant metadata + constant offset as a constant!
5896   // TopPTR, Null, AnyNull, Constant are all singletons
5897   return (offset() == 0) && !below_centerline(_ptr);
5898 }
5899 
5900 //------------------------------add_offset-------------------------------------
5901 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
5902   return make( _ptr, _metadata, xadd_offset(offset));
5903 }
5904 
5905 //-----------------------------filter------------------------------------------
5906 // Do not allow interface-vs.-noninterface joins to collapse to top.
5907 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
5908   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
5909   if (ft == nullptr || ft->empty())
5910     return Type::TOP;           // Canonical empty value
5911   return ft;
5912 }
5913 
5914  //------------------------------get_con----------------------------------------
5915 intptr_t TypeMetadataPtr::get_con() const {
5916   assert( _ptr == Null || _ptr == Constant, "" );
5917   assert(offset() >= 0, "");
5918 
5919   if (offset() != 0) {
5920     // After being ported to the compiler interface, the compiler no longer
5921     // directly manipulates the addresses of oops.  Rather, it only has a pointer
5922     // to a handle at compile time.  This handle is embedded in the generated
5923     // code and dereferenced at the time the nmethod is made.  Until that time,
5924     // it is not reasonable to do arithmetic with the addresses of oops (we don't
5925     // have access to the addresses!).  This does not seem to currently happen,
5926     // but this assertion here is to help prevent its occurrence.
5927     tty->print_cr("Found oop constant with non-zero offset");
5928     ShouldNotReachHere();
5929   }
5930 
5931   return (intptr_t)metadata()->constant_encoding();
5932 }
5933 
5934 //------------------------------cast_to_ptr_type-------------------------------
5935 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
5936   if( ptr == _ptr ) return this;
5937   return make(ptr, metadata(), _offset);
5938 }
5939 

5953   case HalfFloatBot:
5954   case FloatTop:
5955   case FloatCon:
5956   case FloatBot:
5957   case DoubleTop:
5958   case DoubleCon:
5959   case DoubleBot:
5960   case NarrowOop:
5961   case NarrowKlass:
5962   case Bottom:                  // Ye Olde Default
5963     return Type::BOTTOM;
5964   case Top:
5965     return this;
5966 
5967   default:                      // All else is a mistake
5968     typerr(t);
5969 
5970   case AnyPtr: {
5971     // Found an AnyPtr type vs self-OopPtr type
5972     const TypePtr *tp = t->is_ptr();
5973     Offset offset = meet_offset(tp->offset());
5974     PTR ptr = meet_ptr(tp->ptr());
5975     switch (tp->ptr()) {
5976     case Null:
5977       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5978       // else fall through:
5979     case TopPTR:
5980     case AnyNull: {
5981       return make(ptr, _metadata, offset);
5982     }
5983     case BotPTR:
5984     case NotNull:
5985       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5986     default: typerr(t);
5987     }
5988   }
5989 
5990   case RawPtr:
5991   case KlassPtr:
5992   case InstKlassPtr:
5993   case AryKlassPtr:
5994   case OopPtr:
5995   case InstPtr:
5996   case AryPtr:
5997     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5998 
5999   case MetadataPtr: {
6000     const TypeMetadataPtr *tp = t->is_metadataptr();
6001     Offset offset = meet_offset(tp->offset());
6002     PTR tptr = tp->ptr();
6003     PTR ptr = meet_ptr(tptr);
6004     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6005     if (tptr == TopPTR || _ptr == TopPTR ||
6006         metadata()->equals(tp->metadata())) {
6007       return make(ptr, md, offset);
6008     }
6009     // metadata is different
6010     if( ptr == Constant ) {  // Cannot be equal constants, so...
6011       if( tptr == Constant && _ptr != Constant)  return t;
6012       if( _ptr == Constant && tptr != Constant)  return this;
6013       ptr = NotNull;            // Fall down in lattice
6014     }
6015     return make(ptr, nullptr, offset);
6016     break;
6017   }
6018   } // End of switch
6019   return this;                  // Return the double constant
6020 }
6021 
6022 
6023 //------------------------------xdual------------------------------------------
6024 // Dual of a pure metadata pointer.
6025 const Type *TypeMetadataPtr::xdual() const {
6026   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6027 }
6028 
6029 //------------------------------dump2------------------------------------------
6030 #ifndef PRODUCT
6031 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6032   st->print("metadataptr:%s", ptr_msg[_ptr]);
6033   if( metadata() ) st->print(INTPTR_FORMAT, p2i(metadata()));
6034   switch (offset()) {
6035   case OffsetTop: st->print("+top"); break;
6036   case OffsetBot: st->print("+any"); break;
6037   case         0: break;
6038   default:        st->print("+%d",offset()); break;
6039   }
6040 }
6041 #endif
6042 
6043 
6044 //=============================================================================
6045 // Convenience common pre-built type.
6046 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6047 
6048 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6049   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
6050 }
6051 
6052 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6053   return make(Constant, m, Offset(0));
6054 }
6055 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6056   return make(Constant, m, Offset(0));
6057 }
6058 
6059 //------------------------------make-------------------------------------------
6060 // Create a meta data constant
6061 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6062   assert(m == nullptr || !m->is_klass(), "wrong type");
6063   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6064 }
6065 
6066 
6067 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6068   const Type* elem = _ary->_elem;
6069   bool xk = klass_is_exact();
6070   if (elem->make_oopptr() != nullptr) {
6071     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6072     if (elem->is_klassptr()->klass_is_exact() &&
6073         // Even though MyValue is final, [LMyValue is only exact if the array
6074         // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
6075         // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
6076         // If so, we should add '|| is_not_null_free()'
6077         (is_null_free() || !_ary->_elem->make_oopptr()->is_inlinetypeptr())) {
6078       xk = true;
6079     }
6080   }
6081   return TypeAryKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, elem, klass(), Offset(0), is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_flat() || is_null_free());
6082 }
6083 
6084 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6085   if (klass->is_instance_klass()) {
6086     return TypeInstKlassPtr::make(klass, interface_handling);
6087   }
6088   return TypeAryKlassPtr::make(klass, interface_handling);
6089 }
6090 
6091 const TypeKlassPtr* TypeKlassPtr::make(PTR ptr, ciKlass* klass, Offset offset, InterfaceHandling interface_handling) {
6092   if (klass->is_instance_klass()) {
6093     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
6094     return TypeInstKlassPtr::make(ptr, klass, interfaces, offset);
6095   }
6096   return TypeAryKlassPtr::make(ptr, klass, offset, interface_handling);
6097 }
6098 
6099 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)


6100   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
6101   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6102          klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6103 }
6104 
6105 // Is there a single ciKlass* that can represent that type?
6106 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6107   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6108   if (_interfaces->empty()) {
6109     return _klass;
6110   }
6111   if (_klass != ciEnv::current()->Object_klass()) {
6112     if (_interfaces->eq(_klass->as_instance_klass())) {
6113       return _klass;
6114     }
6115     return nullptr;
6116   }
6117   return _interfaces->exact_klass();
6118 }
6119 
6120 //------------------------------eq---------------------------------------------
6121 // Structural equality check for Type representations
6122 bool TypeKlassPtr::eq(const Type *t) const {
6123   const TypeKlassPtr *p = t->is_klassptr();
6124   return
6125     _interfaces->eq(p->_interfaces) &&
6126     TypePtr::eq(p);
6127 }
6128 
6129 //------------------------------hash-------------------------------------------
6130 // Type-specific hashing function.
6131 uint TypeKlassPtr::hash(void) const {
6132   return TypePtr::hash() + _interfaces->hash();
6133 }
6134 
6135 //------------------------------singleton--------------------------------------
6136 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6137 // constants
6138 bool TypeKlassPtr::singleton(void) const {
6139   // detune optimizer to not generate constant klass + constant offset as a constant!
6140   // TopPTR, Null, AnyNull, Constant are all singletons
6141   return (offset() == 0) && !below_centerline(_ptr);
6142 }
6143 
6144 // Do not allow interface-vs.-noninterface joins to collapse to top.
6145 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6146   // logic here mirrors the one from TypeOopPtr::filter. See comments
6147   // there.
6148   const Type* ft = join_helper(kills, include_speculative);
6149 
6150   if (ft->empty()) {
6151     return Type::TOP;           // Canonical empty value
6152   }
6153 
6154   return ft;
6155 }
6156 
6157 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6158   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6159     return _interfaces->union_with(other->_interfaces);
6160   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6161     return other->_interfaces;
6162   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6163     return _interfaces;
6164   }
6165   return _interfaces->intersection_with(other->_interfaces);
6166 }
6167 
6168 //------------------------------get_con----------------------------------------
6169 intptr_t TypeKlassPtr::get_con() const {
6170   assert( _ptr == Null || _ptr == Constant, "" );
6171   assert( offset() >= 0, "" );
6172 
6173   if (offset() != 0) {
6174     // After being ported to the compiler interface, the compiler no longer
6175     // directly manipulates the addresses of oops.  Rather, it only has a pointer
6176     // to a handle at compile time.  This handle is embedded in the generated
6177     // code and dereferenced at the time the nmethod is made.  Until that time,
6178     // it is not reasonable to do arithmetic with the addresses of oops (we don't
6179     // have access to the addresses!).  This does not seem to currently happen,
6180     // but this assertion here is to help prevent its occurrence.
6181     tty->print_cr("Found oop constant with non-zero offset");
6182     ShouldNotReachHere();
6183   }
6184 
6185   ciKlass* k = exact_klass();
6186 
6187   return (intptr_t)k->constant_encoding();
6188 }
6189 
6190 //------------------------------dump2------------------------------------------
6191 // Dump Klass Type
6192 #ifndef PRODUCT
6193 void TypeKlassPtr::dump2(Dict & d, uint depth, outputStream *st) const {

6197   case NotNull:
6198     {
6199       const char *name = klass()->name()->as_utf8();
6200       if (name) {
6201         st->print("%s: " INTPTR_FORMAT, name, p2i(klass()));
6202       } else {
6203         ShouldNotReachHere();
6204       }
6205       _interfaces->dump(st);
6206     }
6207   case BotPTR:
6208     if (!WizardMode && !Verbose && _ptr != Constant) break;
6209   case TopPTR:
6210   case AnyNull:
6211     st->print(":%s", ptr_msg[_ptr]);
6212     if (_ptr == Constant) st->print(":exact");
6213     break;
6214   default:
6215     break;
6216   }
6217   if (Verbose) {
6218     if (isa_instklassptr() && is_instklassptr()->flat_in_array()) st->print(":flat in array");



6219   }
6220   _offset.dump2(st);
6221   st->print(" *");
6222 
6223   if (flat_in_array() && !klass()->is_inlinetype()) {
6224     st->print(" (flat in array)");
6225   }
6226 }
6227 #endif
6228 
6229 //=============================================================================
6230 // Convenience common pre-built types.
6231 
6232 // Not-null object klass or below
6233 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6234 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6235 
6236 bool TypeInstKlassPtr::eq(const Type *t) const {
6237   const TypeKlassPtr *p = t->is_klassptr();
6238   return
6239     klass()->equals(p->klass()) &&
6240     flat_in_array() == p->flat_in_array() &&
6241     TypeKlassPtr::eq(p);
6242 }
6243 
6244 uint TypeInstKlassPtr::hash(void) const {
6245   return klass()->hash() + TypeKlassPtr::hash() + (uint)flat_in_array();
6246 }
6247 
6248 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, bool flat_in_array) {
6249   flat_in_array = flat_in_array || k->maybe_flat_in_array();
6250 
6251   TypeInstKlassPtr *r =
6252     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6253 
6254   return r;
6255 }
6256 
6257 //------------------------------add_offset-------------------------------------
6258 // Access internals of klass object
6259 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6260   return make(_ptr, klass(), _interfaces, xadd_offset(offset), flat_in_array());
6261 }
6262 
6263 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6264   return make(_ptr, klass(), _interfaces, Offset(offset), flat_in_array());
6265 }
6266 
6267 //------------------------------cast_to_ptr_type-------------------------------
6268 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6269   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6270   if( ptr == _ptr ) return this;
6271   return make(ptr, _klass, _interfaces, _offset, flat_in_array());
6272 }
6273 
6274 
6275 bool TypeInstKlassPtr::must_be_exact() const {
6276   if (!_klass->is_loaded())  return false;
6277   ciInstanceKlass* ik = _klass->as_instance_klass();
6278   if (ik->is_final())  return true;  // cannot clear xk
6279   return false;
6280 }
6281 
6282 //-----------------------------cast_to_exactness-------------------------------
6283 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6284   if (klass_is_exact == (_ptr == Constant)) return this;
6285   if (must_be_exact()) return this;
6286   ciKlass* k = klass();
6287   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array());
6288 }
6289 
6290 
6291 //-----------------------------as_instance_type--------------------------------
6292 // Corresponding type for an instance of the given class.
6293 // It will be NotNull, and exact if and only if the klass type is exact.
6294 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6295   ciKlass* k = klass();
6296   bool xk = klass_is_exact();
6297   Compile* C = Compile::current();
6298   Dependencies* deps = C->dependencies();
6299   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6300   // Element is an instance
6301   bool klass_is_exact = false;
6302   const TypeInterfaces* interfaces = _interfaces;
6303   if (k->is_loaded()) {
6304     // Try to set klass_is_exact.
6305     ciInstanceKlass* ik = k->as_instance_klass();
6306     klass_is_exact = ik->is_final();
6307     if (!klass_is_exact && klass_change
6308         && deps != nullptr && UseUniqueSubclasses) {
6309       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6310       if (sub != nullptr) {
6311         if (_interfaces->eq(sub)) {
6312           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6313           k = ik = sub;
6314           xk = sub->is_final();
6315         }
6316       }
6317     }
6318   }
6319   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array() && !klass()->is_inlinetype());
6320 }
6321 
6322 //------------------------------xmeet------------------------------------------
6323 // Compute the MEET of two types, return a new Type object.
6324 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6325   // Perform a fast test for common case; meeting the same types together.
6326   if( this == t ) return this;  // Meeting same type-rep?
6327 
6328   // Current "this->_base" is Pointer
6329   switch (t->base()) {          // switch on original type
6330 
6331   case Int:                     // Mixing ints & oops happens when javac
6332   case Long:                    // reuses local variables
6333   case HalfFloatTop:
6334   case HalfFloatCon:
6335   case HalfFloatBot:
6336   case FloatTop:
6337   case FloatCon:
6338   case FloatBot:
6339   case DoubleTop:
6340   case DoubleCon:
6341   case DoubleBot:
6342   case NarrowOop:
6343   case NarrowKlass:
6344   case Bottom:                  // Ye Olde Default
6345     return Type::BOTTOM;
6346   case Top:
6347     return this;
6348 
6349   default:                      // All else is a mistake
6350     typerr(t);
6351 
6352   case AnyPtr: {                // Meeting to AnyPtrs
6353     // Found an AnyPtr type vs self-KlassPtr type
6354     const TypePtr *tp = t->is_ptr();
6355     Offset offset = meet_offset(tp->offset());
6356     PTR ptr = meet_ptr(tp->ptr());
6357     switch (tp->ptr()) {
6358     case TopPTR:
6359       return this;
6360     case Null:
6361       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6362     case AnyNull:
6363       return make(ptr, klass(), _interfaces, offset, flat_in_array());
6364     case BotPTR:
6365     case NotNull:
6366       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6367     default: typerr(t);
6368     }
6369   }
6370 
6371   case RawPtr:
6372   case MetadataPtr:
6373   case OopPtr:
6374   case AryPtr:                  // Meet with AryPtr
6375   case InstPtr:                 // Meet with InstPtr
6376       return TypePtr::BOTTOM;
6377 
6378   //
6379   //             A-top         }
6380   //           /   |   \       }  Tops
6381   //       B-top A-any C-top   }
6382   //          | /  |  \ |      }  Any-nulls
6383   //       B-any   |   C-any   }
6384   //          |    |    |
6385   //       B-con A-con C-con   } constants; not comparable across classes
6386   //          |    |    |
6387   //       B-not   |   C-not   }
6388   //          | \  |  / |      }  not-nulls
6389   //       B-bot A-not C-bot   }
6390   //           \   |   /       }  Bottoms
6391   //             A-bot         }
6392   //
6393 
6394   case InstKlassPtr: {  // Meet two KlassPtr types
6395     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6396     Offset  off     = meet_offset(tkls->offset());
6397     PTR  ptr     = meet_ptr(tkls->ptr());
6398     const TypeInterfaces* interfaces = meet_interfaces(tkls);
6399 
6400     ciKlass* res_klass = nullptr;
6401     bool res_xk = false;
6402     bool res_flat_in_array = false;
6403     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk, res_flat_in_array)) {
6404       case UNLOADED:
6405         ShouldNotReachHere();
6406       case SUBTYPE:
6407       case NOT_SUBTYPE:
6408       case LCA:
6409       case QUICK: {
6410         assert(res_xk == (ptr == Constant), "");
6411         const Type* res = make(ptr, res_klass, interfaces, off, res_flat_in_array);
6412         return res;
6413       }
6414       default:
6415         ShouldNotReachHere();
6416     }
6417   } // End of case KlassPtr
6418   case AryKlassPtr: {                // All arrays inherit from Object class
6419     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6420     Offset offset = meet_offset(tp->offset());
6421     PTR ptr = meet_ptr(tp->ptr());
6422     const TypeInterfaces* interfaces = meet_interfaces(tp);
6423     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6424     const TypeInterfaces* this_interfaces = _interfaces;
6425 
6426     switch (ptr) {
6427     case TopPTR:
6428     case AnyNull:                // Fall 'down' to dual of object klass
6429       // For instances when a subclass meets a superclass we fall
6430       // below the centerline when the superclass is exact. We need to
6431       // do the same here.
6432       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6433         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(), tp->is_atomic(), tp->is_refined_type());
6434       } else {
6435         // cannot subclass, so the meet has to fall badly below the centerline
6436         ptr = NotNull;
6437         interfaces = _interfaces->intersection_with(tp->_interfaces);
6438         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6439       }
6440     case Constant:
6441     case NotNull:
6442     case BotPTR:                // Fall down to object klass
6443       // LCA is object_klass, but if we subclass from the top we can do better
6444       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6445         // If 'this' (InstPtr) is above the centerline and it is Object class
6446         // then we can subclass in the Java class hierarchy.
6447         // For instances when a subclass meets a superclass we fall
6448         // below the centerline when the superclass is exact. We need
6449         // to do the same here.
6450         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
6451           // that is, tp's array type is a subtype of my klass
6452           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(), tp->is_atomic(), tp->is_refined_type());

6453         }
6454       }
6455       // The other case cannot happen, since I cannot be a subtype of an array.
6456       // The meet falls down to Object class below centerline.
6457       if( ptr == Constant )
6458          ptr = NotNull;
6459       interfaces = this_interfaces->intersection_with(tp_interfaces);
6460       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6461     default: typerr(t);
6462     }
6463   }
6464 
6465   } // End of switch
6466   return this;                  // Return the double constant
6467 }
6468 
6469 //------------------------------xdual------------------------------------------
6470 // Dual: compute field-by-field dual
6471 const Type    *TypeInstKlassPtr::xdual() const {
6472   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), flat_in_array());
6473 }
6474 
6475 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) {
6476   static_assert(std::is_base_of<T2, T1>::value, "");
6477   if (!this_one->is_loaded() || !other->is_loaded()) {
6478     return false;
6479   }
6480   if (!this_one->is_instance_type(other)) {
6481     return false;
6482   }
6483 
6484   if (!other_exact) {
6485     return false;
6486   }
6487 
6488   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6489     return true;
6490   }
6491 
6492   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);

6566   const TypeInterfaces* interfaces = _interfaces;
6567   if (k->is_loaded()) {
6568     ciInstanceKlass* ik = k->as_instance_klass();
6569     bool klass_is_exact = ik->is_final();
6570     if (!klass_is_exact &&
6571         deps != nullptr) {
6572       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6573       if (sub != nullptr) {
6574         if (_interfaces->eq(sub)) {
6575           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6576           k = ik = sub;
6577           klass_is_exact = sub->is_final();
6578           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6579         }
6580       }
6581     }
6582   }
6583   return this;
6584 }
6585 
6586 bool TypeInstKlassPtr::can_be_inline_array() const {
6587   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6588 }
6589 
6590 bool TypeAryKlassPtr::can_be_inline_array() const {
6591   return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6592 }
6593 
6594 bool TypeInstPtr::can_be_inline_array() const {
6595   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6596 }
6597 
6598 bool TypeAryPtr::can_be_inline_array() const {
6599   return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6600 }
6601 
6602 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, bool atomic, bool refined_type) {
6603   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type))->hashcons();
6604 }
6605 
6606 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, bool atomic, bool refined_type) {
6607   if (k->is_obj_array_klass()) {
6608     // Element is an object array. Recursively call ourself.
6609     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6610     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6611     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6612   } else if (k->is_type_array_klass()) {
6613     // Element is an typeArray
6614     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6615     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic);
6616   } else if (k->is_flat_array_klass()) {
6617     ciKlass* eklass = k->as_flat_array_klass()->element_klass();
6618     const TypeKlassPtr* etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6619     return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6620   } else {
6621     ShouldNotReachHere();
6622     return nullptr;
6623   }
6624 }
6625 
6626 const TypeAryKlassPtr* TypeAryKlassPtr::make(PTR ptr, ciKlass* k, Offset offset, InterfaceHandling interface_handling, bool refined_type) {
6627   bool flat = k->is_flat_array_klass();
6628   bool null_free = k->as_array_klass()->is_elem_null_free();
6629   bool atomic = k->as_array_klass()->is_elem_atomic();
6630 
6631   bool not_inline = k->is_type_array_klass() || !k->as_array_klass()->element_klass()->can_be_inline_klass(false);
6632   bool not_null_free = (ptr == Constant) ? !null_free : not_inline;
6633   bool not_flat = (ptr == Constant) ? !flat : (!UseArrayFlattening || not_inline ||
6634                    (k->as_array_klass()->element_klass() != nullptr &&
6635                     k->as_array_klass()->element_klass()->is_inlinetype() &&
6636                    !k->as_array_klass()->element_klass()->maybe_flat_in_array()));
6637 
6638   return TypeAryKlassPtr::make(ptr, k, offset, interface_handling, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6639 }
6640 
6641 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling, bool refined_type) {
6642   return TypeAryKlassPtr::make(Constant, klass, Offset(0), interface_handling, refined_type);
6643 }
6644 
6645 // Get the (non-)refined array klass ptr
6646 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_refined_array_klass_ptr(bool refined) const {
6647   if ((refined == is_refined_type()) || !klass_is_exact() || (!exact_klass()->is_obj_array_klass() && !exact_klass()->is_flat_array_klass())) {
6648     return this;
6649   }
6650   ciKlass* eklass = elem()->is_klassptr()->exact_klass_helper();
6651   if (elem()->isa_aryklassptr()) {
6652     eklass = exact_klass()->as_obj_array_klass()->element_klass();
6653   }
6654   ciKlass* array_klass = ciArrayKlass::make(eklass, eklass->is_inlinetype() ? is_null_free() : false, eklass->is_inlinetype() ? is_atomic() : true, refined);
6655   return make(_ptr, array_klass, Offset(0), trust_interfaces, refined);
6656 }
6657 
6658 //------------------------------eq---------------------------------------------
6659 // Structural equality check for Type representations
6660 bool TypeAryKlassPtr::eq(const Type *t) const {
6661   const TypeAryKlassPtr *p = t->is_aryklassptr();
6662   return
6663     _elem == p->_elem &&  // Check array
6664     _flat == p->_flat &&
6665     _not_flat == p->_not_flat &&
6666     _null_free == p->_null_free &&
6667     _not_null_free == p->_not_null_free &&
6668     _atomic == p->_atomic &&
6669     _refined_type == p->_refined_type &&
6670     TypeKlassPtr::eq(p);  // Check sub-parts
6671 }
6672 
6673 //------------------------------hash-------------------------------------------
6674 // Type-specific hashing function.
6675 uint TypeAryKlassPtr::hash(void) const {
6676   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6677       (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0)  + (uint)(_atomic ? 47 : 0) + (uint)(_refined_type ? 48 : 0);
6678 }
6679 
6680 //----------------------compute_klass------------------------------------------
6681 // Compute the defining klass for this class
6682 ciKlass* TypeAryPtr::compute_klass() const {
6683   // Compute _klass based on element type.
6684   ciKlass* k_ary = nullptr;
6685   const TypeInstPtr *tinst;
6686   const TypeAryPtr *tary;
6687   const Type* el = elem();
6688   if (el->isa_narrowoop()) {
6689     el = el->make_ptr();
6690   }
6691 
6692   // Get element klass
6693   if ((tinst = el->isa_instptr()) != nullptr) {
6694     // Leave k_ary at nullptr.
6695   } else if ((tary = el->isa_aryptr()) != nullptr) {
6696     // Leave k_ary at nullptr.
6697   } else if ((el->base() == Type::Top) ||
6698              (el->base() == Type::Bottom)) {
6699     // element type of Bottom occurs from meet of basic type
6700     // and object; Top occurs when doing join on Bottom.
6701     // Leave k_ary at null.
6702   } else {
6703     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6704     // Compute array klass directly from basic type
6705     k_ary = ciTypeArrayKlass::make(el->basic_type());
6706   }
6707   return k_ary;
6708 }
6709 
6710 //------------------------------klass------------------------------------------
6711 // Return the defining klass for this class
6712 ciKlass* TypeAryPtr::klass() const {
6713   if( _klass ) return _klass;   // Return cached value, if possible
6714 
6715   // Oops, need to compute _klass and cache it
6716   ciKlass* k_ary = compute_klass();

6724     // type TypeAryPtr::OOPS.  This Type is shared between all
6725     // active compilations.  However, the ciKlass which represents
6726     // this Type is *not* shared between compilations, so caching
6727     // this value would result in fetching a dangling pointer.
6728     //
6729     // Recomputing the underlying ciKlass for each request is
6730     // a bit less efficient than caching, but calls to
6731     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6732     ((TypeAryPtr*)this)->_klass = k_ary;
6733   }
6734   return k_ary;
6735 }
6736 
6737 // Is there a single ciKlass* that can represent that type?
6738 ciKlass* TypeAryPtr::exact_klass_helper() const {
6739   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6740     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6741     if (k == nullptr) {
6742       return nullptr;
6743     }
6744     k = ciArrayKlass::make(k, is_null_free(), is_atomic(), is_flat() || is_null_free());
6745     return k;
6746   }
6747 
6748   return klass();
6749 }
6750 
6751 const Type* TypeAryPtr::base_element_type(int& dims) const {
6752   const Type* elem = this->elem();
6753   dims = 1;
6754   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6755     elem = elem->make_ptr()->is_aryptr()->elem();
6756     dims++;
6757   }
6758   return elem;
6759 }
6760 
6761 //------------------------------add_offset-------------------------------------
6762 // Access internals of klass object
6763 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6764   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6765 }
6766 
6767 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6768   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6769 }
6770 
6771 //------------------------------cast_to_ptr_type-------------------------------
6772 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6773   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6774   if (ptr == _ptr) return this;
6775   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6776 }
6777 
6778 bool TypeAryKlassPtr::must_be_exact() const {
6779   if (_elem == Type::BOTTOM) return false;
6780   if (_elem == Type::TOP   ) return false;
6781   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6782   if (!tk)             return true;   // a primitive type, like int
6783   // Even though MyValue is final, [LMyValue is only exact if the array
6784   // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
6785   // TODO 8350865 If we know that the array can't be null-free, it's allowed to be exact, right?
6786   // If so, we should add '&& !is_not_null_free()'
6787   if (tk->isa_instklassptr() && tk->klass()->is_inlinetype() && !is_null_free()) {
6788     return false;
6789   }
6790   return tk->must_be_exact();
6791 }
6792 
6793 
6794 //-----------------------------cast_to_exactness-------------------------------
6795 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6796   if (must_be_exact() && !klass_is_exact) return this;  // cannot clear xk
6797   if (klass_is_exact == this->klass_is_exact()) {
6798     return this;
6799   }
6800   ciKlass* k = _klass;
6801   const Type* elem = this->elem();
6802   if (elem->isa_klassptr() && !klass_is_exact) {
6803     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6804   }
6805   bool not_flat = is_not_flat();
6806   bool not_null_free = is_not_null_free();
6807   if (_elem->isa_klassptr()) {
6808     if (klass_is_exact || _elem->isa_aryklassptr()) {
6809       assert((!is_null_free() && !is_flat()) ||
6810              _elem->is_klassptr()->klass()->is_abstract() || _elem->is_klassptr()->klass()->is_java_lang_Object(),
6811              "null-free (or flat) concrete inline type arrays should always be exact");
6812       // An array can't be null-free (or flat) if the klass is exact
6813       not_null_free = true;
6814       not_flat = true;
6815     } else {
6816       // Klass is not exact (anymore), re-compute null-free/flat properties
6817       const TypeOopPtr* exact_etype = TypeOopPtr::make_from_klass_unique(_elem->is_instklassptr()->instance_klass());
6818       bool not_inline = !exact_etype->can_be_inline_type();
6819       not_null_free = not_inline;
6820       not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
6821     }
6822   }
6823   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset, not_flat, not_null_free, _flat, _null_free, _atomic, _refined_type);
6824 }
6825 

6826 //-----------------------------as_instance_type--------------------------------
6827 // Corresponding type for an instance of the given class.
6828 // It will be NotNull, and exact if and only if the klass type is exact.
6829 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6830   ciKlass* k = klass();
6831   bool    xk = klass_is_exact();
6832   const Type* el = nullptr;
6833   if (elem()->isa_klassptr()) {
6834     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6835     k = nullptr;
6836   } else {
6837     el = elem();
6838   }
6839   bool null_free = _null_free;
6840   if (null_free && el->isa_ptr()) {
6841     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6842   }
6843   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS, false, is_flat(), is_not_flat(), is_not_null_free(), is_atomic()), k, xk, Offset(0));
6844 }
6845 
6846 
6847 //------------------------------xmeet------------------------------------------
6848 // Compute the MEET of two types, return a new Type object.
6849 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6850   // Perform a fast test for common case; meeting the same types together.
6851   if( this == t ) return this;  // Meeting same type-rep?
6852 
6853   // Current "this->_base" is Pointer
6854   switch (t->base()) {          // switch on original type
6855 
6856   case Int:                     // Mixing ints & oops happens when javac
6857   case Long:                    // reuses local variables
6858   case HalfFloatTop:
6859   case HalfFloatCon:
6860   case HalfFloatBot:
6861   case FloatTop:
6862   case FloatCon:
6863   case FloatBot:
6864   case DoubleTop:
6865   case DoubleCon:
6866   case DoubleBot:
6867   case NarrowOop:
6868   case NarrowKlass:
6869   case Bottom:                  // Ye Olde Default
6870     return Type::BOTTOM;
6871   case Top:
6872     return this;
6873 
6874   default:                      // All else is a mistake
6875     typerr(t);
6876 
6877   case AnyPtr: {                // Meeting to AnyPtrs
6878     // Found an AnyPtr type vs self-KlassPtr type
6879     const TypePtr *tp = t->is_ptr();
6880     Offset offset = meet_offset(tp->offset());
6881     PTR ptr = meet_ptr(tp->ptr());
6882     switch (tp->ptr()) {
6883     case TopPTR:
6884       return this;
6885     case Null:
6886       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6887     case AnyNull:
6888       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
6889     case BotPTR:
6890     case NotNull:
6891       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6892     default: typerr(t);
6893     }
6894   }
6895 
6896   case RawPtr:
6897   case MetadataPtr:
6898   case OopPtr:
6899   case AryPtr:                  // Meet with AryPtr
6900   case InstPtr:                 // Meet with InstPtr
6901     return TypePtr::BOTTOM;
6902 
6903   //
6904   //             A-top         }
6905   //           /   |   \       }  Tops
6906   //       B-top A-any C-top   }
6907   //          | /  |  \ |      }  Any-nulls
6908   //       B-any   |   C-any   }
6909   //          |    |    |
6910   //       B-con A-con C-con   } constants; not comparable across classes
6911   //          |    |    |
6912   //       B-not   |   C-not   }
6913   //          | \  |  / |      }  not-nulls
6914   //       B-bot A-not C-bot   }
6915   //           \   |   /       }  Bottoms
6916   //             A-bot         }
6917   //
6918 
6919   case AryKlassPtr: {  // Meet two KlassPtr types
6920     const TypeAryKlassPtr *tap = t->is_aryklassptr();
6921     Offset off = meet_offset(tap->offset());
6922     const Type* elem = _elem->meet(tap->_elem);

6923     PTR ptr = meet_ptr(tap->ptr());
6924     ciKlass* res_klass = nullptr;
6925     bool res_xk = false;
6926     bool res_flat = false;
6927     bool res_not_flat = false;
6928     bool res_not_null_free = false;
6929     bool res_atomic = false;
6930     MeetResult res = meet_aryptr(ptr, elem, this, tap,
6931                                  res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic);
6932     assert(res_xk == (ptr == Constant), "");
6933     bool flat = meet_flat(tap->_flat);
6934     bool null_free = meet_null_free(tap->_null_free);
6935     bool atomic = meet_atomic(tap->_atomic);
6936     bool refined_type = _refined_type && tap->_refined_type;
6937     if (res == NOT_SUBTYPE) {
6938       flat = false;
6939       null_free = false;
6940       atomic = false;
6941       refined_type = false;
6942     } else if (res == SUBTYPE) {
6943       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
6944         flat = _flat;
6945         null_free = _null_free;
6946         atomic = _atomic;
6947         refined_type = _refined_type;
6948       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
6949         flat = tap->_flat;
6950         null_free = tap->_null_free;
6951         atomic = tap->_atomic;
6952         refined_type = tap->_refined_type;
6953       } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
6954         flat = _flat || tap->_flat;
6955         null_free = _null_free || tap->_null_free;
6956         atomic = _atomic || tap->_atomic;
6957         refined_type = _refined_type || tap->_refined_type;
6958       } else if (res_xk && _refined_type != tap->_refined_type) {
6959         // This can happen if the phi emitted by LibraryCallKit::load_default_refined_array_klass/load_non_refined_array_klass
6960         // is processed before the typeArray guard is folded. Both inputs are constant but the input corresponding to the
6961         // typeArray will go away. Don't constant fold it yet but wait for the control input to collapse.
6962         ptr = PTR::NotNull;
6963       }
6964     }
6965     return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free, atomic, refined_type);
6966   } // End of case KlassPtr
6967   case InstKlassPtr: {
6968     const TypeInstKlassPtr *tp = t->is_instklassptr();
6969     Offset offset = meet_offset(tp->offset());
6970     PTR ptr = meet_ptr(tp->ptr());
6971     const TypeInterfaces* interfaces = meet_interfaces(tp);
6972     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6973     const TypeInterfaces* this_interfaces = _interfaces;
6974 
6975     switch (ptr) {
6976     case TopPTR:
6977     case AnyNull:                // Fall 'down' to dual of object klass
6978       // For instances when a subclass meets a superclass we fall
6979       // below the centerline when the superclass is exact. We need to
6980       // do the same here.
6981       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6982           !tp->klass_is_exact()) {
6983         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
6984       } else {
6985         // cannot subclass, so the meet has to fall badly below the centerline
6986         ptr = NotNull;
6987         interfaces = this_interfaces->intersection_with(tp->_interfaces);
6988         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
6989       }
6990     case Constant:
6991     case NotNull:
6992     case BotPTR:                // Fall down to object klass
6993       // LCA is object_klass, but if we subclass from the top we can do better
6994       if (above_centerline(tp->ptr())) {
6995         // If 'tp'  is above the centerline and it is Object class
6996         // then we can subclass in the Java class hierarchy.
6997         // For instances when a subclass meets a superclass we fall
6998         // below the centerline when the superclass is exact. We need
6999         // to do the same here.
7000         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7001             !tp->klass_is_exact()) {
7002           // that is, my array type is a subtype of 'tp' klass
7003           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7004         }
7005       }
7006       // The other case cannot happen, since t cannot be a subtype of an array.
7007       // The meet falls down to Object class below centerline.
7008       if (ptr == Constant)
7009          ptr = NotNull;
7010       interfaces = this_interfaces->intersection_with(tp_interfaces);
7011       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, false);
7012     default: typerr(t);
7013     }
7014   }
7015 
7016   } // End of switch
7017   return this;                  // Return the double constant
7018 }
7019 
7020 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) {
7021   static_assert(std::is_base_of<T2, T1>::value, "");
7022 
7023   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7024     return true;
7025   }
7026 
7027   int dummy;
7028   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7029 
7030   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7031     return false;
7032   }
7033 
7034   if (this_one->is_instance_type(other)) {
7035     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7036            other_exact;
7037   }
7038 
7039   assert(this_one->is_array_type(other), "");
7040   const T1* other_ary = this_one->is_array_type(other);
7041   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7042   if (other_top_or_bottom) {
7043     return false;
7044   }
7045 
7046   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7047   const TypePtr* this_elem = this_one->elem()->make_ptr();
7048   if (this_elem != nullptr && other_elem != nullptr) {
7049     if (other->is_null_free() && !this_one->is_null_free()) {
7050       return false; // A nullable array can't be a subtype of a null-free array
7051     }
7052     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7053   }
7054   if (this_elem == nullptr && other_elem == nullptr) {
7055     return this_one->klass()->is_subtype_of(other->klass());
7056   }
7057   return false;
7058 }
7059 
7060 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7061   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7062 }
7063 
7064 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7065   static_assert(std::is_base_of<T2, T1>::value, "");
7066 
7067   int dummy;
7068   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7069 
7070   if (!this_one->is_array_type(other) ||
7071       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

7124   }
7125 
7126   const TypePtr* this_elem = this_one->elem()->make_ptr();
7127   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7128   if (other_elem != nullptr && this_elem != nullptr) {
7129     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7130   }
7131   if (other_elem == nullptr && this_elem == nullptr) {
7132     return this_one->klass()->is_subtype_of(other->klass());
7133   }
7134   return false;
7135 }
7136 
7137 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7138   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7139 }
7140 
7141 //------------------------------xdual------------------------------------------
7142 // Dual: compute field-by-field dual
7143 const Type    *TypeAryKlassPtr::xdual() const {
7144   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset(), !is_not_flat(), !is_not_null_free(), dual_flat(), dual_null_free(), dual_atomic(), _refined_type);
7145 }
7146 
7147 // Is there a single ciKlass* that can represent that type?
7148 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7149   if (elem()->isa_klassptr()) {
7150     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7151     if (k == nullptr) {
7152       return nullptr;
7153     }
7154     k = ciArrayKlass::make(k, k->is_inlinetype() ? is_null_free() : false, k->is_inlinetype() ? is_atomic() : true, _refined_type);
7155     return k;
7156   }
7157 
7158   return klass();
7159 }
7160 
7161 ciKlass* TypeAryKlassPtr::klass() const {
7162   if (_klass != nullptr) {
7163     return _klass;
7164   }
7165   ciKlass* k = nullptr;
7166   if (elem()->isa_klassptr()) {
7167     // leave null
7168   } else if ((elem()->base() == Type::Top) ||
7169              (elem()->base() == Type::Bottom)) {
7170   } else {
7171     k = ciTypeArrayKlass::make(elem()->basic_type());
7172     ((TypeAryKlassPtr*)this)->_klass = k;
7173   }
7174   return k;

7181   switch( _ptr ) {
7182   case Constant:
7183     st->print("precise ");
7184   case NotNull:
7185     {
7186       st->print("[");
7187       _elem->dump2(d, depth, st);
7188       _interfaces->dump(st);
7189       st->print(": ");
7190     }
7191   case BotPTR:
7192     if( !WizardMode && !Verbose && _ptr != Constant ) break;
7193   case TopPTR:
7194   case AnyNull:
7195     st->print(":%s", ptr_msg[_ptr]);
7196     if( _ptr == Constant ) st->print(":exact");
7197     break;
7198   default:
7199     break;
7200   }
7201   if (_flat) st->print(":flat");
7202   if (_null_free) st->print(":null free");
7203   if (_atomic) st->print(":atomic");
7204   if (_refined_type) st->print(":refined_type");
7205   if (Verbose) {
7206     if (_not_flat) st->print(":not flat");
7207     if (_not_null_free) st->print(":nullable");
7208   }
7209 
7210   _offset.dump2(st);
7211 
7212   st->print(" *");
7213 }
7214 #endif
7215 
7216 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7217   const Type* elem = this->elem();
7218   dims = 1;
7219   while (elem->isa_aryklassptr()) {
7220     elem = elem->is_aryklassptr()->elem();
7221     dims++;
7222   }
7223   return elem;
7224 }
7225 
7226 //=============================================================================
7227 // Convenience common pre-built types.
7228 
7229 //------------------------------make-------------------------------------------
7230 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7231                                const TypeTuple *range_sig, const TypeTuple *range_cc) {
7232   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc))->hashcons();
7233 }
7234 
7235 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7236   return make(domain, domain, range, range);
7237 }
7238 
7239 //------------------------------osr_domain-----------------------------
7240 const TypeTuple* osr_domain() {
7241   const Type **fields = TypeTuple::fields(2);
7242   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
7243   return TypeTuple::make(TypeFunc::Parms+1, fields);
7244 }
7245 
7246 //------------------------------make-------------------------------------------
7247 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_osr_compilation) {
7248   Compile* C = Compile::current();
7249   const TypeFunc* tf = nullptr;
7250   if (!is_osr_compilation) {
7251     tf = C->last_tf(method); // check cache
7252     if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
7253   }
7254   // Inline types are not passed/returned by reference, instead each field of
7255   // the inline type is passed/returned as an argument. We maintain two views of
7256   // the argument/return list here: one based on the signature (with an inline
7257   // type argument/return as a single slot), one based on the actual calling
7258   // convention (with an inline type argument/return as a list of its fields).
7259   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7260   // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7261   if (method != C->method() && method->get_Method()->mismatch()) {
7262     has_scalar_args = false;
7263   }
7264   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7265   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7266   ciSignature* sig = method->signature();
7267   bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7268   const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces, false);
7269   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true) : range_sig;
7270   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc);
7271   if (!is_osr_compilation) {
7272     C->set_last_tf(method, tf);  // fill cache
7273   }



7274   return tf;
7275 }
7276 
7277 //------------------------------meet-------------------------------------------
7278 // Compute the MEET of two types.  It returns a new Type object.
7279 const Type *TypeFunc::xmeet( const Type *t ) const {
7280   // Perform a fast test for common case; meeting the same types together.
7281   if( this == t ) return this;  // Meeting same type-rep?
7282 
7283   // Current "this->_base" is Func
7284   switch (t->base()) {          // switch on original type
7285 
7286   case Bottom:                  // Ye Olde Default
7287     return t;
7288 
7289   default:                      // All else is a mistake
7290     typerr(t);
7291 
7292   case Top:
7293     break;
7294   }
7295   return this;                  // Return the double constant
7296 }
7297 
7298 //------------------------------xdual------------------------------------------
7299 // Dual: compute field-by-field dual
7300 const Type *TypeFunc::xdual() const {
7301   return this;
7302 }
7303 
7304 //------------------------------eq---------------------------------------------
7305 // Structural equality check for Type representations
7306 bool TypeFunc::eq( const Type *t ) const {
7307   const TypeFunc *a = (const TypeFunc*)t;
7308   return _domain_sig == a->_domain_sig &&
7309     _domain_cc == a->_domain_cc &&
7310     _range_sig == a->_range_sig &&
7311     _range_cc == a->_range_cc;
7312 }
7313 
7314 //------------------------------hash-------------------------------------------
7315 // Type-specific hashing function.
7316 uint TypeFunc::hash(void) const {
7317   return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc;
7318 }
7319 
7320 //------------------------------dump2------------------------------------------
7321 // Dump Function Type
7322 #ifndef PRODUCT
7323 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7324   if( _range_sig->cnt() <= Parms )
7325     st->print("void");
7326   else {
7327     uint i;
7328     for (i = Parms; i < _range_sig->cnt()-1; i++) {
7329       _range_sig->field_at(i)->dump2(d,depth,st);
7330       st->print("/");
7331     }
7332     _range_sig->field_at(i)->dump2(d,depth,st);
7333   }
7334   st->print(" ");
7335   st->print("( ");
7336   if( !depth || d[this] ) {     // Check for recursive dump
7337     st->print("...)");
7338     return;
7339   }
7340   d.Insert((void*)this,(void*)this);    // Stop recursion
7341   if (Parms < _domain_sig->cnt())
7342     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7343   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7344     st->print(", ");
7345     _domain_sig->field_at(i)->dump2(d,depth-1,st);
7346   }
7347   st->print(" )");
7348 }
7349 #endif
7350 
7351 //------------------------------singleton--------------------------------------
7352 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
7353 // constants (Ldi nodes).  Singletons are integer, float or double constants
7354 // or a single symbol.
7355 bool TypeFunc::singleton(void) const {
7356   return false;                 // Never a singleton
7357 }
7358 
7359 bool TypeFunc::empty(void) const {
7360   return false;                 // Never empty
7361 }
7362 
7363 
7364 BasicType TypeFunc::return_type() const{
7365   if (range_sig()->cnt() == TypeFunc::Parms) {
7366     return T_VOID;
7367   }
7368   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7369 }
< prev index next >