< prev index next >

src/hotspot/share/opto/type.hpp

Print this page

   1 /*
   2  * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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 #ifndef SHARE_OPTO_TYPE_HPP
  26 #define SHARE_OPTO_TYPE_HPP
  27 

  28 #include "opto/adlcVMDeps.hpp"
  29 #include "opto/compile.hpp"
  30 #include "opto/rangeinference.hpp"
  31 #include "runtime/handles.hpp"
  32 
  33 // Portions of code courtesy of Clifford Click
  34 
  35 // Optimization - Graph Style
  36 
  37 
  38 // This class defines a Type lattice.  The lattice is used in the constant
  39 // propagation algorithms, and for some type-checking of the iloc code.
  40 // Basic types include RSD's (lower bound, upper bound, stride for integers),
  41 // float & double precision constants, sets of data-labels and code-labels.
  42 // The complete lattice is described below.  Subtypes have no relationship to
  43 // up or down in the lattice; that is entirely determined by the behavior of
  44 // the MEET/JOIN functions.
  45 
  46 class Dict;
  47 class Type;
  48 class   TypeD;
  49 class   TypeF;
  50 class   TypeH;
  51 class   TypeInteger;

 127     Memory,                     // Abstract store
 128     HalfFloatTop,               // No float value
 129     HalfFloatCon,               // Floating point constant
 130     HalfFloatBot,               // Any float value
 131     FloatTop,                   // No float value
 132     FloatCon,                   // Floating point constant
 133     FloatBot,                   // Any float value
 134     DoubleTop,                  // No double value
 135     DoubleCon,                  // Double precision constant
 136     DoubleBot,                  // Any double value
 137     Bottom,                     // Bottom of lattice
 138     lastype                     // Bogus ending type (not in lattice)
 139   };
 140 
 141   // Signal values for offsets from a base pointer
 142   enum OFFSET_SIGNALS {
 143     OffsetTop = -2000000000,    // undefined offset
 144     OffsetBot = -2000000001     // any possible offset
 145   };
 146 
























 147   // Min and max WIDEN values.
 148   enum WIDEN {
 149     WidenMin = 0,
 150     WidenMax = 3
 151   };
 152 
 153 private:
 154   typedef struct {
 155     TYPES                dual_type;
 156     BasicType            basic_type;
 157     const char*          msg;
 158     bool                 isa_oop;
 159     uint                 ideal_reg;
 160     relocInfo::relocType reloc;
 161   } TypeInfo;
 162 
 163   // Dictionary of types shared among compilations.
 164   static Dict* _shared_type_dict;
 165   static const TypeInfo _type_info[];
 166 

 328   const TypeInstPtr  *isa_instptr() const;       // Returns null if not InstPtr
 329   const TypeInstPtr  *is_instptr() const;        // Instance
 330   const TypeAryPtr   *isa_aryptr() const;        // Returns null if not AryPtr
 331   const TypeAryPtr   *is_aryptr() const;         // Array oop
 332 
 333   template <typename TypeClass>
 334   const TypeClass* cast() const;
 335 
 336   const TypeMetadataPtr   *isa_metadataptr() const;   // Returns null if not oop ptr type
 337   const TypeMetadataPtr   *is_metadataptr() const;    // Java-style GC'd pointer
 338   const TypeKlassPtr      *isa_klassptr() const;      // Returns null if not KlassPtr
 339   const TypeKlassPtr      *is_klassptr() const;       // assert if not KlassPtr
 340   const TypeInstKlassPtr  *isa_instklassptr() const;  // Returns null if not IntKlassPtr
 341   const TypeInstKlassPtr  *is_instklassptr() const;   // assert if not IntKlassPtr
 342   const TypeAryKlassPtr   *isa_aryklassptr() const;   // Returns null if not AryKlassPtr
 343   const TypeAryKlassPtr   *is_aryklassptr() const;    // assert if not AryKlassPtr
 344 
 345   virtual bool      is_finite() const;           // Has a finite value
 346   virtual bool      is_nan()    const;           // Is not a number (NaN)
 347 



 348   // Returns this ptr type or the equivalent ptr type for this compressed pointer.
 349   const TypePtr* make_ptr() const;
 350 
 351   // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
 352   // Asserts if the underlying type is not an oopptr or narrowoop.
 353   const TypeOopPtr* make_oopptr() const;
 354 
 355   // Returns this compressed pointer or the equivalent compressed version
 356   // of this pointer type.
 357   const TypeNarrowOop* make_narrowoop() const;
 358 
 359   // Returns this compressed klass pointer or the equivalent
 360   // compressed version of this pointer type.
 361   const TypeNarrowKlass* make_narrowklass() const;
 362 
 363   // Special test for register pressure heuristic
 364   bool is_floatingpoint() const;        // True if Float or Double base type
 365 
 366   // Do you have memory, directly or through a tuple?
 367   bool has_memory( ) const;

 465   static const Type* get_typeflow_type(ciType* type);
 466 
 467   static const Type* make_from_constant(ciConstant constant,
 468                                         bool require_constant = false,
 469                                         int stable_dimension = 0,
 470                                         bool is_narrow = false,
 471                                         bool is_autobox_cache = false);
 472 
 473   static const Type* make_constant_from_field(ciInstance* holder,
 474                                               int off,
 475                                               bool is_unsigned_load,
 476                                               BasicType loadbt);
 477 
 478   static const Type* make_constant_from_field(ciField* field,
 479                                               ciInstance* holder,
 480                                               BasicType loadbt,
 481                                               bool is_unsigned_load);
 482 
 483   static const Type* make_constant_from_array_element(ciArray* array,
 484                                                       int off,

 485                                                       int stable_dimension,
 486                                                       BasicType loadbt,
 487                                                       bool is_unsigned_load);
 488 
 489   // Speculative type helper methods. See TypePtr.
 490   virtual const TypePtr* speculative() const                                  { return nullptr; }
 491   virtual ciKlass* speculative_type() const                                   { return nullptr; }
 492   virtual ciKlass* speculative_type_not_null() const                          { return nullptr; }
 493   virtual bool speculative_maybe_null() const                                 { return true; }
 494   virtual bool speculative_always_null() const                                { return true; }
 495   virtual const Type* remove_speculative() const                              { return this; }
 496   virtual const Type* cleanup_speculative() const                             { return this; }
 497   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const { return exact_kls != nullptr; }
 498   virtual bool would_improve_ptr(ProfilePtrKind ptr_kind) const { return ptr_kind == ProfileAlwaysNull || ptr_kind == ProfileNeverNull; }
 499   const Type* maybe_remove_speculative(bool include_speculative) const;
 500 
 501   virtual bool maybe_null() const { return true; }
 502   virtual bool is_known_instance() const { return false; }
 503 
 504 private:

 937   const Type ** const _fields;           // Array of field types
 938 
 939 public:
 940   virtual bool eq( const Type *t ) const;
 941   virtual uint hash() const;             // Type specific hashing
 942   virtual bool singleton(void) const;    // TRUE if type is a singleton
 943   virtual bool empty(void) const;        // TRUE if type is vacuous
 944 
 945   // Accessors:
 946   uint cnt() const { return _cnt; }
 947   const Type* field_at(uint i) const {
 948     assert(i < _cnt, "oob");
 949     return _fields[i];
 950   }
 951   void set_field_at(uint i, const Type* t) {
 952     assert(i < _cnt, "oob");
 953     _fields[i] = t;
 954   }
 955 
 956   static const TypeTuple *make( uint cnt, const Type **fields );
 957   static const TypeTuple *make_range(ciSignature *sig, InterfaceHandling interface_handling = ignore_interfaces);
 958   static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig, InterfaceHandling interface_handling);
 959 
 960   // Subroutine call type with space allocated for argument types
 961   // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
 962   static const Type **fields( uint arg_cnt );
 963 
 964   virtual const Type *xmeet( const Type *t ) const;
 965   virtual const Type *xdual() const;    // Compute dual right now.
 966   // Convenience common pre-built types.
 967   static const TypeTuple *IFBOTH;
 968   static const TypeTuple *IFFALSE;
 969   static const TypeTuple *IFTRUE;
 970   static const TypeTuple *IFNEITHER;
 971   static const TypeTuple *LOOPBODY;
 972   static const TypeTuple *MEMBAR;
 973   static const TypeTuple *STORECONDITIONAL;
 974   static const TypeTuple *START_I2C;
 975   static const TypeTuple *INT_PAIR;
 976   static const TypeTuple *LONG_PAIR;
 977   static const TypeTuple *INT_CC_PAIR;
 978   static const TypeTuple *LONG_CC_PAIR;
 979 #ifndef PRODUCT
 980   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 981 #endif
 982 };
 983 
 984 //------------------------------TypeAry----------------------------------------
 985 // Class of Array Types
 986 class TypeAry : public Type {
 987   TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
 988       _elem(elem), _size(size), _stable(stable) {}
 989 public:
 990   virtual bool eq( const Type *t ) const;
 991   virtual uint hash() const;             // Type specific hashing
 992   virtual bool singleton(void) const;    // TRUE if type is a singleton
 993   virtual bool empty(void) const;        // TRUE if type is vacuous
 994 
 995 private:
 996   const Type *_elem;            // Element type of array
 997   const TypeInt *_size;         // Elements in array
 998   const bool _stable;           // Are elements @Stable?







 999   friend class TypeAryPtr;
1000 
1001 public:
1002   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);

1003 
1004   virtual const Type *xmeet( const Type *t ) const;
1005   virtual const Type *xdual() const;    // Compute dual right now.
1006   bool ary_must_be_exact() const;  // true if arrays of such are never generic
1007   virtual const TypeAry* remove_speculative() const;
1008   virtual const Type* cleanup_speculative() const;
1009 #ifndef PRODUCT
1010   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
1011 #endif
1012 };
1013 
1014 //------------------------------TypeVect---------------------------------------
1015 // Class of Vector Types
1016 class TypeVect : public Type {
1017   const BasicType _elem_bt;  // Vector's element type
1018   const uint _length;  // Elements in vector (power of 2)
1019 
1020 protected:
1021   TypeVect(TYPES t, BasicType elem_bt, uint length) : Type(t),
1022     _elem_bt(elem_bt), _length(length) {}

1128 
1129   const Type* xmeet(const Type* t) const;
1130 
1131   bool singleton(void) const;
1132   bool has_non_array_interface() const;
1133 };
1134 
1135 //------------------------------TypePtr----------------------------------------
1136 // Class of machine Pointer Types: raw data, instances or arrays.
1137 // If the _base enum is AnyPtr, then this refers to all of the above.
1138 // Otherwise the _base will indicate which subset of pointers is affected,
1139 // and the class will be inherited from.
1140 class TypePtr : public Type {
1141   friend class TypeNarrowPtr;
1142   friend class Type;
1143 protected:
1144   static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling);
1145 
1146 public:
1147   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };



















1148 protected:
1149   TypePtr(TYPES t, PTR ptr, int offset,
1150           const TypePtr* speculative = nullptr,
1151           int inline_depth = InlineDepthBottom) :
1152     Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
1153     _ptr(ptr) {}
1154   static const PTR ptr_meet[lastPTR][lastPTR];
1155   static const PTR ptr_dual[lastPTR];
1156   static const char * const ptr_msg[lastPTR];
1157 



1158   enum {
1159     InlineDepthBottom = INT_MAX,
1160     InlineDepthTop = -InlineDepthBottom
1161   };
1162 
1163   // Extra type information profiling gave us. We propagate it the
1164   // same way the rest of the type info is propagated. If we want to
1165   // use it, then we have to emit a guard: this part of the type is
1166   // not something we know but something we speculate about the type.
1167   const TypePtr*   _speculative;
1168   // For speculative types, we record at what inlining depth the
1169   // profiling point that provided the data is. We want to favor
1170   // profile data coming from outer scopes which are likely better for
1171   // the current compilation.
1172   int _inline_depth;
1173 
1174   // utility methods to work on the speculative part of the type
1175   const TypePtr* dual_speculative() const;
1176   const TypePtr* xmeet_speculative(const TypePtr* other) const;
1177   bool eq_speculative(const TypePtr* other) const;

1186 #ifndef PRODUCT
1187   void dump_speculative(outputStream* st) const;
1188   void dump_inline_depth(outputStream* st) const;
1189   void dump_offset(outputStream* st) const;
1190 #endif
1191 
1192   // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1193   // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1194   // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1195   // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1196   // encountered so the right logic specific to klasses or oops can be executed.,
1197   enum MeetResult {
1198     QUICK,
1199     UNLOADED,
1200     SUBTYPE,
1201     NOT_SUBTYPE,
1202     LCA
1203   };
1204   template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type,
1205                                                             const T* other_type, ciKlass*& res_klass, bool& res_xk);


1206 
1207   template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
1208                                                   ciKlass*& res_klass, bool& res_xk);
1209 
1210   template <class T1, class T2> static bool is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1211   template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other);
1212   template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1213   template <class T1, class T2> static bool is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1214   template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other);
1215   template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1216   template <class T1, class T2> static bool is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk);
1217   template <class T1, class T2> static bool is_meet_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_xk, bool other_xk);
1218 public:
1219   const int _offset;            // Offset into oop, with TOP & BOT
1220   const PTR _ptr;               // Pointer equivalence class
1221 
1222   int offset() const { return _offset; }
1223   PTR ptr()    const { return _ptr; }
1224 
1225   static const TypePtr *make(TYPES t, PTR ptr, int offset,
1226                              const TypePtr* speculative = nullptr,
1227                              int inline_depth = InlineDepthBottom);
1228 
1229   // Return a 'ptr' version of this type
1230   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1231 
1232   virtual intptr_t get_con() const;
1233 
1234   int xadd_offset( intptr_t offset ) const;
1235   virtual const TypePtr* add_offset(intptr_t offset) const;
1236   virtual const TypePtr* with_offset(intptr_t offset) const;

1237   virtual bool eq(const Type *t) const;
1238   virtual uint hash() const;             // Type specific hashing
1239 
1240   virtual bool singleton(void) const;    // TRUE if type is a singleton
1241   virtual bool empty(void) const;        // TRUE if type is vacuous
1242   virtual const Type *xmeet( const Type *t ) const;
1243   virtual const Type *xmeet_helper( const Type *t ) const;
1244   int meet_offset( int offset ) const;
1245   int dual_offset( ) const;
1246   virtual const Type *xdual() const;    // Compute dual right now.
1247 
1248   // meet, dual and join over pointer equivalence sets
1249   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1250   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
1251 
1252   // This is textually confusing unless one recalls that
1253   // join(t) == dual()->meet(t->dual())->dual().
1254   PTR join_ptr( const PTR in_ptr ) const {
1255     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1256   }
1257 
1258   // Speculative type helper methods.
1259   virtual const TypePtr* speculative() const { return _speculative; }
1260   int inline_depth() const                   { return _inline_depth; }
1261   virtual ciKlass* speculative_type() const;
1262   virtual ciKlass* speculative_type_not_null() const;
1263   virtual bool speculative_maybe_null() const;
1264   virtual bool speculative_always_null() const;
1265   virtual const TypePtr* remove_speculative() const;
1266   virtual const Type* cleanup_speculative() const;
1267   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1268   virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1269   virtual const TypePtr* with_inline_depth(int depth) const;
1270 
1271   virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1272 
















1273   // Tests for relation to centerline of type lattice:
1274   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1275   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1276   // Convenience common pre-built types.
1277   static const TypePtr *NULL_PTR;
1278   static const TypePtr *NOTNULL;
1279   static const TypePtr *BOTTOM;
1280 #ifndef PRODUCT
1281   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1282 #endif
1283 };
1284 
1285 //------------------------------TypeRawPtr-------------------------------------
1286 // Class of raw pointers, pointers to things other than Oops.  Examples
1287 // include the stack pointer, top of heap, card-marking area, handles, etc.
1288 class TypeRawPtr : public TypePtr {
1289 protected:
1290   TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
1291 public:
1292   virtual bool eq( const Type *t ) const;
1293   virtual uint hash() const;    // Type specific hashing
1294 
1295   const address _bits;          // Constant value, if applicable
1296 
1297   static const TypeRawPtr *make( PTR ptr );
1298   static const TypeRawPtr *make( address bits );
1299 
1300   // Return a 'ptr' version of this type
1301   virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1302 
1303   virtual intptr_t get_con() const;
1304 
1305   virtual const TypePtr* add_offset(intptr_t offset) const;
1306   virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;}
1307 
1308   virtual const Type *xmeet( const Type *t ) const;
1309   virtual const Type *xdual() const;    // Compute dual right now.
1310   // Convenience common pre-built types.
1311   static const TypeRawPtr *BOTTOM;
1312   static const TypeRawPtr *NOTNULL;
1313 #ifndef PRODUCT
1314   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1315 #endif
1316 };
1317 
1318 //------------------------------TypeOopPtr-------------------------------------
1319 // Some kind of oop (Java pointer), either instance or array.
1320 class TypeOopPtr : public TypePtr {
1321   friend class TypeAry;
1322   friend class TypePtr;
1323   friend class TypeInstPtr;
1324   friend class TypeAryPtr;
1325 protected:
1326  TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset, int instance_id,
1327             const TypePtr* speculative, int inline_depth);
1328 public:
1329   virtual bool eq( const Type *t ) const;
1330   virtual uint hash() const;             // Type specific hashing
1331   virtual bool singleton(void) const;    // TRUE if type is a singleton
1332   enum {
1333    InstanceTop = -1,   // undefined instance
1334    InstanceBot = 0     // any possible instance
1335   };
1336 protected:
1337 
1338   // Oop is null, unless this is a constant oop.
1339   ciObject*     _const_oop;   // Constant oop
1340   // If _klass is null, then so is _sig.  This is an unloaded klass.
1341   ciKlass*      _klass;       // Klass object
1342 
1343   const TypeInterfaces* _interfaces;
1344 
1345   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1346   bool          _klass_is_exact;
1347   bool          _is_ptr_to_narrowoop;
1348   bool          _is_ptr_to_narrowklass;
1349   bool          _is_ptr_to_boxed_value;

1350 
1351   // If not InstanceTop or InstanceBot, indicates that this is
1352   // a particular instance of this type which is distinct.
1353   // This is the node index of the allocation node creating this instance.
1354   int           _instance_id;
1355 
1356   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling);
1357 
1358   int dual_instance_id() const;
1359   int meet_instance_id(int uid) const;
1360 
1361   const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const;
1362 
1363   // Do not allow interface-vs.-noninterface joins to collapse to top.
1364   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1365 
1366   virtual ciKlass* exact_klass_helper() const { return nullptr; }
1367   virtual ciKlass* klass() const { return _klass;     }
1368 
1369 #ifndef PRODUCT
1370   void dump_instance_id(outputStream* st) const;
1371 #endif // PRODUCT
1372 
1373 public:
1374 
1375   bool is_java_subtype_of(const TypeOopPtr* other) const {
1376     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1377   }
1378 
1379   bool is_same_java_type_as(const TypePtr* other) const {
1380     return is_same_java_type_as_helper(other->is_oopptr());
1381   }
1382 
1383   virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const {
1384     ShouldNotReachHere(); return false;
1385   }
1386 
1387   bool maybe_java_subtype_of(const TypeOopPtr* other) const {

1398     return make_from_klass_common(klass, true, false, interface_handling);
1399   }
1400   // Same as before, but will produce an exact type, even if
1401   // the klass is not final, as long as it has exactly one implementation.
1402   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1403     return make_from_klass_common(klass, true, true, interface_handling);
1404   }
1405   // Same as before, but does not respects UseUniqueSubclasses.
1406   // Use this only for creating array element types.
1407   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1408     return make_from_klass_common(klass, false, false, interface_handling);
1409   }
1410   // Creates a singleton type given an object.
1411   // If the object cannot be rendered as a constant,
1412   // may return a non-singleton type.
1413   // If require_constant, produce a null if a singleton is not possible.
1414   static const TypeOopPtr* make_from_constant(ciObject* o,
1415                                               bool require_constant = false);
1416 
1417   // Make a generic (unclassed) pointer to an oop.
1418   static const TypeOopPtr* make(PTR ptr, int offset, int instance_id,
1419                                 const TypePtr* speculative = nullptr,
1420                                 int inline_depth = InlineDepthBottom);
1421 
1422   ciObject* const_oop()    const { return _const_oop; }
1423   // Exact klass, possibly an interface or an array of interface
1424   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1425   ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1426 
1427   virtual bool  is_loaded() const { return klass()->is_loaded(); }
1428   virtual bool klass_is_exact()    const { return _klass_is_exact; }
1429 
1430   // Returns true if this pointer points at memory which contains a
1431   // compressed oop references.
1432   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1433   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1434   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }

1435   bool is_known_instance()       const { return _instance_id > 0; }
1436   int  instance_id()             const { return _instance_id; }
1437   bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }



1438 
1439   virtual intptr_t get_con() const;
1440 
1441   virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1442 
1443   virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1444 
1445   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1446 
1447   // corresponding pointer to klass, for a given instance
1448   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1449 
1450   virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1451   virtual const TypePtr* add_offset(intptr_t offset) const;
1452 
1453   // Speculative type helper methods.
1454   virtual const TypeOopPtr* remove_speculative() const;
1455   virtual const Type* cleanup_speculative() const;
1456   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1457   virtual const TypePtr* with_inline_depth(int depth) const;

1480     return _interfaces;
1481   };
1482 
1483   const TypeOopPtr* is_reference_type(const Type* other) const {
1484     return other->isa_oopptr();
1485   }
1486 
1487   const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1488     return other->isa_aryptr();
1489   }
1490 
1491   const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1492     return other->isa_instptr();
1493   }
1494 };
1495 
1496 //------------------------------TypeInstPtr------------------------------------
1497 // Class of Java object pointers, pointing either to non-array Java instances
1498 // or to a Klass* (including array klasses).
1499 class TypeInstPtr : public TypeOopPtr {
1500   TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off, int instance_id,
1501               const TypePtr* speculative, int inline_depth);




1502   virtual bool eq( const Type *t ) const;
1503   virtual uint hash() const;             // Type specific hashing
1504 
1505   ciKlass* exact_klass_helper() const;
1506 
1507 public:
1508 
1509   // Instance klass, ignoring any interface
1510   ciInstanceKlass* instance_klass() const {
1511     assert(!(klass()->is_loaded() && klass()->is_interface()), "");
1512     return klass()->as_instance_klass();
1513   }
1514 
1515   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1516   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1517   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1518 
1519   // Make a pointer to a constant oop.
1520   static const TypeInstPtr *make(ciObject* o) {
1521     ciKlass* k = o->klass();
1522     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1523     return make(TypePtr::Constant, k, interfaces, true, o, 0, InstanceBot);
1524   }
1525   // Make a pointer to a constant oop with offset.
1526   static const TypeInstPtr *make(ciObject* o, int offset) {
1527     ciKlass* k = o->klass();
1528     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1529     return make(TypePtr::Constant, k, interfaces, true, o, offset, InstanceBot);
1530   }
1531 
1532   // Make a pointer to some value of type klass.
1533   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1534     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
1535     return make(ptr, klass, interfaces, false, nullptr, 0, InstanceBot);
1536   }
1537 
1538   // Make a pointer to some non-polymorphic value of exactly type klass.
1539   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1540     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1541     return make(ptr, klass, interfaces, true, nullptr, 0, InstanceBot);
1542   }
1543 
1544   // Make a pointer to some value of type klass with offset.
1545   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1546     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1547     return make(ptr, klass, interfaces, false, nullptr, offset, InstanceBot);
1548   }
1549 
1550   static const TypeInstPtr *make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,


1551                                  int instance_id = InstanceBot,
1552                                  const TypePtr* speculative = nullptr,
1553                                  int inline_depth = InlineDepthBottom);
1554 
1555   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot) {

1556     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1557     return make(ptr, k, interfaces, xk, o, offset, instance_id);
1558   }
1559 
1560   /** Create constant type for a constant boxed value */
1561   const Type* get_const_boxed_value() const;
1562 
1563   // If this is a java.lang.Class constant, return the type for it or null.
1564   // Pass to Type::get_const_type to turn it to a type, which will usually
1565   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1566   ciType* java_mirror_type() const;
1567 
1568   virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1569 
1570   virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const;
1571 
1572   virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const;
1573 

