< 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/debug.hpp"

  49 #include "utilities/ostream.hpp"
  50 #include "utilities/powerOfTwo.hpp"
  51 #include "utilities/stringUtils.hpp"
  52 #if INCLUDE_SHENANDOAHGC
  53 #include "gc/shenandoah/c2/shenandoahBarrierSetC2.hpp"
  54 #endif // INCLUDE_SHENANDOAHGC
  55 
  56 // Portions of code courtesy of Clifford Click
  57 
  58 // Optimization - Graph Style
  59 
  60 // Dictionary of types shared among compilations.
  61 Dict* Type::_shared_type_dict = nullptr;












































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

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



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

 309     case T_NARROWOOP: loadbt = T_OBJECT; break;
 310     case T_ARRAY:     loadbt = T_OBJECT; break;
 311     case T_ADDRESS:   loadbt = T_OBJECT; break;
 312     default:                             break;
 313   }
 314   if (conbt == loadbt) {
 315     if (is_unsigned && conbt == T_BYTE) {
 316       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 317       return ciConstant(T_INT, con.as_int() & 0xFF);
 318     } else {
 319       return con;
 320     }
 321   }
 322   if (conbt == T_SHORT && loadbt == T_CHAR) {
 323     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 324     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 325   }
 326   return ciConstant(); // T_ILLEGAL
 327 }
 328 
 329 // Try to constant-fold a stable array element.
 330 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int stable_dimension,
 331                                                    BasicType loadbt, bool is_unsigned_load) {
 332   // Decode the results of GraphKit::array_element_address.
 333   ciConstant element_value = array->element_value_by_offset(off);
 334   if (element_value.basic_type() == T_ILLEGAL) {
 335     return nullptr; // wrong offset
 336   }
 337   ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
 338 
 339   assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
 340          type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
 341 
 342   if (con.is_valid() &&          // not a mismatched access
 343       !con.is_null_or_zero()) {  // not a default value
 344     bool is_narrow_oop = (loadbt == T_NARROWOOP);
 345     return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
 346   }
 347   return nullptr;
 348 }
 349 

































 350 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
 351   ciField* field;
 352   ciType* type = holder->java_mirror_type();
 353   if (type != nullptr && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
 354     // Static field
 355     field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
 356   } else {
 357     // Instance field
 358     field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
 359   }
 360   if (field == nullptr) {
 361     return nullptr; // Wrong offset
 362   }
 363   return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
 364 }
 365 
 366 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
 367                                            BasicType loadbt, bool is_unsigned_load) {
 368   if (!field->is_constant()) {
 369     return nullptr; // Non-constant field

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

 631 
 632   // Nobody should ask _array_body_type[T_NARROWOOP]. Use null as assert.
 633   TypeAryPtr::_array_body_type[T_NARROWOOP] = nullptr;
 634   TypeAryPtr::_array_body_type[T_OBJECT]  = TypeAryPtr::OOPS;

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

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

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

 960   ~VerifyMeet() {
 961     assert(_C->_type_verify->_depth != 0, "");
 962     _C->_type_verify->_depth--;
 963     if (_C->_type_verify->_depth == 0) {
 964       _C->_type_verify->_cache.trunc_to(0);
 965     }
 966   }
 967 
 968   const Type* meet(const Type* t1, const Type* t2) const {
 969     return _C->_type_verify->meet(t1, t2);
 970   }
 971 
 972   void add(const Type* t1, const Type* t2, const Type* res) const {
 973     _C->_type_verify->add(t1, t2, res);
 974   }
 975 };
 976 
 977 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
 978   Compile* C = Compile::current();
 979   const Type* mt2 = verify.meet(t, this);



 980   if (mt != mt2) {
 981     tty->print_cr("=== Meet Not Commutative ===");
 982     tty->print("t           = ");   t->dump(); tty->cr();
 983     tty->print("this        = ");      dump(); tty->cr();
 984     tty->print("t meet this = "); mt2->dump(); tty->cr();
 985     tty->print("this meet t = ");  mt->dump(); tty->cr();
 986     fatal("meet not commutative");
 987   }
 988   const Type* dual_join = mt->_dual;
 989   const Type* t2t    = verify.meet(dual_join,t->_dual);
 990   const Type* t2this = verify.meet(dual_join,this->_dual);
 991 
 992   // Interface meet Oop is Not Symmetric:
 993   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
 994   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
 995 









 996   if (t2t != t->_dual || t2this != this->_dual) {
 997     tty->print_cr("=== Meet Not Symmetric ===");
 998     tty->print("t   =                   ");              t->dump(); tty->cr();
 999     tty->print("this=                   ");                 dump(); tty->cr();
1000     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
1001 
1002     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
1003     tty->print("this_dual=              ");          _dual->dump(); tty->cr();
1004     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
1005 

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

1007     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();









1008 
1009     fatal("meet not symmetric");
1010   }
1011 }
1012 #endif
1013 
1014 //------------------------------meet-------------------------------------------
1015 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
1016 // commutative and the lattice is symmetric.
1017 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1018   if (isa_narrowoop() && t->isa_narrowoop()) {
1019     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1020     return result->make_narrowoop();
1021   }
1022   if (isa_narrowklass() && t->isa_narrowklass()) {
1023     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1024     return result->make_narrowklass();
1025   }
1026 
1027 #ifdef ASSERT
1028   Compile* C = Compile::current();
1029   VerifyMeet verify(C);
1030 #endif
1031 
1032   const Type *this_t = maybe_remove_speculative(include_speculative);
1033   t = t->maybe_remove_speculative(include_speculative);
1034 
1035   const Type *mt = this_t->xmeet(t);
1036 #ifdef ASSERT
1037   verify.add(this_t, t, mt);
1038   if (isa_narrowoop() || t->isa_narrowoop()) {
1039     return mt;
1040   }
1041   if (isa_narrowklass() || t->isa_narrowklass()) {
1042     return mt;
1043   }



1044   this_t->check_symmetrical(t, mt, verify);
1045   const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1046   this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1047 #endif
1048   return mt;
1049 }
1050 
1051 //------------------------------xmeet------------------------------------------
1052 // Compute the MEET of two types.  It returns a new Type object.
1053 const Type *Type::xmeet( const Type *t ) const {
1054   // Perform a fast test for common case; meeting the same types together.
1055   if( this == t ) return this;  // Meeting same type-rep?
1056 
1057   // Meeting TOP with anything?
1058   if( _base == Top ) return t;
1059 
1060   // Meeting BOTTOM with anything?
1061   if( _base == Bottom ) return BOTTOM;
1062 
1063   // Current "this->_base" is one of: Bad, Multi, Control, Top,

2054 void TypeLong::dump_verbose() const {
2055   TypeIntHelper::int_type_dump(this, tty, true);
2056 }
2057 #endif
2058 
2059 //=============================================================================
2060 // Convenience common pre-built types.
2061 const TypeTuple *TypeTuple::IFBOTH;     // Return both arms of IF as reachable
2062 const TypeTuple *TypeTuple::IFFALSE;
2063 const TypeTuple *TypeTuple::IFTRUE;
2064 const TypeTuple *TypeTuple::IFNEITHER;
2065 const TypeTuple *TypeTuple::LOOPBODY;
2066 const TypeTuple *TypeTuple::MEMBAR;
2067 const TypeTuple *TypeTuple::STORECONDITIONAL;
2068 const TypeTuple *TypeTuple::START_I2C;
2069 const TypeTuple *TypeTuple::INT_PAIR;
2070 const TypeTuple *TypeTuple::LONG_PAIR;
2071 const TypeTuple *TypeTuple::INT_CC_PAIR;
2072 const TypeTuple *TypeTuple::LONG_CC_PAIR;
2073 





















2074 //------------------------------make-------------------------------------------
2075 // Make a TypeTuple from the range of a method signature
2076 const TypeTuple *TypeTuple::make_range(ciSignature* sig, InterfaceHandling interface_handling) {
2077   ciType* return_type = sig->return_type();
2078   uint arg_cnt = return_type->size();







2079   const Type **field_array = fields(arg_cnt);
2080   switch (return_type->basic_type()) {
2081   case T_LONG:
2082     field_array[TypeFunc::Parms]   = TypeLong::LONG;
2083     field_array[TypeFunc::Parms+1] = Type::HALF;
2084     break;
2085   case T_DOUBLE:
2086     field_array[TypeFunc::Parms]   = Type::DOUBLE;
2087     field_array[TypeFunc::Parms+1] = Type::HALF;
2088     break;
2089   case T_OBJECT:














2090   case T_ARRAY:
2091   case T_BOOLEAN:
2092   case T_CHAR:
2093   case T_FLOAT:
2094   case T_BYTE:
2095   case T_SHORT:
2096   case T_INT:
2097     field_array[TypeFunc::Parms] = get_const_type(return_type, interface_handling);
2098     break;
2099   case T_VOID:
2100     break;
2101   default:
2102     ShouldNotReachHere();
2103   }
2104   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2105 }
2106 
2107 // Make a TypeTuple from the domain of a method signature
2108 const TypeTuple *TypeTuple::make_domain(ciInstanceKlass* recv, ciSignature* sig, InterfaceHandling interface_handling) {
2109   uint arg_cnt = sig->size();








2110 
2111   uint pos = TypeFunc::Parms;
2112   const Type **field_array;
2113   if (recv != nullptr) {
2114     arg_cnt++;
2115     field_array = fields(arg_cnt);
2116     // Use get_const_type here because it respects UseUniqueSubclasses:
2117     field_array[pos++] = get_const_type(recv, interface_handling)->join_speculative(TypePtr::NOTNULL);
2118   } else {
2119     field_array = fields(arg_cnt);

2120   }
2121 
2122   int i = 0;
2123   while (pos < TypeFunc::Parms + arg_cnt) {
2124     ciType* type = sig->type_at(i);

2125 
2126     switch (type->basic_type()) {
2127     case T_LONG:
2128       field_array[pos++] = TypeLong::LONG;
2129       field_array[pos++] = Type::HALF;
2130       break;
2131     case T_DOUBLE:
2132       field_array[pos++] = Type::DOUBLE;
2133       field_array[pos++] = Type::HALF;
2134       break;
2135     case T_OBJECT:









2136     case T_ARRAY:
2137     case T_FLOAT:
2138     case T_INT:
2139       field_array[pos++] = get_const_type(type, interface_handling);
2140       break;
2141     case T_BOOLEAN:
2142     case T_CHAR:
2143     case T_BYTE:
2144     case T_SHORT:
2145       field_array[pos++] = TypeInt::INT;
2146       break;
2147     default:
2148       ShouldNotReachHere();
2149     }
2150     i++;
2151   }

2152 
2153   return (TypeTuple*)(new TypeTuple(TypeFunc::Parms + arg_cnt, field_array))->hashcons();
2154 }
2155 
2156 const TypeTuple *TypeTuple::make( uint cnt, const Type **fields ) {
2157   return (TypeTuple*)(new TypeTuple(cnt,fields))->hashcons();
2158 }
2159 
2160 //------------------------------fields-----------------------------------------
2161 // Subroutine call type with space allocated for argument types
2162 // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
2163 const Type **TypeTuple::fields( uint arg_cnt ) {
2164   const Type **flds = (const Type **)(Compile::current()->type_arena()->AmallocWords((TypeFunc::Parms+arg_cnt)*sizeof(Type*) ));
2165   flds[TypeFunc::Control  ] = Type::CONTROL;
2166   flds[TypeFunc::I_O      ] = Type::ABIO;
2167   flds[TypeFunc::Memory   ] = Type::MEMORY;
2168   flds[TypeFunc::FramePtr ] = TypeRawPtr::BOTTOM;
2169   flds[TypeFunc::ReturnAdr] = Type::RETURN_ADDRESS;
2170 
2171   return flds;

2266     if (_fields[i]->empty())  return true;
2267   }
2268   return false;
2269 }
2270 
2271 //=============================================================================
2272 // Convenience common pre-built types.
2273 
2274 inline const TypeInt* normalize_array_size(const TypeInt* size) {
2275   // Certain normalizations keep us sane when comparing types.
2276   // We do not want arrayOop variables to differ only by the wideness
2277   // of their index types.  Pick minimum wideness, since that is the
2278   // forced wideness of small ranges anyway.
2279   if (size->_widen != Type::WidenMin)
2280     return TypeInt::make(size->_lo, size->_hi, Type::WidenMin);
2281   else
2282     return size;
2283 }
2284 
2285 //------------------------------make-------------------------------------------
2286 const TypeAry* TypeAry::make(const Type* elem, const TypeInt* size, bool stable) {

2287   if (UseCompressedOops && elem->isa_oopptr()) {
2288     elem = elem->make_narrowoop();
2289   }
2290   size = normalize_array_size(size);
2291   return (TypeAry*)(new TypeAry(elem,size,stable))->hashcons();
2292 }
2293 
2294 //------------------------------meet-------------------------------------------
2295 // Compute the MEET of two types.  It returns a new Type object.
2296 const Type *TypeAry::xmeet( const Type *t ) const {
2297   // Perform a fast test for common case; meeting the same types together.
2298   if( this == t ) return this;  // Meeting same type-rep?
2299 
2300   // Current "this->_base" is Ary
2301   switch (t->base()) {          // switch on original type
2302 
2303   case Bottom:                  // Ye Olde Default
2304     return t;
2305 
2306   default:                      // All else is a mistake
2307     typerr(t);
2308 
2309   case Array: {                 // Meeting 2 arrays?
2310     const TypeAry* a = t->is_ary();
2311     const Type* size = _size->xmeet(a->_size);
2312     const TypeInt* isize = size->isa_int();
2313     if (isize == nullptr) {
2314       assert(size == Type::TOP || size == Type::BOTTOM, "");
2315       return size;
2316     }
2317     return TypeAry::make(_elem->meet_speculative(a->_elem),
2318                          isize, _stable && a->_stable);




2319   }
2320   case Top:
2321     break;
2322   }
2323   return this;                  // Return the double constant
2324 }
2325 
2326 //------------------------------xdual------------------------------------------
2327 // Dual: compute field-by-field dual
2328 const Type *TypeAry::xdual() const {
2329   const TypeInt* size_dual = _size->dual()->is_int();
2330   size_dual = normalize_array_size(size_dual);
2331   return new TypeAry(_elem->dual(), size_dual, !_stable);
2332 }
2333 
2334 //------------------------------eq---------------------------------------------
2335 // Structural equality check for Type representations
2336 bool TypeAry::eq( const Type *t ) const {
2337   const TypeAry *a = (const TypeAry*)t;
2338   return _elem == a->_elem &&
2339     _stable == a->_stable &&
2340     _size == a->_size;





2341 }
2342 
2343 //------------------------------hash-------------------------------------------
2344 // Type-specific hashing function.
2345 uint TypeAry::hash(void) const {
2346   return (uint)(uintptr_t)_elem + (uint)(uintptr_t)_size + (uint)(_stable ? 43 : 0);

2347 }
2348 
2349 /**
2350  * Return same type without a speculative part in the element
2351  */
2352 const TypeAry* TypeAry::remove_speculative() const {
2353   return make(_elem->remove_speculative(), _size, _stable);
2354 }
2355 
2356 /**
2357  * Return same type with cleaned up speculative part of element
2358  */
2359 const Type* TypeAry::cleanup_speculative() const {
2360   return make(_elem->cleanup_speculative(), _size, _stable);
2361 }
2362 
2363 /**
2364  * Return same type but with a different inline depth (used for speculation)
2365  *
2366  * @param depth  depth to meet with
2367  */
2368 const TypePtr* TypePtr::with_inline_depth(int depth) const {
2369   if (!UseInlineDepthForSpeculativeTypes) {
2370     return this;
2371   }
2372   return make(AnyPtr, _ptr, _offset, _speculative, depth);
2373 }
2374 
2375 //------------------------------dump2------------------------------------------
2376 #ifndef PRODUCT
2377 void TypeAry::dump2( Dict &d, uint depth, outputStream *st ) const {
2378   if (_stable)  st->print("stable:");






2379   _elem->dump2(d, depth, st);
2380   st->print("[");
2381   _size->dump2(d, depth, st);
2382   st->print("]");
2383 }
2384 #endif
2385 
2386 //------------------------------singleton--------------------------------------
2387 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
2388 // constants (Ldi nodes).  Singletons are integer, float or double constants
2389 // or a single symbol.
2390 bool TypeAry::singleton(void) const {
2391   return false;                 // Never a singleton
2392 }
2393 
2394 bool TypeAry::empty(void) const {
2395   return _elem->empty() || _size->empty();
2396 }
2397 
2398 //--------------------------ary_must_be_exact----------------------------------
2399 bool TypeAry::ary_must_be_exact() const {
2400   // This logic looks at the element type of an array, and returns true
2401   // if the element type is either a primitive or a final instance class.
2402   // In such cases, an array built on this ary must have no subclasses.
2403   if (_elem == BOTTOM)      return false;  // general array not exact
2404   if (_elem == TOP   )      return false;  // inverted general array not exact
2405   const TypeOopPtr*  toop = nullptr;
2406   if (UseCompressedOops && _elem->isa_narrowoop()) {
2407     toop = _elem->make_ptr()->isa_oopptr();
2408   } else {
2409     toop = _elem->isa_oopptr();
2410   }
2411   if (!toop)                return true;   // a primitive type, like int
2412   if (!toop->is_loaded())   return false;  // unloaded class
2413   const TypeInstPtr* tinst;
2414   if (_elem->isa_narrowoop())
2415     tinst = _elem->make_ptr()->isa_instptr();
2416   else
2417     tinst = _elem->isa_instptr();
2418   if (tinst)
2419     return tinst->instance_klass()->is_final();











2420   const TypeAryPtr*  tap;
2421   if (_elem->isa_narrowoop())
2422     tap = _elem->make_ptr()->isa_aryptr();
2423   else
2424     tap = _elem->isa_aryptr();
2425   if (tap)
2426     return tap->ary()->ary_must_be_exact();
2427   return false;
2428 }
2429 
2430 //==============================TypeVect=======================================
2431 // Convenience common pre-built types.
2432 const TypeVect* TypeVect::VECTA = nullptr; // vector length agnostic
2433 const TypeVect* TypeVect::VECTS = nullptr; //  32-bit vectors
2434 const TypeVect* TypeVect::VECTD = nullptr; //  64-bit vectors
2435 const TypeVect* TypeVect::VECTX = nullptr; // 128-bit vectors
2436 const TypeVect* TypeVect::VECTY = nullptr; // 256-bit vectors
2437 const TypeVect* TypeVect::VECTZ = nullptr; // 512-bit vectors
2438 const TypeVect* TypeVect::VECTMASK = nullptr; // predicate/mask vector
2439 

2580 
2581 //=============================================================================
2582 // Convenience common pre-built types.
2583 const TypePtr *TypePtr::NULL_PTR;
2584 const TypePtr *TypePtr::NOTNULL;
2585 const TypePtr *TypePtr::BOTTOM;
2586 
2587 //------------------------------meet-------------------------------------------
2588 // Meet over the PTR enum
2589 const TypePtr::PTR TypePtr::ptr_meet[TypePtr::lastPTR][TypePtr::lastPTR] = {
2590   //              TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,
2591   { /* Top     */ TopPTR,    AnyNull,   Constant, Null,   NotNull, BotPTR,},
2592   { /* AnyNull */ AnyNull,   AnyNull,   Constant, BotPTR, NotNull, BotPTR,},
2593   { /* Constant*/ Constant,  Constant,  Constant, BotPTR, NotNull, BotPTR,},
2594   { /* Null    */ Null,      BotPTR,    BotPTR,   Null,   BotPTR,  BotPTR,},
2595   { /* NotNull */ NotNull,   NotNull,   NotNull,  BotPTR, NotNull, BotPTR,},
2596   { /* BotPTR  */ BotPTR,    BotPTR,    BotPTR,   BotPTR, BotPTR,  BotPTR,}
2597 };
2598 
2599 //------------------------------make-------------------------------------------
2600 const TypePtr *TypePtr::make(TYPES t, enum PTR ptr, int offset, const TypePtr* speculative, int inline_depth) {
2601   return (TypePtr*)(new TypePtr(t,ptr,offset, speculative, inline_depth))->hashcons();
2602 }
2603 
2604 //------------------------------cast_to_ptr_type-------------------------------
2605 const TypePtr* TypePtr::cast_to_ptr_type(PTR ptr) const {
2606   assert(_base == AnyPtr, "subclass must override cast_to_ptr_type");
2607   if( ptr == _ptr ) return this;
2608   return make(_base, ptr, _offset, _speculative, _inline_depth);
2609 }
2610 
2611 //------------------------------get_con----------------------------------------
2612 intptr_t TypePtr::get_con() const {
2613   assert( _ptr == Null, "" );
2614   return _offset;
2615 }
2616 
2617 //------------------------------meet-------------------------------------------
2618 // Compute the MEET of two types.  It returns a new Type object.
2619 const Type *TypePtr::xmeet(const Type *t) const {
2620   const Type* res = xmeet_helper(t);
2621   if (res->isa_ptr() == nullptr) {
2622     return res;
2623   }
2624 
2625   const TypePtr* res_ptr = res->is_ptr();
2626   if (res_ptr->speculative() != nullptr) {
2627     // type->speculative() is null means that speculation is no better
2628     // than type, i.e. type->speculative() == type. So there are 2
2629     // ways to represent the fact that we have no useful speculative
2630     // data and we should use a single one to be able to test for
2631     // equality between types. Check whether type->speculative() ==
2632     // type and set speculative to null if it is the case.
2633     if (res_ptr->remove_speculative() == res_ptr->speculative()) {
2634       return res_ptr->remove_speculative();

2668     int depth = meet_inline_depth(tp->inline_depth());
2669     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2670   }
2671   case RawPtr:                  // For these, flip the call around to cut down
2672   case OopPtr:
2673   case InstPtr:                 // on the cases I have to handle.
2674   case AryPtr:
2675   case MetadataPtr:
2676   case KlassPtr:
2677   case InstKlassPtr:
2678   case AryKlassPtr:
2679     return t->xmeet(this);      // Call in reverse direction
2680   default:                      // All else is a mistake
2681     typerr(t);
2682 
2683   }
2684   return this;
2685 }
2686 
2687 //------------------------------meet_offset------------------------------------
2688 int TypePtr::meet_offset( int offset ) const {
2689   // Either is 'TOP' offset?  Return the other offset!
2690   if( _offset == OffsetTop ) return offset;
2691   if( offset == OffsetTop ) return _offset;
2692   // If either is different, return 'BOTTOM' offset
2693   if( _offset != offset ) return OffsetBot;
2694   return _offset;
2695 }
2696 
2697 //------------------------------dual_offset------------------------------------
2698 int TypePtr::dual_offset( ) const {
2699   if( _offset == OffsetTop ) return OffsetBot;// Map 'TOP' into 'BOTTOM'
2700   if( _offset == OffsetBot ) return OffsetTop;// Map 'BOTTOM' into 'TOP'
2701   return _offset;               // Map everything else into self
2702 }
2703 
2704 //------------------------------xdual------------------------------------------
2705 // Dual: compute field-by-field dual
2706 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2707   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2708 };












2709 const Type *TypePtr::xdual() const {
2710   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2711 }
2712 
2713 //------------------------------xadd_offset------------------------------------
2714 int TypePtr::xadd_offset( intptr_t offset ) const {
2715   // Adding to 'TOP' offset?  Return 'TOP'!
2716   if( _offset == OffsetTop || offset == OffsetTop ) return OffsetTop;
2717   // Adding to 'BOTTOM' offset?  Return 'BOTTOM'!
2718   if( _offset == OffsetBot || offset == OffsetBot ) return OffsetBot;
2719   // Addition overflows or "accidentally" equals to OffsetTop? Return 'BOTTOM'!
2720   offset += (intptr_t)_offset;
2721   if (offset != (int)offset || offset == OffsetTop) return OffsetBot;
2722 
2723   // assert( _offset >= 0 && _offset+offset >= 0, "" );
2724   // It is possible to construct a negative offset during PhaseCCP
2725 
2726   return (int)offset;        // Sum valid offsets
2727 }
2728 
2729 //------------------------------add_offset-------------------------------------
2730 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2731   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2732 }
2733 
2734 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2735   return make(AnyPtr, _ptr, offset, _speculative, _inline_depth);
2736 }
2737 
2738 //------------------------------eq---------------------------------------------
2739 // Structural equality check for Type representations
2740 bool TypePtr::eq( const Type *t ) const {
2741   const TypePtr *a = (const TypePtr*)t;
2742   return _ptr == a->ptr() && _offset == a->offset() && eq_speculative(a) && _inline_depth == a->_inline_depth;
2743 }
2744 
2745 //------------------------------hash-------------------------------------------
2746 // Type-specific hashing function.
2747 uint TypePtr::hash(void) const {
2748   return (uint)_ptr + (uint)_offset + (uint)hash_speculative() + (uint)_inline_depth;
2749 }
2750 
2751 /**
2752  * Return same type without a speculative part
2753  */
2754 const TypePtr* TypePtr::remove_speculative() const {
2755   if (_speculative == nullptr) {
2756     return this;
2757   }
2758   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2759   return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2760 }
2761 
2762 /**
2763  * Return same type but drop speculative part if we know we won't use
2764  * it
2765  */
2766 const Type* TypePtr::cleanup_speculative() const {
2767   if (speculative() == nullptr) {
2768     return this;

2985     return false;
2986   }
2987   // We already know the speculative type cannot be null
2988   if (!speculative_maybe_null()) {
2989     return false;
2990   }
2991   // We already know this is always null
2992   if (this == TypePtr::NULL_PTR) {
2993     return false;
2994   }
2995   // We already know the speculative type is always null
2996   if (speculative_always_null()) {
2997     return false;
2998   }
2999   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3000     return false;
3001   }
3002   return true;
3003 }
3004 



























3005 //------------------------------dump2------------------------------------------
3006 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3007   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3008 };
3009 
3010 #ifndef PRODUCT
3011 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3012   st->print("ptr:%s", ptr_msg[_ptr]);
3013   dump_offset(st);
3014   dump_inline_depth(st);
3015   dump_speculative(st);
3016 }
3017 
3018 void TypePtr::dump_offset(outputStream* st) const {
3019   if (_offset == OffsetBot) {
3020     st->print("+bot");
3021   } else if (_offset == OffsetTop) {
3022     st->print("+top");
3023   } else {
3024     st->print("+%d", _offset);
3025   }
3026 }
3027 
3028 /**
3029  *dump the speculative part of the type
3030  */
3031 void TypePtr::dump_speculative(outputStream *st) const {
3032   if (_speculative != nullptr) {
3033     st->print(" (speculative=");
3034     _speculative->dump_on(st);
3035     st->print(")");
3036   }
3037 }
3038 
3039 /**
3040  *dump the inline depth of the type
3041  */
3042 void TypePtr::dump_inline_depth(outputStream *st) const {
3043   if (_inline_depth != InlineDepthBottom) {
3044     if (_inline_depth == InlineDepthTop) {
3045       st->print(" (inline_depth=InlineDepthTop)");
3046     } else {
3047       st->print(" (inline_depth=%d)", _inline_depth);
3048     }
3049   }
3050 }
















3051 #endif
3052 
3053 //------------------------------singleton--------------------------------------
3054 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3055 // constants
3056 bool TypePtr::singleton(void) const {
3057   // TopPTR, Null, AnyNull, Constant are all singletons
3058   return (_offset != OffsetBot) && !below_centerline(_ptr);
3059 }
3060 
3061 bool TypePtr::empty(void) const {
3062   return (_offset == OffsetTop) || above_centerline(_ptr);
3063 }
3064 
3065 //=============================================================================
3066 // Convenience common pre-built types.
3067 const TypeRawPtr *TypeRawPtr::BOTTOM;
3068 const TypeRawPtr *TypeRawPtr::NOTNULL;
3069 
3070 //------------------------------make-------------------------------------------
3071 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3072   assert( ptr != Constant, "what is the constant?" );
3073   assert( ptr != Null, "Use TypePtr for null" );
3074   return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3075 }
3076 
3077 const TypeRawPtr *TypeRawPtr::make(address bits) {
3078   assert(bits != nullptr, "Use TypePtr for null");
3079   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3080 }
3081 
3082 //------------------------------cast_to_ptr_type-------------------------------

3450 #endif
3451 
3452 // Can't be implemented because there's no way to know if the type is above or below the center line.
3453 const Type* TypeInterfaces::xmeet(const Type* t) const {
3454   ShouldNotReachHere();
3455   return Type::xmeet(t);
3456 }
3457 
3458 bool TypeInterfaces::singleton(void) const {
3459   ShouldNotReachHere();
3460   return Type::singleton();
3461 }
3462 
3463 bool TypeInterfaces::has_non_array_interface() const {
3464   assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3465 
3466   return !TypeAryPtr::_array_interfaces->contains(this);
3467 }
3468 
3469 //------------------------------TypeOopPtr-------------------------------------
3470 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,
3471                        int instance_id, const TypePtr* speculative, int inline_depth)
3472   : TypePtr(t, ptr, offset, speculative, inline_depth),
3473     _const_oop(o), _klass(k),
3474     _interfaces(interfaces),
3475     _klass_is_exact(xk),
3476     _is_ptr_to_narrowoop(false),
3477     _is_ptr_to_narrowklass(false),
3478     _is_ptr_to_boxed_value(false),

3479     _instance_id(instance_id) {
3480 #ifdef ASSERT
3481   if (klass() != nullptr && klass()->is_loaded()) {
3482     interfaces->verify_is_loaded();
3483   }
3484 #endif
3485   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3486       (offset > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3487     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset);









3488   }

3489 #ifdef _LP64
3490   if (_offset > 0 || _offset == Type::OffsetTop || _offset == Type::OffsetBot) {
3491     if (_offset == oopDesc::klass_offset_in_bytes()) {
3492       _is_ptr_to_narrowklass = true;
3493     } else if (klass() == nullptr) {
3494       // Array with unknown body type
3495       assert(this->isa_aryptr(), "only arrays without klass");
3496       _is_ptr_to_narrowoop = UseCompressedOops;
3497     } else if (this->isa_aryptr()) {
3498       _is_ptr_to_narrowoop = (UseCompressedOops && klass()->is_obj_array_klass() &&
3499                              _offset != arrayOopDesc::length_offset_in_bytes());














3500     } else if (klass()->is_instance_klass()) {
3501       ciInstanceKlass* ik = klass()->as_instance_klass();
3502       if (this->isa_klassptr()) {
3503         // Perm objects don't use compressed references
3504       } else if (_offset == OffsetBot || _offset == OffsetTop) {
3505         // unsafe access
3506         _is_ptr_to_narrowoop = UseCompressedOops;
3507       } else {
3508         assert(this->isa_instptr(), "must be an instance ptr.");
3509 
3510         if (klass() == ciEnv::current()->Class_klass() &&
3511             (_offset == java_lang_Class::klass_offset() ||
3512              _offset == java_lang_Class::array_klass_offset())) {
3513           // Special hidden fields from the Class.
3514           assert(this->isa_instptr(), "must be an instance ptr.");
3515           _is_ptr_to_narrowoop = false;
3516         } else if (klass() == ciEnv::current()->Class_klass() &&
3517                    _offset >= InstanceMirrorKlass::offset_of_static_fields()) {
3518           // Static fields
3519           BasicType basic_elem_type = T_ILLEGAL;
3520           if (const_oop() != nullptr) {
3521             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3522             basic_elem_type = k->get_field_type_by_offset(_offset, true);
3523           }
3524           if (basic_elem_type != T_ILLEGAL) {
3525             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3526           } else {
3527             // unsafe access
3528             _is_ptr_to_narrowoop = UseCompressedOops;
3529           }
3530         } else {
3531           // Instance fields which contains a compressed oop references.
3532           BasicType basic_elem_type = ik->get_field_type_by_offset(_offset, false);

3533           if (basic_elem_type != T_ILLEGAL) {
3534             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3535           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3536             // Compile::find_alias_type() cast exactness on all types to verify
3537             // that it does not affect alias type.
3538             _is_ptr_to_narrowoop = UseCompressedOops;
3539           } else {
3540             // Type for the copy start in LibraryCallKit::inline_native_clone().
3541             _is_ptr_to_narrowoop = UseCompressedOops;
3542           }
3543         }
3544       }
3545     }
3546   }
3547 #endif
3548 }
3549 
3550 //------------------------------make-------------------------------------------
3551 const TypeOopPtr *TypeOopPtr::make(PTR ptr, int offset, int instance_id,
3552                                      const TypePtr* speculative, int inline_depth) {
3553   assert(ptr != Constant, "no constant generic pointers");
3554   ciKlass*  k = Compile::current()->env()->Object_klass();
3555   bool      xk = false;
3556   ciObject* o = nullptr;
3557   const TypeInterfaces* interfaces = TypeInterfaces::make();
3558   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, instance_id, speculative, inline_depth))->hashcons();
3559 }
3560 
3561 
3562 //------------------------------cast_to_ptr_type-------------------------------
3563 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3564   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3565   if( ptr == _ptr ) return this;
3566   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3567 }
3568 
3569 //-----------------------------cast_to_instance_id----------------------------
3570 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3571   // There are no instances of a general oop.
3572   // Return self unchanged.
3573   return this;
3574 }
3575 
3576 //-----------------------------cast_to_exactness-------------------------------
3577 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3578   // There is no such thing as an exact general oop.
3579   // Return self unchanged.
3580   return this;
3581 }
3582 
3583 
3584 //------------------------------as_klass_type----------------------------------
3585 // Return the klass type corresponding to this instance or array type.
3586 // It is the type that is loaded from an object of this type.
3587 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3588   ShouldNotReachHere();
3589   return nullptr;
3590 }
3591 
3592 //------------------------------meet-------------------------------------------
3593 // Compute the MEET of two types.  It returns a new Type object.
3594 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3595   // Perform a fast test for common case; meeting the same types together.
3596   if( this == t ) return this;  // Meeting same type-rep?
3597 
3598   // Current "this->_base" is OopPtr
3599   switch (t->base()) {          // switch on original type
3600 
3601   case Int:                     // Mixing ints & oops happens when javac
3602   case Long:                    // reuses local variables
3603   case HalfFloatTop:

3612   case NarrowOop:
3613   case NarrowKlass:
3614   case Bottom:                  // Ye Olde Default
3615     return Type::BOTTOM;
3616   case Top:
3617     return this;
3618 
3619   default:                      // All else is a mistake
3620     typerr(t);
3621 
3622   case RawPtr:
3623   case MetadataPtr:
3624   case KlassPtr:
3625   case InstKlassPtr:
3626   case AryKlassPtr:
3627     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3628 
3629   case AnyPtr: {
3630     // Found an AnyPtr type vs self-OopPtr type
3631     const TypePtr *tp = t->is_ptr();
3632     int offset = meet_offset(tp->offset());
3633     PTR ptr = meet_ptr(tp->ptr());
3634     const TypePtr* speculative = xmeet_speculative(tp);
3635     int depth = meet_inline_depth(tp->inline_depth());
3636     switch (tp->ptr()) {
3637     case Null:
3638       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3639       // else fall through:
3640     case TopPTR:
3641     case AnyNull: {
3642       int instance_id = meet_instance_id(InstanceTop);
3643       return make(ptr, offset, instance_id, speculative, depth);
3644     }
3645     case BotPTR:
3646     case NotNull:
3647       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3648     default: typerr(t);
3649     }
3650   }
3651 
3652   case OopPtr: {                 // Meeting to other OopPtrs

3654     int instance_id = meet_instance_id(tp->instance_id());
3655     const TypePtr* speculative = xmeet_speculative(tp);
3656     int depth = meet_inline_depth(tp->inline_depth());
3657     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3658   }
3659 
3660   case InstPtr:                  // For these, flip the call around to cut down
3661   case AryPtr:
3662     return t->xmeet(this);      // Call in reverse direction
3663 
3664   } // End of switch
3665   return this;                  // Return the double constant
3666 }
3667 
3668 
3669 //------------------------------xdual------------------------------------------
3670 // Dual of a pure heap pointer.  No relevant klass or oop information.
3671 const Type *TypeOopPtr::xdual() const {
3672   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3673   assert(const_oop() == nullptr,             "no constants here");
3674   return new TypeOopPtr(_base, dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());
3675 }
3676 
3677 //--------------------------make_from_klass_common-----------------------------
3678 // Computes the element-type given a klass.
3679 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3680   if (klass->is_instance_klass()) {
3681     Compile* C = Compile::current();
3682     Dependencies* deps = C->dependencies();
3683     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3684     // Element is an instance
3685     bool klass_is_exact = false;

3686     if (klass->is_loaded()) {
3687       // Try to set klass_is_exact.
3688       ciInstanceKlass* ik = klass->as_instance_klass();
3689       klass_is_exact = ik->is_final();
3690       if (!klass_is_exact && klass_change
3691           && deps != nullptr && UseUniqueSubclasses) {
3692         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3693         if (sub != nullptr) {
3694           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3695           klass = ik = sub;
3696           klass_is_exact = sub->is_final();
3697         }
3698       }
3699       if (!klass_is_exact && try_for_exact && deps != nullptr &&
3700           !ik->is_interface() && !ik->has_subklass()) {
3701         // Add a dependence; if concrete subclass added we need to recompile
3702         deps->assert_leaf_type(ik);
3703         klass_is_exact = true;
3704       }
3705     }

3706     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3707     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, 0);
3708   } else if (klass->is_obj_array_klass()) {
3709     // Element is an object array. Recursively call ourself.
3710     ciKlass* eklass = klass->as_obj_array_klass()->element_klass();
3711     const TypeOopPtr *etype = TypeOopPtr::make_from_klass_common(eklass, false, try_for_exact, interface_handling);
3712     bool xk = etype->klass_is_exact();
3713     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);






























3714     // We used to pass NotNull in here, asserting that the sub-arrays
3715     // are all not-null.  This is not true in generally, as code can
3716     // slam nulls down in the subarrays.
3717     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, 0);
3718     return arr;
3719   } else if (klass->is_type_array_klass()) {
3720     // Element is an typeArray
3721     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
3722     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS);

3723     // We used to pass NotNull in here, asserting that the array pointer
3724     // is not-null. That was not true in general.
3725     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, 0);
3726     return arr;
3727   } else {
3728     ShouldNotReachHere();
3729     return nullptr;
3730   }
3731 }
3732 
3733 //------------------------------make_from_constant-----------------------------
3734 // Make a java pointer from an oop constant
3735 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
3736   assert(!o->is_null_object(), "null object not yet handled here.");
3737 
3738   const bool make_constant = require_constant || o->should_be_constant();
3739 
3740   ciKlass* klass = o->klass();
3741   if (klass->is_instance_klass()) {
3742     // Element is an instance
3743     if (make_constant) {
3744       return TypeInstPtr::make(o);
3745     } else {
3746       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, 0);
3747     }
3748   } else if (klass->is_obj_array_klass()) {
3749     // Element is an object array. Recursively call ourself.
3750     const TypeOopPtr *etype =
3751       TypeOopPtr::make_from_klass_raw(klass->as_obj_array_klass()->element_klass(), trust_interfaces);
3752     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));






3753     // We used to pass NotNull in here, asserting that the sub-arrays
3754     // are all not-null.  This is not true in generally, as code can
3755     // slam nulls down in the subarrays.
3756     if (make_constant) {
3757       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3758     } else {
3759       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3760     }
3761   } else if (klass->is_type_array_klass()) {
3762     // Element is an typeArray
3763     const Type* etype =
3764       (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
3765     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()));
3766     // We used to pass NotNull in here, asserting that the array pointer
3767     // is not-null. That was not true in general.
3768     if (make_constant) {
3769       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, 0);
3770     } else {
3771       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, 0);
3772     }
3773   }
3774 
3775   fatal("unhandled object type");
3776   return nullptr;
3777 }
3778 
3779 //------------------------------get_con----------------------------------------
3780 intptr_t TypeOopPtr::get_con() const {
3781   assert( _ptr == Null || _ptr == Constant, "" );
3782   assert( _offset >= 0, "" );
3783 
3784   if (_offset != 0) {
3785     // After being ported to the compiler interface, the compiler no longer
3786     // directly manipulates the addresses of oops.  Rather, it only has a pointer
3787     // to a handle at compile time.  This handle is embedded in the generated
3788     // code and dereferenced at the time the nmethod is made.  Until that time,
3789     // it is not reasonable to do arithmetic with the addresses of oops (we don't
3790     // have access to the addresses!).  This does not seem to currently happen,
3791     // but this assertion here is to help prevent its occurrence.
3792     tty->print_cr("Found oop constant with non-zero offset");
3793     ShouldNotReachHere();
3794   }
3795 
3796   return (intptr_t)const_oop()->constant_encoding();
3797 }
3798 
3799 
3800 //-----------------------------filter------------------------------------------
3801 // Do not allow interface-vs.-noninterface joins to collapse to top.
3802 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
3803 
3804   const Type* ft = join_helper(kills, include_speculative);

3850   dump_speculative(st);
3851 }
3852 
3853 void TypeOopPtr::dump_instance_id(outputStream* st) const {
3854   if (_instance_id == InstanceTop) {
3855     st->print(",iid=top");
3856   } else if (_instance_id == InstanceBot) {
3857     st->print(",iid=bot");
3858   } else {
3859     st->print(",iid=%d", _instance_id);
3860   }
3861 }
3862 #endif
3863 
3864 //------------------------------singleton--------------------------------------
3865 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3866 // constants
3867 bool TypeOopPtr::singleton(void) const {
3868   // detune optimizer to not generate constant oop + constant offset as a constant!
3869   // TopPTR, Null, AnyNull, Constant are all singletons
3870   return (_offset == 0) && !below_centerline(_ptr);
3871 }
3872 
3873 //------------------------------add_offset-------------------------------------
3874 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
3875   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
3876 }
3877 
3878 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
3879   return make(_ptr, offset, _instance_id, with_offset_speculative(offset), _inline_depth);
3880 }
3881 
3882 /**
3883  * Return same type without a speculative part
3884  */
3885 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
3886   if (_speculative == nullptr) {
3887     return this;
3888   }
3889   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
3890   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
3891 }
3892 
3893 /**
3894  * Return same type but drop speculative part if we know we won't use
3895  * it
3896  */
3897 const Type* TypeOopPtr::cleanup_speculative() const {
3898   // If the klass is exact and the ptr is not null then there's
3899   // nothing that the speculative type can help us with

3972 const TypeInstPtr *TypeInstPtr::BOTTOM;
3973 const TypeInstPtr *TypeInstPtr::MIRROR;
3974 const TypeInstPtr *TypeInstPtr::MARK;
3975 const TypeInstPtr *TypeInstPtr::KLASS;
3976 
3977 // Is there a single ciKlass* that can represent that type?
3978 ciKlass* TypeInstPtr::exact_klass_helper() const {
3979   if (_interfaces->empty()) {
3980     return _klass;
3981   }
3982   if (_klass != ciEnv::current()->Object_klass()) {
3983     if (_interfaces->eq(_klass->as_instance_klass())) {
3984       return _klass;
3985     }
3986     return nullptr;
3987   }
3988   return _interfaces->exact_klass();
3989 }
3990 
3991 //------------------------------TypeInstPtr-------------------------------------
3992 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off,
3993                          int instance_id, const TypePtr* speculative, int inline_depth)
3994   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, instance_id, speculative, inline_depth) {



3995   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
3996   assert(k != nullptr &&
3997          (k->is_loaded() || o == nullptr),
3998          "cannot have constants with non-loaded klass");
3999 };
4000 
4001 //------------------------------make-------------------------------------------
4002 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4003                                      ciKlass* k,
4004                                      const TypeInterfaces* interfaces,
4005                                      bool xk,
4006                                      ciObject* o,
4007                                      int offset,

4008                                      int instance_id,
4009                                      const TypePtr* speculative,
4010                                      int inline_depth) {
4011   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4012   // Either const_oop() is null or else ptr is Constant
4013   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4014           "constant pointers must have a value supplied" );
4015   // Ptr is never Null
4016   assert( ptr != Null, "null pointers are not typed" );
4017 
4018   assert(instance_id <= 0 || xk, "instances are always exactly typed");

4019   if (ptr == Constant) {
4020     // Note:  This case includes meta-object constants, such as methods.
4021     xk = true;
4022   } else if (k->is_loaded()) {
4023     ciInstanceKlass* ik = k->as_instance_klass();
4024     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4025     assert(!ik->is_interface(), "no interface here");
4026     if (xk && ik->is_interface())  xk = false;  // no exact interface
4027   }
4028 



4029   // Now hash this baby
4030   TypeInstPtr *result =
4031     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o ,offset, instance_id, speculative, inline_depth))->hashcons();
4032 
4033   return result;
4034 }
4035 
4036 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4037   if (k->is_instance_klass()) {
4038     if (k->is_loaded()) {
4039       if (k->is_interface() && interface_handling == ignore_interfaces) {
4040         assert(interface, "no interface expected");
4041         k = ciEnv::current()->Object_klass();
4042         const TypeInterfaces* interfaces = TypeInterfaces::make();
4043         return interfaces;
4044       }
4045       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4046       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4047       if (k->is_interface()) {
4048         assert(interface, "no interface expected");
4049         k = ciEnv::current()->Object_klass();
4050       } else {
4051         assert(klass, "no instance klass expected");

4077   switch (bt) {
4078     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4079     case T_INT:      return TypeInt::make(constant.as_int());
4080     case T_CHAR:     return TypeInt::make(constant.as_char());
4081     case T_BYTE:     return TypeInt::make(constant.as_byte());
4082     case T_SHORT:    return TypeInt::make(constant.as_short());
4083     case T_FLOAT:    return TypeF::make(constant.as_float());
4084     case T_DOUBLE:   return TypeD::make(constant.as_double());
4085     case T_LONG:     return TypeLong::make(constant.as_long());
4086     default:         break;
4087   }
4088   fatal("Invalid boxed value type '%s'", type2name(bt));
4089   return nullptr;
4090 }
4091 
4092 //------------------------------cast_to_ptr_type-------------------------------
4093 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4094   if( ptr == _ptr ) return this;
4095   // Reconstruct _sig info here since not a problem with later lazy
4096   // construction, _sig will show up on demand.
4097   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _instance_id, _speculative, _inline_depth);
4098 }
4099 
4100 
4101 //-----------------------------cast_to_exactness-------------------------------
4102 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4103   if( klass_is_exact == _klass_is_exact ) return this;
4104   if (!_klass->is_loaded())  return this;
4105   ciInstanceKlass* ik = _klass->as_instance_klass();
4106   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4107   assert(!ik->is_interface(), "no interface here");
4108   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, _instance_id, _speculative, _inline_depth);

4109 }
4110 
4111 //-----------------------------cast_to_instance_id----------------------------
4112 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4113   if( instance_id == _instance_id ) return this;
4114   return make(_ptr, klass(),  _interfaces, _klass_is_exact, const_oop(), _offset, instance_id, _speculative, _inline_depth);
4115 }
4116 
4117 //------------------------------xmeet_unloaded---------------------------------
4118 // Compute the MEET of two InstPtrs when at least one is unloaded.
4119 // Assume classes are different since called after check for same name/class-loader
4120 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4121   int off = meet_offset(tinst->offset());
4122   PTR ptr = meet_ptr(tinst->ptr());
4123   int instance_id = meet_instance_id(tinst->instance_id());
4124   const TypePtr* speculative = xmeet_speculative(tinst);
4125   int depth = meet_inline_depth(tinst->inline_depth());
4126 
4127   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4128   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4129   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4130     //
4131     // Meet unloaded class with java/lang/Object
4132     //
4133     // Meet
4134     //          |                     Unloaded Class
4135     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4136     //  ===================================================================
4137     //   TOP    | ..........................Unloaded......................|
4138     //  AnyNull |  U-AN    |................Unloaded......................|
4139     // Constant | ... O-NN .................................. |   O-BOT   |
4140     //  NotNull | ... O-NN .................................. |   O-BOT   |
4141     //  BOTTOM  | ........................Object-BOTTOM ..................|
4142     //
4143     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4144     //
4145     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded->with_speculative(speculative); }
4146     else if (loaded->ptr() == TypePtr::AnyNull)  { return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, instance_id, speculative, depth); }




4147     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4148     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4149       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM->with_speculative(speculative);  }
4150       else                                       { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4151     }
4152     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4153 
4154     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4155   }
4156 
4157   // Both are unloaded, not the same class, not Object
4158   // Or meet unloaded with a different loaded class, not java/lang/Object
4159   if (ptr != TypePtr::BotPTR) {
4160     return TypeInstPtr::NOTNULL->with_speculative(speculative);
4161   }
4162   return TypeInstPtr::BOTTOM->with_speculative(speculative);
4163 }
4164 
4165 
4166 //------------------------------meet-------------------------------------------

4190   case Top:
4191     return this;
4192 
4193   default:                      // All else is a mistake
4194     typerr(t);
4195 
4196   case MetadataPtr:
4197   case KlassPtr:
4198   case InstKlassPtr:
4199   case AryKlassPtr:
4200   case RawPtr: return TypePtr::BOTTOM;
4201 
4202   case AryPtr: {                // All arrays inherit from Object class
4203     // Call in reverse direction to avoid duplication
4204     return t->is_aryptr()->xmeet_helper(this);
4205   }
4206 
4207   case OopPtr: {                // Meeting to OopPtrs
4208     // Found a OopPtr type vs self-InstPtr type
4209     const TypeOopPtr *tp = t->is_oopptr();
4210     int offset = meet_offset(tp->offset());
4211     PTR ptr = meet_ptr(tp->ptr());
4212     switch (tp->ptr()) {
4213     case TopPTR:
4214     case AnyNull: {
4215       int instance_id = meet_instance_id(InstanceTop);
4216       const TypePtr* speculative = xmeet_speculative(tp);
4217       int depth = meet_inline_depth(tp->inline_depth());
4218       return make(ptr, klass(), _interfaces, klass_is_exact(),
4219                   (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4220     }
4221     case NotNull:
4222     case BotPTR: {
4223       int instance_id = meet_instance_id(tp->instance_id());
4224       const TypePtr* speculative = xmeet_speculative(tp);
4225       int depth = meet_inline_depth(tp->inline_depth());
4226       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4227     }
4228     default: typerr(t);
4229     }
4230   }
4231 
4232   case AnyPtr: {                // Meeting to AnyPtrs
4233     // Found an AnyPtr type vs self-InstPtr type
4234     const TypePtr *tp = t->is_ptr();
4235     int offset = meet_offset(tp->offset());
4236     PTR ptr = meet_ptr(tp->ptr());
4237     int instance_id = meet_instance_id(InstanceTop);
4238     const TypePtr* speculative = xmeet_speculative(tp);
4239     int depth = meet_inline_depth(tp->inline_depth());
4240     switch (tp->ptr()) {
4241     case Null:
4242       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4243       // else fall through to AnyNull
4244     case TopPTR:
4245     case AnyNull: {
4246       return make(ptr, klass(), _interfaces, klass_is_exact(),
4247                   (ptr == Constant ? const_oop() : nullptr), offset, instance_id, speculative, depth);
4248     }
4249     case NotNull:
4250     case BotPTR:
4251       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4252     default: typerr(t);
4253     }
4254   }
4255 
4256   /*
4257                  A-top         }
4258                /   |   \       }  Tops
4259            B-top A-any C-top   }
4260               | /  |  \ |      }  Any-nulls
4261            B-any   |   C-any   }
4262               |    |    |
4263            B-con A-con C-con   } constants; not comparable across classes
4264               |    |    |
4265            B-not   |   C-not   }
4266               | \  |  / |      }  not-nulls
4267            B-bot A-not C-bot   }
4268                \   |   /       }  Bottoms
4269                  A-bot         }
4270   */
4271 
4272   case InstPtr: {                // Meeting 2 Oops?
4273     // Found an InstPtr sub-type vs self-InstPtr type
4274     const TypeInstPtr *tinst = t->is_instptr();
4275     int off = meet_offset(tinst->offset());
4276     PTR ptr = meet_ptr(tinst->ptr());
4277     int instance_id = meet_instance_id(tinst->instance_id());
4278     const TypePtr* speculative = xmeet_speculative(tinst);
4279     int depth = meet_inline_depth(tinst->inline_depth());
4280     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4281 
4282     ciKlass* tinst_klass = tinst->klass();
4283     ciKlass* this_klass  = klass();
4284 
4285     ciKlass* res_klass = nullptr;
4286     bool res_xk = false;
4287     const Type* res;
4288     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4289 
4290     if (kind == UNLOADED) {
4291       // One of these classes has not been loaded
4292       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4293 #ifndef PRODUCT
4294       if (PrintOpto && Verbose) {
4295         tty->print("meet of unloaded classes resulted in: ");
4296         unloaded_meet->dump();
4297         tty->cr();
4298         tty->print("  this == ");
4299         dump();
4300         tty->cr();
4301         tty->print(" tinst == ");
4302         tinst->dump();
4303         tty->cr();
4304       }
4305 #endif
4306       res = unloaded_meet;
4307     } else {

4308       if (kind == NOT_SUBTYPE && instance_id > 0) {
4309         instance_id = InstanceBot;
4310       } else if (kind == LCA) {
4311         instance_id = InstanceBot;
4312       }
4313       ciObject* o = nullptr;             // Assume not constant when done
4314       ciObject* this_oop = const_oop();
4315       ciObject* tinst_oop = tinst->const_oop();
4316       if (ptr == Constant) {
4317         if (this_oop != nullptr && tinst_oop != nullptr &&
4318             this_oop->equals(tinst_oop))
4319           o = this_oop;
4320         else if (above_centerline(_ptr)) {
4321           assert(!tinst_klass->is_interface(), "");
4322           o = tinst_oop;
4323         } else if (above_centerline(tinst->_ptr)) {
4324           assert(!this_klass->is_interface(), "");
4325           o = this_oop;
4326         } else
4327           ptr = NotNull;
4328       }
4329       res = make(ptr, res_klass, interfaces, res_xk, o, off, instance_id, speculative, depth);
4330     }
4331 
4332     return res;
4333 
4334   } // End of case InstPtr
4335 
4336   } // End of switch
4337   return this;                  // Return the double constant
4338 }
4339 
4340 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4341                                                             ciKlass*& res_klass, bool& res_xk) {
4342   ciKlass* this_klass = this_type->klass();
4343   ciKlass* other_klass = other_type->klass();

4344   bool this_xk = this_type->klass_is_exact();
4345   bool other_xk = other_type->klass_is_exact();
4346   PTR this_ptr = this_type->ptr();
4347   PTR other_ptr = other_type->ptr();
4348   const TypeInterfaces* this_interfaces = this_type->interfaces();
4349   const TypeInterfaces* other_interfaces = other_type->interfaces();
4350   // Check for easy case; klasses are equal (and perhaps not loaded!)
4351   // If we have constants, then we created oops so classes are loaded
4352   // and we can handle the constants further down.  This case handles
4353   // both-not-loaded or both-loaded classes
4354   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4355     res_klass = this_klass;
4356     res_xk = this_xk;
4357     return QUICK;
4358   }
4359 
4360   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4361   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4362     return UNLOADED;
4363   }

4369   // If both are up and they do NOT subtype, "fall hard".
4370   // If both are down and they subtype, take the supertype class.
4371   // If both are down and they do NOT subtype, "fall hard".
4372   // Constants treated as down.
4373 
4374   // Now, reorder the above list; observe that both-down+subtype is also
4375   // "fall hard"; "fall hard" becomes the default case:
4376   // If we split one up & one down AND they subtype, take the down man.
4377   // If both are up and they subtype, take the subtype class.
4378 
4379   // If both are down and they subtype, "fall hard".
4380   // If both are down and they do NOT subtype, "fall hard".
4381   // If both are up and they do NOT subtype, "fall hard".
4382   // If we split one up & one down AND they do NOT subtype, "fall hard".
4383 
4384   // If a proper subtype is exact, and we return it, we return it exactly.
4385   // If a proper supertype is exact, there can be no subtyping relationship!
4386   // If both types are equal to the subtype, exactness is and-ed below the
4387   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4388 
4389   // Check for subtyping:
4390   const T* subtype = nullptr;
4391   bool subtype_exact = false;
4392   if (this_type->is_same_java_type_as(other_type)) {

4393     subtype = this_type;
4394     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4395   } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4396     subtype = this_type;     // Pick subtyping class
4397     subtype_exact = this_xk;
4398   } else if(!this_xk && other_type->is_meet_subtype_of(this_type)) {
4399     subtype = other_type;    // Pick subtyping class
4400     subtype_exact = other_xk;
4401   }
4402 
4403   if (subtype) {
4404     if (above_centerline(ptr)) { // both are up?

4405       this_type = other_type = subtype;
4406       this_xk = other_xk = subtype_exact;
4407     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4408       this_type = other_type; // tinst is down; keep down man

4409       this_xk = other_xk;
4410     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {

4411       other_type = this_type; // this is down; keep down man
4412       other_xk = this_xk;
4413     } else {

4414       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4415     }
4416   }
4417 
4418   // Check for classes now being equal
4419   if (this_type->is_same_java_type_as(other_type)) {
4420     // If the klasses are equal, the constants may still differ.  Fall to
4421     // NotNull if they do (neither constant is null; that is a special case
4422     // handled elsewhere).
4423     res_klass = this_type->klass();
4424     res_xk = this_xk;
4425     return SUBTYPE;
4426   } // Else classes are not equal
4427 
4428   // Since klasses are different, we require a LCA in the Java
4429   // class hierarchy - which means we have to fall to at least NotNull.
4430   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4431     ptr = NotNull;
4432   }
4433 
4434   interfaces = this_interfaces->intersection_with(other_interfaces);
4435 
4436   // Now we find the LCA of Java classes
4437   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4438 
4439   res_klass = k;
4440   res_xk = false;
4441 
4442   return LCA;
4443 }
4444 


































4445 //------------------------java_mirror_type--------------------------------------
4446 ciType* TypeInstPtr::java_mirror_type() const {
4447   // must be a singleton type
4448   if( const_oop() == nullptr )  return nullptr;
4449 
4450   // must be of type java.lang.Class
4451   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;
4452 
4453   return const_oop()->as_instance()->java_mirror_type();
4454 }
4455 
4456 
4457 //------------------------------xdual------------------------------------------
4458 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4459 // inheritance mechanism.
4460 const Type *TypeInstPtr::xdual() const {
4461   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(), dual_instance_id(), dual_speculative(), dual_inline_depth());

4462 }
4463 
4464 //------------------------------eq---------------------------------------------
4465 // Structural equality check for Type representations
4466 bool TypeInstPtr::eq( const Type *t ) const {
4467   const TypeInstPtr *p = t->is_instptr();
4468   return
4469     klass()->equals(p->klass()) &&

4470     _interfaces->eq(p->_interfaces) &&
4471     TypeOopPtr::eq(p);          // Check sub-type stuff
4472 }
4473 
4474 //------------------------------hash-------------------------------------------
4475 // Type-specific hashing function.
4476 uint TypeInstPtr::hash(void) const {
4477   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash();
4478 }
4479 
4480 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4481   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4482 }
4483 
4484 
4485 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4486   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4487 }
4488 
4489 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4490   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4491 }
4492 
4493 
4494 //------------------------------dump2------------------------------------------
4495 // Dump oop Type
4496 #ifndef PRODUCT
4497 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {

4501   _interfaces->dump(st);
4502 
4503   if (_ptr == Constant && (WizardMode || Verbose)) {
4504     ResourceMark rm;
4505     stringStream ss;
4506 
4507     st->print(" ");
4508     const_oop()->print_oop(&ss);
4509     // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4510     // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4511     char* buf = ss.as_string(/* c_heap= */false);
4512     StringUtils::replace_no_expand(buf, "\n", "");
4513     st->print_raw(buf);
4514   }
4515 
4516   st->print(":%s", ptr_msg[_ptr]);
4517   if (_klass_is_exact) {
4518     st->print(":exact");
4519   }
4520 


4521   dump_offset(st);
4522   dump_instance_id(st);
4523   dump_inline_depth(st);
4524   dump_speculative(st);

4525 }
4526 #endif
4527 







4528 //------------------------------add_offset-------------------------------------
4529 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4530   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset),
4531               _instance_id, add_offset_speculative(offset), _inline_depth);
4532 }
4533 
4534 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4535   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), offset,
4536               _instance_id, with_offset_speculative(offset), _inline_depth);
4537 }
4538 
4539 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4540   if (_speculative == nullptr) {
4541     return this;
4542   }
4543   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4544   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset,
4545               _instance_id, nullptr, _inline_depth);
4546 }
4547 
4548 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4549   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, speculative, _inline_depth);
4550 }
4551 
4552 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4553   if (!UseInlineDepthForSpeculativeTypes) {
4554     return this;
4555   }
4556   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _instance_id, _speculative, depth);
4557 }
4558 
4559 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4560   assert(is_known_instance(), "should be known");
4561   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, instance_id, _speculative, _inline_depth);








4562 }
4563 
4564 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4565   bool xk = klass_is_exact();
4566   ciInstanceKlass* ik = klass()->as_instance_klass();
4567   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4568     if (_interfaces->eq(ik)) {
4569       Compile* C = Compile::current();
4570       Dependencies* deps = C->dependencies();
4571       deps->assert_leaf_type(ik);
4572       xk = true;
4573     }
4574   }
4575   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, 0);

4576 }
4577 
4578 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) {
4579   static_assert(std::is_base_of<T2, T1>::value, "");
4580 
4581   if (!this_one->is_instance_type(other)) {
4582     return false;
4583   }
4584 
4585   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4586     return true;
4587   }
4588 
4589   return this_one->klass()->is_subtype_of(other->klass()) &&
4590          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4591 }
4592 
4593 
4594 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4595   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);

4600   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4601     return true;
4602   }
4603 
4604   if (this_one->is_instance_type(other)) {
4605     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4606   }
4607 
4608   int dummy;
4609   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4610   if (this_top_or_bottom) {
4611     return false;
4612   }
4613 
4614   const T1* other_ary = this_one->is_array_type(other);
4615   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4616   const TypePtr* this_elem = this_one->elem()->make_ptr();
4617   if (other_elem != nullptr && this_elem != nullptr) {
4618     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4619   }
4620 
4621   if (other_elem == nullptr && this_elem == nullptr) {
4622     return this_one->klass()->is_subtype_of(other->klass());
4623   }
4624 
4625   return false;
4626 }
4627 
4628 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4629   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4630 }
4631 
4632 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4633   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
4634 }
4635 
4636 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
4637   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4638 }
4639 
4640 //=============================================================================
4641 // Convenience common pre-built types.
4642 const TypeAryPtr* TypeAryPtr::BOTTOM;
4643 const TypeAryPtr* TypeAryPtr::RANGE;
4644 const TypeAryPtr* TypeAryPtr::OOPS;
4645 const TypeAryPtr* TypeAryPtr::NARROWOOPS;
4646 const TypeAryPtr* TypeAryPtr::BYTES;
4647 const TypeAryPtr* TypeAryPtr::SHORTS;
4648 const TypeAryPtr* TypeAryPtr::CHARS;
4649 const TypeAryPtr* TypeAryPtr::INTS;
4650 const TypeAryPtr* TypeAryPtr::LONGS;
4651 const TypeAryPtr* TypeAryPtr::FLOATS;
4652 const TypeAryPtr* TypeAryPtr::DOUBLES;

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

4739     if (size->is_con()) {
4740       lo = hi;
4741     }
4742     chg = true;
4743   }
4744   // Negative length arrays will produce weird intermediate dead fast-path code
4745   if (lo > hi) {
4746     return TypeInt::ZERO;
4747   }
4748   if (!chg) {
4749     return size;
4750   }
4751   return TypeInt::make(lo, hi, Type::WidenMin);
4752 }
4753 
4754 //-------------------------------cast_to_size----------------------------------
4755 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
4756   assert(new_size != nullptr, "");
4757   new_size = narrow_size_type(new_size);
4758   if (new_size == size())  return this;
4759   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable());
4760   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);










































































