1574   virtual const TypePtr* add_offset(intptr_t offset) const;
1575   virtual const TypeInstPtr* with_offset(intptr_t offset) const;
1576 
1577   // Speculative type helper methods.
1578   virtual const TypeInstPtr* remove_speculative() const;
1579   const TypeInstPtr* with_speculative(const TypePtr* speculative) const;
1580   virtual const TypePtr* with_inline_depth(int depth) const;
1581   virtual const TypePtr* with_instance_id(int instance_id) const;
1582 








1583   // the core of the computation of the meet of 2 types
1584   virtual const Type *xmeet_helper(const Type *t) const;
1585   virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const;
1586   virtual const Type *xdual() const;    // Compute dual right now.
1587 
1588   const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1589 


1590   // Convenience common pre-built types.
1591   static const TypeInstPtr *NOTNULL;
1592   static const TypeInstPtr *BOTTOM;
1593   static const TypeInstPtr *MIRROR;
1594   static const TypeInstPtr *MARK;
1595   static const TypeInstPtr *KLASS;
1596 #ifndef PRODUCT
1597   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1598 #endif
1599 
1600 private:
1601   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1602 
1603   virtual bool is_meet_same_type_as(const TypePtr* other) const {
1604     return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces);
1605   }
1606 
1607 };
1608 
1609 //------------------------------TypeAryPtr-------------------------------------
1610 // Class of Java array pointers
1611 class TypeAryPtr : public TypeOopPtr {
1612   friend class Type;
1613   friend class TypePtr;

1614   friend class TypeInterfaces;
1615 
1616   TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1617               int offset, int instance_id, bool is_autobox_cache,
1618               const TypePtr* speculative, int inline_depth)
1619     : TypeOopPtr(AryPtr,ptr,k,_array_interfaces,xk,o,offset, instance_id, speculative, inline_depth),
1620     _ary(ary),
1621     _is_autobox_cache(is_autobox_cache)