4761 }
4762 
4763 //------------------------------cast_to_stable---------------------------------
4764 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
4765   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
4766     return this;
4767 
4768   const Type* elem = this->elem();
4769   const TypePtr* elem_ptr = elem->make_ptr();
4770 
4771   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
4772     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
4773     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
4774   }
4775 
4776   const TypeAry* new_ary = TypeAry::make(elem, size(), stable);
4777 
4778   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth);
4779 }
4780 
4781 //-----------------------------stable_dimension--------------------------------
4782 int TypeAryPtr::stable_dimension() const {
4783   if (!is_stable())  return 0;
4784   int dim = 1;
4785   const TypePtr* elem_ptr = elem()->make_ptr();
4786   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
4787     dim += elem_ptr->is_aryptr()->stable_dimension();
4788   return dim;
4789 }
4790 
4791 //----------------------cast_to_autobox_cache-----------------------------------
4792 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
4793   if (is_autobox_cache())  return this;
4794   const TypeOopPtr* etype = elem()->make_oopptr();
4795   if (etype == nullptr)  return this;
4796   // The pointers in the autobox arrays are always non-null.
4797   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
4798   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable());
4799   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
4800 }
4801 
4802 //------------------------------eq---------------------------------------------
4803 // Structural equality check for Type representations
4804 bool TypeAryPtr::eq( const Type *t ) const {
4805   const TypeAryPtr *p = t->is_aryptr();
4806   return
4807     _ary == p->_ary &&  // Check array
4808     TypeOopPtr::eq(p);  // Check sub-parts

4809 }
4810 
4811 //------------------------------hash-------------------------------------------
4812 // Type-specific hashing function.
4813 uint TypeAryPtr::hash(void) const {
4814   return (uint)(uintptr_t)_ary + TypeOopPtr::hash();
4815 }
4816 
4817 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4818   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4819 }
4820 
4821 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4822   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
4823 }
4824 
4825 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4826   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
4827 }
4828 //------------------------------meet-------------------------------------------
4829 // Compute the MEET of two types.  It returns a new Type object.
4830 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
4831   // Perform a fast test for common case; meeting the same types together.
4832   if( this == t ) return this;  // Meeting same type-rep?
4833   // Current "this->_base" is Pointer
4834   switch (t->base()) {          // switch on original type

4841   case HalfFloatBot:
4842   case FloatTop:
4843   case FloatCon:
4844   case FloatBot:
4845   case DoubleTop:
4846   case DoubleCon:
4847   case DoubleBot:
4848   case NarrowOop:
4849   case NarrowKlass:
4850   case Bottom:                  // Ye Olde Default
4851     return Type::BOTTOM;
4852   case Top:
4853     return this;
4854 
4855   default:                      // All else is a mistake
4856     typerr(t);
4857 
4858   case OopPtr: {                // Meeting to OopPtrs
4859     // Found a OopPtr type vs self-AryPtr type
4860     const TypeOopPtr *tp = t->is_oopptr();
4861     int offset = meet_offset(tp->offset());
4862     PTR ptr = meet_ptr(tp->ptr());
4863     int depth = meet_inline_depth(tp->inline_depth());
4864     const TypePtr* speculative = xmeet_speculative(tp);
4865     switch (tp->ptr()) {
4866     case TopPTR:
4867     case AnyNull: {
4868       int instance_id = meet_instance_id(InstanceTop);
4869       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4870                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4871     }
4872     case BotPTR:
4873     case NotNull: {
4874       int instance_id = meet_instance_id(tp->instance_id());
4875       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4876     }
4877     default: ShouldNotReachHere();
4878     }
4879   }
4880 
4881   case AnyPtr: {                // Meeting two AnyPtrs
4882     // Found an AnyPtr type vs self-AryPtr type
4883     const TypePtr *tp = t->is_ptr();
4884     int offset = meet_offset(tp->offset());
4885     PTR ptr = meet_ptr(tp->ptr());
4886     const TypePtr* speculative = xmeet_speculative(tp);
4887     int depth = meet_inline_depth(tp->inline_depth());
4888     switch (tp->ptr()) {
4889     case TopPTR:
4890       return this;
4891     case BotPTR:
4892     case NotNull:
4893       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4894     case Null:
4895       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4896       // else fall through to AnyNull
4897     case AnyNull: {
4898       int instance_id = meet_instance_id(InstanceTop);
4899       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4900                   _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4901     }
4902     default: ShouldNotReachHere();
4903     }
4904   }
4905 
4906   case MetadataPtr:
4907   case KlassPtr:
4908   case InstKlassPtr:
4909   case AryKlassPtr:
4910   case RawPtr: return TypePtr::BOTTOM;
4911 
4912   case AryPtr: {                // Meeting 2 references?
4913     const TypeAryPtr *tap = t->is_aryptr();
4914     int off = meet_offset(tap->offset());

4915     const Type* tm = _ary->meet_speculative(tap->_ary);
4916     const TypeAry* tary = tm->isa_ary();
4917     if (tary == nullptr) {
4918       assert(tm == Type::TOP || tm == Type::BOTTOM, "");
4919       return tm;
4920     }
4921     PTR ptr = meet_ptr(tap->ptr());
4922     int instance_id = meet_instance_id(tap->instance_id());
4923     const TypePtr* speculative = xmeet_speculative(tap);
4924     int depth = meet_inline_depth(tap->inline_depth());
4925 
4926     ciKlass* res_klass = nullptr;
4927     bool res_xk = false;




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














4931     }
4932 
4933     ciObject* o = nullptr;             // Assume not constant when done
4934     ciObject* this_oop = const_oop();
4935     ciObject* tap_oop = tap->const_oop();
4936     if (ptr == Constant) {
4937       if (this_oop != nullptr && tap_oop != nullptr &&
4938           this_oop->equals(tap_oop)) {
4939         o = tap_oop;
4940       } else if (above_centerline(_ptr)) {
4941         o = tap_oop;
4942       } else if (above_centerline(tap->_ptr)) {
4943         o = this_oop;
4944       } else {
4945         ptr = NotNull;
4946       }
4947     }
4948     return make(ptr, o, TypeAry::make(elem, tary->_size, tary->_stable), res_klass, res_xk, off, instance_id, speculative, depth);
4949   }
4950 
4951   // All arrays inherit from Object class
4952   case InstPtr: {
4953     const TypeInstPtr *tp = t->is_instptr();
4954     int offset = meet_offset(tp->offset());
4955     PTR ptr = meet_ptr(tp->ptr());
4956     int instance_id = meet_instance_id(tp->instance_id());
4957     const TypePtr* speculative = xmeet_speculative(tp);
4958     int depth = meet_inline_depth(tp->inline_depth());
4959     const TypeInterfaces* interfaces = meet_interfaces(tp);
4960     const TypeInterfaces* tp_interfaces = tp->_interfaces;
4961     const TypeInterfaces* this_interfaces = _interfaces;
4962 
4963     switch (ptr) {
4964     case TopPTR:
4965     case AnyNull:                // Fall 'down' to dual of object klass
4966       // For instances when a subclass meets a superclass we fall
4967       // below the centerline when the superclass is exact. We need to
4968       // do the same here.
4969       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {
4970         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);












4971       } else {
4972         // cannot subclass, so the meet has to fall badly below the centerline
4973         ptr = NotNull;
4974         instance_id = InstanceBot;
4975         interfaces = this_interfaces->intersection_with(tp_interfaces);
4976         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr,offset, instance_id, speculative, depth);

4977       }
4978     case Constant:
4979     case NotNull:
4980     case BotPTR:                // Fall down to object klass
4981       // LCA is object_klass, but if we subclass from the top we can do better
4982       if (above_centerline(tp->ptr())) {
4983         // If 'tp'  is above the centerline and it is Object class
4984         // then we can subclass in the Java class hierarchy.
4985         // For instances when a subclass meets a superclass we fall
4986         // below the centerline when the superclass is exact. We need
4987         // to do the same here.
4988         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) && !tp->klass_is_exact()) {



4989           // that is, my array type is a subtype of 'tp' klass
4990           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
4991                       _ary, _klass, _klass_is_exact, offset, instance_id, speculative, depth);
4992         }
4993       }
4994       // The other case cannot happen, since t cannot be a subtype of an array.
4995       // The meet falls down to Object class below centerline.
4996       if (ptr == Constant) {
4997          ptr = NotNull;
4998       }
4999       if (instance_id > 0) {
5000         instance_id = InstanceBot;
5001       }


5002       interfaces = this_interfaces->intersection_with(tp_interfaces);
5003       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, instance_id, speculative, depth);


5004     default: typerr(t);
5005     }
5006   }
5007   }
5008   return this;                  // Lint noise
5009 }
5010 
5011 
5012 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary,
5013                                                            const T* other_ary, ciKlass*& res_klass, bool& res_xk) {
5014   int dummy;
5015   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5016   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5017   ciKlass* this_klass = this_ary->klass();
5018   ciKlass* other_klass = other_ary->klass();
5019   bool this_xk = this_ary->klass_is_exact();
5020   bool other_xk = other_ary->klass_is_exact();
5021   PTR this_ptr = this_ary->ptr();
5022   PTR other_ptr = other_ary->ptr();









5023   res_klass = nullptr;
5024   MeetResult result = SUBTYPE;






5025   if (elem->isa_int()) {
5026     // Integral array element types have irrelevant lattice relations.
5027     // It is the klass that determines array layout, not the element type.
5028     if (this_top_or_bottom)
5029       res_klass = other_klass;
5030     else if (other_top_or_bottom || other_klass == this_klass) {
5031       res_klass = this_klass;
5032     } else {
5033       // Something like byte[int+] meets char[int+].
5034       // This must fall to bottom, not (int[-128..65535])[int+].
5035       // instance_id = InstanceBot;
5036       elem = Type::BOTTOM;
5037       result = NOT_SUBTYPE;
5038       if (above_centerline(ptr) || ptr == Constant) {
5039         ptr = NotNull;
5040         res_xk = false;
5041         return NOT_SUBTYPE;
5042       }
5043     }
5044   } else {// Non integral arrays.
5045     // Must fall to bottom if exact klasses in upper lattice
5046     // are not equal or super klass is exact.
5047     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5048         // meet with top[] and bottom[] are processed further down:
5049         !this_top_or_bottom && !other_top_or_bottom &&
5050         // both are exact and not equal:

5052          // 'tap'  is exact and super or unrelated:
5053          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5054          // 'this' is exact and super or unrelated:
5055          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5056       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5057         elem = Type::BOTTOM;
5058       }
5059       ptr = NotNull;
5060       res_xk = false;
5061       return NOT_SUBTYPE;
5062     }
5063   }
5064 
5065   res_xk = false;
5066   switch (other_ptr) {
5067     case AnyNull:
5068     case TopPTR:
5069       // Compute new klass on demand, do not use tap->_klass
5070       if (below_centerline(this_ptr)) {
5071         res_xk = this_xk;



5072       } else {
5073         res_xk = (other_xk || this_xk);
5074       }
5075       return result;
5076     case Constant: {
5077       if (this_ptr == Constant) {


5078         res_xk = true;
5079       } else if(above_centerline(this_ptr)) {
5080         res_xk = true;
5081       } else {
5082         // Only precise for identical arrays
5083         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));






5084       }
5085       return result;
5086     }
5087     case NotNull:
5088     case BotPTR:
5089       // Compute new klass on demand, do not use tap->_klass
5090       if (above_centerline(this_ptr)) {
5091         res_xk = other_xk;



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






5095       }
5096       return result;
5097     default:  {
5098       ShouldNotReachHere();
5099       return result;
5100     }
5101   }
5102   return result;
5103 }
5104 
5105 
5106 //------------------------------xdual------------------------------------------
5107 // Dual: compute field-by-field dual
5108 const Type *TypeAryPtr::xdual() const {
5109   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());










5110 }
5111 
5112 //------------------------------dump2------------------------------------------
5113 #ifndef PRODUCT
5114 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5115   st->print("aryptr:");
5116   _ary->dump2(d, depth, st);
5117   _interfaces->dump(st);
5118 
5119   if (_ptr == Constant) {
5120     const_oop()->print(st);
5121   }
5122 
5123   st->print(":%s", ptr_msg[_ptr]);
5124   if (_klass_is_exact) {
5125     st->print(":exact");
5126   }
5127 
5128   if( _offset != 0 ) {






















5129     BasicType basic_elem_type = elem()->basic_type();
5130     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5131     if( _offset == OffsetTop )       st->print("+undefined");
5132     else if( _offset == OffsetBot )  st->print("+any");
5133     else if( _offset < header_size ) st->print("+%d", _offset);
5134     else {
5135       if (basic_elem_type == T_ILLEGAL) {
5136         st->print("+any");
5137       } else {
5138         int elem_size = type2aelembytes(basic_elem_type);
5139         st->print("[%d]", (_offset - header_size)/elem_size);
5140       }
5141     }
5142   }
5143 
5144   dump_instance_id(st);
5145   dump_inline_depth(st);
5146   dump_speculative(st);
5147 }
5148 #endif
5149 
5150 bool TypeAryPtr::empty(void) const {
5151   if (_ary->empty())       return true;




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













5174 }
5175 
5176 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5177   if (!UseInlineDepthForSpeculativeTypes) {
5178     return this;
5179   }
5180   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _instance_id, _speculative, depth);














































5181 }
5182 
5183 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5184   assert(is_known_instance(), "should be known");
5185   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, instance_id, _speculative, _inline_depth);
5186 }
5187 
5188 //=============================================================================
5189 

5190 //------------------------------hash-------------------------------------------
5191 // Type-specific hashing function.
5192 uint TypeNarrowPtr::hash(void) const {
5193   return _ptrtype->hash() + 7;
5194 }
5195 
5196 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5197   return _ptrtype->singleton();
5198 }
5199 
5200 bool TypeNarrowPtr::empty(void) const {
5201   return _ptrtype->empty();
5202 }
5203 
5204 intptr_t TypeNarrowPtr::get_con() const {
5205   return _ptrtype->get_con();
5206 }
5207 
5208 bool TypeNarrowPtr::eq( const Type *t ) const {
5209   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

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

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

5423   case HalfFloatBot:
5424   case FloatTop:
5425   case FloatCon:
5426   case FloatBot:
5427   case DoubleTop:
5428   case DoubleCon:
5429   case DoubleBot:
5430   case NarrowOop:
5431   case NarrowKlass:
5432   case Bottom:                  // Ye Olde Default
5433     return Type::BOTTOM;
5434   case Top:
5435     return this;
5436 
5437   default:                      // All else is a mistake
5438     typerr(t);
5439 
5440   case AnyPtr: {
5441     // Found an AnyPtr type vs self-OopPtr type
5442     const TypePtr *tp = t->is_ptr();
5443     int offset = meet_offset(tp->offset());
5444     PTR ptr = meet_ptr(tp->ptr());
5445     switch (tp->ptr()) {
5446     case Null:
5447       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5448       // else fall through:
5449     case TopPTR:
5450     case AnyNull: {
5451       return make(ptr, _metadata, offset);
5452     }
5453     case BotPTR:
5454     case NotNull:
5455       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5456     default: typerr(t);
5457     }
5458   }
5459 
5460   case RawPtr:
5461   case KlassPtr:
5462   case InstKlassPtr:
5463   case AryKlassPtr:
5464   case OopPtr:
5465   case InstPtr:
5466   case AryPtr:
5467     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
5468 
5469   case MetadataPtr: {
5470     const TypeMetadataPtr *tp = t->is_metadataptr();
5471     int offset = meet_offset(tp->offset());
5472     PTR tptr = tp->ptr();
5473     PTR ptr = meet_ptr(tptr);
5474     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
5475     if (tptr == TopPTR || _ptr == TopPTR ||
5476         metadata()->equals(tp->metadata())) {
5477       return make(ptr, md, offset);
5478     }
5479     // metadata is different
5480     if( ptr == Constant ) {  // Cannot be equal constants, so...
5481       if( tptr == Constant && _ptr != Constant)  return t;
5482       if( _ptr == Constant && tptr != Constant)  return this;
5483       ptr = NotNull;            // Fall down in lattice
5484     }
5485     return make(ptr, nullptr, offset);
5486     break;
5487   }
5488   } // End of switch
5489   return this;                  // Return the double constant
5490 }
5491 

5495 const Type *TypeMetadataPtr::xdual() const {
5496   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
5497 }
5498 
5499 //------------------------------dump2------------------------------------------
5500 #ifndef PRODUCT
5501 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5502   st->print("metadataptr:%s", ptr_msg[_ptr]);
5503   if (metadata() != nullptr) {
5504     st->print(":" INTPTR_FORMAT, p2i(metadata()));
5505   }
5506   dump_offset(st);
5507 }
5508 #endif
5509 
5510 
5511 //=============================================================================
5512 // Convenience common pre-built type.
5513 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
5514 
5515 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset):
5516   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
5517 }
5518 
5519 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
5520   return make(Constant, m, 0);
5521 }
5522 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
5523   return make(Constant, m, 0);
5524 }
5525 
5526 //------------------------------make-------------------------------------------
5527 // Create a meta data constant
5528 const TypeMetadataPtr *TypeMetadataPtr::make(PTR ptr, ciMetadata* m, int offset) {
5529   assert(m == nullptr || !m->is_klass(), "wrong type");
5530   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
5531 }
5532 
5533 
5534 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
5535   const Type* elem = _ary->_elem;
5536   bool xk = klass_is_exact();

5537   if (elem->make_oopptr() != nullptr) {

5538     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
5539     if (elem->is_klassptr()->klass_is_exact()) {
5540       xk = true;









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

5665     TypeKlassPtr::eq(p);
5666 }
5667 
5668 uint TypeInstKlassPtr::hash(void) const {
5669   return klass()->hash() + TypeKlassPtr::hash();
5670 }
5671 
5672 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset) {



5673   TypeInstKlassPtr *r =
5674     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset))->hashcons();
5675 
5676   return r;
5677 }
5678 







5679 //------------------------------add_offset-------------------------------------
5680 // Access internals of klass object
5681 const TypePtr* TypeInstKlassPtr::add_offset( intptr_t offset ) const {
5682   return make( _ptr, klass(), _interfaces, xadd_offset(offset) );
5683 }
5684 
5685 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
5686   return make(_ptr, klass(), _interfaces, offset);
5687 }
5688 
5689 //------------------------------cast_to_ptr_type-------------------------------
5690 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
5691   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
5692   if( ptr == _ptr ) return this;
5693   return make(ptr, _klass, _interfaces, _offset);
5694 }
5695 
5696 
5697 bool TypeInstKlassPtr::must_be_exact() const {
5698   if (!_klass->is_loaded())  return false;
5699   ciInstanceKlass* ik = _klass->as_instance_klass();
5700   if (ik->is_final())  return true;  // cannot clear xk
5701   return false;
5702 }
5703 
5704 //-----------------------------cast_to_exactness-------------------------------
5705 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
5706   if (klass_is_exact == (_ptr == Constant)) return this;
5707   if (must_be_exact()) return this;
5708   ciKlass* k = klass();
5709   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset);

5710 }
5711 
5712 
5713 //-----------------------------as_instance_type--------------------------------
5714 // Corresponding type for an instance of the given class.
5715 // It will be NotNull, and exact if and only if the klass type is exact.
5716 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
5717   ciKlass* k = klass();
5718   bool xk = klass_is_exact();
5719   Compile* C = Compile::current();
5720   Dependencies* deps = C->dependencies();
5721   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5722   // Element is an instance
5723   bool klass_is_exact = false;
5724   const TypeInterfaces* interfaces = _interfaces;

5725   if (k->is_loaded()) {
5726     // Try to set klass_is_exact.
5727     ciInstanceKlass* ik = k->as_instance_klass();
5728     klass_is_exact = ik->is_final();
5729     if (!klass_is_exact && klass_change
5730         && deps != nullptr && UseUniqueSubclasses) {
5731       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5732       if (sub != nullptr) {
5733         if (_interfaces->eq(sub)) {
5734           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5735           k = ik = sub;
5736           xk = sub->is_final();
5737         }
5738       }
5739     }
5740   }
5741   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, 0);


5742 }
5743 
5744 //------------------------------xmeet------------------------------------------
5745 // Compute the MEET of two types, return a new Type object.
5746 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
5747   // Perform a fast test for common case; meeting the same types together.
5748   if( this == t ) return this;  // Meeting same type-rep?
5749 
5750   // Current "this->_base" is Pointer
5751   switch (t->base()) {          // switch on original type
5752 
5753   case Int:                     // Mixing ints & oops happens when javac
5754   case Long:                    // reuses local variables
5755   case HalfFloatTop:
5756   case HalfFloatCon:
5757   case HalfFloatBot:
5758   case FloatTop:
5759   case FloatCon:
5760   case FloatBot:
5761   case DoubleTop:
5762   case DoubleCon:
5763   case DoubleBot:
5764   case NarrowOop:
5765   case NarrowKlass:
5766   case Bottom:                  // Ye Olde Default
5767     return Type::BOTTOM;
5768   case Top:
5769     return this;
5770 
5771   default:                      // All else is a mistake
5772     typerr(t);
5773 
5774   case AnyPtr: {                // Meeting to AnyPtrs
5775     // Found an AnyPtr type vs self-KlassPtr type
5776     const TypePtr *tp = t->is_ptr();
5777     int offset = meet_offset(tp->offset());
5778     PTR ptr = meet_ptr(tp->ptr());
5779     switch (tp->ptr()) {
5780     case TopPTR:
5781       return this;
5782     case Null:
5783       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5784     case AnyNull:
5785       return make( ptr, klass(), _interfaces, offset );
5786     case BotPTR:
5787     case NotNull:
5788       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
5789     default: typerr(t);
5790     }
5791   }
5792 
5793   case RawPtr:
5794   case MetadataPtr:
5795   case OopPtr:
5796   case AryPtr:                  // Meet with AryPtr
5797   case InstPtr:                 // Meet with InstPtr
5798     return TypePtr::BOTTOM;
5799 
5800   //
5801   //             A-top         }
5802   //           /   |   \       }  Tops
5803   //       B-top A-any C-top   }
5804   //          | /  |  \ |      }  Any-nulls
5805   //       B-any   |   C-any   }
5806   //          |    |    |
5807   //       B-con A-con C-con   } constants; not comparable across classes
5808   //          |    |    |
5809   //       B-not   |   C-not   }
5810   //          | \  |  / |      }  not-nulls
5811   //       B-bot A-not C-bot   }
5812   //           \   |   /       }  Bottoms
5813   //             A-bot         }
5814   //
5815 
5816   case InstKlassPtr: {  // Meet two KlassPtr types
5817     const TypeInstKlassPtr *tkls = t->is_instklassptr();
5818     int  off     = meet_offset(tkls->offset());
5819     PTR  ptr     = meet_ptr(tkls->ptr());
5820     const TypeInterfaces* interfaces = meet_interfaces(tkls);
5821 
5822     ciKlass* res_klass = nullptr;
5823     bool res_xk = false;
5824     switch(meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {

5825       case UNLOADED:
5826         ShouldNotReachHere();
5827       case SUBTYPE:
5828       case NOT_SUBTYPE:
5829       case LCA:
5830       case QUICK: {
5831         assert(res_xk == (ptr == Constant), "");
5832         const Type* res = make(ptr, res_klass, interfaces, off);
5833         return res;
5834       }
5835       default:
5836         ShouldNotReachHere();
5837     }
5838   } // End of case KlassPtr
5839   case AryKlassPtr: {                // All arrays inherit from Object class
5840     const TypeAryKlassPtr *tp = t->is_aryklassptr();
5841     int offset = meet_offset(tp->offset());
5842     PTR ptr = meet_ptr(tp->ptr());
5843     const TypeInterfaces* interfaces = meet_interfaces(tp);
5844     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5845     const TypeInterfaces* this_interfaces = _interfaces;
5846 
5847     switch (ptr) {
5848     case TopPTR:
5849     case AnyNull:                // Fall 'down' to dual of object klass
5850       // For instances when a subclass meets a superclass we fall
5851       // below the centerline when the superclass is exact. We need to
5852       // do the same here.
5853       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {
5854         return TypeAryKlassPtr::make(ptr, tp->elem(), tp->klass(), offset);



5855       } else {
5856         // cannot subclass, so the meet has to fall badly below the centerline
5857         ptr = NotNull;
5858         interfaces = _interfaces->intersection_with(tp->_interfaces);
5859         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);

5860       }
5861     case Constant:
5862     case NotNull:
5863     case BotPTR:                // Fall down to object klass
5864       // LCA is object_klass, but if we subclass from the top we can do better
5865       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
5866         // If 'this' (InstPtr) is above the centerline and it is Object class
5867         // then we can subclass in the Java class hierarchy.
5868         // For instances when a subclass meets a superclass we fall
5869         // below the centerline when the superclass is exact. We need
5870         // to do the same here.
5871         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) && !klass_is_exact()) {



5872           // that is, tp's array type is a subtype of my klass
5873           return TypeAryKlassPtr::make(ptr,
5874                                        tp->elem(), tp->klass(), offset);
5875         }
5876       }
5877       // The other case cannot happen, since I cannot be a subtype of an array.
5878       // The meet falls down to Object class below centerline.
5879       if( ptr == Constant )
5880          ptr = NotNull;
5881       interfaces = this_interfaces->intersection_with(tp_interfaces);
5882       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);


5883     default: typerr(t);
5884     }
5885   }
5886 
5887   } // End of switch
5888   return this;                  // Return the double constant
5889 }
5890 
5891 //------------------------------xdual------------------------------------------
5892 // Dual: compute field-by-field dual
5893 const Type    *TypeInstKlassPtr::xdual() const {
5894   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset());
5895 }
5896 
5897 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) {
5898   static_assert(std::is_base_of<T2, T1>::value, "");
5899   if (!this_one->is_loaded() || !other->is_loaded()) {
5900     return false;
5901   }
5902   if (!this_one->is_instance_type(other)) {
5903     return false;
5904   }
5905 
5906   if (!other_exact) {
5907     return false;
5908   }
5909 
5910   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
5911     return true;
5912   }
5913 
5914   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);

5968 
5969   if (this_exact) {
5970     return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
5971   }
5972 
5973   return true;
5974 }
5975 
5976 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
5977   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
5978 }
5979 
5980 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
5981   if (!UseUniqueSubclasses) {
5982     return this;
5983   }
5984   ciKlass* k = klass();
5985   Compile* C = Compile::current();
5986   Dependencies* deps = C->dependencies();
5987   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
5988   const TypeInterfaces* interfaces = _interfaces;
5989   if (k->is_loaded()) {
5990     ciInstanceKlass* ik = k->as_instance_klass();
5991     bool klass_is_exact = ik->is_final();
5992     if (!klass_is_exact &&
5993         deps != nullptr) {
5994       ciInstanceKlass* sub = ik->unique_concrete_subklass();
5995       if (sub != nullptr) {
5996         if (_interfaces->eq(sub)) {


5997           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
5998           k = ik = sub;
5999           klass_is_exact = sub->is_final();
6000           return TypeKlassPtr::make(klass_is_exact ? Constant : _ptr, k, _offset);
6001         }
6002       }
6003     }
6004   }
6005   return this;
6006 }
6007 




6008 #ifndef PRODUCT
6009 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
6010   st->print("instklassptr:");
6011   klass()->print_name_on(st);
6012   _interfaces->dump(st);
6013   st->print(":%s", ptr_msg[_ptr]);
6014   dump_offset(st);

6015 }
6016 #endif // PRODUCT
6017 
6018 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, const Type* elem, ciKlass* k, int offset) {
6019   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset))->hashcons();
6020 }
6021 
6022 const TypeAryKlassPtr *TypeAryKlassPtr::make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling) {













6023   if (k->is_obj_array_klass()) {
6024     // Element is an object array. Recursively call ourself.
6025     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6026     const TypeKlassPtr *etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6027     return TypeAryKlassPtr::make(ptr, etype, nullptr, offset);
6028   } else if (k->is_type_array_klass()) {
6029     // Element is an typeArray
6030     const Type* etype = get_const_basic_type(k->as_type_array_klass()->element_type());
6031     return TypeAryKlassPtr::make(ptr, etype, k, offset);
6032   } else {
6033     ShouldNotReachHere();
6034     return nullptr;
6035   }


6036 }
6037 
6038 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6039   return TypeAryKlassPtr::make(Constant, klass, 0, interface_handling);



























6040 }
6041 
6042 //------------------------------eq---------------------------------------------
6043 // Structural equality check for Type representations
6044 bool TypeAryKlassPtr::eq(const Type *t) const {
6045   const TypeAryKlassPtr *p = t->is_aryklassptr();
6046   return
6047     _elem == p->_elem &&  // Check array






6048     TypeKlassPtr::eq(p);  // Check sub-parts
6049 }
6050 
6051 //------------------------------hash-------------------------------------------
6052 // Type-specific hashing function.
6053 uint TypeAryKlassPtr::hash(void) const {
6054   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash();

6055 }
6056 
6057 //----------------------compute_klass------------------------------------------
6058 // Compute the defining klass for this class
6059 ciKlass* TypeAryPtr::compute_klass() const {
6060   // Compute _klass based on element type.
6061   ciKlass* k_ary = nullptr;
6062   const TypeInstPtr *tinst;
6063   const TypeAryPtr *tary;
6064   const Type* el = elem();
6065   if (el->isa_narrowoop()) {
6066     el = el->make_ptr();
6067   }
6068 
6069   // Get element klass
6070   if ((tinst = el->isa_instptr()) != nullptr) {
6071     // Leave k_ary at null.
6072   } else if ((tary = el->isa_aryptr()) != nullptr) {
6073     // Leave k_ary at null.
6074   } else if ((el->base() == Type::Top) ||
6075              (el->base() == Type::Bottom)) {
6076     // element type of Bottom occurs from meet of basic type
6077     // and object; Top occurs when doing join on Bottom.
6078     // Leave k_ary at null.
6079   } else {
6080     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6081     // Compute array klass directly from basic type
6082     k_ary = ciTypeArrayKlass::make(el->basic_type());
6083   }
6084   return k_ary;
6085 }
6086 
6087 //------------------------------klass------------------------------------------
6088 // Return the defining klass for this class
6089 ciKlass* TypeAryPtr::klass() const {
6090   if( _klass ) return _klass;   // Return cached value, if possible
6091 
6092   // Oops, need to compute _klass and cache it
6093   ciKlass* k_ary = compute_klass();

6101     // type TypeAryPtr::OOPS.  This Type is shared between all
6102     // active compilations.  However, the ciKlass which represents
6103     // this Type is *not* shared between compilations, so caching
6104     // this value would result in fetching a dangling pointer.
6105     //
6106     // Recomputing the underlying ciKlass for each request is
6107     // a bit less efficient than caching, but calls to
6108     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6109     ((TypeAryPtr*)this)->_klass = k_ary;
6110   }
6111   return k_ary;
6112 }
6113 
6114 // Is there a single ciKlass* that can represent that type?
6115 ciKlass* TypeAryPtr::exact_klass_helper() const {
6116   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6117     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6118     if (k == nullptr) {
6119       return nullptr;
6120     }
6121     k = ciObjArrayKlass::make(k);
6122     return k;








6123   }
6124 
6125   return klass();
6126 }
6127 
6128 const Type* TypeAryPtr::base_element_type(int& dims) const {
6129   const Type* elem = this->elem();
6130   dims = 1;
6131   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6132     elem = elem->make_ptr()->is_aryptr()->elem();
6133     dims++;
6134   }
6135   return elem;
6136 }
6137 
6138 //------------------------------add_offset-------------------------------------
6139 // Access internals of klass object
6140 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6141   return make(_ptr, elem(), klass(), xadd_offset(offset));
6142 }
6143 
6144 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6145   return make(_ptr, elem(), klass(), offset);
6146 }
6147 
6148 //------------------------------cast_to_ptr_type-------------------------------
6149 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6150   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6151   if (ptr == _ptr) return this;
6152   return make(ptr, elem(), _klass, _offset);
6153 }
6154 
6155 bool TypeAryKlassPtr::must_be_exact() const {
6156   if (_elem == Type::BOTTOM) return false;
6157   if (_elem == Type::TOP   ) return false;
6158   const TypeKlassPtr*  tk = _elem->isa_klassptr();
6159   if (!tk)             return true;   // a primitive type, like int
6160   return tk->must_be_exact();
6161 }



6162 



6163 
6164 //-----------------------------cast_to_exactness-------------------------------
6165 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6166   if (must_be_exact()) return this;  // cannot clear xk
6167   ciKlass* k = _klass;




6168   const Type* elem = this->elem();
6169   if (elem->isa_klassptr() && !klass_is_exact) {
6170     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6171   }
6172   return make(klass_is_exact ? Constant : NotNull, elem, k, _offset);
6173 }
6174 















6175 
6176 //-----------------------------as_instance_type--------------------------------
6177 // Corresponding type for an instance of the given class.
6178 // It will be NotNull, and exact if and only if the klass type is exact.
6179 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6180   ciKlass* k = klass();
6181   bool    xk = klass_is_exact();
6182   const Type* el = nullptr;
6183   if (elem()->isa_klassptr()) {
6184     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6185     k = nullptr;
6186   } else {
6187     el = elem();
6188   }
6189   return TypeAryPtr::make(TypePtr::BotPTR, TypeAry::make(el, TypeInt::POS), k, xk, 0);




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





6274     assert(res_xk == (ptr == Constant), "");
6275     return make(ptr, elem, res_klass, off);
































6276   } // End of case KlassPtr
6277   case InstKlassPtr: {
6278     const TypeInstKlassPtr *tp = t->is_instklassptr();
6279     int offset = meet_offset(tp->offset());
6280     PTR ptr = meet_ptr(tp->ptr());
6281     const TypeInterfaces* interfaces = meet_interfaces(tp);
6282     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6283     const TypeInterfaces* this_interfaces = _interfaces;
6284 
6285     switch (ptr) {
6286     case TopPTR:
6287     case AnyNull:                // Fall 'down' to dual of object klass
6288       // For instances when a subclass meets a superclass we fall
6289       // below the centerline when the superclass is exact. We need to
6290       // do the same here.


6291       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6292           !tp->klass_is_exact()) {
6293         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset);
6294       } else {
6295         // cannot subclass, so the meet has to fall badly below the centerline
6296         ptr = NotNull;
6297         interfaces = this_interfaces->intersection_with(tp->_interfaces);
6298         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);

6299       }
6300     case Constant:
6301     case NotNull:
6302     case BotPTR:                // Fall down to object klass
6303       // LCA is object_klass, but if we subclass from the top we can do better
6304       if (above_centerline(tp->ptr())) {
6305         // If 'tp'  is above the centerline and it is Object class
6306         // then we can subclass in the Java class hierarchy.
6307         // For instances when a subclass meets a superclass we fall
6308         // below the centerline when the superclass is exact. We need
6309         // to do the same here.


6310         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
6311             !tp->klass_is_exact()) {
6312           // that is, my array type is a subtype of 'tp' klass
6313           return make(ptr, _elem, _klass, offset);
6314         }
6315       }
6316       // The other case cannot happen, since t cannot be a subtype of an array.
6317       // The meet falls down to Object class below centerline.
6318       if (ptr == Constant)
6319          ptr = NotNull;
6320       interfaces = this_interfaces->intersection_with(tp_interfaces);
6321       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset);


6322     default: typerr(t);
6323     }
6324   }
6325 
6326   } // End of switch
6327   return this;                  // Return the double constant
6328 }
6329 
6330 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) {
6331   static_assert(std::is_base_of<T2, T1>::value, "");
6332 
6333   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
6334     return true;
6335   }
6336 
6337   int dummy;
6338   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6339 
6340   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
6341     return false;
6342   }
6343 
6344   if (this_one->is_instance_type(other)) {
6345     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
6346            other_exact;
6347   }
6348 
6349   assert(this_one->is_array_type(other), "");
6350   const T1* other_ary = this_one->is_array_type(other);
6351   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
6352   if (other_top_or_bottom) {
6353     return false;
6354   }
6355 
6356   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6357   const TypePtr* this_elem = this_one->elem()->make_ptr();
6358   if (this_elem != nullptr && other_elem != nullptr) {



6359     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6360   }
6361   if (this_elem == nullptr && other_elem == nullptr) {
6362     return this_one->klass()->is_subtype_of(other->klass());
6363   }
6364   return false;
6365 }
6366 
6367 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6368   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6369 }
6370 
6371 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
6372   static_assert(std::is_base_of<T2, T1>::value, "");
6373 
6374   int dummy;
6375   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
6376 
6377   if (!this_one->is_array_type(other) ||
6378       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

6431   }
6432 
6433   const TypePtr* this_elem = this_one->elem()->make_ptr();
6434   const TypePtr* other_elem = other_ary->elem()->make_ptr();
6435   if (other_elem != nullptr && this_elem != nullptr) {
6436     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
6437   }
6438   if (other_elem == nullptr && this_elem == nullptr) {
6439     return this_one->klass()->is_subtype_of(other->klass());
6440   }
6441   return false;
6442 }
6443 
6444 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6445   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
6446 }
6447 
6448 //------------------------------xdual------------------------------------------
6449 // Dual: compute field-by-field dual
6450 const Type    *TypeAryKlassPtr::xdual() const {
6451   return new TypeAryKlassPtr(dual_ptr(), elem()->dual(), klass(), dual_offset());
6452 }
6453 
6454 // Is there a single ciKlass* that can represent that type?
6455 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
6456   if (elem()->isa_klassptr()) {
6457     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
6458     if (k == nullptr) {
6459       return nullptr;
6460     }
6461     k = ciObjArrayKlass::make(k);

6462     return k;
6463   }
6464 
6465   return klass();
6466 }
6467 
6468 ciKlass* TypeAryKlassPtr::klass() const {
6469   if (_klass != nullptr) {
6470     return _klass;
6471   }
6472   ciKlass* k = nullptr;
6473   if (elem()->isa_klassptr()) {
6474     // leave null
6475   } else if ((elem()->base() == Type::Top) ||
6476              (elem()->base() == Type::Bottom)) {
6477   } else {
6478     k = ciTypeArrayKlass::make(elem()->basic_type());
6479     ((TypeAryKlassPtr*)this)->_klass = k;
6480   }
6481   return k;
6482 }
6483 
6484 //------------------------------dump2------------------------------------------
6485 // Dump Klass Type
6486 #ifndef PRODUCT
6487 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
6488   st->print("aryklassptr:[");
6489   _elem->dump2(d, depth, st);
6490   _interfaces->dump(st);
6491   st->print(":%s", ptr_msg[_ptr]);








6492   dump_offset(st);
6493 }
6494 #endif
6495 
6496 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
6497   const Type* elem = this->elem();
6498   dims = 1;
6499   while (elem->isa_aryklassptr()) {
6500     elem = elem->is_aryklassptr()->elem();
6501     dims++;
6502   }
6503   return elem;
6504 }
6505 
6506 //=============================================================================
6507 // Convenience common pre-built types.
6508 
6509 //------------------------------make-------------------------------------------
6510 const TypeFunc *TypeFunc::make( const TypeTuple *domain, const TypeTuple *range ) {
6511   return (TypeFunc*)(new TypeFunc(domain,range))->hashcons();


6512 }
6513 
6514 //------------------------------make-------------------------------------------
6515 const TypeFunc *TypeFunc::make(ciMethod* method) {

















6516   Compile* C = Compile::current();
6517   const TypeFunc* tf = C->last_tf(method); // check cache
6518   if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
6519   const TypeTuple *domain;
6520   if (method->is_static()) {
6521     domain = TypeTuple::make_domain(nullptr, method->signature(), ignore_interfaces);
6522   } else {
6523     domain = TypeTuple::make_domain(method->holder(), method->signature(), ignore_interfaces);


















6524   }
6525   const TypeTuple *range  = TypeTuple::make_range(method->signature(), ignore_interfaces);
6526   tf = TypeFunc::make(domain, range);
6527   C->set_last_tf(method, tf);  // fill cache
6528   return tf;
6529 }
6530 
6531 //------------------------------meet-------------------------------------------
6532 // Compute the MEET of two types.  It returns a new Type object.
6533 const Type *TypeFunc::xmeet( const Type *t ) const {
6534   // Perform a fast test for common case; meeting the same types together.
6535   if( this == t ) return this;  // Meeting same type-rep?
6536 
6537   // Current "this->_base" is Func
6538   switch (t->base()) {          // switch on original type
6539 
6540   case Bottom:                  // Ye Olde Default
6541     return t;
6542 
6543   default:                      // All else is a mistake
6544     typerr(t);
6545 
6546   case Top:
6547     break;
6548   }
6549   return this;                  // Return the double constant
6550 }
6551 
6552 //------------------------------xdual------------------------------------------
6553 // Dual: compute field-by-field dual
6554 const Type *TypeFunc::xdual() const {
6555   return this;
6556 }
6557 
6558 //------------------------------eq---------------------------------------------
6559 // Structural equality check for Type representations
6560 bool TypeFunc::eq( const Type *t ) const {
6561   const TypeFunc *a = (const TypeFunc*)t;
6562   return _domain == a->_domain &&
6563     _range == a->_range;



6564 }
6565 
6566 //------------------------------hash-------------------------------------------
6567 // Type-specific hashing function.
6568 uint TypeFunc::hash(void) const {
6569   return (uint)(uintptr_t)_domain + (uint)(uintptr_t)_range;
6570 }
6571 
6572 //------------------------------dump2------------------------------------------
6573 // Dump Function Type
6574 #ifndef PRODUCT
6575 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
6576   if( _range->cnt() <= Parms )
6577     st->print("void");
6578   else {
6579     uint i;
6580     for (i = Parms; i < _range->cnt()-1; i++) {
6581       _range->field_at(i)->dump2(d,depth,st);
6582       st->print("/");
6583     }
6584     _range->field_at(i)->dump2(d,depth,st);
6585   }
6586   st->print(" ");
6587   st->print("( ");
6588   if( !depth || d[this] ) {     // Check for recursive dump
6589     st->print("...)");
6590     return;
6591   }
6592   d.Insert((void*)this,(void*)this);    // Stop recursion
6593   if (Parms < _domain->cnt())
6594     _domain->field_at(Parms)->dump2(d,depth-1,st);
6595   for (uint i = Parms+1; i < _domain->cnt(); i++) {
6596     st->print(", ");
6597     _domain->field_at(i)->dump2(d,depth-1,st);
6598   }
6599   st->print(" )");
6600 }
6601 #endif
6602 
6603 //------------------------------singleton--------------------------------------
6604 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6605 // constants (Ldi nodes).  Singletons are integer, float or double constants
6606 // or a single symbol.
6607 bool TypeFunc::singleton(void) const {
6608   return false;                 // Never a singleton
6609 }
6610 
6611 bool TypeFunc::empty(void) const {
6612   return false;                 // Never empty
6613 }
6614 
6615 
6616 BasicType TypeFunc::return_type() const{
6617   if (range()->cnt() == TypeFunc::Parms) {
6618     return T_VOID;
6619   }
6620   return range()->field_at(TypeFunc::Parms)->basic_type();
6621 }

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

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

 363     case T_NARROWOOP: loadbt = T_OBJECT; break;
 364     case T_ARRAY:     loadbt = T_OBJECT; break;
 365     case T_ADDRESS:   loadbt = T_OBJECT; break;
 366     default:                             break;
 367   }
 368   if (conbt == loadbt) {
 369     if (is_unsigned && conbt == T_BYTE) {
 370       // LoadB (T_BYTE) with a small mask (<=8-bit) is converted to LoadUB (T_BYTE).
 371       return ciConstant(T_INT, con.as_int() & 0xFF);
 372     } else {
 373       return con;
 374     }
 375   }
 376   if (conbt == T_SHORT && loadbt == T_CHAR) {
 377     // LoadS (T_SHORT) with a small mask (<=16-bit) is converted to LoadUS (T_CHAR).
 378     return ciConstant(T_INT, con.as_int() & 0xFFFF);
 379   }
 380   return ciConstant(); // T_ILLEGAL
 381 }
 382 
 383 static const Type* make_constant_from_non_flat_array_element(ciArray* array, int off, int stable_dimension,

 384                                                    BasicType loadbt, bool is_unsigned_load) {
 385   // Decode the results of GraphKit::array_element_address.
 386   ciConstant element_value = array->element_value_by_offset(off);
 387   if (element_value.basic_type() == T_ILLEGAL) {
 388     return nullptr; // wrong offset
 389   }
 390   ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
 391 
 392   assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
 393          type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
 394 
 395   if (con.is_valid() &&          // not a mismatched access
 396       !con.is_null_or_zero()) {  // not a default value
 397     bool is_narrow_oop = (loadbt == T_NARROWOOP);
 398     return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
 399   }
 400   return nullptr;
 401 }
 402 
 403 static const Type* make_constant_from_flat_array_element(ciFlatArray* array, int off, int field_offset, int stable_dimension,
 404                                                          BasicType loadbt, bool is_unsigned_load) {
 405   if (!array->is_null_free()) {
 406     ciConstant nm_value = array->null_marker_of_element_by_offset(off);
 407     if (!nm_value.is_valid() || !nm_value.as_boolean()) {
 408       return nullptr;
 409     }
 410   }
 411   ciConstant element_value = array->field_value_by_offset(off + field_offset);
 412   if (element_value.basic_type() == T_ILLEGAL) {
 413     return nullptr; // wrong offset
 414   }
 415   ciConstant con = check_mismatched_access(element_value, loadbt, is_unsigned_load);
 416 
 417   assert(con.basic_type() != T_ILLEGAL, "elembt=%s; loadbt=%s; unsigned=%d",
 418          type2name(element_value.basic_type()), type2name(loadbt), is_unsigned_load);
 419 
 420   if (con.is_valid()) { // not a mismatched access
 421     bool is_narrow_oop = (loadbt == T_NARROWOOP);
 422     return Type::make_from_constant(con, /*require_constant=*/true, stable_dimension, is_narrow_oop, /*is_autobox_cache=*/false);
 423   }
 424   return nullptr;
 425 }
 426 
 427 // Try to constant-fold a stable array element.
 428 const Type* Type::make_constant_from_array_element(ciArray* array, int off, int field_offset, int stable_dimension,
 429                                                    BasicType loadbt, bool is_unsigned_load) {
 430   if (array->is_flat()) {
 431     return make_constant_from_flat_array_element(array->as_flat_array(), off, field_offset, stable_dimension, loadbt, is_unsigned_load);
 432   }
 433   return make_constant_from_non_flat_array_element(array, off, stable_dimension, loadbt, is_unsigned_load);
 434 }
 435 
 436 const Type* Type::make_constant_from_field(ciInstance* holder, int off, bool is_unsigned_load, BasicType loadbt) {
 437   ciField* field;
 438   ciType* type = holder->java_mirror_type();
 439   if (type != nullptr && type->is_instance_klass() && off >= InstanceMirrorKlass::offset_of_static_fields()) {
 440     // Static field
 441     field = type->as_instance_klass()->get_field_by_offset(off, /*is_static=*/true);
 442   } else {
 443     // Instance field
 444     field = holder->klass()->as_instance_klass()->get_field_by_offset(off, /*is_static=*/false);
 445   }
 446   if (field == nullptr) {
 447     return nullptr; // Wrong offset
 448   }
 449   return Type::make_constant_from_field(field, holder, loadbt, is_unsigned_load);
 450 }
 451 
 452 const Type* Type::make_constant_from_field(ciField* field, ciInstance* holder,
 453                                            BasicType loadbt, bool is_unsigned_load) {
 454   if (!field->is_constant()) {
 455     return nullptr; // Non-constant field

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

1050   ~VerifyMeet() {
1051     assert(_C->_type_verify->_depth != 0, "");
1052     _C->_type_verify->_depth--;
1053     if (_C->_type_verify->_depth == 0) {
1054       _C->_type_verify->_cache.trunc_to(0);
1055     }
1056   }
1057 
1058   const Type* meet(const Type* t1, const Type* t2) const {
1059     return _C->_type_verify->meet(t1, t2);
1060   }
1061 
1062   void add(const Type* t1, const Type* t2, const Type* res) const {
1063     _C->_type_verify->add(t1, t2, res);
1064   }
1065 };
1066 
1067 void Type::check_symmetrical(const Type* t, const Type* mt, const VerifyMeet& verify) const {
1068   Compile* C = Compile::current();
1069   const Type* mt2 = verify.meet(t, this);
1070 
1071   // Verify that:
1072   //      this meet t == t meet this
1073   if (mt != mt2) {
1074     tty->print_cr("=== Meet Not Commutative ===");
1075     tty->print("t           = ");   t->dump(); tty->cr();
1076     tty->print("this        = ");      dump(); tty->cr();
1077     tty->print("t meet this = "); mt2->dump(); tty->cr();
1078     tty->print("this meet t = ");  mt->dump(); tty->cr();
1079     fatal("meet not commutative");
1080   }
1081   const Type* dual_join = mt->_dual;
1082   const Type* t2t    = verify.meet(dual_join,t->_dual);
1083   const Type* t2this = verify.meet(dual_join,this->_dual);
1084 
1085   // Interface meet Oop is Not Symmetric:
1086   // Interface:AnyNull meet Oop:AnyNull == Interface:AnyNull
1087   // Interface:NotNull meet Oop:NotNull == java/lang/Object:NotNull
1088 
1089   // Verify that:
1090   // 1)     mt_dual meet t_dual    == t_dual
1091   //    which corresponds to
1092   //       !(t meet this)  meet !t ==
1093   //       (!t join !this) meet !t == !t
1094   // 2)    mt_dual meet this_dual     == this_dual
1095   //    which corresponds to
1096   //       !(t meet this)  meet !this ==
1097   //       (!t join !this) meet !this == !this
1098   if (t2t != t->_dual || t2this != this->_dual) {
1099     tty->print_cr("=== Meet Not Symmetric ===");
1100     tty->print("t   =                   ");              t->dump(); tty->cr();
1101     tty->print("this=                   ");                 dump(); tty->cr();
1102     tty->print("mt=(t meet this)=       ");             mt->dump(); tty->cr();
1103 
1104     tty->print("t_dual=                 ");       t->_dual->dump(); tty->cr();
1105     tty->print("this_dual=              ");          _dual->dump(); tty->cr();
1106     tty->print("mt_dual=                ");      mt->_dual->dump(); tty->cr();
1107 
1108     // 1)
1109     tty->print("mt_dual meet t_dual=    "); t2t           ->dump(); tty->cr();
1110     // 2)
1111     tty->print("mt_dual meet this_dual= "); t2this        ->dump(); tty->cr();
1112     tty->cr();
1113     tty->print_cr("Fail: ");
1114     if (t2t != t->_dual) {
1115       tty->print_cr("- mt_dual meet t_dual != t_dual");
1116     }
1117     if (t2this != this->_dual) {
1118       tty->print_cr("- mt_dual meet this_dual != this_dual");
1119     }
1120     tty->cr();
1121 
1122     fatal("meet not symmetric");
1123   }
1124 }
1125 #endif
1126 
1127 //------------------------------meet-------------------------------------------
1128 // Compute the MEET of two types.  NOT virtual.  It enforces that meet is
1129 // commutative and the lattice is symmetric.
1130 const Type *Type::meet_helper(const Type *t, bool include_speculative) const {
1131   if (isa_narrowoop() && t->isa_narrowoop()) {
1132     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1133     return result->make_narrowoop();
1134   }
1135   if (isa_narrowklass() && t->isa_narrowklass()) {
1136     const Type* result = make_ptr()->meet_helper(t->make_ptr(), include_speculative);
1137     return result->make_narrowklass();
1138   }
1139 
1140 #ifdef ASSERT
1141   Compile* C = Compile::current();
1142   VerifyMeet verify(C);
1143 #endif
1144 
1145   const Type *this_t = maybe_remove_speculative(include_speculative);
1146   t = t->maybe_remove_speculative(include_speculative);
1147 
1148   const Type *mt = this_t->xmeet(t);
1149 #ifdef ASSERT
1150   verify.add(this_t, t, mt);
1151   if (isa_narrowoop() || t->isa_narrowoop()) {
1152     return mt;
1153   }
1154   if (isa_narrowklass() || t->isa_narrowklass()) {
1155     return mt;
1156   }
1157   // TODO 8350865 This currently triggers a verification failure, the code around "// Even though MyValue is final" needs adjustments
1158   if ((this_t->isa_ptr() && this_t->is_ptr()->is_not_flat()) ||
1159       (this_t->_dual->isa_ptr() && this_t->_dual->is_ptr()->is_not_flat())) return mt;
1160   this_t->check_symmetrical(t, mt, verify);
1161   const Type *mt_dual = verify.meet(this_t->_dual, t->_dual);
1162   this_t->_dual->check_symmetrical(t->_dual, mt_dual, verify);
1163 #endif
1164   return mt;
1165 }
1166 
1167 //------------------------------xmeet------------------------------------------
1168 // Compute the MEET of two types.  It returns a new Type object.
1169 const Type *Type::xmeet( const Type *t ) const {
1170   // Perform a fast test for common case; meeting the same types together.
1171   if( this == t ) return this;  // Meeting same type-rep?
1172 
1173   // Meeting TOP with anything?
1174   if( _base == Top ) return t;
1175 
1176   // Meeting BOTTOM with anything?
1177   if( _base == Bottom ) return BOTTOM;
1178 
1179   // Current "this->_base" is one of: Bad, Multi, Control, Top,

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

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

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

2874     int depth = meet_inline_depth(tp->inline_depth());
2875     return make(AnyPtr, meet_ptr(tp->ptr()), meet_offset(tp->offset()), speculative, depth);
2876   }
2877   case RawPtr:                  // For these, flip the call around to cut down
2878   case OopPtr:
2879   case InstPtr:                 // on the cases I have to handle.
2880   case AryPtr:
2881   case MetadataPtr:
2882   case KlassPtr:
2883   case InstKlassPtr:
2884   case AryKlassPtr:
2885     return t->xmeet(this);      // Call in reverse direction
2886   default:                      // All else is a mistake
2887     typerr(t);
2888 
2889   }
2890   return this;
2891 }
2892 
2893 //------------------------------meet_offset------------------------------------
2894 Type::Offset TypePtr::meet_offset(int offset) const {
2895   return _offset.meet(Offset(offset));





2896 }
2897 
2898 //------------------------------dual_offset------------------------------------
2899 Type::Offset TypePtr::dual_offset() const {
2900   return _offset.dual();


2901 }
2902 
2903 //------------------------------xdual------------------------------------------
2904 // Dual: compute field-by-field dual
2905 const TypePtr::PTR TypePtr::ptr_dual[TypePtr::lastPTR] = {
2906   BotPTR, NotNull, Constant, Null, AnyNull, TopPTR
2907 };
2908 
2909 const TypePtr::FlatInArray TypePtr::flat_in_array_dual[Uninitialized] = {
2910   /* TopFlat   -> */ MaybeFlat,
2911   /* Flat      -> */ NotFlat,
2912   /* NotFlat   -> */ Flat,
2913   /* MaybeFlat -> */ TopFlat
2914 };
2915 
2916 const char* const TypePtr::flat_in_array_msg[Uninitialized] = {
2917   "TOP flat in array", "flat in array", "not flat in array", "maybe flat in array"
2918 };
2919 
2920 const Type *TypePtr::xdual() const {
2921   return new TypePtr(AnyPtr, dual_ptr(), dual_offset(), dual_speculative(), dual_inline_depth());
2922 }
2923 
2924 //------------------------------xadd_offset------------------------------------
2925 Type::Offset TypePtr::xadd_offset(intptr_t offset) const {
2926   return _offset.add(offset);











2927 }
2928 
2929 //------------------------------add_offset-------------------------------------
2930 const TypePtr *TypePtr::add_offset( intptr_t offset ) const {
2931   return make(AnyPtr, _ptr, xadd_offset(offset), _speculative, _inline_depth);
2932 }
2933 
2934 const TypePtr *TypePtr::with_offset(intptr_t offset) const {
2935   return make(AnyPtr, _ptr, Offset(offset), _speculative, _inline_depth);
2936 }
2937 
2938 //------------------------------eq---------------------------------------------
2939 // Structural equality check for Type representations
2940 bool TypePtr::eq( const Type *t ) const {
2941   const TypePtr *a = (const TypePtr*)t;
2942   return _ptr == a->ptr() && _offset == a->_offset && eq_speculative(a) && _inline_depth == a->_inline_depth;
2943 }
2944 
2945 //------------------------------hash-------------------------------------------
2946 // Type-specific hashing function.
2947 uint TypePtr::hash(void) const {
2948   return (uint)_ptr + (uint)offset() + (uint)hash_speculative() + (uint)_inline_depth;
2949 }
2950 
2951 /**
2952  * Return same type without a speculative part
2953  */
2954 const TypePtr* TypePtr::remove_speculative() const {
2955   if (_speculative == nullptr) {
2956     return this;
2957   }
2958   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
2959   return make(AnyPtr, _ptr, _offset, nullptr, _inline_depth);
2960 }
2961 
2962 /**
2963  * Return same type but drop speculative part if we know we won't use
2964  * it
2965  */
2966 const Type* TypePtr::cleanup_speculative() const {
2967   if (speculative() == nullptr) {
2968     return this;

3185     return false;
3186   }
3187   // We already know the speculative type cannot be null
3188   if (!speculative_maybe_null()) {
3189     return false;
3190   }
3191   // We already know this is always null
3192   if (this == TypePtr::NULL_PTR) {
3193     return false;
3194   }
3195   // We already know the speculative type is always null
3196   if (speculative_always_null()) {
3197     return false;
3198   }
3199   if (ptr_kind == ProfileAlwaysNull && speculative() != nullptr && speculative()->isa_oopptr()) {
3200     return false;
3201   }
3202   return true;
3203 }
3204 
3205 TypePtr::FlatInArray TypePtr::compute_flat_in_array(ciInstanceKlass* instance_klass, bool is_exact) {
3206   if (!instance_klass->can_be_inline_klass(is_exact)) {
3207     // Definitely not a value class and thus never flat in an array.
3208     return NotFlat;
3209   }
3210   if (instance_klass->is_inlinetype() && instance_klass->as_inline_klass()->is_always_flat_in_array()) {
3211     return Flat;
3212   }
3213   // We don't know.
3214   return MaybeFlat;
3215 }
3216 
3217 // Compute flat in array property if we don't know anything about it (i.e. old_flat_in_array == MaybeFlat).
3218 TypePtr::FlatInArray TypePtr::compute_flat_in_array_if_unknown(ciInstanceKlass* instance_klass, bool is_exact,
3219   FlatInArray old_flat_in_array) {
3220   // It is tempting to add verification code that "NotFlat == no value class" and "Flat == value class".
3221   // However, with type speculation, we could get contradicting flat in array properties that propagate through the
3222   // graph. We could try to stop the introduction of contradicting speculative types in terms of their flat in array
3223   // property. But this is hard because it is sometimes only recognized further down in the graph. Thus, we let an
3224   // inconsistent flat in array property propagating through the graph. This could lead to fold an actual live path
3225   // away. But in this case, the speculated type is wrong and we would trap earlier.
3226   if (old_flat_in_array == MaybeFlat) {
3227       return compute_flat_in_array(instance_klass, is_exact);
3228   }
3229   return old_flat_in_array;
3230 }
3231 
3232 //------------------------------dump2------------------------------------------
3233 const char *const TypePtr::ptr_msg[TypePtr::lastPTR] = {
3234   "TopPTR","AnyNull","Constant","null","NotNull","BotPTR"
3235 };
3236 
3237 #ifndef PRODUCT
3238 void TypePtr::dump2( Dict &d, uint depth, outputStream *st ) const {
3239   st->print("ptr:%s", ptr_msg[_ptr]);
3240   dump_offset(st);
3241   dump_inline_depth(st);
3242   dump_speculative(st);
3243 }
3244 
3245 void TypePtr::dump_offset(outputStream* st) const {
3246   _offset.dump2(st);






3247 }
3248 
3249 /**
3250  *dump the speculative part of the type
3251  */
3252 void TypePtr::dump_speculative(outputStream *st) const {
3253   if (_speculative != nullptr) {
3254     st->print(" (speculative=");
3255     _speculative->dump_on(st);
3256     st->print(")");
3257   }
3258 }
3259 
3260 /**
3261  *dump the inline depth of the type
3262  */
3263 void TypePtr::dump_inline_depth(outputStream *st) const {
3264   if (_inline_depth != InlineDepthBottom) {
3265     if (_inline_depth == InlineDepthTop) {
3266       st->print(" (inline_depth=InlineDepthTop)");
3267     } else {
3268       st->print(" (inline_depth=%d)", _inline_depth);
3269     }
3270   }
3271 }
3272 
3273 void TypePtr::dump_flat_in_array(FlatInArray flat_in_array, outputStream* st) {
3274   switch (flat_in_array) {
3275     case MaybeFlat:
3276     case NotFlat:
3277       if (!Verbose) {
3278         break;
3279       }
3280     case TopFlat:
3281     case Flat:
3282       st->print(" (%s)", flat_in_array_msg[flat_in_array]);
3283       break;
3284     default:
3285       ShouldNotReachHere();
3286   }
3287 }
3288 #endif
3289 
3290 //------------------------------singleton--------------------------------------
3291 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
3292 // constants
3293 bool TypePtr::singleton(void) const {
3294   // TopPTR, Null, AnyNull, Constant are all singletons
3295   return (_offset != Offset::bottom) && !below_centerline(_ptr);
3296 }
3297 
3298 bool TypePtr::empty(void) const {
3299   return (_offset == Offset::top) || above_centerline(_ptr);
3300 }
3301 
3302 //=============================================================================
3303 // Convenience common pre-built types.
3304 const TypeRawPtr *TypeRawPtr::BOTTOM;
3305 const TypeRawPtr *TypeRawPtr::NOTNULL;
3306 
3307 //------------------------------make-------------------------------------------
3308 const TypeRawPtr *TypeRawPtr::make( enum PTR ptr ) {
3309   assert( ptr != Constant, "what is the constant?" );
3310   assert( ptr != Null, "Use TypePtr for null" );
3311   return (TypeRawPtr*)(new TypeRawPtr(ptr,nullptr))->hashcons();
3312 }
3313 
3314 const TypeRawPtr *TypeRawPtr::make(address bits) {
3315   assert(bits != nullptr, "Use TypePtr for null");
3316   return (TypeRawPtr*)(new TypeRawPtr(Constant,bits))->hashcons();
3317 }
3318 
3319 //------------------------------cast_to_ptr_type-------------------------------

3687 #endif
3688 
3689 // Can't be implemented because there's no way to know if the type is above or below the center line.
3690 const Type* TypeInterfaces::xmeet(const Type* t) const {
3691   ShouldNotReachHere();
3692   return Type::xmeet(t);
3693 }
3694 
3695 bool TypeInterfaces::singleton(void) const {
3696   ShouldNotReachHere();
3697   return Type::singleton();
3698 }
3699 
3700 bool TypeInterfaces::has_non_array_interface() const {
3701   assert(TypeAryPtr::_array_interfaces != nullptr, "How come Type::Initialize_shared wasn't called yet?");
3702 
3703   return !TypeAryPtr::_array_interfaces->contains(this);
3704 }
3705 
3706 //------------------------------TypeOopPtr-------------------------------------
3707 TypeOopPtr::TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset,
3708                        int instance_id, const TypePtr* speculative, int inline_depth)
3709   : TypePtr(t, ptr, offset, speculative, inline_depth),
3710     _const_oop(o), _klass(k),
3711     _interfaces(interfaces),
3712     _klass_is_exact(xk),
3713     _is_ptr_to_narrowoop(false),
3714     _is_ptr_to_narrowklass(false),
3715     _is_ptr_to_boxed_value(false),
3716     _is_ptr_to_strict_final_field(false),
3717     _instance_id(instance_id) {
3718 #ifdef ASSERT
3719   if (klass() != nullptr && klass()->is_loaded()) {
3720     interfaces->verify_is_loaded();
3721   }
3722 #endif
3723   if (Compile::current()->eliminate_boxing() && (t == InstPtr) &&
3724       (offset.get() > 0) && xk && (k != nullptr) && k->is_instance_klass()) {
3725     _is_ptr_to_boxed_value = k->as_instance_klass()->is_boxed_value_offset(offset.get());
3726     _is_ptr_to_strict_final_field = _is_ptr_to_boxed_value;
3727   }
3728 
3729   if (klass() != nullptr && klass()->is_instance_klass() && klass()->is_loaded() &&
3730       this->offset() != Type::OffsetBot && this->offset() != Type::OffsetTop) {
3731     ciField* field = klass()->as_instance_klass()->get_field_by_offset(this->offset(), false);
3732     if (field != nullptr && field->is_strict() && field->is_final()) {
3733       _is_ptr_to_strict_final_field = true;
3734     }
3735   }
3736 
3737 #ifdef _LP64
3738   if (this->offset() > 0 || this->offset() == Type::OffsetTop || this->offset() == Type::OffsetBot) {
3739     if (this->offset() == oopDesc::klass_offset_in_bytes()) {
3740       _is_ptr_to_narrowklass = true;
3741     } else if (klass() == nullptr) {
3742       // Array with unknown body type
3743       assert(this->isa_aryptr(), "only arrays without klass");
3744       _is_ptr_to_narrowoop = UseCompressedOops;
3745     } else if (UseCompressedOops && this->isa_aryptr() && this->offset() != arrayOopDesc::length_offset_in_bytes()) {
3746       if (klass()->is_flat_array_klass() && field_offset != Offset::top && field_offset != Offset::bottom) {
3747         // Check if the field of the inline type array element contains oops
3748         ciInlineKlass* vk = klass()->as_flat_array_klass()->element_klass()->as_inline_klass();
3749         int foffset = field_offset.get() + vk->payload_offset();
3750         BasicType field_bt;
3751         ciField* field = vk->get_field_by_offset(foffset, false);
3752         if (field != nullptr) {
3753           field_bt = field->layout_type();
3754         } else {
3755           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);
3756           field_bt = T_BOOLEAN;
3757         }
3758         _is_ptr_to_narrowoop = ::is_reference_type(field_bt);
3759       } else if (klass()->is_obj_array_klass()) {
3760         _is_ptr_to_narrowoop = true;
3761       }
3762     } else if (klass()->is_instance_klass()) {

3763       if (this->isa_klassptr()) {
3764         // Perm objects don't use compressed references
3765       } else if (_offset == Offset::bottom || _offset == Offset::top) {
3766         // unsafe access
3767         _is_ptr_to_narrowoop = UseCompressedOops;
3768       } else {
3769         assert(this->isa_instptr(), "must be an instance ptr.");

3770         if (klass() == ciEnv::current()->Class_klass() &&
3771             (this->offset() == java_lang_Class::klass_offset() ||
3772              this->offset() == java_lang_Class::array_klass_offset())) {
3773           // Special hidden fields from the Class.
3774           assert(this->isa_instptr(), "must be an instance ptr.");
3775           _is_ptr_to_narrowoop = false;
3776         } else if (klass() == ciEnv::current()->Class_klass() &&
3777                    this->offset() >= InstanceMirrorKlass::offset_of_static_fields()) {
3778           // Static fields
3779           BasicType basic_elem_type = T_ILLEGAL;
3780           if (const_oop() != nullptr) {
3781             ciInstanceKlass* k = const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
3782             basic_elem_type = k->get_field_type_by_offset(this->offset(), true);
3783           }
3784           if (basic_elem_type != T_ILLEGAL) {
3785             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3786           } else {
3787             // unsafe access
3788             _is_ptr_to_narrowoop = UseCompressedOops;
3789           }
3790         } else {
3791           // Instance fields which contains a compressed oop references.
3792           ciInstanceKlass* ik = klass()->as_instance_klass();
3793           BasicType basic_elem_type = ik->get_field_type_by_offset(this->offset(), false);
3794           if (basic_elem_type != T_ILLEGAL) {
3795             _is_ptr_to_narrowoop = UseCompressedOops && ::is_reference_type(basic_elem_type);
3796           } else if (klass()->equals(ciEnv::current()->Object_klass())) {
3797             // Compile::find_alias_type() cast exactness on all types to verify
3798             // that it does not affect alias type.
3799             _is_ptr_to_narrowoop = UseCompressedOops;
3800           } else {
3801             // Type for the copy start in LibraryCallKit::inline_native_clone().
3802             _is_ptr_to_narrowoop = UseCompressedOops;
3803           }
3804         }
3805       }
3806     }
3807   }
3808 #endif // _LP64
3809 }
3810 
3811 //------------------------------make-------------------------------------------
3812 const TypeOopPtr *TypeOopPtr::make(PTR ptr, Offset offset, int instance_id,
3813                                    const TypePtr* speculative, int inline_depth) {
3814   assert(ptr != Constant, "no constant generic pointers");
3815   ciKlass*  k = Compile::current()->env()->Object_klass();
3816   bool      xk = false;
3817   ciObject* o = nullptr;
3818   const TypeInterfaces* interfaces = TypeInterfaces::make();
3819   return (TypeOopPtr*)(new TypeOopPtr(OopPtr, ptr, k, interfaces, xk, o, offset, Offset::bottom, instance_id, speculative, inline_depth))->hashcons();
3820 }
3821 
3822 
3823 //------------------------------cast_to_ptr_type-------------------------------
3824 const TypeOopPtr* TypeOopPtr::cast_to_ptr_type(PTR ptr) const {
3825   assert(_base == OopPtr, "subclass must override cast_to_ptr_type");
3826   if( ptr == _ptr ) return this;
3827   return make(ptr, _offset, _instance_id, _speculative, _inline_depth);
3828 }
3829 
3830 //-----------------------------cast_to_instance_id----------------------------
3831 const TypeOopPtr *TypeOopPtr::cast_to_instance_id(int instance_id) const {
3832   // There are no instances of a general oop.
3833   // Return self unchanged.
3834   return this;
3835 }
3836 
3837 //-----------------------------cast_to_exactness-------------------------------
3838 const TypeOopPtr* TypeOopPtr::cast_to_exactness(bool klass_is_exact) const {
3839   // There is no such thing as an exact general oop.
3840   // Return self unchanged.
3841   return this;
3842 }
3843 