1622  {
1623     int dummy;
1624     bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM);
1625 
1626     if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) &&
1627         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes() &&
1628         _offset != arrayOopDesc::klass_offset_in_bytes()) {
1629       _is_ptr_to_narrowoop = true;
1630     }
1631 
1632   }
1633   virtual bool eq( const Type *t ) const;
1634   virtual uint hash() const;    // Type specific hashing
1635   const TypeAry *_ary;          // Array we point into
1636   const bool     _is_autobox_cache;






1637 
1638   ciKlass* compute_klass() const;
1639 
1640   // A pointer to delay allocation to Type::Initialize_shared()
1641 
1642   static const TypeInterfaces* _array_interfaces;
1643   ciKlass* exact_klass_helper() const;
1644   // Only guaranteed non null for array of basic types
1645   ciKlass* klass() const;
1646 
1647 public:
1648 
1649   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1650   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1651   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1652 
1653   // returns base element type, an instance klass (and not interface) for object arrays
1654   const Type* base_element_type(int& dims) const;
1655 
1656   // Accessors
1657   bool  is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); }
1658 
1659   const TypeAry* ary() const  { return _ary; }
1660   const Type*    elem() const { return _ary->_elem; }
1661   const TypeInt* size() const { return _ary->_size; }
1662   bool      is_stable() const { return _ary->_stable; }
1663 







1664   bool is_autobox_cache() const { return _is_autobox_cache; }
1665 
1666   static const TypeAryPtr *make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset,

1667                                 int instance_id = InstanceBot,
1668                                 const TypePtr* speculative = nullptr,
1669                                 int inline_depth = InlineDepthBottom);
1670   // Constant pointer to array
1671   static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,

1672                                 int instance_id = InstanceBot,
1673                                 const TypePtr* speculative = nullptr,
1674                                 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false);

1675 
1676   // Return a 'ptr' version of this type
1677   virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1678 
1679   virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const;
1680 
1681   virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const;
1682 
1683   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1684   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1685 
1686   virtual bool empty(void) const;        // TRUE if type is vacuous
1687   virtual const TypePtr *add_offset( intptr_t offset ) const;
1688   virtual const TypeAryPtr *with_offset( intptr_t offset ) const;
1689   const TypeAryPtr* with_ary(const TypeAry* ary) const;
1690 
1691   // Speculative type helper methods.
1692   virtual const TypeAryPtr* remove_speculative() const;

1693   virtual const TypePtr* with_inline_depth(int depth) const;
1694   virtual const TypePtr* with_instance_id(int instance_id) const;
1695 
1696   // the core of the computation of the meet of 2 types
1697   virtual const Type *xmeet_helper(const Type *t) const;
1698   virtual const Type *xdual() const;    // Compute dual right now.
1699 










1700   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1701   int stable_dimension() const;
1702 
1703   const TypeAryPtr* cast_to_autobox_cache() const;
1704 
1705   static jint max_array_length(BasicType etype) ;







1706   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1707 


1708   // Convenience common pre-built types.
1709   static const TypeAryPtr* BOTTOM;
1710   static const TypeAryPtr* RANGE;
1711   static const TypeAryPtr* OOPS;
1712   static const TypeAryPtr* NARROWOOPS;
1713   static const TypeAryPtr* BYTES;
1714   static const TypeAryPtr* SHORTS;
1715   static const TypeAryPtr* CHARS;
1716   static const TypeAryPtr* INTS;
1717   static const TypeAryPtr* LONGS;
1718   static const TypeAryPtr* FLOATS;
1719   static const TypeAryPtr* DOUBLES;

1720   // selects one of the above:
1721   static const TypeAryPtr *get_array_body_type(BasicType elem) {
1722     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != nullptr, "bad elem type");
1723     return _array_body_type[elem];
1724   }
1725   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1726   // sharpen the type of an int which is used as an array size
1727 #ifndef PRODUCT
1728   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1729 #endif
1730 private:
1731   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1732 };
1733 
1734 //------------------------------TypeMetadataPtr-------------------------------------
1735 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1736 class TypeMetadataPtr : public TypePtr {
1737 protected:
1738   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1739   // Do not allow interface-vs.-noninterface joins to collapse to top.
1740   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1741 public:
1742   virtual bool eq( const Type *t ) const;
1743   virtual uint hash() const;             // Type specific hashing
1744   virtual bool singleton(void) const;    // TRUE if type is a singleton
1745 
1746 private:
1747   ciMetadata*   _metadata;
1748 
1749 public:
1750   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1751 
1752   static const TypeMetadataPtr* make(ciMethod* m);
1753   static const TypeMetadataPtr* make(ciMethodData* m);
1754 
1755   ciMetadata* metadata() const { return _metadata; }
1756 
1757   virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1758 
1759   virtual const TypePtr *add_offset( intptr_t offset ) const;
1760 
1761   virtual const Type *xmeet( const Type *t ) const;
1762   virtual const Type *xdual() const;    // Compute dual right now.
1763 
1764   virtual intptr_t get_con() const;
1765 
1766   // Convenience common pre-built types.
1767   static const TypeMetadataPtr *BOTTOM;
1768 
1769 #ifndef PRODUCT
1770   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1771 #endif
1772 };
1773 
1774 //------------------------------TypeKlassPtr-----------------------------------
1775 // Class of Java Klass pointers
1776 class TypeKlassPtr : public TypePtr {
1777   friend class TypeInstKlassPtr;
1778   friend class TypeAryKlassPtr;
1779   friend class TypePtr;
1780 protected:
1781   TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset);
1782 
1783   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1784 
1785 public:
1786   virtual bool eq( const Type *t ) const;
1787   virtual uint hash() const;
1788   virtual bool singleton(void) const;    // TRUE if type is a singleton
1789 
1790 protected:
1791 
1792   ciKlass* _klass;
1793   const TypeInterfaces* _interfaces;
1794   const TypeInterfaces* meet_interfaces(const TypeKlassPtr* other) const;
1795   virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1796   virtual ciKlass* exact_klass_helper() const;
1797   virtual ciKlass* klass() const { return  _klass; }
1798 
1799 public:
1800 
1801   bool is_java_subtype_of(const TypeKlassPtr* other) const {
1802     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1803   }
1804   bool is_same_java_type_as(const TypePtr* other) const {
1805     return is_same_java_type_as_helper(other->is_klassptr());
1806   }
1807 
1808   bool maybe_java_subtype_of(const TypeKlassPtr* other) const {
1809     return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1810   }
1811   virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; }
1812   virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1813   virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1814 
1815   // Exact klass, possibly an interface or an array of interface
1816   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1817   virtual bool klass_is_exact()    const { return _ptr == Constant; }
1818 
1819   static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces);
1820   static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, int offset, InterfaceHandling interface_handling = ignore_interfaces);
1821 
1822   virtual bool  is_loaded() const { return _klass->is_loaded(); }
1823 
1824   virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; }
1825 
1826   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; }
1827 
1828   // corresponding pointer to instance, for a given class
1829   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; }
1830 
1831   virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; }
1832   virtual const Type    *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; }
1833   virtual const Type    *xdual() const { ShouldNotReachHere(); return nullptr; }
1834 
1835   virtual intptr_t get_con() const;
1836 
1837   virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; }
1838 


1839   virtual const TypeKlassPtr* try_improve() const { return this; }
1840 
1841 private:
1842   virtual bool is_meet_subtype_of(const TypePtr* other) const {
1843     return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
1844   }
1845 
1846   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
1847     ShouldNotReachHere(); return false;
1848   }
1849 
1850   virtual const TypeInterfaces* interfaces() const {
1851     return _interfaces;
1852   };
1853 
1854   const TypeKlassPtr* is_reference_type(const Type* other) const {
1855     return other->isa_klassptr();
1856   }
1857 
1858   const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
1859     return other->isa_aryklassptr();
1860   }
1861 
1862   const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
1863     return other->isa_instklassptr();
1864   }
1865 };
1866 
1867 // Instance klass pointer, mirrors TypeInstPtr
1868 class TypeInstKlassPtr : public TypeKlassPtr {


1869 
1870   TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
1871     : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset) {

1872     assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
1873   }
1874 
1875   virtual bool must_be_exact() const;
1876 
1877 public:
1878   // Instance klass ignoring any interface
1879   ciInstanceKlass* instance_klass() const {
1880     assert(!klass()->is_interface(), "");
1881     return klass()->as_instance_klass();
1882   }
1883 
1884   bool might_be_an_array() const;
1885 
1886   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1887   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1888   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1889 


1890   static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
1891     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
1892     return make(TypePtr::Constant, k, interfaces, 0);
1893   }
1894   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset);
1895 
1896   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, int offset) {



1897     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1898     return make(ptr, k, interfaces, offset);
1899   }
1900 
1901   virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const;
1902 
1903   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1904 
1905   // corresponding pointer to instance, for a given class
1906   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1907   virtual uint hash() const;
1908   virtual bool eq(const Type *t) const;
1909 


1910   virtual const TypePtr *add_offset( intptr_t offset ) const;
1911   virtual const Type    *xmeet( const Type *t ) const;
1912   virtual const Type    *xdual() const;
1913   virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const;
1914 
1915   virtual const TypeKlassPtr* try_improve() const;
1916 








1917   // Convenience common pre-built types.
1918   static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
1919   static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1920 
1921 #ifndef PRODUCT
1922   virtual void dump2(Dict& d, uint depth, outputStream* st) const;
1923 #endif // PRODUCT
1924 
1925 private:
1926   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1927 };
1928 
1929 // Array klass pointer, mirrors TypeAryPtr
1930 class TypeAryKlassPtr : public TypeKlassPtr {
1931   friend class TypeInstKlassPtr;
1932   friend class Type;
1933   friend class TypePtr;
1934 
1935   const Type *_elem;






1936 
1937   static const TypeInterfaces* _array_interfaces;
1938   TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, int offset)
1939     : TypeKlassPtr(AryKlassPtr, ptr, klass, _array_interfaces, offset), _elem(elem) {
1940     assert(klass == nullptr || klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "");
1941   }
1942 
1943   virtual ciKlass* exact_klass_helper() const;
1944   // Only guaranteed non null for array of basic types
1945   virtual ciKlass* klass() const;
1946 
1947   virtual bool must_be_exact() const;
1948 
























1949 public:
1950 
1951   // returns base element type, an instance klass (and not interface) for object arrays
1952   const Type* base_element_type(int& dims) const;
1953 
1954   static const TypeAryKlassPtr *make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling);
1955 
1956   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1957   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1958   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1959 
1960   bool  is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); }
1961 
1962   static const TypeAryKlassPtr *make(PTR ptr, const Type *elem, ciKlass* k, int offset);
1963   static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling);
1964 



1965   const Type *elem() const { return _elem; }
1966 
1967   virtual bool eq(const Type *t) const;
1968   virtual uint hash() const;             // Type specific hashing
1969 
1970   virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const;
1971 
1972   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1973 
1974   // corresponding pointer to instance, for a given class
1975   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1976 
1977   virtual const TypePtr *add_offset( intptr_t offset ) const;
1978   virtual const Type    *xmeet( const Type *t ) const;
1979   virtual const Type    *xdual() const;      // Compute dual right now.
1980 
1981   virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const;
1982 
1983   virtual bool empty(void) const {
1984     return TypeKlassPtr::empty() || _elem->empty();
1985   }
1986 








1987 #ifndef PRODUCT
1988   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1989 #endif
1990 private:
1991   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1992 };
1993 
1994 class TypeNarrowPtr : public Type {
1995 protected:
1996   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1997 
1998   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
1999                                                   _ptrtype(ptrtype) {
2000     assert(ptrtype->offset() == 0 ||
2001            ptrtype->offset() == OffsetBot ||
2002            ptrtype->offset() == OffsetTop, "no real offsets");
2003   }
2004 
2005   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
2006   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;

2102   }
2103 
2104   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2105     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
2106   }
2107 
2108 public:
2109   static const TypeNarrowKlass *make( const TypePtr* type);
2110 
2111   // static const TypeNarrowKlass *BOTTOM;
2112   static const TypeNarrowKlass *NULL_PTR;
2113 
2114 #ifndef PRODUCT
2115   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2116 #endif
2117 };
2118 
2119 //------------------------------TypeFunc---------------------------------------
2120 // Class of Array Types
2121 class TypeFunc : public Type {
2122   TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function),  _domain(domain), _range(range) {}

2123   virtual bool eq( const Type *t ) const;
2124   virtual uint hash() const;             // Type specific hashing
2125   virtual bool singleton(void) const;    // TRUE if type is a singleton
2126   virtual bool empty(void) const;        // TRUE if type is vacuous
2127 
2128   const TypeTuple* const _domain;     // Domain of inputs
2129   const TypeTuple* const _range;      // Range of results











2130 
2131 public:
2132   // Constants are shared among ADLC and VM
2133   enum { Control    = AdlcVMDeps::Control,
2134          I_O        = AdlcVMDeps::I_O,
2135          Memory     = AdlcVMDeps::Memory,
2136          FramePtr   = AdlcVMDeps::FramePtr,
2137          ReturnAdr  = AdlcVMDeps::ReturnAdr,
2138          Parms      = AdlcVMDeps::Parms
2139   };
2140 
2141 
2142   // Accessors:
2143   const TypeTuple* domain() const { return _domain; }
2144   const TypeTuple* range()  const { return _range; }
2145 
2146   static const TypeFunc *make(ciMethod* method);
2147   static const TypeFunc *make(ciSignature signature, const Type* extra);



2148   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
2149 
2150   virtual const Type *xmeet( const Type *t ) const;
2151   virtual const Type *xdual() const;    // Compute dual right now.
2152 
2153   BasicType return_type() const;
2154 


2155 #ifndef PRODUCT
2156   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2157 #endif
2158   // Convenience common pre-built types.
2159 };
2160 
2161 //------------------------------accessors--------------------------------------
2162 inline bool Type::is_ptr_to_narrowoop() const {
2163 #ifdef _LP64
2164   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
2165 #else
2166   return false;
2167 #endif
2168 }
2169 
2170 inline bool Type::is_ptr_to_narrowklass() const {
2171 #ifdef _LP64
2172   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
2173 #else
2174   return false;

2411 }
2412 
2413 inline const TypeNarrowOop* Type::make_narrowoop() const {
2414   return (_base == NarrowOop) ? is_narrowoop() :
2415                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2416 }
2417 
2418 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2419   return (_base == NarrowKlass) ? is_narrowklass() :
2420                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2421 }
2422 
2423 inline bool Type::is_floatingpoint() const {
2424   if( (_base == HalfFloatCon)  || (_base == HalfFloatBot) ||
2425       (_base == FloatCon)  || (_base == FloatBot) ||
2426       (_base == DoubleCon) || (_base == DoubleBot) )
2427     return true;
2428   return false;
2429 }
2430 








2431 template <>
2432 inline const TypeInt* Type::cast<TypeInt>() const {
2433   return is_int();
2434 }
2435 
2436 template <>
2437 inline const TypeLong* Type::cast<TypeLong>() const {
2438   return is_long();
2439 }
2440 
2441 template <>
2442 inline const TypeInt* Type::try_cast<TypeInt>() const {
2443   return isa_int();
2444 }
2445 
2446 template <>
2447 inline const TypeLong* Type::try_cast<TypeLong>() const {
2448   return isa_long();
2449 }
2450 

2456 
2457 // For type queries and asserts
2458 #define is_intptr_t  is_long
2459 #define isa_intptr_t isa_long
2460 #define find_intptr_t_type find_long_type
2461 #define find_intptr_t_con  find_long_con
2462 #define TypeX        TypeLong
2463 #define Type_X       Type::Long
2464 #define TypeX_X      TypeLong::LONG
2465 #define TypeX_ZERO   TypeLong::ZERO
2466 // For 'ideal_reg' machine registers
2467 #define Op_RegX      Op_RegL
2468 // For phase->intcon variants
2469 #define MakeConX     longcon
2470 #define ConXNode     ConLNode
2471 // For array index arithmetic
2472 #define MulXNode     MulLNode
2473 #define AndXNode     AndLNode
2474 #define OrXNode      OrLNode
2475 #define CmpXNode     CmpLNode

2476 #define SubXNode     SubLNode
2477 #define LShiftXNode  LShiftLNode
2478 // For object size computation:
2479 #define AddXNode     AddLNode
2480 #define RShiftXNode  RShiftLNode
2481 // For card marks and hashcodes
2482 #define URShiftXNode URShiftLNode
2483 // For shenandoahSupport
2484 #define LoadXNode    LoadLNode
2485 #define StoreXNode   StoreLNode
2486 // Opcodes
2487 #define Op_LShiftX   Op_LShiftL
2488 #define Op_AndX      Op_AndL
2489 #define Op_AddX      Op_AddL
2490 #define Op_SubX      Op_SubL
2491 #define Op_XorX      Op_XorL
2492 #define Op_URShiftX  Op_URShiftL
2493 #define Op_LoadX     Op_LoadL

2494 // conversions
2495 #define ConvI2X(x)   ConvI2L(x)
2496 #define ConvL2X(x)   (x)
2497 #define ConvX2I(x)   ConvL2I(x)
2498 #define ConvX2L(x)   (x)
2499 #define ConvX2UL(x)  (x)
2500 
2501 #else
2502 
2503 // For type queries and asserts
2504 #define is_intptr_t  is_int
2505 #define isa_intptr_t isa_int
2506 #define find_intptr_t_type find_int_type
2507 #define find_intptr_t_con  find_int_con
2508 #define TypeX        TypeInt
2509 #define Type_X       Type::Int
2510 #define TypeX_X      TypeInt::INT
2511 #define TypeX_ZERO   TypeInt::ZERO
2512 // For 'ideal_reg' machine registers
2513 #define Op_RegX      Op_RegI
2514 // For phase->intcon variants
2515 #define MakeConX     intcon
2516 #define ConXNode     ConINode
2517 // For array index arithmetic
2518 #define MulXNode     MulINode
2519 #define AndXNode     AndINode
2520 #define OrXNode      OrINode
2521 #define CmpXNode     CmpINode

2522 #define SubXNode     SubINode
2523 #define LShiftXNode  LShiftINode
2524 // For object size computation:
2525 #define AddXNode     AddINode
2526 #define RShiftXNode  RShiftINode
2527 // For card marks and hashcodes
2528 #define URShiftXNode URShiftINode
2529 // For shenandoahSupport
2530 #define LoadXNode    LoadINode
2531 #define StoreXNode   StoreINode
2532 // Opcodes
2533 #define Op_LShiftX   Op_LShiftI
2534 #define Op_AndX      Op_AndI
2535 #define Op_AddX      Op_AddI
2536 #define Op_SubX      Op_SubI
2537 #define Op_XorX      Op_XorI
2538 #define Op_URShiftX  Op_URShiftI
2539 #define Op_LoadX     Op_LoadI