3844 //------------------------------as_klass_type----------------------------------
3845 // Return the klass type corresponding to this instance or array type.
3846 // It is the type that is loaded from an object of this type.
3847 const TypeKlassPtr* TypeOopPtr::as_klass_type(bool try_for_exact) const {
3848   ShouldNotReachHere();
3849   return nullptr;
3850 }
3851 
3852 //------------------------------meet-------------------------------------------
3853 // Compute the MEET of two types.  It returns a new Type object.
3854 const Type *TypeOopPtr::xmeet_helper(const Type *t) const {
3855   // Perform a fast test for common case; meeting the same types together.
3856   if( this == t ) return this;  // Meeting same type-rep?
3857 
3858   // Current "this->_base" is OopPtr
3859   switch (t->base()) {          // switch on original type
3860 
3861   case Int:                     // Mixing ints & oops happens when javac
3862   case Long:                    // reuses local variables
3863   case HalfFloatTop:

3872   case NarrowOop:
3873   case NarrowKlass:
3874   case Bottom:                  // Ye Olde Default
3875     return Type::BOTTOM;
3876   case Top:
3877     return this;
3878 
3879   default:                      // All else is a mistake
3880     typerr(t);
3881 
3882   case RawPtr:
3883   case MetadataPtr:
3884   case KlassPtr:
3885   case InstKlassPtr:
3886   case AryKlassPtr:
3887     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
3888 
3889   case AnyPtr: {
3890     // Found an AnyPtr type vs self-OopPtr type
3891     const TypePtr *tp = t->is_ptr();
3892     Offset offset = meet_offset(tp->offset());
3893     PTR ptr = meet_ptr(tp->ptr());
3894     const TypePtr* speculative = xmeet_speculative(tp);
3895     int depth = meet_inline_depth(tp->inline_depth());
3896     switch (tp->ptr()) {
3897     case Null:
3898       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3899       // else fall through:
3900     case TopPTR:
3901     case AnyNull: {
3902       int instance_id = meet_instance_id(InstanceTop);
3903       return make(ptr, offset, instance_id, speculative, depth);
3904     }
3905     case BotPTR:
3906     case NotNull:
3907       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
3908     default: typerr(t);
3909     }
3910   }
3911 
3912   case OopPtr: {                 // Meeting to other OopPtrs

3914     int instance_id = meet_instance_id(tp->instance_id());
3915     const TypePtr* speculative = xmeet_speculative(tp);
3916     int depth = meet_inline_depth(tp->inline_depth());
3917     return make(meet_ptr(tp->ptr()), meet_offset(tp->offset()), instance_id, speculative, depth);
3918   }
3919 
3920   case InstPtr:                  // For these, flip the call around to cut down
3921   case AryPtr:
3922     return t->xmeet(this);      // Call in reverse direction
3923 
3924   } // End of switch
3925   return this;                  // Return the double constant
3926 }
3927 
3928 
3929 //------------------------------xdual------------------------------------------
3930 // Dual of a pure heap pointer.  No relevant klass or oop information.
3931 const Type *TypeOopPtr::xdual() const {
3932   assert(klass() == Compile::current()->env()->Object_klass(), "no klasses here");
3933   assert(const_oop() == nullptr,             "no constants here");
3934   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());
3935 }
3936 
3937 //--------------------------make_from_klass_common-----------------------------
3938 // Computes the element-type given a klass.
3939 const TypeOopPtr* TypeOopPtr::make_from_klass_common(ciKlass *klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling) {
3940   if (klass->is_instance_klass() || klass->is_inlinetype()) {
3941     Compile* C = Compile::current();
3942     Dependencies* deps = C->dependencies();
3943     assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
3944     // Element is an instance
3945     bool klass_is_exact = false;
3946     ciInstanceKlass* ik = klass->as_instance_klass();
3947     if (klass->is_loaded()) {
3948       // Try to set klass_is_exact.

3949       klass_is_exact = ik->is_final();
3950       if (!klass_is_exact && klass_change
3951           && deps != nullptr && UseUniqueSubclasses) {
3952         ciInstanceKlass* sub = ik->unique_concrete_subklass();
3953         if (sub != nullptr) {
3954           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
3955           klass = ik = sub;
3956           klass_is_exact = sub->is_final();
3957         }
3958       }
3959       if (!klass_is_exact && try_for_exact && deps != nullptr &&
3960           !ik->is_interface() && !ik->has_subklass()) {
3961         // Add a dependence; if concrete subclass added we need to recompile
3962         deps->assert_leaf_type(ik);
3963         klass_is_exact = true;
3964       }
3965     }
3966     FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
3967     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
3968     return TypeInstPtr::make(TypePtr::BotPTR, klass, interfaces, klass_is_exact, nullptr, Offset(0), flat_in_array);
3969   } else if (klass->is_obj_array_klass()) {
3970     // Element is an object or inline type array. Recursively call ourself.
3971     ciObjArrayKlass* array_klass = klass->as_obj_array_klass();
3972     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_common(array_klass->element_klass(), /* klass_change= */ false, try_for_exact, interface_handling);
3973     bool xk = array_klass->is_loaded() && array_klass->is_refined();
3974 
3975     // Determine null-free/flat properties
3976     bool flat;
3977     bool not_flat;
3978     bool not_null_free;
3979     bool atomic;
3980     if (xk) {
3981       flat = array_klass->is_flat_array_klass();
3982       not_flat = !flat;
3983       bool is_null_free = array_klass->is_elem_null_free();
3984       not_null_free = !is_null_free;
3985       atomic = array_klass->is_elem_atomic();
3986 
3987       if (is_null_free) {
3988         etype = etype->join_speculative(NOTNULL)->is_oopptr();
3989       }
3990     } else {
3991       const TypeOopPtr* exact_etype = etype;
3992       if (etype->can_be_inline_type()) {
3993         // Use exact type if element can be an inline type
3994         exact_etype = TypeOopPtr::make_from_klass_common(klass->as_array_klass()->element_klass(), /* klass_change= */ true, /* try_for_exact= */ true, interface_handling);
3995       }
3996 
3997       flat = false;
3998       bool not_inline = !exact_etype->can_be_inline_type();
3999       not_null_free = not_inline;
4000       not_flat = !UseArrayFlattening || not_inline || (exact_etype->is_inlinetypeptr() && !exact_etype->inline_klass()->maybe_flat_in_array());
4001       atomic = not_flat;
4002     }
4003 
4004     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS, /* stable= */ false, flat, not_flat, not_null_free, atomic);
4005     // We used to pass NotNull in here, asserting that the sub-arrays
4006     // are all not-null.  This is not true in generally, as code can
4007     // slam nullptrs down in the subarrays.
4008     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, nullptr, xk, Offset(0));
4009     return arr;
4010   } else if (klass->is_type_array_klass()) {
4011     // Element is an typeArray
4012     const Type* etype = get_const_basic_type(klass->as_type_array_klass()->element_type());
4013     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::POS,
4014                                         /* stable= */ false, /* flat= */ false, /* not_flat= */ true, /* not_null_free= */ true, true);
4015     // We used to pass NotNull in here, asserting that the array pointer
4016     // is not-null. That was not true in general.
4017     const TypeAryPtr* arr = TypeAryPtr::make(TypePtr::BotPTR, arr0, klass, true, Offset(0));
4018     return arr;
4019   } else {
4020     ShouldNotReachHere();
4021     return nullptr;
4022   }
4023 }
4024 
4025 //------------------------------make_from_constant-----------------------------
4026 // Make a java pointer from an oop constant
4027 const TypeOopPtr* TypeOopPtr::make_from_constant(ciObject* o, bool require_constant) {
4028   assert(!o->is_null_object(), "null object not yet handled here.");
4029 
4030   const bool make_constant = require_constant || o->should_be_constant();
4031 
4032   ciKlass* klass = o->klass();
4033   if (klass->is_instance_klass() || klass->is_inlinetype()) {
4034     // Element is an instance or inline type
4035     if (make_constant) {
4036       return TypeInstPtr::make(o);
4037     } else {
4038       return TypeInstPtr::make(TypePtr::NotNull, klass, true, nullptr, Offset(0));
4039     }
4040   } else if (klass->is_obj_array_klass()) {
4041     // Element is an object array. Recursively call ourself.
4042     const TypeOopPtr* etype = TypeOopPtr::make_from_klass_raw(klass->as_array_klass()->element_klass(), trust_interfaces);
4043     bool is_flat = o->as_array()->is_flat();
4044     bool is_null_free = o->as_array()->is_null_free();
4045     if (is_null_free) {
4046       etype = etype->join_speculative(TypePtr::NOTNULL)->is_oopptr();
4047     }
4048     bool is_atomic = o->as_array()->is_atomic();
4049     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ is_flat,
4050                                         /* not_flat= */ !is_flat, /* not_null_free= */ !is_null_free, /* atomic= */ is_atomic);
4051     // We used to pass NotNull in here, asserting that the sub-arrays
4052     // are all not-null.  This is not true in generally, as code can
4053     // slam nulls down in the subarrays.
4054     if (make_constant) {
4055       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4056     } else {
4057       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4058     }
4059   } else if (klass->is_type_array_klass()) {
4060     // Element is an typeArray
4061     const Type* etype = (Type*)get_const_basic_type(klass->as_type_array_klass()->element_type());
4062     const TypeAry* arr0 = TypeAry::make(etype, TypeInt::make(o->as_array()->length()), /* stable= */ false, /* flat= */ false,
4063                                         /* not_flat= */ true, /* not_null_free= */ true, true);
4064     // We used to pass NotNull in here, asserting that the array pointer
4065     // is not-null. That was not true in general.
4066     if (make_constant) {
4067       return TypeAryPtr::make(TypePtr::Constant, o, arr0, klass, true, Offset(0));
4068     } else {
4069       return TypeAryPtr::make(TypePtr::NotNull, arr0, klass, true, Offset(0));
4070     }
4071   }
4072 
4073   fatal("unhandled object type");
4074   return nullptr;
4075 }
4076 
4077 //------------------------------get_con----------------------------------------
4078 intptr_t TypeOopPtr::get_con() const {
4079   assert( _ptr == Null || _ptr == Constant, "" );
4080   assert(offset() >= 0, "");
4081 
4082   if (offset() != 0) {
4083     // After being ported to the compiler interface, the compiler no longer
4084     // directly manipulates the addresses of oops.  Rather, it only has a pointer
4085     // to a handle at compile time.  This handle is embedded in the generated
4086     // code and dereferenced at the time the nmethod is made.  Until that time,
4087     // it is not reasonable to do arithmetic with the addresses of oops (we don't
4088     // have access to the addresses!).  This does not seem to currently happen,
4089     // but this assertion here is to help prevent its occurrence.
4090     tty->print_cr("Found oop constant with non-zero offset");
4091     ShouldNotReachHere();
4092   }
4093 
4094   return (intptr_t)const_oop()->constant_encoding();
4095 }
4096 
4097 
4098 //-----------------------------filter------------------------------------------
4099 // Do not allow interface-vs.-noninterface joins to collapse to top.
4100 const Type *TypeOopPtr::filter_helper(const Type *kills, bool include_speculative) const {
4101 
4102   const Type* ft = join_helper(kills, include_speculative);

4148   dump_speculative(st);
4149 }
4150 
4151 void TypeOopPtr::dump_instance_id(outputStream* st) const {
4152   if (_instance_id == InstanceTop) {
4153     st->print(",iid=top");
4154   } else if (_instance_id == InstanceBot) {
4155     st->print(",iid=bot");
4156   } else {
4157     st->print(",iid=%d", _instance_id);
4158   }
4159 }
4160 #endif
4161 
4162 //------------------------------singleton--------------------------------------
4163 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
4164 // constants
4165 bool TypeOopPtr::singleton(void) const {
4166   // detune optimizer to not generate constant oop + constant offset as a constant!
4167   // TopPTR, Null, AnyNull, Constant are all singletons
4168   return (offset() == 0) && !below_centerline(_ptr);
4169 }
4170 
4171 //------------------------------add_offset-------------------------------------
4172 const TypePtr* TypeOopPtr::add_offset(intptr_t offset) const {
4173   return make(_ptr, xadd_offset(offset), _instance_id, add_offset_speculative(offset), _inline_depth);
4174 }
4175 
4176 const TypeOopPtr* TypeOopPtr::with_offset(intptr_t offset) const {
4177   return make(_ptr, Offset(offset), _instance_id, with_offset_speculative(offset), _inline_depth);
4178 }
4179 
4180 /**
4181  * Return same type without a speculative part
4182  */
4183 const TypeOopPtr* TypeOopPtr::remove_speculative() const {
4184   if (_speculative == nullptr) {
4185     return this;
4186   }
4187   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4188   return make(_ptr, _offset, _instance_id, nullptr, _inline_depth);
4189 }
4190 
4191 /**
4192  * Return same type but drop speculative part if we know we won't use
4193  * it
4194  */
4195 const Type* TypeOopPtr::cleanup_speculative() const {
4196   // If the klass is exact and the ptr is not null then there's
4197   // nothing that the speculative type can help us with

4270 const TypeInstPtr *TypeInstPtr::BOTTOM;
4271 const TypeInstPtr *TypeInstPtr::MIRROR;
4272 const TypeInstPtr *TypeInstPtr::MARK;
4273 const TypeInstPtr *TypeInstPtr::KLASS;
4274 
4275 // Is there a single ciKlass* that can represent that type?
4276 ciKlass* TypeInstPtr::exact_klass_helper() const {
4277   if (_interfaces->empty()) {
4278     return _klass;
4279   }
4280   if (_klass != ciEnv::current()->Object_klass()) {
4281     if (_interfaces->eq(_klass->as_instance_klass())) {
4282       return _klass;
4283     }
4284     return nullptr;
4285   }
4286   return _interfaces->exact_klass();
4287 }
4288 
4289 //------------------------------TypeInstPtr-------------------------------------
4290 TypeInstPtr::TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset off,
4291                          FlatInArray flat_in_array, int instance_id, const TypePtr* speculative, int inline_depth)
4292   : TypeOopPtr(InstPtr, ptr, k, interfaces, xk, o, off, Offset::bottom, instance_id, speculative, inline_depth),
4293     _flat_in_array(flat_in_array) {
4294 
4295   assert(flat_in_array != Uninitialized, "must be set now");
4296   assert(k == nullptr || !k->is_loaded() || !k->is_interface(), "no interface here");
4297   assert(k != nullptr &&
4298          (k->is_loaded() || o == nullptr),
4299          "cannot have constants with non-loaded klass");
4300 };
4301 
4302 //------------------------------make-------------------------------------------
4303 const TypeInstPtr *TypeInstPtr::make(PTR ptr,
4304                                      ciKlass* k,
4305                                      const TypeInterfaces* interfaces,
4306                                      bool xk,
4307                                      ciObject* o,
4308                                      Offset offset,
4309                                      FlatInArray flat_in_array,
4310                                      int instance_id,
4311                                      const TypePtr* speculative,
4312                                      int inline_depth) {
4313   assert( !k->is_loaded() || k->is_instance_klass(), "Must be for instance");
4314   // Either const_oop() is null or else ptr is Constant
4315   assert( (!o && ptr != Constant) || (o && ptr == Constant),
4316           "constant pointers must have a value supplied" );
4317   // Ptr is never Null
4318   assert( ptr != Null, "null pointers are not typed" );
4319 
4320   assert(instance_id <= 0 || xk, "instances are always exactly typed");
4321   ciInstanceKlass* ik = k->as_instance_klass();
4322   if (ptr == Constant) {
4323     // Note:  This case includes meta-object constants, such as methods.
4324     xk = true;
4325   } else if (k->is_loaded()) {

4326     if (!xk && ik->is_final())     xk = true;   // no inexact final klass
4327     assert(!ik->is_interface(), "no interface here");
4328     if (xk && ik->is_interface())  xk = false;  // no exact interface
4329   }
4330 
4331   if (flat_in_array == Uninitialized) {
4332     flat_in_array = compute_flat_in_array(ik, xk);
4333   }
4334   // Now hash this baby
4335   TypeInstPtr *result =
4336     (TypeInstPtr*)(new TypeInstPtr(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id, speculative, inline_depth))->hashcons();
4337 
4338   return result;
4339 }
4340 
4341 const TypeInterfaces* TypePtr::interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling) {
4342   if (k->is_instance_klass()) {
4343     if (k->is_loaded()) {
4344       if (k->is_interface() && interface_handling == ignore_interfaces) {
4345         assert(interface, "no interface expected");
4346         k = ciEnv::current()->Object_klass();
4347         const TypeInterfaces* interfaces = TypeInterfaces::make();
4348         return interfaces;
4349       }
4350       GrowableArray<ciInstanceKlass *>* k_interfaces = k->as_instance_klass()->transitive_interfaces();
4351       const TypeInterfaces* interfaces = TypeInterfaces::make(k_interfaces);
4352       if (k->is_interface()) {
4353         assert(interface, "no interface expected");
4354         k = ciEnv::current()->Object_klass();
4355       } else {
4356         assert(klass, "no instance klass expected");

4382   switch (bt) {
4383     case T_BOOLEAN:  return TypeInt::make(constant.as_boolean());
4384     case T_INT:      return TypeInt::make(constant.as_int());
4385     case T_CHAR:     return TypeInt::make(constant.as_char());
4386     case T_BYTE:     return TypeInt::make(constant.as_byte());
4387     case T_SHORT:    return TypeInt::make(constant.as_short());
4388     case T_FLOAT:    return TypeF::make(constant.as_float());
4389     case T_DOUBLE:   return TypeD::make(constant.as_double());
4390     case T_LONG:     return TypeLong::make(constant.as_long());
4391     default:         break;
4392   }
4393   fatal("Invalid boxed value type '%s'", type2name(bt));
4394   return nullptr;
4395 }
4396 
4397 //------------------------------cast_to_ptr_type-------------------------------
4398 const TypeInstPtr* TypeInstPtr::cast_to_ptr_type(PTR ptr) const {
4399   if( ptr == _ptr ) return this;
4400   // Reconstruct _sig info here since not a problem with later lazy
4401   // construction, _sig will show up on demand.
4402   return make(ptr, klass(), _interfaces, klass_is_exact(), ptr == Constant ? const_oop() : nullptr, _offset, _flat_in_array, _instance_id, _speculative, _inline_depth);
4403 }
4404 
4405 
4406 //-----------------------------cast_to_exactness-------------------------------
4407 const TypeInstPtr* TypeInstPtr::cast_to_exactness(bool klass_is_exact) const {
4408   if( klass_is_exact == _klass_is_exact ) return this;
4409   if (!_klass->is_loaded())  return this;
4410   ciInstanceKlass* ik = _klass->as_instance_klass();
4411   if( (ik->is_final() || _const_oop) )  return this;  // cannot clear xk
4412   assert(!ik->is_interface(), "no interface here");
4413   FlatInArray flat_in_array = compute_flat_in_array(ik, klass_is_exact);
4414   return make(ptr(), klass(), _interfaces, klass_is_exact, const_oop(), _offset, flat_in_array, _instance_id, _speculative, _inline_depth);
4415 }
4416 
4417 //-----------------------------cast_to_instance_id----------------------------
4418 const TypeInstPtr* TypeInstPtr::cast_to_instance_id(int instance_id) const {
4419   if( instance_id == _instance_id ) return this;
4420   return make(_ptr, klass(), _interfaces, _klass_is_exact, const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4421 }
4422 
4423 //------------------------------xmeet_unloaded---------------------------------
4424 // Compute the MEET of two InstPtrs when at least one is unloaded.
4425 // Assume classes are different since called after check for same name/class-loader
4426 const TypeInstPtr *TypeInstPtr::xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const {
4427   Offset off = meet_offset(tinst->offset());
4428   PTR ptr = meet_ptr(tinst->ptr());
4429   int instance_id = meet_instance_id(tinst->instance_id());
4430   const TypePtr* speculative = xmeet_speculative(tinst);
4431   int depth = meet_inline_depth(tinst->inline_depth());
4432 
4433   const TypeInstPtr *loaded    = is_loaded() ? this  : tinst;
4434   const TypeInstPtr *unloaded  = is_loaded() ? tinst : this;
4435   if( loaded->klass()->equals(ciEnv::current()->Object_klass()) ) {
4436     //
4437     // Meet unloaded class with java/lang/Object
4438     //
4439     // Meet
4440     //          |                     Unloaded Class
4441     //  Object  |   TOP    |   AnyNull | Constant |   NotNull |  BOTTOM   |
4442     //  ===================================================================
4443     //   TOP    | ..........................Unloaded......................|
4444     //  AnyNull |  U-AN    |................Unloaded......................|
4445     // Constant | ... O-NN .................................. |   O-BOT   |
4446     //  NotNull | ... O-NN .................................. |   O-BOT   |
4447     //  BOTTOM  | ........................Object-BOTTOM ..................|
4448     //
4449     assert(loaded->ptr() != TypePtr::Null, "insanity check");
4450     //
4451     if (loaded->ptr() == TypePtr::TopPTR)        { return unloaded->with_speculative(speculative); }
4452     else if (loaded->ptr() == TypePtr::AnyNull)  {
4453       FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4454       return make(ptr, unloaded->klass(), interfaces, false, nullptr, off, flat_in_array, instance_id,
4455                   speculative, depth);
4456     }
4457     else if (loaded->ptr() == TypePtr::BotPTR)   { return TypeInstPtr::BOTTOM->with_speculative(speculative); }
4458     else if (loaded->ptr() == TypePtr::Constant || loaded->ptr() == TypePtr::NotNull) {
4459       if (unloaded->ptr() == TypePtr::BotPTR)    { return TypeInstPtr::BOTTOM->with_speculative(speculative);  }
4460       else                                       { return TypeInstPtr::NOTNULL->with_speculative(speculative); }
4461     }
4462     else if (unloaded->ptr() == TypePtr::TopPTR) { return unloaded->with_speculative(speculative); }
4463 
4464     return unloaded->cast_to_ptr_type(TypePtr::AnyNull)->is_instptr()->with_speculative(speculative);
4465   }
4466 
4467   // Both are unloaded, not the same class, not Object
4468   // Or meet unloaded with a different loaded class, not java/lang/Object
4469   if (ptr != TypePtr::BotPTR) {
4470     return TypeInstPtr::NOTNULL->with_speculative(speculative);
4471   }
4472   return TypeInstPtr::BOTTOM->with_speculative(speculative);
4473 }
4474 
4475 
4476 //------------------------------meet-------------------------------------------

4500   case Top:
4501     return this;
4502 
4503   default:                      // All else is a mistake
4504     typerr(t);
4505 
4506   case MetadataPtr:
4507   case KlassPtr:
4508   case InstKlassPtr:
4509   case AryKlassPtr:
4510   case RawPtr: return TypePtr::BOTTOM;
4511 
4512   case AryPtr: {                // All arrays inherit from Object class
4513     // Call in reverse direction to avoid duplication
4514     return t->is_aryptr()->xmeet_helper(this);
4515   }
4516 
4517   case OopPtr: {                // Meeting to OopPtrs
4518     // Found a OopPtr type vs self-InstPtr type
4519     const TypeOopPtr *tp = t->is_oopptr();
4520     Offset offset = meet_offset(tp->offset());
4521     PTR ptr = meet_ptr(tp->ptr());
4522     switch (tp->ptr()) {
4523     case TopPTR:
4524     case AnyNull: {
4525       int instance_id = meet_instance_id(InstanceTop);
4526       const TypePtr* speculative = xmeet_speculative(tp);
4527       int depth = meet_inline_depth(tp->inline_depth());
4528       return make(ptr, klass(), _interfaces, klass_is_exact(),
4529                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4530     }
4531     case NotNull:
4532     case BotPTR: {
4533       int instance_id = meet_instance_id(tp->instance_id());
4534       const TypePtr* speculative = xmeet_speculative(tp);
4535       int depth = meet_inline_depth(tp->inline_depth());
4536       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
4537     }
4538     default: typerr(t);
4539     }
4540   }
4541 
4542   case AnyPtr: {                // Meeting to AnyPtrs
4543     // Found an AnyPtr type vs self-InstPtr type
4544     const TypePtr *tp = t->is_ptr();
4545     Offset offset = meet_offset(tp->offset());
4546     PTR ptr = meet_ptr(tp->ptr());
4547     int instance_id = meet_instance_id(InstanceTop);
4548     const TypePtr* speculative = xmeet_speculative(tp);
4549     int depth = meet_inline_depth(tp->inline_depth());
4550     switch (tp->ptr()) {
4551     case Null:
4552       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
4553       // else fall through to AnyNull
4554     case TopPTR:
4555     case AnyNull: {
4556       return make(ptr, klass(), _interfaces, klass_is_exact(),
4557                   (ptr == Constant ? const_oop() : nullptr), offset, flat_in_array(), instance_id, speculative, depth);
4558     }
4559     case NotNull:
4560     case BotPTR:
4561       return TypePtr::make(AnyPtr, ptr, offset, speculative,depth);
4562     default: typerr(t);
4563     }
4564   }
4565 
4566   /*
4567                  A-top         }
4568                /   |   \       }  Tops
4569            B-top A-any C-top   }
4570               | /  |  \ |      }  Any-nulls
4571            B-any   |   C-any   }
4572               |    |    |
4573            B-con A-con C-con   } constants; not comparable across classes
4574               |    |    |
4575            B-not   |   C-not   }
4576               | \  |  / |      }  not-nulls
4577            B-bot A-not C-bot   }
4578                \   |   /       }  Bottoms
4579                  A-bot         }
4580   */
4581 
4582   case InstPtr: {                // Meeting 2 Oops?
4583     // Found an InstPtr sub-type vs self-InstPtr type
4584     const TypeInstPtr *tinst = t->is_instptr();
4585     Offset off = meet_offset(tinst->offset());
4586     PTR ptr = meet_ptr(tinst->ptr());
4587     int instance_id = meet_instance_id(tinst->instance_id());
4588     const TypePtr* speculative = xmeet_speculative(tinst);
4589     int depth = meet_inline_depth(tinst->inline_depth());
4590     const TypeInterfaces* interfaces = meet_interfaces(tinst);
4591 
4592     ciKlass* tinst_klass = tinst->klass();
4593     ciKlass* this_klass  = klass();
4594 
4595     ciKlass* res_klass = nullptr;
4596     bool res_xk = false;
4597     const Type* res;
4598     MeetResult kind = meet_instptr(ptr, interfaces, this, tinst, res_klass, res_xk);
4599 
4600     if (kind == UNLOADED) {
4601       // One of these classes has not been loaded
4602       const TypeInstPtr* unloaded_meet = xmeet_unloaded(tinst, interfaces);
4603 #ifndef PRODUCT
4604       if (PrintOpto && Verbose) {
4605         tty->print("meet of unloaded classes resulted in: ");
4606         unloaded_meet->dump();
4607         tty->cr();
4608         tty->print("  this == ");
4609         dump();
4610         tty->cr();
4611         tty->print(" tinst == ");
4612         tinst->dump();
4613         tty->cr();
4614       }
4615 #endif
4616       res = unloaded_meet;
4617     } else {
4618       FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tinst->flat_in_array());
4619       if (kind == NOT_SUBTYPE && instance_id > 0) {
4620         instance_id = InstanceBot;
4621       } else if (kind == LCA) {
4622         instance_id = InstanceBot;
4623       }
4624       ciObject* o = nullptr;             // Assume not constant when done
4625       ciObject* this_oop = const_oop();
4626       ciObject* tinst_oop = tinst->const_oop();
4627       if (ptr == Constant) {
4628         if (this_oop != nullptr && tinst_oop != nullptr &&
4629             this_oop->equals(tinst_oop))
4630           o = this_oop;
4631         else if (above_centerline(_ptr)) {
4632           assert(!tinst_klass->is_interface(), "");
4633           o = tinst_oop;
4634         } else if (above_centerline(tinst->_ptr)) {
4635           assert(!this_klass->is_interface(), "");
4636           o = this_oop;
4637         } else
4638           ptr = NotNull;
4639       }
4640       res = make(ptr, res_klass, interfaces, res_xk, o, off, flat_in_array, instance_id, speculative, depth);
4641     }
4642 
4643     return res;
4644 
4645   } // End of case InstPtr
4646 
4647   } // End of switch
4648   return this;                  // Return the double constant
4649 }
4650 
4651 template<class T> TypePtr::MeetResult TypePtr::meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type, const T* other_type,
4652                                                             ciKlass*& res_klass, bool& res_xk) {
4653   ciKlass* this_klass = this_type->klass();
4654   ciKlass* other_klass = other_type->klass();
4655 
4656   bool this_xk = this_type->klass_is_exact();
4657   bool other_xk = other_type->klass_is_exact();
4658   PTR this_ptr = this_type->ptr();
4659   PTR other_ptr = other_type->ptr();
4660   const TypeInterfaces* this_interfaces = this_type->interfaces();
4661   const TypeInterfaces* other_interfaces = other_type->interfaces();
4662   // Check for easy case; klasses are equal (and perhaps not loaded!)
4663   // If we have constants, then we created oops so classes are loaded
4664   // and we can handle the constants further down.  This case handles
4665   // both-not-loaded or both-loaded classes
4666   if (ptr != Constant && this_klass->equals(other_klass) && this_xk == other_xk) {
4667     res_klass = this_klass;
4668     res_xk = this_xk;
4669     return QUICK;
4670   }
4671 
4672   // Classes require inspection in the Java klass hierarchy.  Must be loaded.
4673   if (!other_klass->is_loaded() || !this_klass->is_loaded()) {
4674     return UNLOADED;
4675   }

4681   // If both are up and they do NOT subtype, "fall hard".
4682   // If both are down and they subtype, take the supertype class.
4683   // If both are down and they do NOT subtype, "fall hard".
4684   // Constants treated as down.
4685 
4686   // Now, reorder the above list; observe that both-down+subtype is also
4687   // "fall hard"; "fall hard" becomes the default case:
4688   // If we split one up & one down AND they subtype, take the down man.
4689   // If both are up and they subtype, take the subtype class.
4690 
4691   // If both are down and they subtype, "fall hard".
4692   // If both are down and they do NOT subtype, "fall hard".
4693   // If both are up and they do NOT subtype, "fall hard".
4694   // If we split one up & one down AND they do NOT subtype, "fall hard".
4695 
4696   // If a proper subtype is exact, and we return it, we return it exactly.
4697   // If a proper supertype is exact, there can be no subtyping relationship!
4698   // If both types are equal to the subtype, exactness is and-ed below the
4699   // centerline and or-ed above it.  (N.B. Constants are always exact.)
4700 

4701   const T* subtype = nullptr;
4702   bool subtype_exact = false;
4703   if (this_type->is_same_java_type_as(other_type)) {
4704     // Same klass
4705     subtype = this_type;
4706     subtype_exact = below_centerline(ptr) ? (this_xk && other_xk) : (this_xk || other_xk);
4707   } else if (!other_xk && this_type->is_meet_subtype_of(other_type)) {
4708     subtype = this_type;     // Pick subtyping class
4709     subtype_exact = this_xk;
4710   } else if (!this_xk && other_type->is_meet_subtype_of(this_type)) {
4711     subtype = other_type;    // Pick subtyping class
4712     subtype_exact = other_xk;
4713   }
4714 
4715   if (subtype != nullptr) {
4716     if (above_centerline(ptr)) {
4717       // Both types are empty.
4718       this_type = other_type = subtype;
4719       this_xk = other_xk = subtype_exact;
4720     } else if (above_centerline(this_ptr) && !above_centerline(other_ptr)) {
4721       // this_type is empty while other_type is not. Take other_type.
4722       this_type = other_type;
4723       this_xk = other_xk;
4724     } else if (above_centerline(other_ptr) && !above_centerline(this_ptr)) {
4725       // other_type is empty while this_type is not. Take this_type.
4726       other_type = this_type; // this is down; keep down man

4727     } else {
4728       // this_type and other_type are both non-empty.
4729       this_xk = subtype_exact;  // either they are equal, or we'll do an LCA
4730     }
4731   }
4732 
4733   // Check for classes now being equal
4734   if (this_type->is_same_java_type_as(other_type)) {
4735     // If the klasses are equal, the constants may still differ.  Fall to
4736     // NotNull if they do (neither constant is null; that is a special case
4737     // handled elsewhere).
4738     res_klass = this_type->klass();
4739     res_xk = this_xk;
4740     return SUBTYPE;
4741   } // Else classes are not equal
4742 
4743   // Since klasses are different, we require a LCA in the Java
4744   // class hierarchy - which means we have to fall to at least NotNull.
4745   if (ptr == TopPTR || ptr == AnyNull || ptr == Constant) {
4746     ptr = NotNull;
4747   }
4748 
4749   interfaces = this_interfaces->intersection_with(other_interfaces);
4750 
4751   // Now we find the LCA of Java classes
4752   ciKlass* k = this_klass->least_common_ancestor(other_klass);
4753 
4754   res_klass = k;
4755   res_xk = false;

4756   return LCA;
4757 }
4758 
4759 //                Top-Flat    Flat        Not-Flat    Maybe-Flat
4760 // -------------------------------------------------------------
4761 //    Top-Flat    Top-Flat    Flat        Not-Flat    Maybe-Flat
4762 //        Flat    Flat        Flat        Maybe-Flat  Maybe-Flat
4763 //    Not-Flat    Not-Flat    Maybe-Flat  Not-Flat    Maybe-Flat
4764 //  Maybe-Flat    Maybe-Flat  Maybe-Flat  Maybe-Flat  Maybe-flat
4765 TypePtr::FlatInArray TypePtr::meet_flat_in_array(const FlatInArray left, const FlatInArray right) {
4766   if (left == TopFlat) {
4767     return right;
4768   }
4769   if (right == TopFlat) {
4770     return left;
4771   }
4772   if (left == MaybeFlat || right == MaybeFlat) {
4773     return MaybeFlat;
4774   }
4775 
4776   switch (left) {
4777     case Flat:
4778       if (right == Flat) {
4779         return Flat;
4780       }
4781       return MaybeFlat;
4782     case NotFlat:
4783       if (right == NotFlat) {
4784         return NotFlat;
4785       }
4786       return MaybeFlat;
4787     default:
4788       ShouldNotReachHere();
4789       return Uninitialized;
4790   }
4791 }
4792 
4793 //------------------------java_mirror_type--------------------------------------
4794 ciType* TypeInstPtr::java_mirror_type() const {
4795   // must be a singleton type
4796   if( const_oop() == nullptr )  return nullptr;
4797 
4798   // must be of type java.lang.Class
4799   if( klass() != ciEnv::current()->Class_klass() )  return nullptr;

4800   return const_oop()->as_instance()->java_mirror_type();
4801 }
4802 
4803 
4804 //------------------------------xdual------------------------------------------
4805 // Dual: do NOT dual on klasses.  This means I do NOT understand the Java
4806 // inheritance mechanism.
4807 const Type* TypeInstPtr::xdual() const {
4808   return new TypeInstPtr(dual_ptr(), klass(), _interfaces, klass_is_exact(), const_oop(), dual_offset(),
4809                          dual_flat_in_array(), dual_instance_id(), dual_speculative(), dual_inline_depth());
4810 }
4811 
4812 //------------------------------eq---------------------------------------------
4813 // Structural equality check for Type representations
4814 bool TypeInstPtr::eq( const Type *t ) const {
4815   const TypeInstPtr *p = t->is_instptr();
4816   return
4817     klass()->equals(p->klass()) &&
4818     _flat_in_array == p->_flat_in_array &&
4819     _interfaces->eq(p->_interfaces) &&
4820     TypeOopPtr::eq(p);          // Check sub-type stuff
4821 }
4822 
4823 //------------------------------hash-------------------------------------------
4824 // Type-specific hashing function.
4825 uint TypeInstPtr::hash() const {
4826   return klass()->hash() + TypeOopPtr::hash() + _interfaces->hash() + static_cast<uint>(_flat_in_array);
4827 }
4828 
4829 bool TypeInstPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4830   return TypePtr::is_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4831 }
4832 
4833 
4834 bool TypeInstPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
4835   return TypePtr::is_same_java_type_as_helper_for_instance(this, other);
4836 }
4837 
4838 bool TypeInstPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
4839   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
4840 }
4841 
4842 
4843 //------------------------------dump2------------------------------------------
4844 // Dump oop Type
4845 #ifndef PRODUCT
4846 void TypeInstPtr::dump2(Dict &d, uint depth, outputStream* st) const {

4850   _interfaces->dump(st);
4851 
4852   if (_ptr == Constant && (WizardMode || Verbose)) {
4853     ResourceMark rm;
4854     stringStream ss;
4855 
4856     st->print(" ");
4857     const_oop()->print_oop(&ss);
4858     // 'const_oop->print_oop()' may emit newlines('\n') into ss.
4859     // suppress newlines from it so -XX:+Verbose -XX:+PrintIdeal dumps one-liner for each node.
4860     char* buf = ss.as_string(/* c_heap= */false);
4861     StringUtils::replace_no_expand(buf, "\n", "");
4862     st->print_raw(buf);
4863   }
4864 
4865   st->print(":%s", ptr_msg[_ptr]);
4866   if (_klass_is_exact) {
4867     st->print(":exact");
4868   }
4869 
4870   st->print(" *");
4871 
4872   dump_offset(st);
4873   dump_instance_id(st);
4874   dump_inline_depth(st);
4875   dump_speculative(st);
4876   dump_flat_in_array(_flat_in_array, st);
4877 }
4878 #endif
4879 
4880 bool TypeInstPtr::empty() const {
4881   if (_flat_in_array == TopFlat) {
4882     return true;
4883   }
4884   return TypeOopPtr::empty();
4885 }
4886 
4887 //------------------------------add_offset-------------------------------------
4888 const TypePtr* TypeInstPtr::add_offset(intptr_t offset) const {
4889   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), xadd_offset(offset), _flat_in_array,
4890               _instance_id, add_offset_speculative(offset), _inline_depth);
4891 }
4892 
4893 const TypeInstPtr* TypeInstPtr::with_offset(intptr_t offset) const {
4894   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), Offset(offset), _flat_in_array,
4895               _instance_id, with_offset_speculative(offset), _inline_depth);
4896 }
4897 
4898 const TypeInstPtr* TypeInstPtr::remove_speculative() const {
4899   if (_speculative == nullptr) {
4900     return this;
4901   }
4902   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
4903   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array,
4904               _instance_id, nullptr, _inline_depth);
4905 }
4906 
4907 const TypeInstPtr* TypeInstPtr::with_speculative(const TypePtr* speculative) const {
4908   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, speculative, _inline_depth);
4909 }
4910 
4911 const TypePtr* TypeInstPtr::with_inline_depth(int depth) const {
4912   if (!UseInlineDepthForSpeculativeTypes) {
4913     return this;
4914   }
4915   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, _instance_id, _speculative, depth);
4916 }
4917 
4918 const TypePtr* TypeInstPtr::with_instance_id(int instance_id) const {
4919   assert(is_known_instance(), "should be known");
4920   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, _flat_in_array, instance_id, _speculative, _inline_depth);
4921 }
4922 
4923 const TypeInstPtr *TypeInstPtr::cast_to_flat_in_array() const {
4924   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, Flat, _instance_id, _speculative, _inline_depth);
4925 }
4926 
4927 const TypeInstPtr *TypeInstPtr::cast_to_maybe_flat_in_array() const {
4928   return make(_ptr, klass(), _interfaces, klass_is_exact(), const_oop(), _offset, MaybeFlat, _instance_id, _speculative, _inline_depth);
4929 }
4930 
4931 const TypeKlassPtr* TypeInstPtr::as_klass_type(bool try_for_exact) const {
4932   bool xk = klass_is_exact();
4933   ciInstanceKlass* ik = klass()->as_instance_klass();
4934   if (try_for_exact && !xk && !ik->has_subklass() && !ik->is_final()) {
4935     if (_interfaces->eq(ik)) {
4936       Compile* C = Compile::current();
4937       Dependencies* deps = C->dependencies();
4938       deps->assert_leaf_type(ik);
4939       xk = true;
4940     }
4941   }
4942   FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
4943   return TypeInstKlassPtr::make(xk ? TypePtr::Constant : TypePtr::NotNull, klass(), _interfaces, Offset(0), flat_in_array);
4944 }
4945 
4946 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) {
4947   static_assert(std::is_base_of<T2, T1>::value, "");
4948 
4949   if (!this_one->is_instance_type(other)) {
4950     return false;
4951   }
4952 
4953   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4954     return true;
4955   }
4956 
4957   return this_one->klass()->is_subtype_of(other->klass()) &&
4958          (!this_xk || this_one->_interfaces->contains(other->_interfaces));
4959 }
4960 
4961 
4962 bool TypeInstPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4963   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);