2540 // conversions
2541 #define ConvI2X(x)   (x)
2542 #define ConvL2X(x)   ConvL2I(x)
2543 #define ConvX2I(x)   (x)
2544 #define ConvX2L(x)   ConvI2L(x)
2545 #define ConvX2UL(x)  ConvI2UL(x)
2546 
2547 #endif
2548 
2549 #endif // SHARE_OPTO_TYPE_HPP

   1 /*
   2  * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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 #ifndef SHARE_OPTO_TYPE_HPP
  26 #define SHARE_OPTO_TYPE_HPP
  27 
  28 #include "ci/ciInlineKlass.hpp"
  29 #include "opto/adlcVMDeps.hpp"
  30 #include "opto/compile.hpp"
  31 #include "opto/rangeinference.hpp"

  32 
  33 // Portions of code courtesy of Clifford Click
  34 
  35 // Optimization - Graph Style
  36 
  37 
  38 // This class defines a Type lattice.  The lattice is used in the constant
  39 // propagation algorithms, and for some type-checking of the iloc code.
  40 // Basic types include RSD's (lower bound, upper bound, stride for integers),
  41 // float & double precision constants, sets of data-labels and code-labels.
  42 // The complete lattice is described below.  Subtypes have no relationship to
  43 // up or down in the lattice; that is entirely determined by the behavior of
  44 // the MEET/JOIN functions.
  45 
  46 class Dict;
  47 class Type;
  48 class   TypeD;
  49 class   TypeF;
  50 class   TypeH;
  51 class   TypeInteger;

 127     Memory,                     // Abstract store
 128     HalfFloatTop,               // No float value
 129     HalfFloatCon,               // Floating point constant
 130     HalfFloatBot,               // Any float value
 131     FloatTop,                   // No float value
 132     FloatCon,                   // Floating point constant
 133     FloatBot,                   // Any float value
 134     DoubleTop,                  // No double value
 135     DoubleCon,                  // Double precision constant
 136     DoubleBot,                  // Any double value
 137     Bottom,                     // Bottom of lattice
 138     lastype                     // Bogus ending type (not in lattice)
 139   };
 140 
 141   // Signal values for offsets from a base pointer
 142   enum OFFSET_SIGNALS {
 143     OffsetTop = -2000000000,    // undefined offset
 144     OffsetBot = -2000000001     // any possible offset
 145   };
 146 
 147   class Offset {
 148   private:
 149     int _offset;
 150 
 151   public:
 152     explicit Offset(int offset) : _offset(offset) {}
 153 
 154     const Offset meet(const Offset other) const;
 155     const Offset dual() const;
 156     const Offset add(intptr_t offset) const;
 157     bool operator==(const Offset& other) const {
 158       return _offset == other._offset;
 159     }
 160     bool operator!=(const Offset& other) const {
 161       return _offset != other._offset;
 162     }
 163     int get() const { return _offset; }
 164 
 165     void dump2(outputStream *st) const;
 166 
 167     static const Offset top;
 168     static const Offset bottom;
 169   };
 170 
 171   // Min and max WIDEN values.
 172   enum WIDEN {
 173     WidenMin = 0,
 174     WidenMax = 3
 175   };
 176 
 177 private:
 178   typedef struct {
 179     TYPES                dual_type;
 180     BasicType            basic_type;
 181     const char*          msg;
 182     bool                 isa_oop;
 183     uint                 ideal_reg;
 184     relocInfo::relocType reloc;
 185   } TypeInfo;
 186 
 187   // Dictionary of types shared among compilations.
 188   static Dict* _shared_type_dict;
 189   static const TypeInfo _type_info[];
 190 

 352   const TypeInstPtr  *isa_instptr() const;       // Returns null if not InstPtr
 353   const TypeInstPtr  *is_instptr() const;        // Instance
 354   const TypeAryPtr   *isa_aryptr() const;        // Returns null if not AryPtr
 355   const TypeAryPtr   *is_aryptr() const;         // Array oop
 356 
 357   template <typename TypeClass>
 358   const TypeClass* cast() const;
 359 
 360   const TypeMetadataPtr   *isa_metadataptr() const;   // Returns null if not oop ptr type
 361   const TypeMetadataPtr   *is_metadataptr() const;    // Java-style GC'd pointer
 362   const TypeKlassPtr      *isa_klassptr() const;      // Returns null if not KlassPtr
 363   const TypeKlassPtr      *is_klassptr() const;       // assert if not KlassPtr
 364   const TypeInstKlassPtr  *isa_instklassptr() const;  // Returns null if not IntKlassPtr
 365   const TypeInstKlassPtr  *is_instklassptr() const;   // assert if not IntKlassPtr
 366   const TypeAryKlassPtr   *isa_aryklassptr() const;   // Returns null if not AryKlassPtr
 367   const TypeAryKlassPtr   *is_aryklassptr() const;    // assert if not AryKlassPtr
 368 
 369   virtual bool      is_finite() const;           // Has a finite value
 370   virtual bool      is_nan()    const;           // Is not a number (NaN)
 371 
 372   bool is_inlinetypeptr() const;
 373   virtual ciInlineKlass* inline_klass() const;
 374 
 375   // Returns this ptr type or the equivalent ptr type for this compressed pointer.
 376   const TypePtr* make_ptr() const;
 377 
 378   // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
 379   // Asserts if the underlying type is not an oopptr or narrowoop.
 380   const TypeOopPtr* make_oopptr() const;
 381 
 382   // Returns this compressed pointer or the equivalent compressed version
 383   // of this pointer type.
 384   const TypeNarrowOop* make_narrowoop() const;
 385 
 386   // Returns this compressed klass pointer or the equivalent
 387   // compressed version of this pointer type.
 388   const TypeNarrowKlass* make_narrowklass() const;
 389 
 390   // Special test for register pressure heuristic
 391   bool is_floatingpoint() const;        // True if Float or Double base type
 392 
 393   // Do you have memory, directly or through a tuple?
 394   bool has_memory( ) const;

 492   static const Type* get_typeflow_type(ciType* type);
 493 
 494   static const Type* make_from_constant(ciConstant constant,
 495                                         bool require_constant = false,
 496                                         int stable_dimension = 0,
 497                                         bool is_narrow = false,
 498                                         bool is_autobox_cache = false);
 499 
 500   static const Type* make_constant_from_field(ciInstance* holder,
 501                                               int off,
 502                                               bool is_unsigned_load,
 503                                               BasicType loadbt);
 504 
 505   static const Type* make_constant_from_field(ciField* field,
 506                                               ciInstance* holder,
 507                                               BasicType loadbt,
 508                                               bool is_unsigned_load);
 509 
 510   static const Type* make_constant_from_array_element(ciArray* array,
 511                                                       int off,
 512                                                       int field_offset,
 513                                                       int stable_dimension,
 514                                                       BasicType loadbt,
 515                                                       bool is_unsigned_load);
 516 
 517   // Speculative type helper methods. See TypePtr.
 518   virtual const TypePtr* speculative() const                                  { return nullptr; }
 519   virtual ciKlass* speculative_type() const                                   { return nullptr; }
 520   virtual ciKlass* speculative_type_not_null() const                          { return nullptr; }
 521   virtual bool speculative_maybe_null() const                                 { return true; }
 522   virtual bool speculative_always_null() const                                { return true; }
 523   virtual const Type* remove_speculative() const                              { return this; }
 524   virtual const Type* cleanup_speculative() const                             { return this; }
 525   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const { return exact_kls != nullptr; }
 526   virtual bool would_improve_ptr(ProfilePtrKind ptr_kind) const { return ptr_kind == ProfileAlwaysNull || ptr_kind == ProfileNeverNull; }
 527   const Type* maybe_remove_speculative(bool include_speculative) const;
 528 
 529   virtual bool maybe_null() const { return true; }
 530   virtual bool is_known_instance() const { return false; }
 531 
 532 private:

 965   const Type ** const _fields;           // Array of field types
 966 
 967 public:
 968   virtual bool eq( const Type *t ) const;
 969   virtual uint hash() const;             // Type specific hashing
 970   virtual bool singleton(void) const;    // TRUE if type is a singleton
 971   virtual bool empty(void) const;        // TRUE if type is vacuous
 972 
 973   // Accessors:
 974   uint cnt() const { return _cnt; }
 975   const Type* field_at(uint i) const {
 976     assert(i < _cnt, "oob");
 977     return _fields[i];
 978   }
 979   void set_field_at(uint i, const Type* t) {
 980     assert(i < _cnt, "oob");
 981     _fields[i] = t;
 982   }
 983 
 984   static const TypeTuple *make( uint cnt, const Type **fields );
 985   static const TypeTuple *make_range(ciSignature* sig, InterfaceHandling interface_handling = ignore_interfaces, bool ret_vt_fields = false);
 986   static const TypeTuple *make_domain(ciMethod* method, InterfaceHandling interface_handling, bool vt_fields_as_args = false);
 987 
 988   // Subroutine call type with space allocated for argument types
 989   // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
 990   static const Type **fields( uint arg_cnt );
 991 
 992   virtual const Type *xmeet( const Type *t ) const;
 993   virtual const Type *xdual() const;    // Compute dual right now.
 994   // Convenience common pre-built types.
 995   static const TypeTuple *IFBOTH;
 996   static const TypeTuple *IFFALSE;
 997   static const TypeTuple *IFTRUE;
 998   static const TypeTuple *IFNEITHER;
 999   static const TypeTuple *LOOPBODY;
1000   static const TypeTuple *MEMBAR;
1001   static const TypeTuple *STORECONDITIONAL;
1002   static const TypeTuple *START_I2C;
1003   static const TypeTuple *INT_PAIR;
1004   static const TypeTuple *LONG_PAIR;
1005   static const TypeTuple *INT_CC_PAIR;
1006   static const TypeTuple *LONG_CC_PAIR;
1007 #ifndef PRODUCT
1008   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
1009 #endif
1010 };
1011 
1012 //------------------------------TypeAry----------------------------------------
1013 // Class of Array Types
1014 class TypeAry : public Type {
1015   TypeAry(const Type* elem, const TypeInt* size, bool stable, bool flat, bool not_flat, bool not_null_free, bool atomic) : Type(Array),
1016       _elem(elem), _size(size), _stable(stable), _flat(flat), _not_flat(not_flat), _not_null_free(not_null_free), _atomic(atomic) {}
1017 public:
1018   virtual bool eq( const Type *t ) const;
1019   virtual uint hash() const;             // Type specific hashing
1020   virtual bool singleton(void) const;    // TRUE if type is a singleton
1021   virtual bool empty(void) const;        // TRUE if type is vacuous
1022 
1023 private:
1024   const Type *_elem;            // Element type of array
1025   const TypeInt *_size;         // Elements in array
1026   const bool _stable;           // Are elements @Stable?
1027 
1028   // Inline type array properties
1029   const bool _flat;             // Array is flat
1030   const bool _not_flat;         // Array is never flat
1031   const bool _not_null_free;    // Array is never null-free
1032   const bool _atomic;           // Array is atomic
1033 
1034   friend class TypeAryPtr;
1035 
1036 public:
1037   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable,
1038                              bool flat, bool not_flat, bool not_null_free, bool atomic);
1039 
1040   virtual const Type *xmeet( const Type *t ) const;
1041   virtual const Type *xdual() const;    // Compute dual right now.
1042   bool ary_must_be_exact() const;  // true if arrays of such are never generic
1043   virtual const TypeAry* remove_speculative() const;
1044   virtual const Type* cleanup_speculative() const;
1045 #ifndef PRODUCT
1046   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
1047 #endif
1048 };
1049 
1050 //------------------------------TypeVect---------------------------------------
1051 // Class of Vector Types
1052 class TypeVect : public Type {
1053   const BasicType _elem_bt;  // Vector's element type
1054   const uint _length;  // Elements in vector (power of 2)
1055 
1056 protected:
1057   TypeVect(TYPES t, BasicType elem_bt, uint length) : Type(t),
1058     _elem_bt(elem_bt), _length(length) {}

1164 
1165   const Type* xmeet(const Type* t) const;
1166 
1167   bool singleton(void) const;
1168   bool has_non_array_interface() const;
1169 };
1170 
1171 //------------------------------TypePtr----------------------------------------
1172 // Class of machine Pointer Types: raw data, instances or arrays.
1173 // If the _base enum is AnyPtr, then this refers to all of the above.
1174 // Otherwise the _base will indicate which subset of pointers is affected,
1175 // and the class will be inherited from.
1176 class TypePtr : public Type {
1177   friend class TypeNarrowPtr;
1178   friend class Type;
1179 protected:
1180   static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling);
1181 
1182 public:
1183   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
1184 
1185   // Only applies to TypeInstPtr and TypeInstKlassPtr. Since the common super class is TypePtr, it is defined here.
1186   //
1187   // FlatInArray defines the following Boolean Lattice structure
1188   //
1189   //     TopFlat
1190   //    /      \
1191   //  Flat   NotFlat
1192   //    \      /
1193   //   MaybeFlat
1194   //
1195   // with meet (see TypePtr::meet_flat_in_array()) and join (implemented over dual, see TypePtr::flat_in_array_dual)
1196   enum FlatInArray {
1197     TopFlat,        // Dedicated top element and dual of MaybeFlat. Result when joining Flat and NotFlat.
1198     Flat,           // An instance is always flat in an array.
1199     NotFlat,        // An instance is never flat in an array.
1200     MaybeFlat,      // We don't know whether an instance is flat in an array.
1201     Uninitialized   // Used when the flat in array property was not computed, yet - should never actually end up in a type.
1202   };
1203 protected:
1204   TypePtr(TYPES t, PTR ptr, Offset offset,
1205           const TypePtr* speculative = nullptr,
1206           int inline_depth = InlineDepthBottom) :
1207     Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
1208     _ptr(ptr) {}
1209   static const PTR ptr_meet[lastPTR][lastPTR];
1210   static const PTR ptr_dual[lastPTR];
1211   static const char * const ptr_msg[lastPTR];
1212 
1213   static const FlatInArray flat_in_array_dual[Uninitialized];
1214   static const char* const flat_in_array_msg[Uninitialized];
1215 
1216   enum {
1217     InlineDepthBottom = INT_MAX,
1218     InlineDepthTop = -InlineDepthBottom
1219   };
1220 
1221   // Extra type information profiling gave us. We propagate it the
1222   // same way the rest of the type info is propagated. If we want to
1223   // use it, then we have to emit a guard: this part of the type is
1224   // not something we know but something we speculate about the type.
1225   const TypePtr*   _speculative;
1226   // For speculative types, we record at what inlining depth the
1227   // profiling point that provided the data is. We want to favor
1228   // profile data coming from outer scopes which are likely better for
1229   // the current compilation.
1230   int _inline_depth;
1231 
1232   // utility methods to work on the speculative part of the type
1233   const TypePtr* dual_speculative() const;
1234   const TypePtr* xmeet_speculative(const TypePtr* other) const;
1235   bool eq_speculative(const TypePtr* other) const;

1244 #ifndef PRODUCT
1245   void dump_speculative(outputStream* st) const;
1246   void dump_inline_depth(outputStream* st) const;
1247   void dump_offset(outputStream* st) const;
1248 #endif
1249 
1250   // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1251   // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1252   // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1253   // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1254   // encountered so the right logic specific to klasses or oops can be executed.,
1255   enum MeetResult {
1256     QUICK,
1257     UNLOADED,
1258     SUBTYPE,
1259     NOT_SUBTYPE,
1260     LCA
1261   };
1262   template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type,
1263                                                             const T* other_type, ciKlass*& res_klass, bool& res_xk);
1264  protected:
1265   static FlatInArray meet_flat_in_array(FlatInArray left, FlatInArray other);
1266 
1267   template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
1268                                                   ciKlass*& res_klass, bool& res_xk, bool &res_flat, bool &res_not_flat, bool &res_not_null_free, bool &res_atomic);
1269 
1270   template <class T1, class T2> static bool is_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1271   template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other);
1272   template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1273   template <class T1, class T2> static bool is_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1274   template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other);
1275   template <class T1, class T2> static bool maybe_java_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_exact, bool other_exact);
1276   template <class T1, class T2> static bool is_meet_subtype_of_helper_for_instance(const T1* this_one, const T2* other, bool this_xk, bool other_xk);
1277   template <class T1, class T2> static bool is_meet_subtype_of_helper_for_array(const T1* this_one, const T2* other, bool this_xk, bool other_xk);
1278 public:
1279   const Offset _offset;         // Offset into oop, with TOP & BOT
1280   const PTR _ptr;               // Pointer equivalence class
1281 
1282   int offset() const { return _offset.get(); }
1283   PTR ptr()    const { return _ptr; }
1284 
1285   static const TypePtr* make(TYPES t, PTR ptr, Offset offset,
1286                              const TypePtr* speculative = nullptr,
1287                              int inline_depth = InlineDepthBottom);
1288 
1289   // Return a 'ptr' version of this type
1290   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1291 
1292   virtual intptr_t get_con() const;
1293 
1294   Type::Offset xadd_offset(intptr_t offset) const;
1295   virtual const TypePtr* add_offset(intptr_t offset) const;
1296   virtual const TypePtr* with_offset(intptr_t offset) const;
1297   virtual int flat_offset() const { return offset(); }
1298   virtual bool eq(const Type *t) const;
1299   virtual uint hash() const;             // Type specific hashing
1300 
1301   virtual bool singleton(void) const;    // TRUE if type is a singleton
1302   virtual bool empty(void) const;        // TRUE if type is vacuous
1303   virtual const Type *xmeet( const Type *t ) const;
1304   virtual const Type *xmeet_helper( const Type *t ) const;
1305   Offset meet_offset(int offset) const;
1306   Offset dual_offset() const;
1307   virtual const Type *xdual() const;    // Compute dual right now.
1308 
1309   // meet, dual and join over pointer equivalence sets
1310   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1311   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
1312 
1313   // This is textually confusing unless one recalls that
1314   // join(t) == dual()->meet(t->dual())->dual().
1315   PTR join_ptr( const PTR in_ptr ) const {
1316     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1317   }
1318 
1319   // Speculative type helper methods.
1320   virtual const TypePtr* speculative() const { return _speculative; }
1321   int inline_depth() const                   { return _inline_depth; }
1322   virtual ciKlass* speculative_type() const;
1323   virtual ciKlass* speculative_type_not_null() const;
1324   virtual bool speculative_maybe_null() const;
1325   virtual bool speculative_always_null() const;
1326   virtual const TypePtr* remove_speculative() const;
1327   virtual const Type* cleanup_speculative() const;
1328   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1329   virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1330   virtual const TypePtr* with_inline_depth(int depth) const;
1331 
1332   virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1333 
1334   NOT_PRODUCT(static void dump_flat_in_array(FlatInArray flat_in_array, outputStream* st);)
1335 
1336   static FlatInArray compute_flat_in_array(ciInstanceKlass* instance_klass, bool is_exact);
1337   FlatInArray compute_flat_in_array_if_unknown(ciInstanceKlass* instance_klass, bool is_exact,
1338                                                FlatInArray old_flat_in_array) const;
1339 
1340   virtual bool can_be_inline_type() const { return false; }
1341   virtual bool is_flat_in_array()     const { return flat_in_array() == Flat; }
1342   virtual bool is_not_flat_in_array() const { return flat_in_array() == NotFlat; }
1343   virtual FlatInArray flat_in_array() const { return NotFlat; }
1344   virtual bool is_flat()            const { return false; }
1345   virtual bool is_not_flat()        const { return false; }
1346   virtual bool is_null_free()       const { return false; }
1347   virtual bool is_not_null_free()   const { return false; }
1348   virtual bool is_atomic()          const { return false; }
1349 
1350   // Tests for relation to centerline of type lattice:
1351   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1352   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1353   // Convenience common pre-built types.
1354   static const TypePtr *NULL_PTR;
1355   static const TypePtr *NOTNULL;
1356   static const TypePtr *BOTTOM;
1357 #ifndef PRODUCT
1358   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1359 #endif
1360 };
1361 
1362 //------------------------------TypeRawPtr-------------------------------------
1363 // Class of raw pointers, pointers to things other than Oops.  Examples
1364 // include the stack pointer, top of heap, card-marking area, handles, etc.
1365 class TypeRawPtr : public TypePtr {
1366 protected:
1367   TypeRawPtr(PTR ptr, address bits) : TypePtr(RawPtr,ptr,Offset(0)), _bits(bits){}
1368 public:
1369   virtual bool eq( const Type *t ) const;
1370   virtual uint hash() const;    // Type specific hashing
1371 
1372   const address _bits;          // Constant value, if applicable
1373 
1374   static const TypeRawPtr *make( PTR ptr );
1375   static const TypeRawPtr *make( address bits );
1376 
1377   // Return a 'ptr' version of this type
1378   virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1379 
1380   virtual intptr_t get_con() const;
1381 
1382   virtual const TypePtr* add_offset(intptr_t offset) const;
1383   virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;}
1384 
1385   virtual const Type *xmeet( const Type *t ) const;
1386   virtual const Type *xdual() const;    // Compute dual right now.
1387   // Convenience common pre-built types.
1388   static const TypeRawPtr *BOTTOM;
1389   static const TypeRawPtr *NOTNULL;
1390 #ifndef PRODUCT
1391   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1392 #endif
1393 };
1394 
1395 //------------------------------TypeOopPtr-------------------------------------
1396 // Some kind of oop (Java pointer), either instance or array.
1397 class TypeOopPtr : public TypePtr {
1398   friend class TypeAry;
1399   friend class TypePtr;
1400   friend class TypeInstPtr;
1401   friend class TypeAryPtr;
1402 protected:
1403  TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset, Offset field_offset, int instance_id,
1404             const TypePtr* speculative, int inline_depth);
1405 public:
1406   virtual bool eq( const Type *t ) const;
1407   virtual uint hash() const;             // Type specific hashing
1408   virtual bool singleton(void) const;    // TRUE if type is a singleton
1409   enum {
1410    InstanceTop = -1,   // undefined instance
1411    InstanceBot = 0     // any possible instance
1412   };
1413 protected:
1414 
1415   // Oop is null, unless this is a constant oop.
1416   ciObject*     _const_oop;   // Constant oop
1417   // If _klass is null, then so is _sig.  This is an unloaded klass.
1418   ciKlass*      _klass;       // Klass object
1419 
1420   const TypeInterfaces* _interfaces;
1421 
1422   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1423   bool          _klass_is_exact;
1424   bool          _is_ptr_to_narrowoop;
1425   bool          _is_ptr_to_narrowklass;
1426   bool          _is_ptr_to_boxed_value;
1427   bool          _is_ptr_to_strict_final_field;
1428 
1429   // If not InstanceTop or InstanceBot, indicates that this is
1430   // a particular instance of this type which is distinct.
1431   // This is the node index of the allocation node creating this instance.
1432   int           _instance_id;
1433 
1434   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling);
1435 
1436   int dual_instance_id() const;
1437   int meet_instance_id(int uid) const;
1438 
1439   const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const;
1440 
1441   // Do not allow interface-vs.-noninterface joins to collapse to top.
1442   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1443 
1444   virtual ciKlass* exact_klass_helper() const { return nullptr; }
1445   virtual ciKlass* klass() const { return _klass; }
1446 
1447 #ifndef PRODUCT
1448   void dump_instance_id(outputStream* st) const;
1449 #endif // PRODUCT
1450 
1451 public:
1452 
1453   bool is_java_subtype_of(const TypeOopPtr* other) const {
1454     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1455   }
1456 
1457   bool is_same_java_type_as(const TypePtr* other) const {
1458     return is_same_java_type_as_helper(other->is_oopptr());
1459   }
1460 
1461   virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const {
1462     ShouldNotReachHere(); return false;
1463   }
1464 
1465   bool maybe_java_subtype_of(const TypeOopPtr* other) const {

1476     return make_from_klass_common(klass, true, false, interface_handling);
1477   }
1478   // Same as before, but will produce an exact type, even if
1479   // the klass is not final, as long as it has exactly one implementation.
1480   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1481     return make_from_klass_common(klass, true, true, interface_handling);
1482   }
1483   // Same as before, but does not respects UseUniqueSubclasses.
1484   // Use this only for creating array element types.
1485   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1486     return make_from_klass_common(klass, false, false, interface_handling);
1487   }
1488   // Creates a singleton type given an object.
1489   // If the object cannot be rendered as a constant,
1490   // may return a non-singleton type.
1491   // If require_constant, produce a null if a singleton is not possible.
1492   static const TypeOopPtr* make_from_constant(ciObject* o,
1493                                               bool require_constant = false);
1494 
1495   // Make a generic (unclassed) pointer to an oop.
1496   static const TypeOopPtr* make(PTR ptr, Offset offset, int instance_id,
1497                                 const TypePtr* speculative = nullptr,
1498                                 int inline_depth = InlineDepthBottom);
1499 
1500   ciObject* const_oop()    const { return _const_oop; }
1501   // Exact klass, possibly an interface or an array of interface
1502   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1503   ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1504 
1505   virtual bool  is_loaded() const { return klass()->is_loaded(); }
1506   virtual bool klass_is_exact()    const { return _klass_is_exact; }
1507 
1508   // Returns true if this pointer points at memory which contains a
1509   // compressed oop references.
1510   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1511   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1512   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }
1513   bool is_ptr_to_strict_final_field() const { return _is_ptr_to_strict_final_field; }
1514   bool is_known_instance()       const { return _instance_id > 0; }
1515   int  instance_id()             const { return _instance_id; }
1516   bool is_known_instance_field() const { return is_known_instance() && _offset.get() >= 0; }
1517 
1518   virtual bool can_be_inline_type() const { return (_klass == nullptr || _klass->can_be_inline_klass(_klass_is_exact)); }
1519   virtual bool can_be_inline_array() const { ShouldNotReachHere(); return false; }
1520 
1521   virtual intptr_t get_con() const;
1522 
1523   virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1524 
1525   virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1526 
1527   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1528 
1529   // corresponding pointer to klass, for a given instance
1530   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1531 
1532   virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1533   virtual const TypePtr* add_offset(intptr_t offset) const;
1534 
1535   // Speculative type helper methods.
1536   virtual const TypeOopPtr* remove_speculative() const;
1537   virtual const Type* cleanup_speculative() const;
1538   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1539   virtual const TypePtr* with_inline_depth(int depth) const;

1562     return _interfaces;
1563   };
1564 
1565   const TypeOopPtr* is_reference_type(const Type* other) const {
1566     return other->isa_oopptr();
1567   }
1568 
1569   const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1570     return other->isa_aryptr();
1571   }
1572 
1573   const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1574     return other->isa_instptr();
1575   }
1576 };
1577 
1578 //------------------------------TypeInstPtr------------------------------------
1579 // Class of Java object pointers, pointing either to non-array Java instances
1580 // or to a Klass* (including array klasses).
1581 class TypeInstPtr : public TypeOopPtr {
1582   // Can this instance be in a flat array?
1583   FlatInArray _flat_in_array;
1584 
1585   TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset,
1586               FlatInArray flat_in_array, int instance_id, const TypePtr* speculative,
1587               int inline_depth);
1588   virtual bool eq( const Type *t ) const;
1589   virtual uint hash() const;             // Type specific hashing

1590   ciKlass* exact_klass_helper() const;
1591 
1592 public:
1593 
1594   // Instance klass, ignoring any interface
1595   ciInstanceKlass* instance_klass() const {
1596     assert(!(klass()->is_loaded() && klass()->is_interface()), "");
1597     return klass()->as_instance_klass();
1598   }
1599 
1600   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1601   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1602   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1603 
1604   // Make a pointer to a constant oop.
1605   static const TypeInstPtr *make(ciObject* o) {
1606     ciKlass* k = o->klass();
1607     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1608     return make(TypePtr::Constant, k, interfaces, true, o, Offset(0));
1609   }
1610   // Make a pointer to a constant oop with offset.
1611   static const TypeInstPtr *make(ciObject* o, Offset offset) {
1612     ciKlass* k = o->klass();
1613     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1614     return make(TypePtr::Constant, k, interfaces, true, o, offset);
1615   }
1616 
1617   // Make a pointer to some value of type klass.
1618   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1619     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
1620     return make(ptr, klass, interfaces, false, nullptr, Offset(0));
1621   }
1622 
1623   // Make a pointer to some non-polymorphic value of exactly type klass.
1624   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1625     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1626     return make(ptr, klass, interfaces, true, nullptr, Offset(0));
1627   }
1628 
1629   // Make a pointer to some value of type klass with offset.
1630   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, Offset offset) {
1631     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1632     return make(ptr, klass, interfaces, false, nullptr, offset);
1633   }
1634 
1635   // Make a pointer to an oop.
1636   static const TypeInstPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset,
1637                                  FlatInArray flat_in_array = Uninitialized,
1638                                  int instance_id = InstanceBot,
1639                                  const TypePtr* speculative = nullptr,
1640                                  int inline_depth = InlineDepthBottom);
1641 
1642   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, int instance_id = InstanceBot,
1643                                  FlatInArray flat_in_array = Uninitialized) {
1644     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1645     return make(ptr, k, interfaces, xk, o, offset, flat_in_array, instance_id);
1646   }
1647 
1648   /** Create constant type for a constant boxed value */
1649   const Type* get_const_boxed_value() const;
1650 
1651   // If this is a java.lang.Class constant, return the type for it or null.
1652   // Pass to Type::get_const_type to turn it to a type, which will usually
1653   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1654   ciType* java_mirror_type() const;
1655 
1656   virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1657 
1658   virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const;
1659 
1660   virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const;
1661 
1662   virtual bool empty() const;
1663   virtual const TypePtr* add_offset(intptr_t offset) const;
1664   virtual const TypeInstPtr* with_offset(intptr_t offset) const;
1665 
1666   // Speculative type helper methods.
1667   virtual const TypeInstPtr* remove_speculative() const;
1668   const TypeInstPtr* with_speculative(const TypePtr* speculative) const;
1669   virtual const TypePtr* with_inline_depth(int depth) const;
1670   virtual const TypePtr* with_instance_id(int instance_id) const;
1671 
1672   virtual const TypeInstPtr* cast_to_flat_in_array() const;
1673   virtual const TypeInstPtr* cast_to_maybe_flat_in_array() const;
1674   virtual FlatInArray flat_in_array() const { return _flat_in_array; }
1675 
1676   FlatInArray dual_flat_in_array() const {
1677     return flat_in_array_dual[_flat_in_array];
1678   }
1679 
1680   // the core of the computation of the meet of 2 types
1681   virtual const Type *xmeet_helper(const Type *t) const;
1682   virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const;
1683   virtual const Type *xdual() const;    // Compute dual right now.
1684 
1685   const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1686 
1687   virtual bool can_be_inline_array() const;
1688 
1689   // Convenience common pre-built types.
1690   static const TypeInstPtr *NOTNULL;
1691   static const TypeInstPtr *BOTTOM;
1692   static const TypeInstPtr *MIRROR;
1693   static const TypeInstPtr *MARK;
1694   static const TypeInstPtr *KLASS;
1695 #ifndef PRODUCT
1696   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1697 #endif
1698 
1699 private:
1700   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1701 
1702   virtual bool is_meet_same_type_as(const TypePtr* other) const {
1703     return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces);
1704   }
1705 
1706 };
1707 
1708 //------------------------------TypeAryPtr-------------------------------------
1709 // Class of Java array pointers
1710 class TypeAryPtr : public TypeOopPtr {
1711   friend class Type;
1712   friend class TypePtr;
1713   friend class TypeInstPtr;
1714   friend class TypeInterfaces;
1715 
1716   TypeAryPtr(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1717              Offset offset, Offset field_offset, int instance_id, bool is_autobox_cache,
1718              const TypePtr* speculative, int inline_depth)
1719     : TypeOopPtr(AryPtr, ptr, k, _array_interfaces, xk, o, offset, field_offset, instance_id, speculative, inline_depth),
1720     _ary(ary),
1721     _is_autobox_cache(is_autobox_cache),
1722     _field_offset(field_offset)
1723  {
1724     int dummy;
1725     bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM);
1726 
1727     if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) &&
1728         _offset.get() != 0 && _offset.get() != arrayOopDesc::length_offset_in_bytes() &&
1729         _offset.get() != arrayOopDesc::klass_offset_in_bytes()) {
1730       _is_ptr_to_narrowoop = true;
1731     }
1732 
1733   }
1734   virtual bool eq( const Type *t ) const;
1735   virtual uint hash() const;    // Type specific hashing
1736   const TypeAry *_ary;          // Array we point into
1737   const bool     _is_autobox_cache;
1738   // For flat inline type arrays, each field of the inline type in
1739   // the array has its own memory slice so we need to keep track of
1740   // which field is accessed
1741   const Offset _field_offset;
1742   Offset meet_field_offset(const Type::Offset offset) const;
1743   Offset dual_field_offset() const;
1744 
1745   ciKlass* compute_klass() const;
1746 
1747   // A pointer to delay allocation to Type::Initialize_shared()
1748 
1749   static const TypeInterfaces* _array_interfaces;
1750   ciKlass* exact_klass_helper() const;
1751   // Only guaranteed non null for array of basic types
1752   ciKlass* klass() const;
1753 
1754 public:
1755 
1756   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1757   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1758   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1759 
1760   // returns base element type, an instance klass (and not interface) for object arrays
1761   const Type* base_element_type(int& dims) const;
1762 
1763   // Accessors
1764   bool  is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); }
1765 
1766   const TypeAry* ary() const  { return _ary; }
1767   const Type*    elem() const { return _ary->_elem; }
1768   const TypeInt* size() const { return _ary->_size; }
1769   bool      is_stable() const { return _ary->_stable; }
1770 
1771   // Inline type array properties
1772   bool is_flat()          const { return _ary->_flat; }
1773   bool is_not_flat()      const { return _ary->_not_flat; }
1774   bool is_null_free()     const { return _ary->_elem->make_ptr() != nullptr && (_ary->_elem->make_ptr()->ptr() == NotNull || _ary->_elem->make_ptr()->ptr() == AnyNull); }
1775   bool is_not_null_free() const { return _ary->_not_null_free; }
1776   bool is_atomic()        const { return _ary->_atomic; }
1777 
1778   bool is_autobox_cache() const { return _is_autobox_cache; }
1779 
1780   static const TypeAryPtr* make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset,
1781                                 Offset field_offset = Offset::bottom,
1782                                 int instance_id = InstanceBot,
1783                                 const TypePtr* speculative = nullptr,
1784                                 int inline_depth = InlineDepthBottom);
1785   // Constant pointer to array
1786   static const TypeAryPtr* make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset,
1787                                 Offset field_offset = Offset::bottom,
1788                                 int instance_id = InstanceBot,
1789                                 const TypePtr* speculative = nullptr,
1790                                 int inline_depth = InlineDepthBottom,
1791                                 bool is_autobox_cache = false);
1792 
1793   // Return a 'ptr' version of this type
1794   virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1795 
1796   virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const;
1797 
1798   virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const;
1799 
1800   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1801   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1802 
1803   virtual bool empty(void) const;        // TRUE if type is vacuous
1804   virtual const TypePtr *add_offset( intptr_t offset ) const;
1805   virtual const TypeAryPtr *with_offset( intptr_t offset ) const;
1806   const TypeAryPtr* with_ary(const TypeAry* ary) const;
1807 
1808   // Speculative type helper methods.
1809   virtual const TypeAryPtr* remove_speculative() const;
1810   virtual const Type* cleanup_speculative() const;
1811   virtual const TypePtr* with_inline_depth(int depth) const;
1812   virtual const TypePtr* with_instance_id(int instance_id) const;
1813 
1814   // the core of the computation of the meet of 2 types
1815   virtual const Type *xmeet_helper(const Type *t) const;
1816   virtual const Type *xdual() const;    // Compute dual right now.
1817 
1818   // Inline type array properties
1819   const TypeAryPtr* cast_to_flat(bool flat) const;
1820   const TypeAryPtr* cast_to_not_flat(bool not_flat = true) const;
1821   const TypeAryPtr* cast_to_null_free(bool null_free) const;
1822   const TypeAryPtr* cast_to_not_null_free(bool not_null_free = true) const;
1823   const TypeAryPtr* update_properties(const TypeAryPtr* new_type) const;
1824   jint flat_layout_helper() const;
1825   int flat_elem_size() const;
1826   int flat_log_elem_size() const;
1827 
1828   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1829   int stable_dimension() const;
1830 
1831   const TypeAryPtr* cast_to_autobox_cache() const;
1832 
1833   static jint max_array_length(BasicType etype);
1834 
1835   int flat_offset() const;
1836   const Offset field_offset() const { return _field_offset; }
1837   const TypeAryPtr* with_field_offset(int offset) const;
1838   const TypePtr* add_field_offset_and_offset(intptr_t offset) const;
1839 
1840   virtual bool can_be_inline_type() const { return false; }
1841   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1842 
1843   virtual bool can_be_inline_array() const;
1844 
1845   // Convenience common pre-built types.
1846   static const TypeAryPtr* BOTTOM;
1847   static const TypeAryPtr *RANGE;
1848   static const TypeAryPtr *OOPS;
1849   static const TypeAryPtr *NARROWOOPS;
1850   static const TypeAryPtr *BYTES;
1851   static const TypeAryPtr *SHORTS;
1852   static const TypeAryPtr *CHARS;
1853   static const TypeAryPtr *INTS;
1854   static const TypeAryPtr *LONGS;
1855   static const TypeAryPtr *FLOATS;
1856   static const TypeAryPtr *DOUBLES;
1857   static const TypeAryPtr *INLINES;
1858   // selects one of the above:
1859   static const TypeAryPtr *get_array_body_type(BasicType elem) {
1860     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != nullptr, "bad elem type");
1861     return _array_body_type[elem];
1862   }
1863   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1864   // sharpen the type of an int which is used as an array size
1865 #ifndef PRODUCT
1866   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1867 #endif
1868 private:
1869   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1870 };
1871 
1872 //------------------------------TypeMetadataPtr-------------------------------------
1873 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1874 class TypeMetadataPtr : public TypePtr {
1875 protected:
1876   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset);
1877   // Do not allow interface-vs.-noninterface joins to collapse to top.
1878   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1879 public:
1880   virtual bool eq( const Type *t ) const;
1881   virtual uint hash() const;             // Type specific hashing
1882   virtual bool singleton(void) const;    // TRUE if type is a singleton
1883 
1884 private:
1885   ciMetadata*   _metadata;
1886 
1887 public:
1888   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, Offset offset);
1889 
1890   static const TypeMetadataPtr* make(ciMethod* m);
1891   static const TypeMetadataPtr* make(ciMethodData* m);
1892 
1893   ciMetadata* metadata() const { return _metadata; }
1894 
1895   virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1896 
1897   virtual const TypePtr *add_offset( intptr_t offset ) const;
1898 
1899   virtual const Type *xmeet( const Type *t ) const;
1900   virtual const Type *xdual() const;    // Compute dual right now.
1901 
1902   virtual intptr_t get_con() const;
1903 
1904   // Convenience common pre-built types.
1905   static const TypeMetadataPtr *BOTTOM;
1906 
1907 #ifndef PRODUCT
1908   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1909 #endif
1910 };
1911 
1912 //------------------------------TypeKlassPtr-----------------------------------
1913 // Class of Java Klass pointers
1914 class TypeKlassPtr : public TypePtr {
1915   friend class TypeInstKlassPtr;
1916   friend class TypeAryKlassPtr;
1917   friend class TypePtr;
1918 protected:
1919   TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset);
1920 
1921   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1922 
1923 public:
1924   virtual bool eq( const Type *t ) const;
1925   virtual uint hash() const;
1926   virtual bool singleton(void) const;    // TRUE if type is a singleton
1927 
1928 protected:
1929 
1930   ciKlass* _klass;
1931   const TypeInterfaces* _interfaces;
1932   const TypeInterfaces* meet_interfaces(const TypeKlassPtr* other) const;
1933   virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1934   virtual ciKlass* exact_klass_helper() const;
1935   virtual ciKlass* klass() const { return  _klass; }
1936 
1937 public:
1938 
1939   bool is_java_subtype_of(const TypeKlassPtr* other) const {
1940     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1941   }
1942   bool is_same_java_type_as(const TypePtr* other) const {
1943     return is_same_java_type_as_helper(other->is_klassptr());
1944   }
1945 
1946   bool maybe_java_subtype_of(const TypeKlassPtr* other) const {
1947     return maybe_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1948   }
1949   virtual bool is_same_java_type_as_helper(const TypeKlassPtr* other) const { ShouldNotReachHere(); return false; }
1950   virtual bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1951   virtual bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const { ShouldNotReachHere(); return false; }
1952 
1953   // Exact klass, possibly an interface or an array of interface
1954   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1955   virtual bool klass_is_exact()    const { return _ptr == Constant; }
1956 
1957   static const TypeKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces);

1958 
1959   virtual bool  is_loaded() const { return _klass->is_loaded(); }
1960 
1961   virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; }
1962 
1963   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; }
1964 
1965   // corresponding pointer to instance, for a given class
1966   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; }
1967 
1968   virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; }
1969   virtual const Type    *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; }
1970   virtual const Type    *xdual() const { ShouldNotReachHere(); return nullptr; }
1971 
1972   virtual intptr_t get_con() const;
1973 
1974   virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; }
1975 
1976   virtual bool can_be_inline_array() const { ShouldNotReachHere(); return false; }
1977 
1978   virtual const TypeKlassPtr* try_improve() const { return this; }
1979 
1980 private:
1981   virtual bool is_meet_subtype_of(const TypePtr* other) const {
1982     return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
1983   }
1984 
1985   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
1986     ShouldNotReachHere(); return false;
1987   }
1988 
1989   virtual const TypeInterfaces* interfaces() const {
1990     return _interfaces;
1991   };
1992 
1993   const TypeKlassPtr* is_reference_type(const Type* other) const {
1994     return other->isa_klassptr();
1995   }
1996 
1997   const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
1998     return other->isa_aryklassptr();
1999   }
2000 
2001   const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
2002     return other->isa_instklassptr();
2003   }
2004 };
2005 
2006 // Instance klass pointer, mirrors TypeInstPtr
2007 class TypeInstKlassPtr : public TypeKlassPtr {
2008   // Can an instance of this class be in a flat array?
2009   const FlatInArray _flat_in_array;
2010 
2011   TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset, FlatInArray flat_in_array)
2012     : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset), _flat_in_array(flat_in_array) {
2013     assert(flat_in_array != Uninitialized, "must be set now");
2014     assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
2015   }
2016 
2017   virtual bool must_be_exact() const;
2018 
2019 public:
2020   // Instance klass ignoring any interface
2021   ciInstanceKlass* instance_klass() const {
2022     assert(!klass()->is_interface(), "");
2023     return klass()->as_instance_klass();
2024   }
2025 
2026   bool might_be_an_array() const;
2027 
2028   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
2029   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
2030   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
2031 
2032   virtual bool can_be_inline_type() const { return (_klass == nullptr || _klass->can_be_inline_klass(klass_is_exact())); }
2033 
2034   static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
2035     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
2036     return make(TypePtr::Constant, k, interfaces, Offset(0));
2037   }