4968   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty()) {
4969     return true;
4970   }
4971 
4972   if (this_one->is_instance_type(other)) {
4973     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces);
4974   }
4975 
4976   int dummy;
4977   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
4978   if (this_top_or_bottom) {
4979     return false;
4980   }
4981 
4982   const T1* other_ary = this_one->is_array_type(other);
4983   const TypePtr* other_elem = other_ary->elem()->make_ptr();
4984   const TypePtr* this_elem = this_one->elem()->make_ptr();
4985   if (other_elem != nullptr && this_elem != nullptr) {
4986     return this_one->is_reference_type(this_elem)->is_meet_subtype_of_helper(this_one->is_reference_type(other_elem), this_xk, other_xk);
4987   }

4988   if (other_elem == nullptr && this_elem == nullptr) {
4989     return this_one->klass()->is_subtype_of(other->klass());
4990   }
4991 
4992   return false;
4993 }
4994 
4995 bool TypeAryPtr::is_meet_subtype_of_helper(const TypeOopPtr *other, bool this_xk, bool other_xk) const {
4996   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
4997 }
4998 
4999 bool TypeInstKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5000   return TypePtr::is_meet_subtype_of_helper_for_instance(this, other, this_xk, other_xk);
5001 }
5002 
5003 bool TypeAryKlassPtr::is_meet_subtype_of_helper(const TypeKlassPtr *other, bool this_xk, bool other_xk) const {
5004   return TypePtr::is_meet_subtype_of_helper_for_array(this, other, this_xk, other_xk);
5005 }
5006 
5007 //=============================================================================
5008 // Convenience common pre-built types.
5009 const TypeAryPtr* TypeAryPtr::BOTTOM;
5010 const TypeAryPtr *TypeAryPtr::RANGE;
5011 const TypeAryPtr *TypeAryPtr::OOPS;
5012 const TypeAryPtr *TypeAryPtr::NARROWOOPS;
5013 const TypeAryPtr *TypeAryPtr::BYTES;
5014 const TypeAryPtr *TypeAryPtr::SHORTS;
5015 const TypeAryPtr *TypeAryPtr::CHARS;
5016 const TypeAryPtr *TypeAryPtr::INTS;
5017 const TypeAryPtr *TypeAryPtr::LONGS;
5018 const TypeAryPtr *TypeAryPtr::FLOATS;
5019 const TypeAryPtr *TypeAryPtr::DOUBLES;
5020 const TypeAryPtr *TypeAryPtr::INLINES;
5021 
5022 //------------------------------make-------------------------------------------
5023 const TypeAryPtr* TypeAryPtr::make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5024                                    int instance_id, const TypePtr* speculative, int inline_depth) {
5025   assert(!(k == nullptr && ary->_elem->isa_int()),
5026          "integral arrays must be pre-equipped with a class");
5027   if (!xk)  xk = ary->ary_must_be_exact();
5028   assert(instance_id <= 0 || xk, "instances are always exactly typed");
5029   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5030       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5031     k = nullptr;
5032   }
5033   return (TypeAryPtr*)(new TypeAryPtr(ptr, nullptr, ary, k, xk, offset, field_offset, instance_id, false, speculative, inline_depth))->hashcons();
5034 }
5035 
5036 //------------------------------make-------------------------------------------
5037 const TypeAryPtr* TypeAryPtr::make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset, Offset field_offset,
5038                                    int instance_id, const TypePtr* speculative, int inline_depth,
5039                                    bool is_autobox_cache) {
5040   assert(!(k == nullptr && ary->_elem->isa_int()),
5041          "integral arrays must be pre-equipped with a class");
5042   assert( (ptr==Constant && o) || (ptr!=Constant && !o), "" );
5043   if (!xk)  xk = (o != nullptr) || ary->ary_must_be_exact();
5044   assert(instance_id <= 0 || xk, "instances are always exactly typed");
5045   if (k != nullptr && k->is_loaded() && k->is_obj_array_klass() &&
5046       k->as_obj_array_klass()->base_element_klass()->is_interface()) {
5047     k = nullptr;
5048   }
5049   return (TypeAryPtr*)(new TypeAryPtr(ptr, o, ary, k, xk, offset, field_offset, instance_id, is_autobox_cache, speculative, inline_depth))->hashcons();
5050 }
5051 
5052 //------------------------------cast_to_ptr_type-------------------------------
5053 const TypeAryPtr* TypeAryPtr::cast_to_ptr_type(PTR ptr) const {
5054   if( ptr == _ptr ) return this;
5055   return make(ptr, ptr == Constant ? const_oop() : nullptr, _ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5056 }
5057 
5058 
5059 //-----------------------------cast_to_exactness-------------------------------
5060 const TypeAryPtr* TypeAryPtr::cast_to_exactness(bool klass_is_exact) const {
5061   if( klass_is_exact == _klass_is_exact ) return this;
5062   if (_ary->ary_must_be_exact())  return this;  // cannot clear xk
5063   return make(ptr(), const_oop(), _ary, klass(), klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5064 }
5065 
5066 //-----------------------------cast_to_instance_id----------------------------
5067 const TypeAryPtr* TypeAryPtr::cast_to_instance_id(int instance_id) const {
5068   if( instance_id == _instance_id ) return this;
5069   return make(_ptr, const_oop(), _ary, klass(), _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth, _is_autobox_cache);
5070 }
5071 
5072 
5073 //-----------------------------max_array_length-------------------------------
5074 // A wrapper around arrayOopDesc::max_array_length(etype) with some input normalization.
5075 jint TypeAryPtr::max_array_length(BasicType etype) {
5076   if (!is_java_primitive(etype) && !::is_reference_type(etype)) {
5077     if (etype == T_NARROWOOP) {
5078       etype = T_OBJECT;
5079     } else if (etype == T_ILLEGAL) { // bottom[]
5080       etype = T_BYTE; // will produce conservatively high value
5081     } else {
5082       fatal("not an element type: %s", type2name(etype));
5083     }
5084   }
5085   return arrayOopDesc::max_array_length(etype);
5086 }
5087 
5088 //-----------------------------narrow_size_type-------------------------------
5089 // Narrow the given size type to the index range for the given array base type.

5107     if (size->is_con()) {
5108       lo = hi;
5109     }
5110     chg = true;
5111   }
5112   // Negative length arrays will produce weird intermediate dead fast-path code
5113   if (lo > hi) {
5114     return TypeInt::ZERO;
5115   }
5116   if (!chg) {
5117     return size;
5118   }
5119   return TypeInt::make(lo, hi, Type::WidenMin);
5120 }
5121 
5122 //-------------------------------cast_to_size----------------------------------
5123 const TypeAryPtr* TypeAryPtr::cast_to_size(const TypeInt* new_size) const {
5124   assert(new_size != nullptr, "");
5125   new_size = narrow_size_type(new_size);
5126   if (new_size == size())  return this;
5127   const TypeAry* new_ary = TypeAry::make(elem(), new_size, is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5128   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5129 }
5130 
5131 const TypeAryPtr* TypeAryPtr::cast_to_flat(bool flat) const {
5132   if (flat == is_flat()) {
5133     return this;
5134   }
5135   assert(!flat || !is_not_flat(), "inconsistency");
5136   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), flat, is_not_flat(), is_not_null_free(), is_atomic());
5137   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5138   if (res->speculative() == res->remove_speculative()) {
5139     return res->remove_speculative();
5140   }
5141   return res;
5142 }
5143 
5144 //-------------------------------cast_to_not_flat------------------------------
5145 const TypeAryPtr* TypeAryPtr::cast_to_not_flat(bool not_flat) const {
5146   if (not_flat == is_not_flat()) {
5147     return this;
5148   }
5149   assert(!not_flat || !is_flat(), "inconsistency");
5150   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), not_flat, is_not_null_free(), is_atomic());
5151   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5152   // We keep the speculative part if it contains information about flat-/nullability.
5153   // Make sure it's removed if it's not better than the non-speculative type anymore.
5154   if (res->speculative() == res->remove_speculative()) {
5155     return res->remove_speculative();
5156   }
5157   return res;
5158 }
5159 
5160 const TypeAryPtr* TypeAryPtr::cast_to_null_free(bool null_free) const {
5161   if (null_free == is_null_free()) {
5162     return this;
5163   }
5164   assert(!null_free || !is_not_null_free(), "inconsistency");
5165   const Type* elem = this->elem();
5166   const Type* new_elem = elem->make_ptr();
5167   if (null_free) {
5168     new_elem = new_elem->join_speculative(TypePtr::NOTNULL);
5169   } else {
5170     new_elem = new_elem->meet_speculative(TypePtr::NULL_PTR);
5171   }
5172   new_elem = elem->isa_narrowoop() ? new_elem->make_narrowoop() : new_elem;
5173   const TypeAry* new_ary = TypeAry::make(new_elem, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5174   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5175   if (res->speculative() == res->remove_speculative()) {
5176     return res->remove_speculative();
5177   }
5178   assert(res->speculative() == nullptr || res->speculative()->with_inline_depth(res->inline_depth())->higher_equal(res->remove_speculative()),
5179            "speculative type must not be narrower than non-speculative type");
5180   return res;
5181 }
5182 
5183 //-------------------------------cast_to_not_null_free-------------------------
5184 const TypeAryPtr* TypeAryPtr::cast_to_not_null_free(bool not_null_free) const {
5185   if (not_null_free == is_not_null_free()) {
5186     return this;
5187   }
5188   assert(!not_null_free || !is_null_free(), "inconsistency");
5189   const TypeAry* new_ary = TypeAry::make(elem(), size(), is_stable(), is_flat(), is_not_flat(), not_null_free, is_atomic());
5190   const TypePtr* new_spec = _speculative;
5191   if (new_spec != nullptr) {
5192     // Could be 'null free' from profiling, which would contradict the cast.
5193     new_spec = new_spec->is_aryptr()->cast_to_null_free(false)->cast_to_not_null_free();
5194   }
5195   const TypeAryPtr* res = make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset,
5196                                _instance_id, new_spec, _inline_depth, _is_autobox_cache);
5197   // We keep the speculative part if it contains information about flat-/nullability.
5198   // Make sure it's removed if it's not better than the non-speculative type anymore.
5199   if (res->speculative() == res->remove_speculative()) {
5200     return res->remove_speculative();
5201   }
5202   assert(res->speculative() == nullptr || res->speculative()->with_inline_depth(res->inline_depth())->higher_equal(res->remove_speculative()),
5203            "speculative type must not be narrower than non-speculative type");
5204   return res;
5205 }
5206 
5207 //---------------------------------update_properties---------------------------
5208 const TypeAryPtr* TypeAryPtr::update_properties(const TypeAryPtr* from) const {
5209   if ((from->is_flat()          && is_not_flat()) ||
5210       (from->is_not_flat()      && is_flat()) ||
5211       (from->is_null_free()     && is_not_null_free()) ||
5212       (from->is_not_null_free() && is_null_free())) {
5213     return nullptr; // Inconsistent properties
5214   }
5215   const TypeAryPtr* res = this;
5216   if (from->is_not_null_free()) {
5217     res = res->cast_to_not_null_free();
5218   }
5219   if (from->is_not_flat()) {
5220     res = res->cast_to_not_flat();
5221   }
5222   return res;
5223 }
5224 
5225 jint TypeAryPtr::flat_layout_helper() const {
5226   return exact_klass()->as_flat_array_klass()->layout_helper();
5227 }
5228 
5229 int TypeAryPtr::flat_elem_size() const {
5230   return exact_klass()->as_flat_array_klass()->element_byte_size();
5231 }
5232 
5233 int TypeAryPtr::flat_log_elem_size() const {
5234   return exact_klass()->as_flat_array_klass()->log2_element_size();
5235 }
5236 
5237 //------------------------------cast_to_stable---------------------------------
5238 const TypeAryPtr* TypeAryPtr::cast_to_stable(bool stable, int stable_dimension) const {
5239   if (stable_dimension <= 0 || (stable_dimension == 1 && stable == this->is_stable()))
5240     return this;
5241 
5242   const Type* elem = this->elem();
5243   const TypePtr* elem_ptr = elem->make_ptr();
5244 
5245   if (stable_dimension > 1 && elem_ptr != nullptr && elem_ptr->isa_aryptr()) {
5246     // If this is widened from a narrow oop, TypeAry::make will re-narrow it.
5247     elem = elem_ptr = elem_ptr->is_aryptr()->cast_to_stable(stable, stable_dimension - 1);
5248   }
5249 
5250   const TypeAry* new_ary = TypeAry::make(elem, size(), stable, is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5251 
5252   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5253 }
5254 
5255 //-----------------------------stable_dimension--------------------------------
5256 int TypeAryPtr::stable_dimension() const {
5257   if (!is_stable())  return 0;
5258   int dim = 1;
5259   const TypePtr* elem_ptr = elem()->make_ptr();
5260   if (elem_ptr != nullptr && elem_ptr->isa_aryptr())
5261     dim += elem_ptr->is_aryptr()->stable_dimension();
5262   return dim;
5263 }
5264 
5265 //----------------------cast_to_autobox_cache-----------------------------------
5266 const TypeAryPtr* TypeAryPtr::cast_to_autobox_cache() const {
5267   if (is_autobox_cache())  return this;
5268   const TypeOopPtr* etype = elem()->make_oopptr();
5269   if (etype == nullptr)  return this;
5270   // The pointers in the autobox arrays are always non-null.
5271   etype = etype->cast_to_ptr_type(TypePtr::NotNull)->is_oopptr();
5272   const TypeAry* new_ary = TypeAry::make(etype, size(), is_stable(), is_flat(), is_not_flat(), is_not_null_free(), is_atomic());
5273   return make(ptr(), const_oop(), new_ary, klass(), klass_is_exact(), _offset, _field_offset, _instance_id, _speculative, _inline_depth, /*is_autobox_cache=*/true);
5274 }
5275 
5276 //------------------------------eq---------------------------------------------
5277 // Structural equality check for Type representations
5278 bool TypeAryPtr::eq( const Type *t ) const {
5279   const TypeAryPtr *p = t->is_aryptr();
5280   return
5281     _ary == p->_ary &&  // Check array
5282     TypeOopPtr::eq(p) &&// Check sub-parts
5283     _field_offset == p->_field_offset;
5284 }
5285 
5286 //------------------------------hash-------------------------------------------
5287 // Type-specific hashing function.
5288 uint TypeAryPtr::hash(void) const {
5289   return (uint)(uintptr_t)_ary + TypeOopPtr::hash() + _field_offset.get();
5290 }
5291 
5292 bool TypeAryPtr::is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5293   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5294 }
5295 
5296 bool TypeAryPtr::is_same_java_type_as_helper(const TypeOopPtr* other) const {
5297   return TypePtr::is_same_java_type_as_helper_for_array(this, other);
5298 }
5299 
5300 bool TypeAryPtr::maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const {
5301   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
5302 }
5303 //------------------------------meet-------------------------------------------
5304 // Compute the MEET of two types.  It returns a new Type object.
5305 const Type *TypeAryPtr::xmeet_helper(const Type *t) const {
5306   // Perform a fast test for common case; meeting the same types together.
5307   if( this == t ) return this;  // Meeting same type-rep?
5308   // Current "this->_base" is Pointer
5309   switch (t->base()) {          // switch on original type

5316   case HalfFloatBot:
5317   case FloatTop:
5318   case FloatCon:
5319   case FloatBot:
5320   case DoubleTop:
5321   case DoubleCon:
5322   case DoubleBot:
5323   case NarrowOop:
5324   case NarrowKlass:
5325   case Bottom:                  // Ye Olde Default
5326     return Type::BOTTOM;
5327   case Top:
5328     return this;
5329 
5330   default:                      // All else is a mistake
5331     typerr(t);
5332 
5333   case OopPtr: {                // Meeting to OopPtrs
5334     // Found a OopPtr type vs self-AryPtr type
5335     const TypeOopPtr *tp = t->is_oopptr();
5336     Offset offset = meet_offset(tp->offset());
5337     PTR ptr = meet_ptr(tp->ptr());
5338     int depth = meet_inline_depth(tp->inline_depth());
5339     const TypePtr* speculative = xmeet_speculative(tp);
5340     switch (tp->ptr()) {
5341     case TopPTR:
5342     case AnyNull: {
5343       int instance_id = meet_instance_id(InstanceTop);
5344       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5345                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5346     }
5347     case BotPTR:
5348     case NotNull: {
5349       int instance_id = meet_instance_id(tp->instance_id());
5350       return TypeOopPtr::make(ptr, offset, instance_id, speculative, depth);
5351     }
5352     default: ShouldNotReachHere();
5353     }
5354   }
5355 
5356   case AnyPtr: {                // Meeting two AnyPtrs
5357     // Found an AnyPtr type vs self-AryPtr type
5358     const TypePtr *tp = t->is_ptr();
5359     Offset offset = meet_offset(tp->offset());
5360     PTR ptr = meet_ptr(tp->ptr());
5361     const TypePtr* speculative = xmeet_speculative(tp);
5362     int depth = meet_inline_depth(tp->inline_depth());
5363     switch (tp->ptr()) {
5364     case TopPTR:
5365       return this;
5366     case BotPTR:
5367     case NotNull:
5368       return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5369     case Null:
5370       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, speculative, depth);
5371       // else fall through to AnyNull
5372     case AnyNull: {
5373       int instance_id = meet_instance_id(InstanceTop);
5374       return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5375                   _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5376     }
5377     default: ShouldNotReachHere();
5378     }
5379   }
5380 
5381   case MetadataPtr:
5382   case KlassPtr:
5383   case InstKlassPtr:
5384   case AryKlassPtr:
5385   case RawPtr: return TypePtr::BOTTOM;
5386 
5387   case AryPtr: {                // Meeting 2 references?
5388     const TypeAryPtr *tap = t->is_aryptr();
5389     Offset off = meet_offset(tap->offset());
5390     Offset field_off = meet_field_offset(tap->field_offset());
5391     const Type* tm = _ary->meet_speculative(tap->_ary);
5392     const TypeAry* tary = tm->isa_ary();
5393     if (tary == nullptr) {
5394       assert(tm == Type::TOP || tm == Type::BOTTOM, "");
5395       return tm;
5396     }
5397     PTR ptr = meet_ptr(tap->ptr());
5398     int instance_id = meet_instance_id(tap->instance_id());
5399     const TypePtr* speculative = xmeet_speculative(tap);
5400     int depth = meet_inline_depth(tap->inline_depth());
5401 
5402     ciKlass* res_klass = nullptr;
5403     bool res_xk = false;
5404     bool res_flat = false;
5405     bool res_not_flat = false;
5406     bool res_not_null_free = false;
5407     bool res_atomic = false;
5408     const Type* elem = tary->_elem;
5409     if (meet_aryptr(ptr, elem, this, tap, res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic) == NOT_SUBTYPE) {
5410       instance_id = InstanceBot;
5411     } else if (this->is_flat() != tap->is_flat()) {
5412       // Meeting flat inline type array with non-flat array. Adjust (field) offset accordingly.
5413       if (tary->_flat) {
5414         // Result is in a flat representation
5415         off = Offset(is_flat() ? offset() : tap->offset());
5416         field_off = is_flat() ? field_offset() : tap->field_offset();
5417       } else if (below_centerline(ptr)) {
5418         // Result is in a non-flat representation
5419         off = Offset(flat_offset()).meet(Offset(tap->flat_offset()));
5420         field_off = (field_off == Offset::top) ? Offset::top : Offset::bottom;
5421       } else if (flat_offset() == tap->flat_offset()) {
5422         off = Offset(!is_flat() ? offset() : tap->offset());
5423         field_off = !is_flat() ? field_offset() : tap->field_offset();
5424       }
5425     }
5426 
5427     ciObject* o = nullptr;             // Assume not constant when done
5428     ciObject* this_oop = const_oop();
5429     ciObject* tap_oop = tap->const_oop();
5430     if (ptr == Constant) {
5431       if (this_oop != nullptr && tap_oop != nullptr &&
5432           this_oop->equals(tap_oop)) {
5433         o = tap_oop;
5434       } else if (above_centerline(_ptr)) {
5435         o = tap_oop;
5436       } else if (above_centerline(tap->_ptr)) {
5437         o = this_oop;
5438       } else {
5439         ptr = NotNull;
5440       }
5441     }
5442     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);
5443   }
5444 
5445   // All arrays inherit from Object class
5446   case InstPtr: {
5447     const TypeInstPtr *tp = t->is_instptr();
5448     Offset offset = meet_offset(tp->offset());
5449     PTR ptr = meet_ptr(tp->ptr());
5450     int instance_id = meet_instance_id(tp->instance_id());
5451     const TypePtr* speculative = xmeet_speculative(tp);
5452     int depth = meet_inline_depth(tp->inline_depth());
5453     const TypeInterfaces* interfaces = meet_interfaces(tp);
5454     const TypeInterfaces* tp_interfaces = tp->_interfaces;
5455     const TypeInterfaces* this_interfaces = _interfaces;
5456 
5457     switch (ptr) {
5458     case TopPTR:
5459     case AnyNull:                // Fall 'down' to dual of object klass
5460       // For instances when a subclass meets a superclass we fall
5461       // below the centerline when the superclass is exact. We need to
5462       // do the same here.
5463       //
5464       // Flat in array:
5465       // We do
5466       //   dual(TypeAryPtr) MEET dual(TypeInstPtr)
5467       // If TypeInstPtr is anything else than Object, then the result of the meet is bottom Object (i.e. we could have
5468       // instances or arrays).
5469       // If TypeInstPtr is an Object and either
5470       // - exact
5471       // - inexact AND flat in array == dual(not flat in array) (i.e. not an array type)
5472       // then the result of the meet is bottom Object (i.e. we could have instances or arrays).
5473       // Otherwise, we meet two array pointers and create a new TypeAryPtr.
5474       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5475           !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5476         return TypeAryPtr::make(ptr, _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5477       } else {
5478         // cannot subclass, so the meet has to fall badly below the centerline
5479         ptr = NotNull;
5480         instance_id = InstanceBot;
5481         interfaces = this_interfaces->intersection_with(tp_interfaces);
5482         FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5483         return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset, flat_in_array, instance_id, speculative, depth);
5484       }
5485     case Constant:
5486     case NotNull:
5487     case BotPTR: { // Fall down to object klass
5488       // LCA is object_klass, but if we subclass from the top we can do better
5489       if (above_centerline(tp->ptr())) {
5490         // If 'tp'  is above the centerline and it is Object class
5491         // then we can subclass in the Java class hierarchy.
5492         // For instances when a subclass meets a superclass we fall
5493         // below the centerline when the superclass is exact. We need
5494         // to do the same here.
5495 
5496         // Flat in array: We do TypeAryPtr MEET dual(TypeInstPtr), same applies as above in TopPTR/AnyNull case.
5497         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
5498             !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
5499           // that is, my array type is a subtype of 'tp' klass
5500           return make(ptr, (ptr == Constant ? const_oop() : nullptr),
5501                       _ary, _klass, _klass_is_exact, offset, _field_offset, instance_id, speculative, depth);
5502         }
5503       }
5504       // The other case cannot happen, since t cannot be a subtype of an array.
5505       // The meet falls down to Object class below centerline.
5506       if (ptr == Constant) {
5507         ptr = NotNull;
5508       }
5509       if (instance_id > 0) {
5510         instance_id = InstanceBot;
5511       }
5512 
5513       FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
5514       interfaces = this_interfaces->intersection_with(tp_interfaces);
5515       return TypeInstPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, false, nullptr, offset,
5516                                flat_in_array, instance_id, speculative, depth);
5517     }
5518     default: typerr(t);
5519     }
5520   }
5521   }
5522   return this;                  // Lint noise
5523 }
5524 
5525 
5526 template<class T> TypePtr::MeetResult TypePtr::meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
5527                                                            ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool& res_not_flat, bool& res_not_null_free, bool &res_atomic) {
5528   int dummy;
5529   bool this_top_or_bottom = (this_ary->base_element_type(dummy) == Type::TOP || this_ary->base_element_type(dummy) == Type::BOTTOM);
5530   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
5531   ciKlass* this_klass = this_ary->klass();
5532   ciKlass* other_klass = other_ary->klass();
5533   bool this_xk = this_ary->klass_is_exact();
5534   bool other_xk = other_ary->klass_is_exact();
5535   PTR this_ptr = this_ary->ptr();
5536   PTR other_ptr = other_ary->ptr();
5537   bool this_flat = this_ary->is_flat();
5538   bool this_not_flat = this_ary->is_not_flat();
5539   bool other_flat = other_ary->is_flat();
5540   bool other_not_flat = other_ary->is_not_flat();
5541   bool this_not_null_free = this_ary->is_not_null_free();
5542   bool other_not_null_free = other_ary->is_not_null_free();
5543   bool this_atomic = this_ary->is_atomic();
5544   bool other_atomic = other_ary->is_atomic();
5545   const bool same_nullness = this_ary->is_null_free() == other_ary->is_null_free();
5546   res_klass = nullptr;
5547   MeetResult result = SUBTYPE;
5548   res_flat = this_flat && other_flat;
5549   bool res_null_free = this_ary->is_null_free() && other_ary->is_null_free();
5550   res_not_flat = this_not_flat && other_not_flat;
5551   res_not_null_free = this_not_null_free && other_not_null_free;
5552   res_atomic = this_atomic && other_atomic;
5553 
5554   if (elem->isa_int()) {
5555     // Integral array element types have irrelevant lattice relations.
5556     // It is the klass that determines array layout, not the element type.
5557       if (this_top_or_bottom) {
5558         res_klass = other_klass;
5559       } else if (other_top_or_bottom || other_klass == this_klass) {
5560       res_klass = this_klass;
5561     } else {
5562       // Something like byte[int+] meets char[int+].
5563       // This must fall to bottom, not (int[-128..65535])[int+].
5564       // instance_id = InstanceBot;
5565       elem = Type::BOTTOM;
5566       result = NOT_SUBTYPE;
5567       if (above_centerline(ptr) || ptr == Constant) {
5568         ptr = NotNull;
5569         res_xk = false;
5570         return NOT_SUBTYPE;
5571       }
5572     }
5573   } else {// Non integral arrays.
5574     // Must fall to bottom if exact klasses in upper lattice
5575     // are not equal or super klass is exact.
5576     if ((above_centerline(ptr) || ptr == Constant) && !this_ary->is_same_java_type_as(other_ary) &&
5577         // meet with top[] and bottom[] are processed further down:
5578         !this_top_or_bottom && !other_top_or_bottom &&
5579         // both are exact and not equal:

5581          // 'tap'  is exact and super or unrelated:
5582          (other_xk && !other_ary->is_meet_subtype_of(this_ary)) ||
5583          // 'this' is exact and super or unrelated:
5584          (this_xk && !this_ary->is_meet_subtype_of(other_ary)))) {
5585       if (above_centerline(ptr) || (elem->make_ptr() && above_centerline(elem->make_ptr()->_ptr))) {
5586         elem = Type::BOTTOM;
5587       }
5588       ptr = NotNull;
5589       res_xk = false;
5590       return NOT_SUBTYPE;
5591     }
5592   }
5593 
5594   res_xk = false;
5595   switch (other_ptr) {
5596     case AnyNull:
5597     case TopPTR:
5598       // Compute new klass on demand, do not use tap->_klass
5599       if (below_centerline(this_ptr)) {
5600         res_xk = this_xk;
5601         if (this_ary->is_flat()) {
5602           elem = this_ary->elem();
5603         }
5604       } else {
5605         res_xk = (other_xk || this_xk);
5606       }
5607       break;
5608     case Constant: {
5609       if (this_ptr == Constant && same_nullness) {
5610         // Only exact if same nullness since:
5611         //     null-free [LMyValue <: nullable [LMyValue.
5612         res_xk = true;
5613       } else if (above_centerline(this_ptr)) {
5614         res_xk = true;
5615       } else {
5616         // Only precise for identical arrays
5617         res_xk = this_xk && (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom));
5618         // Even though MyValue is final, [LMyValue is only exact if the array
5619         // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5620         if (res_xk && !res_null_free && !res_not_null_free) {
5621           ptr = NotNull;
5622           res_xk = false;
5623         }
5624       }
5625       break;
5626     }
5627     case NotNull:
5628     case BotPTR:
5629       // Compute new klass on demand, do not use tap->_klass
5630       if (above_centerline(this_ptr)) {
5631         res_xk = other_xk;
5632         if (other_ary->is_flat()) {
5633           elem = other_ary->elem();
5634         }
5635       } else {
5636         res_xk = (other_xk && this_xk) &&
5637                  (this_ary->is_same_java_type_as(other_ary) || (this_top_or_bottom && other_top_or_bottom)); // Only precise for identical arrays
5638         // Even though MyValue is final, [LMyValue is only exact if the array
5639         // is (not) null-free due to null-free [LMyValue <: null-able [LMyValue.
5640         if (res_xk && !res_null_free && !res_not_null_free) {
5641           ptr = NotNull;
5642           res_xk = false;
5643         }
5644       }
5645       break;
5646     default:  {
5647       ShouldNotReachHere();
5648       return result;
5649     }
5650   }
5651   return result;
5652 }
5653 
5654 
5655 //------------------------------xdual------------------------------------------
5656 // Dual: compute field-by-field dual
5657 const Type *TypeAryPtr::xdual() const {
5658   bool xk = _klass_is_exact;
5659   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());
5660 }
5661 
5662 Type::Offset TypeAryPtr::meet_field_offset(const Type::Offset offset) const {
5663   return _field_offset.meet(offset);
5664 }
5665 
5666 //------------------------------dual_offset------------------------------------
5667 Type::Offset TypeAryPtr::dual_field_offset() const {
5668   return _field_offset.dual();
5669 }
5670 
5671 //------------------------------dump2------------------------------------------
5672 #ifndef PRODUCT
5673 void TypeAryPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
5674   st->print("aryptr:");
5675   _ary->dump2(d, depth, st);
5676   _interfaces->dump(st);
5677 
5678   if (_ptr == Constant) {
5679     const_oop()->print(st);
5680   }
5681 
5682   st->print(":%s", ptr_msg[_ptr]);
5683   if (_klass_is_exact) {
5684     st->print(":exact");
5685   }
5686 
5687   if (is_flat()) {
5688     st->print(":flat");
5689     st->print("(");
5690     _field_offset.dump2(st);
5691     st->print(")");
5692   } else if (is_not_flat()) {
5693     st->print(":not_flat");
5694   }
5695   if (is_null_free()) {
5696     st->print(":null free");
5697   }
5698   if (is_atomic()) {
5699     st->print(":atomic");
5700   }
5701   if (Verbose) {
5702     if (is_not_flat()) {
5703       st->print(":not flat");
5704     }
5705     if (is_not_null_free()) {
5706       st->print(":nullable");
5707     }
5708   }
5709   if (offset() != 0) {
5710     BasicType basic_elem_type = elem()->basic_type();
5711     int header_size = arrayOopDesc::base_offset_in_bytes(basic_elem_type);
5712     if( _offset == Offset::top )       st->print("+undefined");
5713     else if( _offset == Offset::bottom )  st->print("+any");
5714     else if( offset() < header_size ) st->print("+%d", offset());
5715     else {
5716       if (basic_elem_type == T_ILLEGAL) {
5717         st->print("+any");
5718       } else {
5719         int elem_size = type2aelembytes(basic_elem_type);
5720         st->print("[%d]", (offset() - header_size)/elem_size);
5721       }
5722     }
5723   }
5724 
5725   dump_instance_id(st);
5726   dump_inline_depth(st);
5727   dump_speculative(st);
5728 }
5729 #endif
5730 
5731 bool TypeAryPtr::empty(void) const {
5732   if (_ary->empty())       return true;
5733   // TODO 8350865 This should go to the meet implementation
5734   if (is_flat() && is_not_flat()) {
5735     return true;
5736   }
5737   return TypeOopPtr::empty();
5738 }
5739 
5740 //------------------------------add_offset-------------------------------------
5741 const TypePtr* TypeAryPtr::add_offset(intptr_t offset) const {
5742   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);
5743 }
5744 
5745 const TypeAryPtr* TypeAryPtr::with_offset(intptr_t offset) const {
5746   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);
5747 }
5748 
5749 const TypeAryPtr* TypeAryPtr::with_ary(const TypeAry* ary) const {
5750   return make(_ptr, _const_oop, ary, _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, _inline_depth, _is_autobox_cache);
5751 }
5752 
5753 const TypeAryPtr* TypeAryPtr::remove_speculative() const {
5754   if (_speculative == nullptr) {
5755     return this;
5756   }
5757   assert(_inline_depth == InlineDepthTop || _inline_depth == InlineDepthBottom, "non speculative type shouldn't have inline depth");
5758   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);
5759 }
5760 
5761 const Type* TypeAryPtr::cleanup_speculative() const {
5762   if (speculative() == nullptr) {
5763     return this;
5764   }
5765   // Keep speculative part if it contains information about flat-/nullability
5766   const TypeAryPtr* spec_aryptr = speculative()->isa_aryptr();
5767   if (spec_aryptr != nullptr && !above_centerline(spec_aryptr->ptr()) &&
5768       (spec_aryptr->is_not_flat() || spec_aryptr->is_not_null_free())) {
5769     return this;
5770   }
5771   return TypeOopPtr::cleanup_speculative();
5772 }
5773 
5774 const TypePtr* TypeAryPtr::with_inline_depth(int depth) const {
5775   if (!UseInlineDepthForSpeculativeTypes) {
5776     return this;
5777   }
5778   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, _instance_id, _speculative, depth, _is_autobox_cache);
5779 }
5780 
5781 const TypeAryPtr* TypeAryPtr::with_field_offset(int offset) const {
5782   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);
5783 }
5784 
5785 const TypePtr* TypeAryPtr::add_field_offset_and_offset(intptr_t offset) const {
5786   if (!is_flat() || !klass_is_exact() || offset == OffsetBot || offset == OffsetTop) {
5787     return add_offset(offset);
5788   }
5789 
5790   // Handle flat concrete value class array with known 'offset' which could refer to an actual field in the flat storage.
5791   int adj = 0;
5792   if (_offset != Offset::bottom && _offset != Offset::top) {
5793     adj = _offset.get();
5794     offset += _offset.get();
5795   }
5796   uint header = arrayOopDesc::base_offset_in_bytes(T_FLAT_ELEMENT);
5797   if (_field_offset != Offset::bottom && _field_offset != Offset::top) {
5798     offset += _field_offset.get();
5799     if (_offset == Offset::bottom || _offset == Offset::top) {
5800       offset += header;
5801     }
5802   }
5803   if (elem()->make_oopptr()->is_inlinetypeptr() && (offset >= (intptr_t)header || offset < 0)) {
5804     // Try to get the field of the inline type array element we are pointing to
5805     ciInlineKlass* vk = elem()->inline_klass();
5806     int shift = flat_log_elem_size();
5807     int mask = (1 << shift) - 1;
5808     int field_offset = static_cast<int>((offset - header) & mask);
5809     ciField* field = vk->get_field_by_offset(field_offset + vk->payload_offset(), false);
5810     if (field != nullptr || field_offset == vk->null_marker_offset_in_payload()) {
5811       return with_field_offset(field_offset)->add_offset(offset - field_offset - adj);
5812     }
5813   }
5814   return add_offset(offset - adj);
5815 }
5816 
5817 // Return offset incremented by field_offset for flat inline type arrays
5818 int TypeAryPtr::flat_offset() const {
5819   int offset = _offset.get();
5820   if (offset != OffsetBot && offset != OffsetTop &&
5821       _field_offset != Offset::bottom && _field_offset != Offset::top) {
5822     offset += _field_offset.get();
5823   }
5824   return offset;
5825 }
5826 
5827 const TypePtr* TypeAryPtr::with_instance_id(int instance_id) const {
5828   assert(is_known_instance(), "should be known");
5829   return make(_ptr, _const_oop, _ary->remove_speculative()->is_ary(), _klass, _klass_is_exact, _offset, _field_offset, instance_id, _speculative, _inline_depth);
5830 }
5831 
5832 //=============================================================================
5833 
5834 
5835 //------------------------------hash-------------------------------------------
5836 // Type-specific hashing function.
5837 uint TypeNarrowPtr::hash(void) const {
5838   return _ptrtype->hash() + 7;
5839 }
5840 
5841 bool TypeNarrowPtr::singleton(void) const {    // TRUE if type is a singleton
5842   return _ptrtype->singleton();
5843 }
5844 
5845 bool TypeNarrowPtr::empty(void) const {
5846   return _ptrtype->empty();
5847 }
5848 
5849 intptr_t TypeNarrowPtr::get_con() const {
5850   return _ptrtype->get_con();
5851 }
5852 
5853 bool TypeNarrowPtr::eq( const Type *t ) const {
5854   const TypeNarrowPtr* tc = isa_same_narrowptr(t);

5908   case HalfFloatTop:
5909   case HalfFloatCon:
5910   case HalfFloatBot:
5911   case FloatTop:
5912   case FloatCon:
5913   case FloatBot:
5914   case DoubleTop:
5915   case DoubleCon:
5916   case DoubleBot:
5917   case AnyPtr:
5918   case RawPtr:
5919   case OopPtr:
5920   case InstPtr:
5921   case AryPtr:
5922   case MetadataPtr:
5923   case KlassPtr:
5924   case InstKlassPtr:
5925   case AryKlassPtr:
5926   case NarrowOop:
5927   case NarrowKlass:

5928   case Bottom:                  // Ye Olde Default
5929     return Type::BOTTOM;
5930   case Top:
5931     return this;
5932 
5933   default:                      // All else is a mistake
5934     typerr(t);
5935 
5936   } // End of switch
5937 
5938   return this;
5939 }
5940 
5941 #ifndef PRODUCT
5942 void TypeNarrowPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
5943   _ptrtype->dump2(d, depth, st);
5944 }
5945 #endif
5946 
5947 const TypeNarrowOop *TypeNarrowOop::BOTTOM;