2038 
2039   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, Offset offset,
2040                                       FlatInArray flat_in_array = Uninitialized);
2041 
2042   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, Offset offset, FlatInArray flat_in_array = Uninitialized) {
2043     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
2044     return make(ptr, k, interfaces, offset, flat_in_array);
2045   }
2046 
2047   virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const;
2048 
2049   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
2050 
2051   // corresponding pointer to instance, for a given class
2052   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
2053   virtual uint hash() const;
2054   virtual bool eq(const Type *t) const;
2055 
2056 
2057   virtual bool empty() const;
2058   virtual const TypePtr *add_offset( intptr_t offset ) const;
2059   virtual const Type    *xmeet( const Type *t ) const;
2060   virtual const Type    *xdual() const;
2061   virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const;
2062 
2063   virtual const TypeKlassPtr* try_improve() const;
2064 
2065   virtual FlatInArray flat_in_array() const { return _flat_in_array; }
2066 
2067   FlatInArray dual_flat_in_array() const {
2068     return flat_in_array_dual[_flat_in_array];
2069   }
2070 
2071   virtual bool can_be_inline_array() const;
2072 
2073   // Convenience common pre-built types.
2074   static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
2075   static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
2076 
2077 #ifndef PRODUCT
2078   virtual void dump2(Dict& d, uint depth, outputStream* st) const;
2079 #endif // PRODUCT
2080 
2081 private:
2082   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
2083 };
2084 
2085 // Array klass pointer, mirrors TypeAryPtr
2086 class TypeAryKlassPtr : public TypeKlassPtr {
2087   friend class TypeInstKlassPtr;
2088   friend class Type;
2089   friend class TypePtr;
2090 
2091   const Type *_elem;
2092   const bool _not_flat;      // Array is never flat
2093   const bool _not_null_free; // Array is never null-free
2094   const bool _flat;
2095   const bool _null_free;
2096   const bool _atomic;
2097   const bool _refined_type;
2098 
2099   static const TypeInterfaces* _array_interfaces;
2100   TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, Offset offset, bool not_flat, int not_null_free, bool flat, bool null_free, bool atomic, bool refined_type)
2101     : TypeKlassPtr(AryKlassPtr, ptr, klass, _array_interfaces, offset), _elem(elem), _not_flat(not_flat), _not_null_free(not_null_free), _flat(flat), _null_free(null_free), _atomic(atomic), _refined_type(refined_type) {
2102     assert(klass == nullptr || klass->is_type_array_klass() || klass->is_flat_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "");
2103   }
2104 
2105   virtual ciKlass* exact_klass_helper() const;
2106   // Only guaranteed non null for array of basic types
2107   virtual ciKlass* klass() const;
2108 
2109   virtual bool must_be_exact() const;
2110 
2111   bool dual_flat() const {
2112     return _flat;
2113   }
2114 
2115   bool meet_flat(bool other) const {
2116     return _flat && other;
2117   }
2118 
2119   bool dual_null_free() const {
2120     return _null_free;
2121   }
2122 
2123   bool meet_null_free(bool other) const {
2124     return _null_free && other;
2125   }
2126 
2127   bool dual_atomic() const {
2128     return _atomic;
2129   }
2130 
2131   bool meet_atomic(bool other) const {
2132     return _atomic && other;
2133   }
2134 
2135 public:
2136 
2137   // returns base element type, an instance klass (and not interface) for object arrays
2138   const Type* base_element_type(int& dims) const;
2139 
2140   static const 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);
2141 
2142   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
2143   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
2144   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
2145 
2146   bool  is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); }
2147 
2148   static const 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);
2149   static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling);
2150 
2151   const TypeAryKlassPtr* cast_to_non_refined() const;
2152   const TypeAryKlassPtr* cast_to_refined_array_klass_ptr(bool refined = true) const;
2153 
2154   const Type *elem() const { return _elem; }
2155 
2156   virtual bool eq(const Type *t) const;
2157   virtual uint hash() const;             // Type specific hashing
2158 
2159   virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const;
2160 
2161   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
2162 
2163   // corresponding pointer to instance, for a given class
2164   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
2165 
2166   virtual const TypePtr *add_offset( intptr_t offset ) const;
2167   virtual const Type    *xmeet( const Type *t ) const;
2168   virtual const Type    *xdual() const;      // Compute dual right now.
2169 
2170   virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const;
2171 
2172   virtual bool empty(void) const {
2173     return TypeKlassPtr::empty() || _elem->empty();
2174   }
2175 
2176   bool is_flat()          const { return _flat; }
2177   bool is_not_flat()      const { return _not_flat; }
2178   bool is_null_free()     const { return _null_free; }
2179   bool is_not_null_free() const { return _not_null_free; }
2180   bool is_atomic()        const { return _atomic; }
2181   bool is_refined_type()  const { return _refined_type; }
2182   virtual bool can_be_inline_array() const;
2183 
2184 #ifndef PRODUCT
2185   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2186 #endif
2187 private:
2188   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
2189 };
2190 
2191 class TypeNarrowPtr : public Type {
2192 protected:
2193   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
2194 
2195   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
2196                                                   _ptrtype(ptrtype) {
2197     assert(ptrtype->offset() == 0 ||
2198            ptrtype->offset() == OffsetBot ||
2199            ptrtype->offset() == OffsetTop, "no real offsets");
2200   }
2201 
2202   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
2203   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;

2299   }
2300 
2301   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2302     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
2303   }
2304 
2305 public:
2306   static const TypeNarrowKlass *make( const TypePtr* type);
2307 
2308   // static const TypeNarrowKlass *BOTTOM;
2309   static const TypeNarrowKlass *NULL_PTR;
2310 
2311 #ifndef PRODUCT
2312   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2313 #endif
2314 };
2315 
2316 //------------------------------TypeFunc---------------------------------------
2317 // Class of Array Types
2318 class TypeFunc : public Type {
2319   TypeFunc(const TypeTuple *domain_sig, const TypeTuple *domain_cc, const TypeTuple *range_sig, const TypeTuple *range_cc)
2320     : Type(Function), _domain_sig(domain_sig), _domain_cc(domain_cc), _range_sig(range_sig), _range_cc(range_cc) {}
2321   virtual bool eq( const Type *t ) const;
2322   virtual uint hash() const;             // Type specific hashing
2323   virtual bool singleton(void) const;    // TRUE if type is a singleton
2324   virtual bool empty(void) const;        // TRUE if type is vacuous
2325 
2326   // Domains of inputs: inline type arguments are not passed by
2327   // reference, instead each field of the inline type is passed as an
2328   // argument. We maintain 2 views of the argument list here: one
2329   // based on the signature (with an inline type argument as a single
2330   // slot), one based on the actual calling convention (with a value
2331   // type argument as a list of its fields).
2332   const TypeTuple* const _domain_sig;
2333   const TypeTuple* const _domain_cc;
2334   // Range of results. Similar to domains: an inline type result can be
2335   // returned in registers in which case range_cc lists all fields and
2336   // is the actual calling convention.
2337   const TypeTuple* const _range_sig;
2338   const TypeTuple* const _range_cc;
2339 
2340 public:
2341   // Constants are shared among ADLC and VM
2342   enum { Control    = AdlcVMDeps::Control,
2343          I_O        = AdlcVMDeps::I_O,
2344          Memory     = AdlcVMDeps::Memory,
2345          FramePtr   = AdlcVMDeps::FramePtr,
2346          ReturnAdr  = AdlcVMDeps::ReturnAdr,
2347          Parms      = AdlcVMDeps::Parms
2348   };
2349 
2350 
2351   // Accessors:
2352   const TypeTuple* domain_sig() const { return _domain_sig; }
2353   const TypeTuple* domain_cc()  const { return _domain_cc; }
2354   const TypeTuple* range_sig()  const { return _range_sig; }
2355   const TypeTuple* range_cc()   const { return _range_cc; }
2356 
2357   static const TypeFunc* make(ciMethod* method, bool is_osr_compilation = false);
2358   static const TypeFunc *make(const TypeTuple* domain_sig, const TypeTuple* domain_cc,
2359                               const TypeTuple* range_sig, const TypeTuple* range_cc);
2360   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
2361 
2362   virtual const Type *xmeet( const Type *t ) const;
2363   virtual const Type *xdual() const;    // Compute dual right now.
2364 
2365   BasicType return_type() const;
2366 
2367   bool returns_inline_type_as_fields() const { return range_sig() != range_cc(); }
2368 
2369 #ifndef PRODUCT
2370   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2371 #endif
2372   // Convenience common pre-built types.
2373 };
2374 
2375 //------------------------------accessors--------------------------------------
2376 inline bool Type::is_ptr_to_narrowoop() const {
2377 #ifdef _LP64
2378   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
2379 #else
2380   return false;
2381 #endif
2382 }
2383 
2384 inline bool Type::is_ptr_to_narrowklass() const {
2385 #ifdef _LP64
2386   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
2387 #else
2388   return false;

2625 }
2626 
2627 inline const TypeNarrowOop* Type::make_narrowoop() const {
2628   return (_base == NarrowOop) ? is_narrowoop() :
2629                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2630 }
2631 
2632 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2633   return (_base == NarrowKlass) ? is_narrowklass() :
2634                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2635 }
2636 
2637 inline bool Type::is_floatingpoint() const {
2638   if( (_base == HalfFloatCon)  || (_base == HalfFloatBot) ||
2639       (_base == FloatCon)  || (_base == FloatBot) ||
2640       (_base == DoubleCon) || (_base == DoubleBot) )
2641     return true;
2642   return false;
2643 }
2644 
2645 inline bool Type::is_inlinetypeptr() const {
2646   return isa_instptr() != nullptr && is_instptr()->instance_klass()->is_inlinetype();
2647 }
2648 
2649 inline ciInlineKlass* Type::inline_klass() const {
2650   return make_ptr()->is_instptr()->instance_klass()->as_inline_klass();
2651 }
2652 
2653 template <>
2654 inline const TypeInt* Type::cast<TypeInt>() const {
2655   return is_int();
2656 }
2657 
2658 template <>
2659 inline const TypeLong* Type::cast<TypeLong>() const {
2660   return is_long();
2661 }
2662 
2663 template <>
2664 inline const TypeInt* Type::try_cast<TypeInt>() const {
2665   return isa_int();
2666 }
2667 
2668 template <>
2669 inline const TypeLong* Type::try_cast<TypeLong>() const {
2670   return isa_long();
2671 }
2672 

2678 
2679 // For type queries and asserts
2680 #define is_intptr_t  is_long
2681 #define isa_intptr_t isa_long
2682 #define find_intptr_t_type find_long_type
2683 #define find_intptr_t_con  find_long_con
2684 #define TypeX        TypeLong
2685 #define Type_X       Type::Long
2686 #define TypeX_X      TypeLong::LONG
2687 #define TypeX_ZERO   TypeLong::ZERO
2688 // For 'ideal_reg' machine registers
2689 #define Op_RegX      Op_RegL
2690 // For phase->intcon variants
2691 #define MakeConX     longcon
2692 #define ConXNode     ConLNode
2693 // For array index arithmetic
2694 #define MulXNode     MulLNode
2695 #define AndXNode     AndLNode
2696 #define OrXNode      OrLNode
2697 #define CmpXNode     CmpLNode
2698 #define CmpUXNode    CmpULNode
2699 #define SubXNode     SubLNode
2700 #define LShiftXNode  LShiftLNode
2701 // For object size computation:
2702 #define AddXNode     AddLNode
2703 #define RShiftXNode  RShiftLNode
2704 // For card marks and hashcodes
2705 #define URShiftXNode URShiftLNode
2706 // For shenandoahSupport
2707 #define LoadXNode    LoadLNode
2708 #define StoreXNode   StoreLNode
2709 // Opcodes
2710 #define Op_LShiftX   Op_LShiftL
2711 #define Op_AndX      Op_AndL
2712 #define Op_AddX      Op_AddL
2713 #define Op_SubX      Op_SubL
2714 #define Op_XorX      Op_XorL
2715 #define Op_URShiftX  Op_URShiftL
2716 #define Op_LoadX     Op_LoadL
2717 #define Op_StoreX    Op_StoreL
2718 // conversions
2719 #define ConvI2X(x)   ConvI2L(x)
2720 #define ConvL2X(x)   (x)
2721 #define ConvX2I(x)   ConvL2I(x)
2722 #define ConvX2L(x)   (x)
2723 #define ConvX2UL(x)  (x)
2724 
2725 #else
2726 
2727 // For type queries and asserts
2728 #define is_intptr_t  is_int
2729 #define isa_intptr_t isa_int
2730 #define find_intptr_t_type find_int_type
2731 #define find_intptr_t_con  find_int_con
2732 #define TypeX        TypeInt
2733 #define Type_X       Type::Int
2734 #define TypeX_X      TypeInt::INT
2735 #define TypeX_ZERO   TypeInt::ZERO
2736 // For 'ideal_reg' machine registers
2737 #define Op_RegX      Op_RegI
2738 // For phase->intcon variants
2739 #define MakeConX     intcon
2740 #define ConXNode     ConINode
2741 // For array index arithmetic
2742 #define MulXNode     MulINode
2743 #define AndXNode     AndINode
2744 #define OrXNode      OrINode
2745 #define CmpXNode     CmpINode
2746 #define CmpUXNode    CmpUNode
2747 #define SubXNode     SubINode
2748 #define LShiftXNode  LShiftINode
2749 // For object size computation:
2750 #define AddXNode     AddINode
2751 #define RShiftXNode  RShiftINode
2752 // For card marks and hashcodes
2753 #define URShiftXNode URShiftINode
2754 // For shenandoahSupport
2755 #define LoadXNode    LoadINode
2756 #define StoreXNode   StoreINode
2757 // Opcodes
2758 #define Op_LShiftX   Op_LShiftI
2759 #define Op_AndX      Op_AndI
2760 #define Op_AddX      Op_AddI
2761 #define Op_SubX      Op_SubI
2762 #define Op_XorX      Op_XorI
2763 #define Op_URShiftX  Op_URShiftI
2764 #define Op_LoadX     Op_LoadI
2765 #define Op_StoreX    Op_StoreI
2766 // conversions
2767 #define ConvI2X(x)   (x)
2768 #define ConvL2X(x)   ConvL2I(x)
2769 #define ConvX2I(x)   (x)
2770 #define ConvX2L(x)   ConvI2L(x)
2771 #define ConvX2UL(x)  ConvI2UL(x)
2772 
2773 #endif
2774 
2775 #endif // SHARE_OPTO_TYPE_HPP
< prev index next >