5991     return (one == two) && TypePtr::eq(t);
5992   } else {
5993     return one->equals(two) && TypePtr::eq(t);
5994   }
5995 }
5996 
5997 //------------------------------hash-------------------------------------------
5998 // Type-specific hashing function.
5999 uint TypeMetadataPtr::hash(void) const {
6000   return
6001     (metadata() ? metadata()->hash() : 0) +
6002     TypePtr::hash();
6003 }
6004 
6005 //------------------------------singleton--------------------------------------
6006 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6007 // constants
6008 bool TypeMetadataPtr::singleton(void) const {
6009   // detune optimizer to not generate constant metadata + constant offset as a constant!
6010   // TopPTR, Null, AnyNull, Constant are all singletons
6011   return (offset() == 0) && !below_centerline(_ptr);
6012 }
6013 
6014 //------------------------------add_offset-------------------------------------
6015 const TypePtr* TypeMetadataPtr::add_offset( intptr_t offset ) const {
6016   return make( _ptr, _metadata, xadd_offset(offset));
6017 }
6018 
6019 //-----------------------------filter------------------------------------------
6020 // Do not allow interface-vs.-noninterface joins to collapse to top.
6021 const Type *TypeMetadataPtr::filter_helper(const Type *kills, bool include_speculative) const {
6022   const TypeMetadataPtr* ft = join_helper(kills, include_speculative)->isa_metadataptr();
6023   if (ft == nullptr || ft->empty())
6024     return Type::TOP;           // Canonical empty value
6025   return ft;
6026 }
6027 
6028  //------------------------------get_con----------------------------------------
6029 intptr_t TypeMetadataPtr::get_con() const {
6030   assert( _ptr == Null || _ptr == Constant, "" );
6031   assert(offset() >= 0, "");
6032 
6033   if (offset() != 0) {
6034     // After being ported to the compiler interface, the compiler no longer
6035     // directly manipulates the addresses of oops.  Rather, it only has a pointer
6036     // to a handle at compile time.  This handle is embedded in the generated
6037     // code and dereferenced at the time the nmethod is made.  Until that time,
6038     // it is not reasonable to do arithmetic with the addresses of oops (we don't
6039     // have access to the addresses!).  This does not seem to currently happen,
6040     // but this assertion here is to help prevent its occurrence.
6041     tty->print_cr("Found oop constant with non-zero offset");
6042     ShouldNotReachHere();
6043   }
6044 
6045   return (intptr_t)metadata()->constant_encoding();
6046 }
6047 
6048 //------------------------------cast_to_ptr_type-------------------------------
6049 const TypeMetadataPtr* TypeMetadataPtr::cast_to_ptr_type(PTR ptr) const {
6050   if( ptr == _ptr ) return this;
6051   return make(ptr, metadata(), _offset);
6052 }
6053 

6067   case HalfFloatBot:
6068   case FloatTop:
6069   case FloatCon:
6070   case FloatBot:
6071   case DoubleTop:
6072   case DoubleCon:
6073   case DoubleBot:
6074   case NarrowOop:
6075   case NarrowKlass:
6076   case Bottom:                  // Ye Olde Default
6077     return Type::BOTTOM;
6078   case Top:
6079     return this;
6080 
6081   default:                      // All else is a mistake
6082     typerr(t);
6083 
6084   case AnyPtr: {
6085     // Found an AnyPtr type vs self-OopPtr type
6086     const TypePtr *tp = t->is_ptr();
6087     Offset offset = meet_offset(tp->offset());
6088     PTR ptr = meet_ptr(tp->ptr());
6089     switch (tp->ptr()) {
6090     case Null:
6091       if (ptr == Null)  return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6092       // else fall through:
6093     case TopPTR:
6094     case AnyNull: {
6095       return make(ptr, _metadata, offset);
6096     }
6097     case BotPTR:
6098     case NotNull:
6099       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6100     default: typerr(t);
6101     }
6102   }
6103 
6104   case RawPtr:
6105   case KlassPtr:
6106   case InstKlassPtr:
6107   case AryKlassPtr:
6108   case OopPtr:
6109   case InstPtr:
6110   case AryPtr:
6111     return TypePtr::BOTTOM;     // Oop meet raw is not well defined
6112 
6113   case MetadataPtr: {
6114     const TypeMetadataPtr *tp = t->is_metadataptr();
6115     Offset offset = meet_offset(tp->offset());
6116     PTR tptr = tp->ptr();
6117     PTR ptr = meet_ptr(tptr);
6118     ciMetadata* md = (tptr == TopPTR) ? metadata() : tp->metadata();
6119     if (tptr == TopPTR || _ptr == TopPTR ||
6120         metadata()->equals(tp->metadata())) {
6121       return make(ptr, md, offset);
6122     }
6123     // metadata is different
6124     if( ptr == Constant ) {  // Cannot be equal constants, so...
6125       if( tptr == Constant && _ptr != Constant)  return t;
6126       if( _ptr == Constant && tptr != Constant)  return this;
6127       ptr = NotNull;            // Fall down in lattice
6128     }
6129     return make(ptr, nullptr, offset);
6130     break;
6131   }
6132   } // End of switch
6133   return this;                  // Return the double constant
6134 }
6135 

6139 const Type *TypeMetadataPtr::xdual() const {
6140   return new TypeMetadataPtr(dual_ptr(), metadata(), dual_offset());
6141 }
6142 
6143 //------------------------------dump2------------------------------------------
6144 #ifndef PRODUCT
6145 void TypeMetadataPtr::dump2( Dict &d, uint depth, outputStream *st ) const {
6146   st->print("metadataptr:%s", ptr_msg[_ptr]);
6147   if (metadata() != nullptr) {
6148     st->print(":" INTPTR_FORMAT, p2i(metadata()));
6149   }
6150   dump_offset(st);
6151 }
6152 #endif
6153 
6154 
6155 //=============================================================================
6156 // Convenience common pre-built type.
6157 const TypeMetadataPtr *TypeMetadataPtr::BOTTOM;
6158 
6159 TypeMetadataPtr::TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset):
6160   TypePtr(MetadataPtr, ptr, offset), _metadata(metadata) {
6161 }
6162 
6163 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethod* m) {
6164   return make(Constant, m, Offset(0));
6165 }
6166 const TypeMetadataPtr* TypeMetadataPtr::make(ciMethodData* m) {
6167   return make(Constant, m, Offset(0));
6168 }
6169 
6170 //------------------------------make-------------------------------------------
6171 // Create a meta data constant
6172 const TypeMetadataPtr* TypeMetadataPtr::make(PTR ptr, ciMetadata* m, Offset offset) {
6173   assert(m == nullptr || !m->is_klass(), "wrong type");
6174   return (TypeMetadataPtr*)(new TypeMetadataPtr(ptr, m, offset))->hashcons();
6175 }
6176 
6177 
6178 const TypeKlassPtr* TypeAryPtr::as_klass_type(bool try_for_exact) const {
6179   const Type* elem = _ary->_elem;
6180   bool xk = klass_is_exact();
6181   bool is_refined = false;
6182   if (elem->make_oopptr() != nullptr) {
6183     is_refined = true;
6184     elem = elem->make_oopptr()->as_klass_type(try_for_exact);
6185     if (elem->isa_aryklassptr()) {
6186       const TypeAryKlassPtr* elem_klass = elem->is_aryklassptr();
6187       if (elem_klass->is_refined_type()) {
6188         elem = elem_klass->cast_to_non_refined();
6189       }
6190     } else {
6191       const TypeInstKlassPtr* elem_klass = elem->is_instklassptr();
6192       if (try_for_exact && !xk && elem_klass->klass_is_exact() &&
6193           !elem_klass->exact_klass()->as_instance_klass()->can_be_inline_klass()) {
6194         xk = true;
6195       }
6196     }
6197   }
6198   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_refined);
6199 }
6200 
6201 const TypeKlassPtr* TypeKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6202   if (klass->is_instance_klass()) {
6203     return TypeInstKlassPtr::make(klass, interface_handling);
6204   }
6205   return TypeAryKlassPtr::make(klass, interface_handling);
6206 }
6207 
6208 TypeKlassPtr::TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset)










6209   : TypePtr(t, ptr, offset), _klass(klass), _interfaces(interfaces) {
6210   assert(klass == nullptr || !klass->is_loaded() || (klass->is_instance_klass() && !klass->is_interface()) ||
6211          klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "no interface here");
6212 }
6213 
6214 // Is there a single ciKlass* that can represent that type?
6215 ciKlass* TypeKlassPtr::exact_klass_helper() const {
6216   assert(_klass->is_instance_klass() && !_klass->is_interface(), "No interface");
6217   if (_interfaces->empty()) {
6218     return _klass;
6219   }
6220   if (_klass != ciEnv::current()->Object_klass()) {
6221     if (_interfaces->eq(_klass->as_instance_klass())) {
6222       return _klass;
6223     }
6224     return nullptr;
6225   }
6226   return _interfaces->exact_klass();
6227 }
6228 
6229 //------------------------------eq---------------------------------------------
6230 // Structural equality check for Type representations
6231 bool TypeKlassPtr::eq(const Type *t) const {
6232   const TypeKlassPtr *p = t->is_klassptr();
6233   return
6234     _interfaces->eq(p->_interfaces) &&
6235     TypePtr::eq(p);
6236 }
6237 
6238 //------------------------------hash-------------------------------------------
6239 // Type-specific hashing function.
6240 uint TypeKlassPtr::hash(void) const {
6241   return TypePtr::hash() + _interfaces->hash();
6242 }
6243 
6244 //------------------------------singleton--------------------------------------
6245 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
6246 // constants
6247 bool TypeKlassPtr::singleton(void) const {
6248   // detune optimizer to not generate constant klass + constant offset as a constant!
6249   // TopPTR, Null, AnyNull, Constant are all singletons
6250   return (offset() == 0) && !below_centerline(_ptr);
6251 }
6252 
6253 // Do not allow interface-vs.-noninterface joins to collapse to top.
6254 const Type *TypeKlassPtr::filter_helper(const Type *kills, bool include_speculative) const {
6255   // logic here mirrors the one from TypeOopPtr::filter. See comments
6256   // there.
6257   const Type* ft = join_helper(kills, include_speculative);
6258 
6259   if (ft->empty()) {
6260     return Type::TOP;           // Canonical empty value
6261   }
6262 
6263   return ft;
6264 }
6265 
6266 const TypeInterfaces* TypeKlassPtr::meet_interfaces(const TypeKlassPtr* other) const {
6267   if (above_centerline(_ptr) && above_centerline(other->_ptr)) {
6268     return _interfaces->union_with(other->_interfaces);
6269   } else if (above_centerline(_ptr) && !above_centerline(other->_ptr)) {
6270     return other->_interfaces;
6271   } else if (above_centerline(other->_ptr) && !above_centerline(_ptr)) {
6272     return _interfaces;
6273   }
6274   return _interfaces->intersection_with(other->_interfaces);
6275 }
6276 
6277 //------------------------------get_con----------------------------------------
6278 intptr_t TypeKlassPtr::get_con() const {
6279   assert( _ptr == Null || _ptr == Constant, "" );
6280   assert( offset() >= 0, "" );
6281 
6282   if (offset() != 0) {
6283     // After being ported to the compiler interface, the compiler no longer
6284     // directly manipulates the addresses of oops.  Rather, it only has a pointer
6285     // to a handle at compile time.  This handle is embedded in the generated
6286     // code and dereferenced at the time the nmethod is made.  Until that time,
6287     // it is not reasonable to do arithmetic with the addresses of oops (we don't
6288     // have access to the addresses!).  This does not seem to currently happen,
6289     // but this assertion here is to help prevent its occurrence.
6290     tty->print_cr("Found oop constant with non-zero offset");
6291     ShouldNotReachHere();
6292   }
6293 
6294   ciKlass* k = exact_klass();
6295 
6296   return (intptr_t)k->constant_encoding();
6297 }
6298 
6299 //=============================================================================
6300 // Convenience common pre-built types.
6301 
6302 // Not-null object klass or below
6303 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT;
6304 const TypeInstKlassPtr *TypeInstKlassPtr::OBJECT_OR_NULL;
6305 
6306 bool TypeInstKlassPtr::eq(const Type *t) const {
6307   const TypeInstKlassPtr* p = t->is_instklassptr();
6308   return
6309     klass()->equals(p->klass()) &&
6310     _flat_in_array == p->_flat_in_array &&
6311     TypeKlassPtr::eq(p);
6312 }
6313 
6314 uint TypeInstKlassPtr::hash() const {
6315   return klass()->hash() + TypeKlassPtr::hash() + static_cast<uint>(_flat_in_array);
6316 }
6317 
6318 const TypeInstKlassPtr *TypeInstKlassPtr::make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset, FlatInArray flat_in_array) {
6319   if (flat_in_array == Uninitialized) {
6320     flat_in_array = compute_flat_in_array(k->as_instance_klass(), ptr == Constant);
6321   }
6322   TypeInstKlassPtr *r =
6323     (TypeInstKlassPtr*)(new TypeInstKlassPtr(ptr, k, interfaces, offset, flat_in_array))->hashcons();
6324 
6325   return r;
6326 }
6327 
6328 bool TypeInstKlassPtr::empty() const {
6329   if (_flat_in_array == TopFlat) {
6330     return true;
6331   }
6332   return TypeKlassPtr::empty();
6333 }
6334 
6335 //------------------------------add_offset-------------------------------------
6336 // Access internals of klass object
6337 const TypePtr *TypeInstKlassPtr::add_offset( intptr_t offset ) const {
6338   return make(_ptr, klass(), _interfaces, xadd_offset(offset), _flat_in_array);
6339 }
6340 
6341 const TypeInstKlassPtr* TypeInstKlassPtr::with_offset(intptr_t offset) const {
6342   return make(_ptr, klass(), _interfaces, Offset(offset), _flat_in_array);
6343 }
6344 
6345 //------------------------------cast_to_ptr_type-------------------------------
6346 const TypeInstKlassPtr* TypeInstKlassPtr::cast_to_ptr_type(PTR ptr) const {
6347   assert(_base == InstKlassPtr, "subclass must override cast_to_ptr_type");
6348   if( ptr == _ptr ) return this;
6349   return make(ptr, _klass, _interfaces, _offset, _flat_in_array);
6350 }
6351 
6352 
6353 bool TypeInstKlassPtr::must_be_exact() const {
6354   if (!_klass->is_loaded())  return false;
6355   ciInstanceKlass* ik = _klass->as_instance_klass();
6356   if (ik->is_final())  return true;  // cannot clear xk
6357   return false;
6358 }
6359 
6360 //-----------------------------cast_to_exactness-------------------------------
6361 const TypeKlassPtr* TypeInstKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6362   if (klass_is_exact == (_ptr == Constant)) return this;
6363   if (must_be_exact()) return this;
6364   ciKlass* k = klass();
6365   FlatInArray flat_in_array = compute_flat_in_array(k->as_instance_klass(), klass_is_exact);
6366   return make(klass_is_exact ? Constant : NotNull, k, _interfaces, _offset, flat_in_array);
6367 }
6368 
6369 
6370 //-----------------------------as_instance_type--------------------------------
6371 // Corresponding type for an instance of the given class.
6372 // It will be NotNull, and exact if and only if the klass type is exact.
6373 const TypeOopPtr* TypeInstKlassPtr::as_instance_type(bool klass_change) const {
6374   ciKlass* k = klass();
6375   bool xk = klass_is_exact();
6376   Compile* C = Compile::current();
6377   Dependencies* deps = C->dependencies();
6378   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");
6379   // Element is an instance
6380   bool klass_is_exact = false;
6381   const TypeInterfaces* interfaces = _interfaces;
6382   ciInstanceKlass* ik = k->as_instance_klass();
6383   if (k->is_loaded()) {
6384     // Try to set klass_is_exact.

6385     klass_is_exact = ik->is_final();
6386     if (!klass_is_exact && klass_change
6387         && deps != nullptr && UseUniqueSubclasses) {
6388       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6389       if (sub != nullptr) {
6390         if (_interfaces->eq(sub)) {
6391           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6392           k = ik = sub;
6393           xk = sub->is_final();
6394         }
6395       }
6396     }
6397   }
6398 
6399   FlatInArray flat_in_array = compute_flat_in_array_if_unknown(ik, xk, _flat_in_array);
6400   return TypeInstPtr::make(TypePtr::BotPTR, k, interfaces, xk, nullptr, Offset(0), flat_in_array);
6401 }
6402 
6403 //------------------------------xmeet------------------------------------------
6404 // Compute the MEET of two types, return a new Type object.
6405 const Type    *TypeInstKlassPtr::xmeet( const Type *t ) const {
6406   // Perform a fast test for common case; meeting the same types together.
6407   if( this == t ) return this;  // Meeting same type-rep?
6408 
6409   // Current "this->_base" is Pointer
6410   switch (t->base()) {          // switch on original type
6411 
6412   case Int:                     // Mixing ints & oops happens when javac
6413   case Long:                    // reuses local variables
6414   case HalfFloatTop:
6415   case HalfFloatCon:
6416   case HalfFloatBot:
6417   case FloatTop:
6418   case FloatCon:
6419   case FloatBot:
6420   case DoubleTop:
6421   case DoubleCon:
6422   case DoubleBot:
6423   case NarrowOop:
6424   case NarrowKlass:
6425   case Bottom:                  // Ye Olde Default
6426     return Type::BOTTOM;
6427   case Top:
6428     return this;
6429 
6430   default:                      // All else is a mistake
6431     typerr(t);
6432 
6433   case AnyPtr: {                // Meeting to AnyPtrs
6434     // Found an AnyPtr type vs self-KlassPtr type
6435     const TypePtr *tp = t->is_ptr();
6436     Offset offset = meet_offset(tp->offset());
6437     PTR ptr = meet_ptr(tp->ptr());
6438     switch (tp->ptr()) {
6439     case TopPTR:
6440       return this;
6441     case Null:
6442       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6443     case AnyNull:
6444       return make(ptr, klass(), _interfaces, offset, _flat_in_array);
6445     case BotPTR:
6446     case NotNull:
6447       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6448     default: typerr(t);
6449     }
6450   }
6451 
6452   case RawPtr:
6453   case MetadataPtr:
6454   case OopPtr:
6455   case AryPtr:                  // Meet with AryPtr
6456   case InstPtr:                 // Meet with InstPtr
6457       return TypePtr::BOTTOM;
6458 
6459   //
6460   //             A-top         }
6461   //           /   |   \       }  Tops
6462   //       B-top A-any C-top   }
6463   //          | /  |  \ |      }  Any-nulls
6464   //       B-any   |   C-any   }
6465   //          |    |    |
6466   //       B-con A-con C-con   } constants; not comparable across classes
6467   //          |    |    |
6468   //       B-not   |   C-not   }
6469   //          | \  |  / |      }  not-nulls
6470   //       B-bot A-not C-bot   }
6471   //           \   |   /       }  Bottoms
6472   //             A-bot         }
6473   //
6474 
6475   case InstKlassPtr: {  // Meet two KlassPtr types
6476     const TypeInstKlassPtr *tkls = t->is_instklassptr();
6477     Offset  off     = meet_offset(tkls->offset());
6478     PTR  ptr     = meet_ptr(tkls->ptr());
6479     const TypeInterfaces* interfaces = meet_interfaces(tkls);
6480 
6481     ciKlass* res_klass = nullptr;
6482     bool res_xk = false;
6483     const FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, tkls->flat_in_array());
6484     switch (meet_instptr(ptr, interfaces, this, tkls, res_klass, res_xk)) {
6485       case UNLOADED:
6486         ShouldNotReachHere();
6487       case SUBTYPE:
6488       case NOT_SUBTYPE:
6489       case LCA:
6490       case QUICK: {
6491         assert(res_xk == (ptr == Constant), "");
6492         const Type* res = make(ptr, res_klass, interfaces, off, flat_in_array);
6493         return res;
6494       }
6495       default:
6496         ShouldNotReachHere();
6497     }
6498   } // End of case KlassPtr
6499   case AryKlassPtr: {                // All arrays inherit from Object class
6500     const TypeAryKlassPtr *tp = t->is_aryklassptr();
6501     Offset offset = meet_offset(tp->offset());
6502     PTR ptr = meet_ptr(tp->ptr());
6503     const TypeInterfaces* interfaces = meet_interfaces(tp);
6504     const TypeInterfaces* tp_interfaces = tp->_interfaces;
6505     const TypeInterfaces* this_interfaces = _interfaces;
6506 
6507     switch (ptr) {
6508     case TopPTR:
6509     case AnyNull:                // Fall 'down' to dual of object klass
6510       // For instances when a subclass meets a superclass we fall
6511       // below the centerline when the superclass is exact. We need to
6512       // do the same here.
6513       //
6514       // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6515       if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6516           !klass_is_exact() && !is_not_flat_in_array()) {
6517         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());
6518       } else {
6519         // cannot subclass, so the meet has to fall badly below the centerline
6520         ptr = NotNull;
6521         interfaces = _interfaces->intersection_with(tp->_interfaces);
6522         FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6523         return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6524       }
6525     case Constant:
6526     case NotNull:
6527     case BotPTR: { // Fall down to object klass
6528       // LCA is object_klass, but if we subclass from the top we can do better
6529       if( above_centerline(_ptr) ) { // if( _ptr == TopPTR || _ptr == AnyNull )
6530         // If 'this' (InstPtr) is above the centerline and it is Object class
6531         // then we can subclass in the Java class hierarchy.
6532         // For instances when a subclass meets a superclass we fall
6533         // below the centerline when the superclass is exact. We need
6534         // to do the same here.
6535         //
6536         // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
6537         if (klass()->equals(ciEnv::current()->Object_klass()) && tp_interfaces->contains(this_interfaces) &&
6538             !klass_is_exact() && !is_not_flat_in_array()) {
6539           // that is, tp's array type is a subtype of my klass
6540           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());

6541         }
6542       }
6543       // The other case cannot happen, since I cannot be a subtype of an array.
6544       // The meet falls down to Object class below centerline.
6545       if( ptr == Constant )
6546         ptr = NotNull;
6547       interfaces = this_interfaces->intersection_with(tp_interfaces);
6548       FlatInArray flat_in_array = meet_flat_in_array(_flat_in_array, NotFlat);
6549       return make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
6550     }
6551     default: typerr(t);
6552     }
6553   }
6554 
6555   } // End of switch
6556   return this;                  // Return the double constant
6557 }
6558 
6559 //------------------------------xdual------------------------------------------
6560 // Dual: compute field-by-field dual
6561 const Type* TypeInstKlassPtr::xdual() const {
6562   return new TypeInstKlassPtr(dual_ptr(), klass(), _interfaces, dual_offset(), dual_flat_in_array());
6563 }
6564 
6565 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) {
6566   static_assert(std::is_base_of<T2, T1>::value, "");
6567   if (!this_one->is_loaded() || !other->is_loaded()) {
6568     return false;
6569   }
6570   if (!this_one->is_instance_type(other)) {
6571     return false;
6572   }
6573 
6574   if (!other_exact) {
6575     return false;
6576   }
6577 
6578   if (other->klass()->equals(ciEnv::current()->Object_klass()) && other->_interfaces->empty()) {
6579     return true;
6580   }
6581 
6582   return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);

6636 
6637   if (this_exact) {
6638     return this_one->klass()->is_subtype_of(other->klass()) && this_one->_interfaces->contains(other->_interfaces);
6639   }
6640 
6641   return true;
6642 }
6643 
6644 bool TypeInstKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
6645   return TypePtr::maybe_java_subtype_of_helper_for_instance(this, other, this_exact, other_exact);
6646 }
6647 
6648 const TypeKlassPtr* TypeInstKlassPtr::try_improve() const {
6649   if (!UseUniqueSubclasses) {
6650     return this;
6651   }
6652   ciKlass* k = klass();
6653   Compile* C = Compile::current();
6654   Dependencies* deps = C->dependencies();
6655   assert((deps != nullptr) == (C->method() != nullptr && C->method()->code_size() > 0), "sanity");

6656   if (k->is_loaded()) {
6657     ciInstanceKlass* ik = k->as_instance_klass();
6658     if (deps != nullptr) {


6659       ciInstanceKlass* sub = ik->unique_concrete_subklass();
6660       if (sub != nullptr) {
6661         bool improve_to_exact = sub->is_final() && _ptr == NotNull;
6662         const TypeInstKlassPtr* improved = TypeInstKlassPtr::make(improve_to_exact ? Constant : _ptr, sub, _offset);
6663         if (improved->_interfaces->contains(_interfaces)) {
6664           deps->assert_abstract_with_unique_concrete_subtype(ik, sub);
6665           return improved;


6666         }
6667       }
6668     }
6669   }
6670   return this;
6671 }
6672 
6673 bool TypeInstKlassPtr::can_be_inline_array() const {
6674   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryKlassPtr::_array_interfaces->contains(_interfaces);
6675 }
6676 
6677 #ifndef PRODUCT
6678 void TypeInstKlassPtr::dump2(Dict& d, uint depth, outputStream* st) const {
6679   st->print("instklassptr:");
6680   klass()->print_name_on(st);
6681   _interfaces->dump(st);
6682   st->print(":%s", ptr_msg[_ptr]);
6683   dump_offset(st);
6684   dump_flat_in_array(_flat_in_array, st);
6685 }
6686 #endif // PRODUCT
6687 
6688 bool TypeAryKlassPtr::can_be_inline_array() const {
6689   return _elem->isa_instklassptr() && _elem->is_instklassptr()->_klass->can_be_inline_klass();
6690 }
6691 
6692 bool TypeInstPtr::can_be_inline_array() const {
6693   return _klass->equals(ciEnv::current()->Object_klass()) && TypeAryPtr::_array_interfaces->contains(_interfaces);
6694 }
6695 
6696 bool TypeAryPtr::can_be_inline_array() const {
6697   return elem()->make_ptr() && elem()->make_ptr()->isa_instptr() && elem()->make_ptr()->is_instptr()->_klass->can_be_inline_klass();
6698 }
6699 
6700 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) {
6701   return (TypeAryKlassPtr*)(new TypeAryKlassPtr(ptr, elem, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type))->hashcons();
6702 }
6703 
6704 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) {
6705   const Type* etype;
6706   if (k->is_obj_array_klass()) {
6707     // Element is an object array. Recursively call ourself.
6708     ciKlass* eklass = k->as_obj_array_klass()->element_klass();
6709     etype = TypeKlassPtr::make(eklass, interface_handling)->cast_to_exactness(false);
6710     k = nullptr;
6711   } else if (k->is_type_array_klass()) {
6712     // Element is an typeArray
6713     etype = get_const_basic_type(k->as_type_array_klass()->element_type());

6714   } else {
6715     ShouldNotReachHere();

6716   }
6717 
6718   return TypeAryKlassPtr::make(ptr, etype, k, offset, not_flat, not_null_free, flat, null_free, atomic, refined_type);
6719 }
6720 
6721 const TypeAryKlassPtr* TypeAryKlassPtr::make(ciKlass* klass, InterfaceHandling interface_handling) {
6722   ciArrayKlass* k = klass->as_array_klass();
6723   if (k->is_refined()) {
6724     return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, !k->is_flat_array_klass(), !k->is_elem_null_free(),
6725                                  k->is_flat_array_klass(), k->is_elem_null_free(), k->is_elem_atomic(), true);
6726   } else {
6727     // Use the default combination to canonicalize all non-refined klass pointers
6728     return TypeAryKlassPtr::make(Constant, k, Offset(0), interface_handling, true, true, false, false, true, false);
6729   }
6730 }
6731 
6732 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_non_refined() const {
6733   assert(is_refined_type(), "must be a refined type");
6734   PTR ptr = _ptr;
6735   // There can be multiple refined array types corresponding to a single unrefined type
6736   if (ptr == NotNull && elem()->is_klassptr()->klass_is_exact()) {
6737     ptr = Constant;
6738   }
6739   return make(ptr, elem(), nullptr, _offset, true, true, false, false, true, false);
6740 }
6741 
6742 // Get the (non-)refined array klass ptr
6743 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_refined_array_klass_ptr(bool refined) const {
6744   if ((refined == is_refined_type()) || !klass_is_exact() || !exact_klass()->is_obj_array_klass()) {
6745     return this;
6746   }
6747   ciArrayKlass* k = exact_klass()->as_array_klass();
6748   k = ciObjArrayKlass::make(k->element_klass(), refined);
6749   return make(k, trust_interfaces);
6750 }
6751 
6752 //------------------------------eq---------------------------------------------
6753 // Structural equality check for Type representations
6754 bool TypeAryKlassPtr::eq(const Type *t) const {
6755   const TypeAryKlassPtr *p = t->is_aryklassptr();
6756   return
6757     _elem == p->_elem &&  // Check array
6758     _flat == p->_flat &&
6759     _not_flat == p->_not_flat &&
6760     _null_free == p->_null_free &&
6761     _not_null_free == p->_not_null_free &&
6762     _atomic == p->_atomic &&
6763     _refined_type == p->_refined_type &&
6764     TypeKlassPtr::eq(p);  // Check sub-parts
6765 }
6766 
6767 //------------------------------hash-------------------------------------------
6768 // Type-specific hashing function.
6769 uint TypeAryKlassPtr::hash(void) const {
6770   return (uint)(uintptr_t)_elem + TypeKlassPtr::hash() + (uint)(_not_flat ? 43 : 0) +
6771       (uint)(_not_null_free ? 44 : 0) + (uint)(_flat ? 45 : 0) + (uint)(_null_free ? 46 : 0)  + (uint)(_atomic ? 47 : 0) + (uint)(_refined_type ? 48 : 0);
6772 }
6773 
6774 //----------------------compute_klass------------------------------------------
6775 // Compute the defining klass for this class
6776 ciKlass* TypeAryPtr::compute_klass() const {
6777   // Compute _klass based on element type.
6778   ciKlass* k_ary = nullptr;
6779   const TypeInstPtr *tinst;
6780   const TypeAryPtr *tary;
6781   const Type* el = elem();
6782   if (el->isa_narrowoop()) {
6783     el = el->make_ptr();
6784   }
6785 
6786   // Get element klass
6787   if ((tinst = el->isa_instptr()) != nullptr) {
6788     // Leave k_ary at nullptr.
6789   } else if ((tary = el->isa_aryptr()) != nullptr) {
6790     // Leave k_ary at nullptr.
6791   } else if ((el->base() == Type::Top) ||
6792              (el->base() == Type::Bottom)) {
6793     // element type of Bottom occurs from meet of basic type
6794     // and object; Top occurs when doing join on Bottom.
6795     // Leave k_ary at null.
6796   } else {
6797     assert(!el->isa_int(), "integral arrays must be pre-equipped with a class");
6798     // Compute array klass directly from basic type
6799     k_ary = ciTypeArrayKlass::make(el->basic_type());
6800   }
6801   return k_ary;
6802 }
6803 
6804 //------------------------------klass------------------------------------------
6805 // Return the defining klass for this class
6806 ciKlass* TypeAryPtr::klass() const {
6807   if( _klass ) return _klass;   // Return cached value, if possible
6808 
6809   // Oops, need to compute _klass and cache it
6810   ciKlass* k_ary = compute_klass();

6818     // type TypeAryPtr::OOPS.  This Type is shared between all
6819     // active compilations.  However, the ciKlass which represents
6820     // this Type is *not* shared between compilations, so caching
6821     // this value would result in fetching a dangling pointer.
6822     //
6823     // Recomputing the underlying ciKlass for each request is
6824     // a bit less efficient than caching, but calls to
6825     // TypeAryPtr::OOPS->klass() are not common enough to matter.
6826     ((TypeAryPtr*)this)->_klass = k_ary;
6827   }
6828   return k_ary;
6829 }
6830 
6831 // Is there a single ciKlass* that can represent that type?
6832 ciKlass* TypeAryPtr::exact_klass_helper() const {
6833   if (_ary->_elem->make_ptr() && _ary->_elem->make_ptr()->isa_oopptr()) {
6834     ciKlass* k = _ary->_elem->make_ptr()->is_oopptr()->exact_klass_helper();
6835     if (k == nullptr) {
6836       return nullptr;
6837     }
6838     if (k->is_array_klass() && k->as_array_klass()->is_refined()) {
6839       // We have no mechanism to create an array of refined arrays
6840       k = ciObjArrayKlass::make(k->as_array_klass()->element_klass(), false);
6841     }
6842     if (klass_is_exact()) {
6843       return ciObjArrayKlass::make(k, true, is_null_free(), is_atomic());
6844     } else {
6845       // We may reach here if called recursively, must be an unrefined type then
6846       return ciObjArrayKlass::make(k, false);
6847     }
6848   }
6849 
6850   return klass();
6851 }
6852 
6853 const Type* TypeAryPtr::base_element_type(int& dims) const {
6854   const Type* elem = this->elem();
6855   dims = 1;
6856   while (elem->make_ptr() && elem->make_ptr()->isa_aryptr()) {
6857     elem = elem->make_ptr()->is_aryptr()->elem();
6858     dims++;
6859   }
6860   return elem;
6861 }
6862 
6863 //------------------------------add_offset-------------------------------------
6864 // Access internals of klass object
6865 const TypePtr* TypeAryKlassPtr::add_offset(intptr_t offset) const {
6866   return make(_ptr, elem(), klass(), xadd_offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6867 }
6868 
6869 const TypeAryKlassPtr* TypeAryKlassPtr::with_offset(intptr_t offset) const {
6870   return make(_ptr, elem(), klass(), Offset(offset), is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6871 }
6872 
6873 //------------------------------cast_to_ptr_type-------------------------------
6874 const TypeAryKlassPtr* TypeAryKlassPtr::cast_to_ptr_type(PTR ptr) const {
6875   assert(_base == AryKlassPtr, "subclass must override cast_to_ptr_type");
6876   if (ptr == _ptr) return this;
6877   return make(ptr, elem(), _klass, _offset, is_not_flat(), is_not_null_free(), _flat, _null_free, _atomic, _refined_type);
6878 }
6879 
6880 bool TypeAryKlassPtr::must_be_exact() const {
6881   assert(klass_is_exact(), "precondition");
6882   if (_elem == Type::BOTTOM || _elem == Type::TOP) {
6883     return false;
6884   }
6885   const TypeKlassPtr* elem = _elem->isa_klassptr();
6886   if (elem == nullptr) {
6887     // primitive arrays
6888     return true;
6889   }
6890 
6891   // refined types are final
6892   return _refined_type;
6893 }
6894 
6895 //-----------------------------cast_to_exactness-------------------------------
6896 const TypeKlassPtr *TypeAryKlassPtr::cast_to_exactness(bool klass_is_exact) const {
6897   if (klass_is_exact == this->klass_is_exact()) {
6898     return this;
6899   }
6900   if (!klass_is_exact && must_be_exact()) {
6901     return this;
6902   }
6903   const Type* elem = this->elem();
6904   if (elem->isa_klassptr() && !klass_is_exact) {
6905     elem = elem->is_klassptr()->cast_to_exactness(klass_is_exact);
6906   }


6907 
6908   if (klass_is_exact) {
6909     // cast_to_exactness(true) really means get the LCA of all values represented by this
6910     // TypeAryKlassPtr. As a result, it must be an unrefined klass pointer.
6911     return make(Constant, elem, nullptr, _offset, true, true, false, false, true, false);
6912   } else {
6913     // cast_to_exactness(false) means get the TypeAryKlassPtr representing all values that subtype
6914     // this value
6915     bool not_inline = !_elem->isa_instklassptr() || !_elem->is_instklassptr()->instance_klass()->can_be_inline_klass();
6916     bool not_flat = !UseArrayFlattening || not_inline ||
6917                     (_elem->isa_instklassptr() && _elem->is_instklassptr()->instance_klass()->is_inlinetype() && !_elem->is_instklassptr()->instance_klass()->maybe_flat_in_array());
6918     bool not_null_free = not_inline;
6919     bool atomic = not_flat;
6920     return make(NotNull, elem, nullptr, _offset, not_flat, not_null_free, false, false, atomic, false);
6921   }
6922 }
6923 
6924 //-----------------------------as_instance_type--------------------------------
6925 // Corresponding type for an instance of the given class.
6926 // It will be NotNull, and exact if and only if the klass type is exact.
6927 const TypeOopPtr* TypeAryKlassPtr::as_instance_type(bool klass_change) const {
6928   ciKlass* k = klass();
6929   bool    xk = klass_is_exact();
6930   const Type* el = nullptr;
6931   if (elem()->isa_klassptr()) {
6932     el = elem()->is_klassptr()->as_instance_type(false)->cast_to_exactness(false);
6933     k = nullptr;
6934   } else {
6935     el = elem();
6936   }
6937   bool null_free = _null_free;
6938   if (null_free && el->isa_ptr()) {
6939     el = el->is_ptr()->join_speculative(TypePtr::NOTNULL);
6940   }
6941   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));
6942 }
6943 
6944 
6945 //------------------------------xmeet------------------------------------------
6946 // Compute the MEET of two types, return a new Type object.
6947 const Type    *TypeAryKlassPtr::xmeet( const Type *t ) const {
6948   // Perform a fast test for common case; meeting the same types together.
6949   if( this == t ) return this;  // Meeting same type-rep?
6950 
6951   // Current "this->_base" is Pointer
6952   switch (t->base()) {          // switch on original type
6953 
6954   case Int:                     // Mixing ints & oops happens when javac
6955   case Long:                    // reuses local variables
6956   case HalfFloatTop:
6957   case HalfFloatCon:
6958   case HalfFloatBot:
6959   case FloatTop:
6960   case FloatCon:
6961   case FloatBot:
6962   case DoubleTop:
6963   case DoubleCon:
6964   case DoubleBot:
6965   case NarrowOop:
6966   case NarrowKlass:
6967   case Bottom:                  // Ye Olde Default
6968     return Type::BOTTOM;
6969   case Top:
6970     return this;
6971 
6972   default:                      // All else is a mistake
6973     typerr(t);
6974 
6975   case AnyPtr: {                // Meeting to AnyPtrs
6976     // Found an AnyPtr type vs self-KlassPtr type
6977     const TypePtr *tp = t->is_ptr();
6978     Offset offset = meet_offset(tp->offset());
6979     PTR ptr = meet_ptr(tp->ptr());
6980     switch (tp->ptr()) {
6981     case TopPTR:
6982       return this;
6983     case Null:
6984       if( ptr == Null ) return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6985     case AnyNull:
6986       return make(ptr, _elem, klass(), offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
6987     case BotPTR:
6988     case NotNull:
6989       return TypePtr::make(AnyPtr, ptr, offset, tp->speculative(), tp->inline_depth());
6990     default: typerr(t);
6991     }
6992   }
6993 
6994   case RawPtr:
6995   case MetadataPtr:
6996   case OopPtr:
6997   case AryPtr:                  // Meet with AryPtr
6998   case InstPtr:                 // Meet with InstPtr
6999     return TypePtr::BOTTOM;
7000 
7001   //
7002   //             A-top         }
7003   //           /   |   \       }  Tops
7004   //       B-top A-any C-top   }
7005   //          | /  |  \ |      }  Any-nulls
7006   //       B-any   |   C-any   }
7007   //          |    |    |
7008   //       B-con A-con C-con   } constants; not comparable across classes
7009   //          |    |    |
7010   //       B-not   |   C-not   }
7011   //          | \  |  / |      }  not-nulls
7012   //       B-bot A-not C-bot   }
7013   //           \   |   /       }  Bottoms
7014   //             A-bot         }
7015   //
7016 
7017   case AryKlassPtr: {  // Meet two KlassPtr types
7018     const TypeAryKlassPtr *tap = t->is_aryklassptr();
7019     Offset off = meet_offset(tap->offset());
7020     const Type* elem = _elem->meet(tap->_elem);

7021     PTR ptr = meet_ptr(tap->ptr());
7022     ciKlass* res_klass = nullptr;
7023     bool res_xk = false;
7024     bool res_flat = false;
7025     bool res_not_flat = false;
7026     bool res_not_null_free = false;
7027     bool res_atomic = false;
7028     MeetResult res = meet_aryptr(ptr, elem, this, tap,
7029                                  res_klass, res_xk, res_flat, res_not_flat, res_not_null_free, res_atomic);
7030     assert(res_xk == (ptr == Constant), "");
7031     bool flat = meet_flat(tap->_flat);
7032     bool null_free = meet_null_free(tap->_null_free);
7033     bool atomic = meet_atomic(tap->_atomic);
7034     bool refined_type = _refined_type && tap->_refined_type;
7035     if (res == NOT_SUBTYPE) {
7036       flat = false;
7037       null_free = false;
7038       atomic = false;
7039       refined_type = false;
7040     } else if (res == SUBTYPE) {
7041       if (above_centerline(tap->ptr()) && !above_centerline(this->ptr())) {
7042         flat = _flat;
7043         null_free = _null_free;
7044         atomic = _atomic;
7045         refined_type = _refined_type;
7046       } else if (above_centerline(this->ptr()) && !above_centerline(tap->ptr())) {
7047         flat = tap->_flat;
7048         null_free = tap->_null_free;
7049         atomic = tap->_atomic;
7050         refined_type = tap->_refined_type;
7051       } else if (above_centerline(this->ptr()) && above_centerline(tap->ptr())) {
7052         flat = _flat || tap->_flat;
7053         null_free = _null_free || tap->_null_free;
7054         atomic = _atomic || tap->_atomic;
7055         refined_type = _refined_type || tap->_refined_type;
7056       } else if (res_xk && _refined_type != tap->_refined_type) {
7057         // This can happen if the phi emitted by LibraryCallKit::load_default_refined_array_klass/load_non_refined_array_klass
7058         // is processed before the typeArray guard is folded. Both inputs are constant but the input corresponding to the
7059         // typeArray will go away. Don't constant fold it yet but wait for the control input to collapse.
7060         ptr = PTR::NotNull;
7061       }
7062     }
7063     return make(ptr, elem, res_klass, off, res_not_flat, res_not_null_free, flat, null_free, atomic, refined_type);
7064   } // End of case KlassPtr
7065   case InstKlassPtr: {
7066     const TypeInstKlassPtr *tp = t->is_instklassptr();
7067     Offset offset = meet_offset(tp->offset());
7068     PTR ptr = meet_ptr(tp->ptr());
7069     const TypeInterfaces* interfaces = meet_interfaces(tp);
7070     const TypeInterfaces* tp_interfaces = tp->_interfaces;
7071     const TypeInterfaces* this_interfaces = _interfaces;
7072 
7073     switch (ptr) {
7074     case TopPTR:
7075     case AnyNull:                // Fall 'down' to dual of object klass
7076       // For instances when a subclass meets a superclass we fall
7077       // below the centerline when the superclass is exact. We need to
7078       // do the same here.
7079       //
7080       // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7081       if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7082           !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7083         return TypeAryKlassPtr::make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7084       } else {
7085         // cannot subclass, so the meet has to fall badly below the centerline
7086         ptr = NotNull;
7087         interfaces = this_interfaces->intersection_with(tp->_interfaces);
7088         FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7089         return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7090       }
7091     case Constant:
7092     case NotNull:
7093     case BotPTR: { // Fall down to object klass
7094       // LCA is object_klass, but if we subclass from the top we can do better
7095       if (above_centerline(tp->ptr())) {
7096         // If 'tp'  is above the centerline and it is Object class
7097         // then we can subclass in the Java class hierarchy.
7098         // For instances when a subclass meets a superclass we fall
7099         // below the centerline when the superclass is exact. We need
7100         // to do the same here.
7101         //
7102         // Flat in array: See explanation for meet with TypeInstPtr in TypeAryPtr::xmeet_helper().
7103         if (tp->klass()->equals(ciEnv::current()->Object_klass()) && this_interfaces->contains(tp_interfaces) &&
7104             !tp->klass_is_exact() && !tp->is_not_flat_in_array()) {
7105           // that is, my array type is a subtype of 'tp' klass
7106           return make(ptr, _elem, _klass, offset, is_not_flat(), is_not_null_free(), is_flat(), is_null_free(), is_atomic(), is_refined_type());
7107         }
7108       }
7109       // The other case cannot happen, since t cannot be a subtype of an array.
7110       // The meet falls down to Object class below centerline.
7111       if (ptr == Constant)
7112         ptr = NotNull;
7113       interfaces = this_interfaces->intersection_with(tp_interfaces);
7114       FlatInArray flat_in_array = meet_flat_in_array(NotFlat, tp->flat_in_array());
7115       return TypeInstKlassPtr::make(ptr, ciEnv::current()->Object_klass(), interfaces, offset, flat_in_array);
7116     }
7117     default: typerr(t);
7118     }
7119   }
7120 
7121   } // End of switch
7122   return this;                  // Return the double constant
7123 }
7124 
7125 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) {
7126   static_assert(std::is_base_of<T2, T1>::value, "");
7127 
7128   if (other->klass() == ciEnv::current()->Object_klass() && other->_interfaces->empty() && other_exact) {
7129     return true;
7130   }
7131 
7132   int dummy;
7133   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7134 
7135   if (!this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {
7136     return false;
7137   }
7138 
7139   if (this_one->is_instance_type(other)) {
7140     return other->klass() == ciEnv::current()->Object_klass() && this_one->_interfaces->contains(other->_interfaces) &&
7141            other_exact;
7142   }
7143 
7144   assert(this_one->is_array_type(other), "");
7145   const T1* other_ary = this_one->is_array_type(other);
7146   bool other_top_or_bottom = (other_ary->base_element_type(dummy) == Type::TOP || other_ary->base_element_type(dummy) == Type::BOTTOM);
7147   if (other_top_or_bottom) {
7148     return false;
7149   }
7150 
7151   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7152   const TypePtr* this_elem = this_one->elem()->make_ptr();
7153   if (this_elem != nullptr && other_elem != nullptr) {
7154     if (other->is_null_free() && !this_one->is_null_free()) {
7155       return false; // A nullable array can't be a subtype of a null-free array
7156     }
7157     return this_one->is_reference_type(this_elem)->is_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7158   }
7159   if (this_elem == nullptr && other_elem == nullptr) {
7160     return this_one->klass()->is_subtype_of(other->klass());
7161   }
7162   return false;
7163 }
7164 
7165 bool TypeAryKlassPtr::is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7166   return TypePtr::is_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7167 }
7168 
7169 template <class T1, class T2> bool TypePtr::is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other) {
7170   static_assert(std::is_base_of<T2, T1>::value, "");
7171 
7172   int dummy;
7173   bool this_top_or_bottom = (this_one->base_element_type(dummy) == Type::TOP || this_one->base_element_type(dummy) == Type::BOTTOM);
7174 
7175   if (!this_one->is_array_type(other) ||
7176       !this_one->is_loaded() || !other->is_loaded() || this_top_or_bottom) {

7229   }
7230 
7231   const TypePtr* this_elem = this_one->elem()->make_ptr();
7232   const TypePtr* other_elem = other_ary->elem()->make_ptr();
7233   if (other_elem != nullptr && this_elem != nullptr) {
7234     return this_one->is_reference_type(this_elem)->maybe_java_subtype_of_helper(this_one->is_reference_type(other_elem), this_exact, other_exact);
7235   }
7236   if (other_elem == nullptr && this_elem == nullptr) {
7237     return this_one->klass()->is_subtype_of(other->klass());
7238   }
7239   return false;
7240 }
7241 
7242 bool TypeAryKlassPtr::maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const {
7243   return TypePtr::maybe_java_subtype_of_helper_for_array(this, other, this_exact, other_exact);
7244 }
7245 
7246 //------------------------------xdual------------------------------------------
7247 // Dual: compute field-by-field dual
7248 const Type    *TypeAryKlassPtr::xdual() const {
7249   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);
7250 }
7251 
7252 // Is there a single ciKlass* that can represent that type?
7253 ciKlass* TypeAryKlassPtr::exact_klass_helper() const {
7254   if (elem()->isa_klassptr()) {
7255     ciKlass* k = elem()->is_klassptr()->exact_klass_helper();
7256     if (k == nullptr) {
7257       return nullptr;
7258     }
7259     assert(!k->is_array_klass() || !k->as_array_klass()->is_refined(), "no mechanism to create an array of refined arrays %s", k->name()->as_utf8());
7260     k = ciArrayKlass::make(k, is_null_free(), is_atomic(), _refined_type);
7261     return k;
7262   }
7263 
7264   return klass();
7265 }
7266 
7267 ciKlass* TypeAryKlassPtr::klass() const {
7268   if (_klass != nullptr) {
7269     return _klass;
7270   }
7271   ciKlass* k = nullptr;
7272   if (elem()->isa_klassptr()) {
7273     // leave null
7274   } else if ((elem()->base() == Type::Top) ||
7275              (elem()->base() == Type::Bottom)) {
7276   } else {
7277     k = ciTypeArrayKlass::make(elem()->basic_type());
7278     ((TypeAryKlassPtr*)this)->_klass = k;
7279   }
7280   return k;
7281 }
7282 
7283 //------------------------------dump2------------------------------------------
7284 // Dump Klass Type
7285 #ifndef PRODUCT
7286 void TypeAryKlassPtr::dump2( Dict & d, uint depth, outputStream *st ) const {
7287   st->print("aryklassptr:[");
7288   _elem->dump2(d, depth, st);
7289   _interfaces->dump(st);
7290   st->print(":%s", ptr_msg[_ptr]);
7291   if (_flat) st->print(":flat");
7292   if (_null_free) st->print(":null free");
7293   if (_atomic) st->print(":atomic");
7294   if (_refined_type) st->print(":refined_type");
7295   if (Verbose) {
7296     if (_not_flat) st->print(":not flat");
7297     if (_not_null_free) st->print(":nullable");
7298   }
7299   dump_offset(st);
7300 }
7301 #endif
7302 
7303 const Type* TypeAryKlassPtr::base_element_type(int& dims) const {
7304   const Type* elem = this->elem();
7305   dims = 1;
7306   while (elem->isa_aryklassptr()) {
7307     elem = elem->is_aryklassptr()->elem();
7308     dims++;
7309   }
7310   return elem;
7311 }
7312 
7313 //=============================================================================
7314 // Convenience common pre-built types.
7315 
7316 //------------------------------make-------------------------------------------
7317 const TypeFunc *TypeFunc::make(const TypeTuple *domain_sig, const TypeTuple* domain_cc,
7318                                const TypeTuple* range_sig, const TypeTuple* range_cc,
7319                                bool scalarized_return) {
7320   return (TypeFunc*)(new TypeFunc(domain_sig, domain_cc, range_sig, range_cc, scalarized_return))->hashcons();
7321 }
7322 
7323 const TypeFunc *TypeFunc::make(const TypeTuple *domain, const TypeTuple *range) {
7324   return make(domain, domain, range, range);
7325 }
7326 
7327 //------------------------------osr_domain-----------------------------
7328 const TypeTuple* osr_domain() {
7329   const Type **fields = TypeTuple::fields(2);
7330   fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM;  // address of osr buffer
7331   return TypeTuple::make(TypeFunc::Parms+1, fields);
7332 }
7333 
7334 // Build a TypeFunc with both the Java-signature view ('sig') and the actual calling-
7335 // convention view ('cc') of inline types. In the signature, an inline type is a single
7336 // oop slot. In the scalarized calling convention, it is expanded to its field
7337 // values (plus null marker and optional oop to the heap buffer).
7338 // The 'is_call' argument distinguishes between the return signature of a method at calls
7339 // vs. at compilation of that method because at calls we return an additional null marker field.
7340 // For OSR and mismatching calls, we fall back to the non-scalarized argument view.
7341 const TypeFunc* TypeFunc::make(ciMethod* method, bool is_call, bool is_osr_compilation) {
7342   Compile* C = Compile::current();
7343   const TypeFunc* tf = nullptr;
7344   // Inline types are not passed/returned by reference, instead each field of
7345   // the inline type is passed/returned as an argument. We maintain two views of
7346   // the argument/return list here: one based on the signature (with an inline
7347   // type argument/return as a single slot), one based on the actual calling
7348   // convention (with an inline type argument/return as a list of its fields).
7349   bool has_scalar_args = method->has_scalarized_args() && !is_osr_compilation;
7350   // Fall back to the non-scalarized calling convention when compiling a call via a mismatching method
7351   if (is_call && method->mismatch()) {
7352     has_scalar_args = false;
7353   }
7354   ciSignature* sig = method->signature();
7355   bool has_scalar_ret = !method->is_native() && sig->return_type()->is_inlinetype() && sig->return_type()->as_inline_klass()->can_be_returned_as_fields();
7356   // Don't cache on scalarized return because the range depends on 'is_call'
7357   if (!is_osr_compilation && !has_scalar_ret) {
7358     tf = C->last_tf(method); // check cache
7359     if (tf != nullptr)  return tf;  // The hit rate here is almost 50%.
7360   }
7361   const TypeTuple* domain_sig = is_osr_compilation ? osr_domain() : TypeTuple::make_domain(method, ignore_interfaces, false);
7362   const TypeTuple* domain_cc = has_scalar_args ? TypeTuple::make_domain(method, ignore_interfaces, true) : domain_sig;
7363   const TypeTuple* range_sig = TypeTuple::make_range(sig, ignore_interfaces);
7364   const TypeTuple* range_cc = has_scalar_ret ? TypeTuple::make_range(sig, ignore_interfaces, true, is_call) : range_sig;
7365   tf = TypeFunc::make(domain_sig, domain_cc, range_sig, range_cc, has_scalar_ret);
7366   if (!is_osr_compilation && !has_scalar_ret) {
7367     C->set_last_tf(method, tf);  // fill cache
7368   }



7369   return tf;
7370 }
7371 
7372 //------------------------------meet-------------------------------------------
7373 // Compute the MEET of two types.  It returns a new Type object.
7374 const Type *TypeFunc::xmeet( const Type *t ) const {
7375   // Perform a fast test for common case; meeting the same types together.
7376   if( this == t ) return this;  // Meeting same type-rep?
7377 
7378   // Current "this->_base" is Func
7379   switch (t->base()) {          // switch on original type
7380 
7381   case Bottom:                  // Ye Olde Default
7382     return t;
7383 
7384   default:                      // All else is a mistake
7385     typerr(t);
7386 
7387   case Top:
7388     break;
7389   }
7390   return this;                  // Return the double constant
7391 }
7392 
7393 //------------------------------xdual------------------------------------------
7394 // Dual: compute field-by-field dual
7395 const Type *TypeFunc::xdual() const {
7396   return this;
7397 }
7398 
7399 //------------------------------eq---------------------------------------------
7400 // Structural equality check for Type representations
7401 bool TypeFunc::eq( const Type *t ) const {
7402   const TypeFunc *a = (const TypeFunc*)t;
7403   return _domain_sig == a->_domain_sig &&
7404     _domain_cc == a->_domain_cc &&
7405     _range_sig == a->_range_sig &&
7406     _range_cc == a->_range_cc &&
7407     _scalarized_return == a->_scalarized_return;
7408 }
7409 
7410 //------------------------------hash-------------------------------------------
7411 // Type-specific hashing function.
7412 uint TypeFunc::hash(void) const {
7413   return (uint)(intptr_t)_domain_sig + (uint)(intptr_t)_domain_cc + (uint)(intptr_t)_range_sig + (uint)(intptr_t)_range_cc + (uint)(intptr_t)_scalarized_return;
7414 }
7415 
7416 //------------------------------dump2------------------------------------------
7417 // Dump Function Type
7418 #ifndef PRODUCT
7419 void TypeFunc::dump2( Dict &d, uint depth, outputStream *st ) const {
7420   if( _range_sig->cnt() <= Parms )
7421     st->print("void");
7422   else {
7423     uint i;
7424     for (i = Parms; i < _range_sig->cnt()-1; i++) {
7425       _range_sig->field_at(i)->dump2(d,depth,st);
7426       st->print("/");
7427     }
7428     _range_sig->field_at(i)->dump2(d,depth,st);
7429   }
7430   st->print(" ");
7431   st->print("( ");
7432   if( !depth || d[this] ) {     // Check for recursive dump
7433     st->print("...)");
7434     return;
7435   }
7436   d.Insert((void*)this,(void*)this);    // Stop recursion
7437   if (Parms < _domain_sig->cnt())
7438     _domain_sig->field_at(Parms)->dump2(d,depth-1,st);
7439   for (uint i = Parms+1; i < _domain_sig->cnt(); i++) {
7440     st->print(", ");
7441     _domain_sig->field_at(i)->dump2(d,depth-1,st);
7442   }
7443   st->print(" )");
7444 }
7445 #endif
7446 
7447 //------------------------------singleton--------------------------------------
7448 // TRUE if Type is a singleton type, FALSE otherwise.   Singletons are simple
7449 // constants (Ldi nodes).  Singletons are integer, float or double constants
7450 // or a single symbol.
7451 bool TypeFunc::singleton(void) const {
7452   return false;                 // Never a singleton
7453 }
7454 
7455 bool TypeFunc::empty(void) const {
7456   return false;                 // Never empty
7457 }
7458 
7459 
7460 BasicType TypeFunc::return_type() const{
7461   if (range_sig()->cnt() == TypeFunc::Parms) {
7462     return T_VOID;
7463   }
7464   return range_sig()->field_at(TypeFunc::Parms)->basic_type();
7465 }
< prev index next >