< prev index next >

src/hotspot/share/opto/type.hpp

Print this page

   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:

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







1015   friend class TypeAryPtr;
1016 
1017 public:
1018   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);

1019 
1020   virtual const Type *xmeet( const Type *t ) const;
1021   virtual const Type *xdual() const;    // Compute dual right now.
1022   bool ary_must_be_exact() const;  // true if arrays of such are never generic
1023   virtual const TypeAry* remove_speculative() const;
1024   virtual const Type* cleanup_speculative() const;
1025 #ifndef PRODUCT
1026   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
1027 #endif
1028 };
1029 
1030 //------------------------------TypeVect---------------------------------------
1031 // Basic class of vector (mask) types.
1032 class TypeVect : public Type {
1033   const BasicType _elem_bt;  // Vector's element type
1034   const uint _length;  // Elements in vector (power of 2)
1035 
1036 protected:
1037   TypeVect(TYPES t, BasicType elem_bt, uint length) : Type(t),
1038     _elem_bt(elem_bt), _length(length) {}

1157 
1158   const Type* xmeet(const Type* t) const;
1159 
1160   bool singleton(void) const;
1161   bool has_non_array_interface() const;
1162 };
1163 
1164 //------------------------------TypePtr----------------------------------------
1165 // Class of machine Pointer Types: raw data, instances or arrays.
1166 // If the _base enum is AnyPtr, then this refers to all of the above.
1167 // Otherwise the _base will indicate which subset of pointers is affected,
1168 // and the class will be inherited from.
1169 class TypePtr : public Type {
1170   friend class TypeNarrowPtr;
1171   friend class Type;
1172 protected:
1173   static const TypeInterfaces* interfaces(ciKlass*& k, bool klass, bool interface, bool array, InterfaceHandling interface_handling);
1174 
1175 public:
1176   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };



















1177 protected:
1178   TypePtr(TYPES t, PTR ptr, int offset,
1179           const TypePtr* speculative = nullptr,
1180           int inline_depth = InlineDepthBottom) :
1181     Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
1182     _ptr(ptr) {}
1183   static const PTR ptr_meet[lastPTR][lastPTR];
1184   static const PTR ptr_dual[lastPTR];
1185   static const char * const ptr_msg[lastPTR];
1186 



1187   enum {
1188     InlineDepthBottom = INT_MAX,
1189     InlineDepthTop = -InlineDepthBottom
1190   };
1191 
1192   // Extra type information profiling gave us. We propagate it the
1193   // same way the rest of the type info is propagated. If we want to
1194   // use it, then we have to emit a guard: this part of the type is
1195   // not something we know but something we speculate about the type.
1196   const TypePtr*   _speculative;
1197   // For speculative types, we record at what inlining depth the
1198   // profiling point that provided the data is. We want to favor
1199   // profile data coming from outer scopes which are likely better for
1200   // the current compilation.
1201   int _inline_depth;
1202 
1203   // utility methods to work on the speculative part of the type
1204   const TypePtr* dual_speculative() const;
1205   const TypePtr* xmeet_speculative(const TypePtr* other) const;
1206   bool eq_speculative(const TypePtr* other) const;

1215 #ifndef PRODUCT
1216   void dump_speculative(outputStream* st) const;
1217   void dump_inline_depth(outputStream* st) const;
1218   void dump_offset(outputStream* st) const;
1219 #endif
1220 
1221   // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1222   // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1223   // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1224   // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1225   // encountered so the right logic specific to klasses or oops can be executed.,
1226   enum MeetResult {
1227     QUICK,
1228     UNLOADED,
1229     SUBTYPE,
1230     NOT_SUBTYPE,
1231     LCA
1232   };
1233   template<class T> static TypePtr::MeetResult meet_instptr(PTR& ptr, const TypeInterfaces*& interfaces, const T* this_type,
1234                                                             const T* other_type, ciKlass*& res_klass, bool& res_xk);


1235 
1236   template<class T> static MeetResult meet_aryptr(PTR& ptr, const Type*& elem, const T* this_ary, const T* other_ary,
1237                                                   ciKlass*& res_klass, bool& res_xk);
1238 
1239   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);
1240   template <class T1, class T2> static bool is_same_java_type_as_helper_for_instance(const T1* this_one, const T2* other);
1241   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);
1242   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);
1243   template <class T1, class T2> static bool is_same_java_type_as_helper_for_array(const T1* this_one, const T2* other);
1244   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);
1245   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);
1246   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);
1247 public:
1248   const int _offset;            // Offset into oop, with TOP & BOT
1249   const PTR _ptr;               // Pointer equivalence class
1250 
1251   int offset() const { return _offset; }
1252   PTR ptr()    const { return _ptr; }
1253 
1254   static const TypePtr *make(TYPES t, PTR ptr, int offset,
1255                              const TypePtr* speculative = nullptr,
1256                              int inline_depth = InlineDepthBottom);
1257 
1258   // Return a 'ptr' version of this type
1259   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1260 
1261   virtual intptr_t get_con() const;
1262 
1263   int xadd_offset( intptr_t offset ) const;
1264   virtual const TypePtr* add_offset(intptr_t offset) const;
1265   virtual const TypePtr* with_offset(intptr_t offset) const;

1266   virtual bool eq(const Type *t) const;
1267   virtual uint hash() const;             // Type specific hashing
1268 
1269   virtual bool singleton(void) const;    // TRUE if type is a singleton
1270   virtual bool empty(void) const;        // TRUE if type is vacuous
1271   virtual const Type *xmeet( const Type *t ) const;
1272   virtual const Type *xmeet_helper( const Type *t ) const;
1273   int meet_offset( int offset ) const;
1274   int dual_offset( ) const;
1275   virtual const Type *xdual() const;    // Compute dual right now.
1276 
1277   // meet, dual and join over pointer equivalence sets
1278   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1279   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
1280 
1281   // This is textually confusing unless one recalls that
1282   // join(t) == dual()->meet(t->dual())->dual().
1283   PTR join_ptr( const PTR in_ptr ) const {
1284     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1285   }
1286 
1287   // Speculative type helper methods.
1288   virtual const TypePtr* speculative() const { return _speculative; }
1289   int inline_depth() const                   { return _inline_depth; }
1290   virtual ciKlass* speculative_type() const;
1291   virtual ciKlass* speculative_type_not_null() const;
1292   virtual bool speculative_maybe_null() const;
1293   virtual bool speculative_always_null() const;
1294   virtual const TypePtr* remove_speculative() const;
1295   virtual const Type* cleanup_speculative() const;
1296   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1297   virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1298   virtual const TypePtr* with_inline_depth(int depth) const;
1299 
1300   virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1301 

















1302   // Tests for relation to centerline of type lattice:
1303   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1304   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1305   // Convenience common pre-built types.
1306   static const TypePtr *NULL_PTR;
1307   static const TypePtr *NOTNULL;
1308   static const TypePtr *BOTTOM;
1309 #ifndef PRODUCT
1310   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1311 #endif
1312 };
1313 
1314 //------------------------------TypeRawPtr-------------------------------------
1315 // Class of raw pointers, pointers to things other than Oops.  Examples
1316 // include the stack pointer, top of heap, card-marking area, handles, etc.
1317 class TypeRawPtr : public TypePtr {
1318 protected:
1319   TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
1320 public:
1321   virtual bool eq( const Type *t ) const;
1322   virtual uint hash() const;    // Type specific hashing
1323 
1324   const address _bits;          // Constant value, if applicable
1325 
1326   static const TypeRawPtr *make( PTR ptr );
1327   static const TypeRawPtr *make( address bits );
1328 
1329   // Return a 'ptr' version of this type
1330   virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1331 
1332   virtual intptr_t get_con() const;
1333 
1334   virtual const TypePtr* add_offset(intptr_t offset) const;
1335   virtual const TypeRawPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr;}
1336 
1337   virtual const Type *xmeet( const Type *t ) const;
1338   virtual const Type *xdual() const;    // Compute dual right now.
1339   // Convenience common pre-built types.
1340   static const TypeRawPtr *BOTTOM;
1341   static const TypeRawPtr *NOTNULL;
1342 #ifndef PRODUCT
1343   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1344 #endif
1345 };
1346 
1347 //------------------------------TypeOopPtr-------------------------------------
1348 // Some kind of oop (Java pointer), either instance or array.
1349 class TypeOopPtr : public TypePtr {
1350   friend class TypeAry;
1351   friend class TypePtr;
1352   friend class TypeInstPtr;
1353   friend class TypeAryPtr;
1354 protected:
1355  TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset, int instance_id,
1356             const TypePtr* speculative, int inline_depth);
1357 public:
1358   virtual bool eq( const Type *t ) const;
1359   virtual uint hash() const;             // Type specific hashing
1360   virtual bool singleton(void) const;    // TRUE if type is a singleton
1361   enum {
1362    InstanceTop = -1,   // undefined instance
1363    InstanceBot = 0     // any possible instance
1364   };
1365 protected:
1366 
1367   // Oop is null, unless this is a constant oop.
1368   ciObject*     _const_oop;   // Constant oop
1369   // If _klass is null, then so is _sig.  This is an unloaded klass.
1370   ciKlass*      _klass;       // Klass object
1371 
1372   const TypeInterfaces* _interfaces;
1373 
1374   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1375   bool          _klass_is_exact;
1376   bool          _is_ptr_to_narrowoop;
1377   bool          _is_ptr_to_narrowklass;
1378   bool          _is_ptr_to_boxed_value;

1379 
1380   // If not InstanceTop or InstanceBot, indicates that this is
1381   // a particular instance of this type which is distinct.
1382   // This is the node index of the allocation node creating this instance.
1383   int           _instance_id;
1384 
1385   static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact, InterfaceHandling interface_handling);
1386 
1387   int dual_instance_id() const;
1388   int meet_instance_id(int uid) const;
1389 
1390   const TypeInterfaces* meet_interfaces(const TypeOopPtr* other) const;
1391 
1392   // Do not allow interface-vs.-noninterface joins to collapse to top.
1393   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1394 
1395   virtual ciKlass* exact_klass_helper() const { return nullptr; }
1396   virtual ciKlass* klass() const { return _klass;     }
1397 
1398 #ifndef PRODUCT
1399   void dump_instance_id(outputStream* st) const;
1400 #endif // PRODUCT
1401 
1402 public:
1403 
1404   bool is_java_subtype_of(const TypeOopPtr* other) const {
1405     return is_java_subtype_of_helper(other, klass_is_exact(), other->klass_is_exact());
1406   }
1407 
1408   bool is_same_java_type_as(const TypePtr* other) const {
1409     return is_same_java_type_as_helper(other->is_oopptr());
1410   }
1411 
1412   virtual bool is_same_java_type_as_helper(const TypeOopPtr* other) const {
1413     ShouldNotReachHere(); return false;
1414   }
1415 
1416   bool maybe_java_subtype_of(const TypeOopPtr* other) const {

1427     return make_from_klass_common(klass, true, false, interface_handling);
1428   }
1429   // Same as before, but will produce an exact type, even if
1430   // the klass is not final, as long as it has exactly one implementation.
1431   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1432     return make_from_klass_common(klass, true, true, interface_handling);
1433   }
1434   // Same as before, but does not respects UseUniqueSubclasses.
1435   // Use this only for creating array element types.
1436   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1437     return make_from_klass_common(klass, false, false, interface_handling);
1438   }
1439   // Creates a singleton type given an object.
1440   // If the object cannot be rendered as a constant,
1441   // may return a non-singleton type.
1442   // If require_constant, produce a null if a singleton is not possible.
1443   static const TypeOopPtr* make_from_constant(ciObject* o,
1444                                               bool require_constant = false);
1445 
1446   // Make a generic (unclassed) pointer to an oop.
1447   static const TypeOopPtr* make(PTR ptr, int offset, int instance_id,
1448                                 const TypePtr* speculative = nullptr,
1449                                 int inline_depth = InlineDepthBottom);
1450 
1451   ciObject* const_oop()    const { return _const_oop; }
1452   // Exact klass, possibly an interface or an array of interface
1453   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1454   ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1455 
1456   virtual bool  is_loaded() const { return klass()->is_loaded(); }
1457   virtual bool klass_is_exact()    const { return _klass_is_exact; }
1458 
1459   // Returns true if this pointer points at memory which contains a
1460   // compressed oop references.
1461   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1462   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1463   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }

1464   bool is_known_instance()       const { return _instance_id > 0; }
1465   int  instance_id()             const { return _instance_id; }
1466   bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }



1467 
1468   virtual intptr_t get_con() const;
1469 
1470   virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1471 
1472   virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1473 
1474   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1475 
1476   // corresponding pointer to klass, for a given instance
1477   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1478 
1479   virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1480   virtual const TypePtr* add_offset(intptr_t offset) const;
1481 
1482   // Speculative type helper methods.
1483   virtual const TypeOopPtr* remove_speculative() const;
1484   virtual const Type* cleanup_speculative() const;
1485   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1486   virtual const TypePtr* with_inline_depth(int depth) const;

1509     return _interfaces;
1510   };
1511 
1512   const TypeOopPtr* is_reference_type(const Type* other) const {
1513     return other->isa_oopptr();
1514   }
1515 
1516   const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1517     return other->isa_aryptr();
1518   }
1519 
1520   const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1521     return other->isa_instptr();
1522   }
1523 };
1524 
1525 //------------------------------TypeInstPtr------------------------------------
1526 // Class of Java object pointers, pointing either to non-array Java instances
1527 // or to a Klass* (including array klasses).
1528 class TypeInstPtr : public TypeOopPtr {
1529   TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int off, int instance_id,
1530               const TypePtr* speculative, int inline_depth);




1531   virtual bool eq( const Type *t ) const;
1532   virtual uint hash() const;             // Type specific hashing
1533 
1534   ciKlass* exact_klass_helper() const;
1535 
1536 public:
1537 
1538   // Instance klass, ignoring any interface
1539   ciInstanceKlass* instance_klass() const {
1540     assert(!(klass()->is_loaded() && klass()->is_interface()), "");
1541     return klass()->as_instance_klass();
1542   }
1543 
1544   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1545   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1546   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1547 
1548   // Make a pointer to a constant oop.
1549   static const TypeInstPtr *make(ciObject* o) {
1550     ciKlass* k = o->klass();
1551     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1552     return make(TypePtr::Constant, k, interfaces, true, o, 0, InstanceBot);
1553   }
1554   // Make a pointer to a constant oop with offset.
1555   static const TypeInstPtr *make(ciObject* o, int offset) {
1556     ciKlass* k = o->klass();
1557     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1558     return make(TypePtr::Constant, k, interfaces, true, o, offset, InstanceBot);
1559   }
1560 
1561   // Make a pointer to some value of type klass.
1562   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1563     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, true, false, interface_handling);
1564     return make(ptr, klass, interfaces, false, nullptr, 0, InstanceBot);
1565   }
1566 
1567   // Make a pointer to some non-polymorphic value of exactly type klass.
1568   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1569     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1570     return make(ptr, klass, interfaces, true, nullptr, 0, InstanceBot);
1571   }
1572 
1573   // Make a pointer to some value of type klass with offset.
1574   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1575     const TypeInterfaces* interfaces = TypePtr::interfaces(klass, true, false, false, ignore_interfaces);
1576     return make(ptr, klass, interfaces, false, nullptr, offset, InstanceBot);
1577   }
1578 
1579   static const TypeInstPtr *make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, int offset,


1580                                  int instance_id = InstanceBot,
1581                                  const TypePtr* speculative = nullptr,
1582                                  int inline_depth = InlineDepthBottom);
1583 
1584   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot) {

1585     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1586     return make(ptr, k, interfaces, xk, o, offset, instance_id);
1587   }
1588 
1589   /** Create constant type for a constant boxed value */
1590   const Type* get_const_boxed_value() const;
1591 
1592   // If this is a java.lang.Class constant, return the type for it or null.
1593   // Pass to Type::get_const_type to turn it to a type, which will usually
1594   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1595   ciType* java_mirror_type() const;
1596 
1597   virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1598 
1599   virtual const TypeInstPtr* cast_to_exactness(bool klass_is_exact) const;
1600 
1601   virtual const TypeInstPtr* cast_to_instance_id(int instance_id) const;
1602 

1603   virtual const TypePtr* add_offset(intptr_t offset) const;
1604   virtual const TypeInstPtr* with_offset(intptr_t offset) const;
1605 
1606   // Speculative type helper methods.
1607   virtual const TypeInstPtr* remove_speculative() const;
1608   const TypeInstPtr* with_speculative(const TypePtr* speculative) const;
1609   virtual const TypePtr* with_inline_depth(int depth) const;
1610   virtual const TypePtr* with_instance_id(int instance_id) const;
1611 








1612   // the core of the computation of the meet of 2 types
1613   virtual const Type *xmeet_helper(const Type *t) const;
1614   virtual const TypeInstPtr *xmeet_unloaded(const TypeInstPtr *tinst, const TypeInterfaces* interfaces) const;
1615   virtual const Type *xdual() const;    // Compute dual right now.
1616 
1617   const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1618 


1619   // Convenience common pre-built types.
1620   static const TypeInstPtr *NOTNULL;
1621   static const TypeInstPtr *BOTTOM;
1622   static const TypeInstPtr *MIRROR;
1623   static const TypeInstPtr *MARK;
1624   static const TypeInstPtr *KLASS;
1625 #ifndef PRODUCT
1626   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1627 #endif
1628 
1629 private:
1630   virtual bool is_meet_subtype_of_helper(const TypeOopPtr* other, bool this_xk, bool other_xk) const;
1631 
1632   virtual bool is_meet_same_type_as(const TypePtr* other) const {
1633     return _klass->equals(other->is_instptr()->_klass) && _interfaces->eq(other->is_instptr()->_interfaces);
1634   }
1635 
1636 };
1637 
1638 //------------------------------TypeAryPtr-------------------------------------
1639 // Class of Java array pointers
1640 class TypeAryPtr : public TypeOopPtr {
1641   friend class Type;
1642   friend class TypePtr;

1643   friend class TypeInterfaces;
1644 
1645   TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1646               int offset, int instance_id, bool is_autobox_cache,
1647               const TypePtr* speculative, int inline_depth)
1648     : TypeOopPtr(AryPtr,ptr,k,_array_interfaces,xk,o,offset, instance_id, speculative, inline_depth),
1649     _ary(ary),
1650     _is_autobox_cache(is_autobox_cache)

1651  {
1652     int dummy;
1653     bool top_or_bottom = (base_element_type(dummy) == Type::TOP || base_element_type(dummy) == Type::BOTTOM);
1654 
1655     if (UseCompressedOops && (elem()->make_oopptr() != nullptr && !top_or_bottom) &&
1656         _offset != 0 && _offset != arrayOopDesc::length_offset_in_bytes() &&
1657         _offset != arrayOopDesc::klass_offset_in_bytes()) {
1658       _is_ptr_to_narrowoop = true;
1659     }
1660 
1661   }
1662   virtual bool eq( const Type *t ) const;
1663   virtual uint hash() const;    // Type specific hashing
1664   const TypeAry *_ary;          // Array we point into
1665   const bool     _is_autobox_cache;






1666 
1667   ciKlass* compute_klass() const;
1668 
1669   // A pointer to delay allocation to Type::Initialize_shared()
1670 
1671   static const TypeInterfaces* _array_interfaces;
1672   ciKlass* exact_klass_helper() const;
1673   // Only guaranteed non null for array of basic types
1674   ciKlass* klass() const;
1675 
1676 public:
1677 
1678   bool is_same_java_type_as_helper(const TypeOopPtr* other) const;
1679   bool is_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1680   bool maybe_java_subtype_of_helper(const TypeOopPtr* other, bool this_exact, bool other_exact) const;
1681 
1682   // returns base element type, an instance klass (and not interface) for object arrays
1683   const Type* base_element_type(int& dims) const;
1684 
1685   // Accessors
1686   bool  is_loaded() const { return (_ary->_elem->make_oopptr() ? _ary->_elem->make_oopptr()->is_loaded() : true); }
1687 
1688   const TypeAry* ary() const  { return _ary; }
1689   const Type*    elem() const { return _ary->_elem; }
1690   const TypeInt* size() const { return _ary->_size; }
1691   bool      is_stable() const { return _ary->_stable; }
1692 







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

1696                                 int instance_id = InstanceBot,
1697                                 const TypePtr* speculative = nullptr,
1698                                 int inline_depth = InlineDepthBottom);
1699   // Constant pointer to array
1700   static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,

1701                                 int instance_id = InstanceBot,
1702                                 const TypePtr* speculative = nullptr,
1703                                 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false);

1704 
1705   // Return a 'ptr' version of this type
1706   virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1707 
1708   virtual const TypeAryPtr* cast_to_exactness(bool klass_is_exact) const;
1709 
1710   virtual const TypeAryPtr* cast_to_instance_id(int instance_id) const;
1711 
1712   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1713   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1714 
1715   virtual bool empty(void) const;        // TRUE if type is vacuous
1716   virtual const TypePtr *add_offset( intptr_t offset ) const;
1717   virtual const TypeAryPtr *with_offset( intptr_t offset ) const;
1718   const TypeAryPtr* with_ary(const TypeAry* ary) const;
1719 
1720   // Speculative type helper methods.
1721   virtual const TypeAryPtr* remove_speculative() const;

1722   virtual const TypePtr* with_inline_depth(int depth) const;
1723   virtual const TypePtr* with_instance_id(int instance_id) const;
1724 
1725   // the core of the computation of the meet of 2 types
1726   virtual const Type *xmeet_helper(const Type *t) const;
1727   virtual const Type *xdual() const;    // Compute dual right now.
1728 










1729   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1730   int stable_dimension() const;
1731 
1732   const TypeAryPtr* cast_to_autobox_cache() const;
1733 
1734   static jint max_array_length(BasicType etype) ;







1735   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1736 


1737   // Convenience common pre-built types.
1738   static const TypeAryPtr* BOTTOM;
1739   static const TypeAryPtr* RANGE;
1740   static const TypeAryPtr* OOPS;
1741   static const TypeAryPtr* NARROWOOPS;
1742   static const TypeAryPtr* BYTES;
1743   static const TypeAryPtr* SHORTS;
1744   static const TypeAryPtr* CHARS;
1745   static const TypeAryPtr* INTS;
1746   static const TypeAryPtr* LONGS;
1747   static const TypeAryPtr* FLOATS;
1748   static const TypeAryPtr* DOUBLES;

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


1868   virtual const TypeKlassPtr* try_improve() const { return this; }
1869 
1870 private:
1871   virtual bool is_meet_subtype_of(const TypePtr* other) const {
1872     return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
1873   }
1874 
1875   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
1876     ShouldNotReachHere(); return false;
1877   }
1878 
1879   virtual const TypeInterfaces* interfaces() const {
1880     return _interfaces;
1881   };
1882 
1883   const TypeKlassPtr* is_reference_type(const Type* other) const {
1884     return other->isa_klassptr();
1885   }
1886 
1887   const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
1888     return other->isa_aryklassptr();
1889   }
1890 
1891   const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
1892     return other->isa_instklassptr();
1893   }
1894 };
1895 
1896 // Instance klass pointer, mirrors TypeInstPtr
1897 class TypeInstKlassPtr : public TypeKlassPtr {


1898 
1899   TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, int offset)
1900     : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset) {

1901     assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
1902   }
1903 
1904   virtual bool must_be_exact() const;
1905 
1906 public:
1907   // Instance klass ignoring any interface
1908   ciInstanceKlass* instance_klass() const {
1909     assert(!klass()->is_interface(), "");
1910     return klass()->as_instance_klass();
1911   }
1912 
1913   bool might_be_an_array() const;
1914 
1915   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1916   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1917   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1918 


1919   static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
1920     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
1921     return make(TypePtr::Constant, k, interfaces, 0);
1922   }
1923   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, int offset);
1924 
1925   static const TypeInstKlassPtr* make(PTR ptr, ciKlass* k, int offset) {



1926     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, false, false, ignore_interfaces);
1927     return make(ptr, k, interfaces, offset);
1928   }
1929 
1930   virtual const TypeInstKlassPtr* cast_to_ptr_type(PTR ptr) const;
1931 
1932   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1933 
1934   // corresponding pointer to instance, for a given class
1935   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
1936   virtual uint hash() const;
1937   virtual bool eq(const Type *t) const;
1938 


1939   virtual const TypePtr *add_offset( intptr_t offset ) const;
1940   virtual const Type    *xmeet( const Type *t ) const;
1941   virtual const Type    *xdual() const;
1942   virtual const TypeInstKlassPtr* with_offset(intptr_t offset) const;
1943 
1944   virtual const TypeKlassPtr* try_improve() const;
1945 








1946   // Convenience common pre-built types.
1947   static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
1948   static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1949 
1950 #ifndef PRODUCT
1951   virtual void dump2(Dict& d, uint depth, outputStream* st) const;
1952 #endif // PRODUCT
1953 
1954 private:
1955   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
1956 };
1957 
1958 // Array klass pointer, mirrors TypeAryPtr
1959 class TypeAryKlassPtr : public TypeKlassPtr {
1960   friend class TypeInstKlassPtr;
1961   friend class Type;
1962   friend class TypePtr;
1963 
1964   const Type *_elem;






1965 
1966   static const TypeInterfaces* _array_interfaces;
1967   TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, int offset)
1968     : TypeKlassPtr(AryKlassPtr, ptr, klass, _array_interfaces, offset), _elem(elem) {
1969     assert(klass == nullptr || klass->is_type_array_klass() || !klass->as_obj_array_klass()->base_element_klass()->is_interface(), "");
1970   }
1971 
1972   virtual ciKlass* exact_klass_helper() const;
1973   // Only guaranteed non null for array of basic types
1974   virtual ciKlass* klass() const;
1975 
1976   virtual bool must_be_exact() const;
1977 
























1978 public:
1979 
1980   // returns base element type, an instance klass (and not interface) for object arrays
1981   const Type* base_element_type(int& dims) const;
1982 
1983   static const TypeAryKlassPtr *make(PTR ptr, ciKlass* k, int offset, InterfaceHandling interface_handling);
1984 
1985   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
1986   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1987   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
1988 
1989   bool  is_loaded() const { return (_elem->isa_klassptr() ? _elem->is_klassptr()->is_loaded() : true); }
1990 
1991   static const TypeAryKlassPtr *make(PTR ptr, const Type *elem, ciKlass* k, int offset);
1992   static const TypeAryKlassPtr* make(ciKlass* klass, InterfaceHandling interface_handling);
1993 



1994   const Type *elem() const { return _elem; }
1995 
1996   virtual bool eq(const Type *t) const;
1997   virtual uint hash() const;             // Type specific hashing
1998 
1999   virtual const TypeAryKlassPtr* cast_to_ptr_type(PTR ptr) const;
2000 
2001   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
2002 
2003   // corresponding pointer to instance, for a given class
2004   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const;
2005 
2006   virtual const TypePtr *add_offset( intptr_t offset ) const;
2007   virtual const Type    *xmeet( const Type *t ) const;
2008   virtual const Type    *xdual() const;      // Compute dual right now.
2009 
2010   virtual const TypeAryKlassPtr* with_offset(intptr_t offset) const;
2011 
2012   virtual bool empty(void) const {
2013     return TypeKlassPtr::empty() || _elem->empty();
2014   }
2015 








2016 #ifndef PRODUCT
2017   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2018 #endif
2019 private:
2020   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const;
2021 };
2022 
2023 class TypeNarrowPtr : public Type {
2024 protected:
2025   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
2026 
2027   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
2028                                                   _ptrtype(ptrtype) {
2029     assert(ptrtype->offset() == 0 ||
2030            ptrtype->offset() == OffsetBot ||
2031            ptrtype->offset() == OffsetTop, "no real offsets");
2032   }
2033 
2034   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
2035   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;

2131   }
2132 
2133   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2134     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
2135   }
2136 
2137 public:
2138   static const TypeNarrowKlass *make( const TypePtr* type);
2139 
2140   // static const TypeNarrowKlass *BOTTOM;
2141   static const TypeNarrowKlass *NULL_PTR;
2142 
2143 #ifndef PRODUCT
2144   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2145 #endif
2146 };
2147 
2148 //------------------------------TypeFunc---------------------------------------
2149 // Class of Array Types
2150 class TypeFunc : public Type {
2151   TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function),  _domain(domain), _range(range) {}

2152   virtual bool eq( const Type *t ) const;
2153   virtual uint hash() const;             // Type specific hashing
2154   virtual bool singleton(void) const;    // TRUE if type is a singleton
2155   virtual bool empty(void) const;        // TRUE if type is vacuous
2156 
2157   const TypeTuple* const _domain;     // Domain of inputs
2158   const TypeTuple* const _range;      // Range of results











2159 
2160 public:
2161   // Constants are shared among ADLC and VM
2162   enum { Control    = AdlcVMDeps::Control,
2163          I_O        = AdlcVMDeps::I_O,
2164          Memory     = AdlcVMDeps::Memory,
2165          FramePtr   = AdlcVMDeps::FramePtr,
2166          ReturnAdr  = AdlcVMDeps::ReturnAdr,
2167          Parms      = AdlcVMDeps::Parms
2168   };
2169 
2170 
2171   // Accessors:
2172   const TypeTuple* domain() const { return _domain; }
2173   const TypeTuple* range()  const { return _range; }
2174 
2175   static const TypeFunc *make(ciMethod* method);
2176   static const TypeFunc *make(ciSignature signature, const Type* extra);



2177   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
2178 
2179   virtual const Type *xmeet( const Type *t ) const;
2180   virtual const Type *xdual() const;    // Compute dual right now.
2181 
2182   BasicType return_type() const;
2183 


2184 #ifndef PRODUCT
2185   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2186 #endif
2187   // Convenience common pre-built types.
2188 };
2189 
2190 //------------------------------accessors--------------------------------------
2191 inline bool Type::is_ptr_to_narrowoop() const {
2192 #ifdef _LP64
2193   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
2194 #else
2195   return false;
2196 #endif
2197 }
2198 
2199 inline bool Type::is_ptr_to_narrowklass() const {
2200 #ifdef _LP64
2201   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
2202 #else
2203   return false;

2440 }
2441 
2442 inline const TypeNarrowOop* Type::make_narrowoop() const {
2443   return (_base == NarrowOop) ? is_narrowoop() :
2444                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2445 }
2446 
2447 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2448   return (_base == NarrowKlass) ? is_narrowklass() :
2449                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2450 }
2451 
2452 inline bool Type::is_floatingpoint() const {
2453   if( (_base == HalfFloatCon)  || (_base == HalfFloatBot) ||
2454       (_base == FloatCon)  || (_base == FloatBot) ||
2455       (_base == DoubleCon) || (_base == DoubleBot) )
2456     return true;
2457   return false;
2458 }
2459 








2460 template <>
2461 inline const TypeInt* Type::cast<TypeInt>() const {
2462   return is_int();
2463 }
2464 
2465 template <>
2466 inline const TypeLong* Type::cast<TypeLong>() const {
2467   return is_long();
2468 }
2469 
2470 template <>
2471 inline const TypeInt* Type::try_cast<TypeInt>() const {
2472   return isa_int();
2473 }
2474 
2475 template <>
2476 inline const TypeLong* Type::try_cast<TypeLong>() const {
2477   return isa_long();
2478 }
2479 

2485 
2486 // For type queries and asserts
2487 #define is_intptr_t  is_long
2488 #define isa_intptr_t isa_long
2489 #define find_intptr_t_type find_long_type
2490 #define find_intptr_t_con  find_long_con
2491 #define TypeX        TypeLong
2492 #define Type_X       Type::Long
2493 #define TypeX_X      TypeLong::LONG
2494 #define TypeX_ZERO   TypeLong::ZERO
2495 // For 'ideal_reg' machine registers
2496 #define Op_RegX      Op_RegL
2497 // For phase->intcon variants
2498 #define MakeConX     longcon
2499 #define ConXNode     ConLNode
2500 // For array index arithmetic
2501 #define MulXNode     MulLNode
2502 #define AndXNode     AndLNode
2503 #define OrXNode      OrLNode
2504 #define CmpXNode     CmpLNode

2505 #define SubXNode     SubLNode
2506 #define LShiftXNode  LShiftLNode
2507 // For object size computation:
2508 #define AddXNode     AddLNode
2509 #define RShiftXNode  RShiftLNode
2510 // For card marks and hashcodes
2511 #define URShiftXNode URShiftLNode
2512 // For shenandoahSupport
2513 #define LoadXNode    LoadLNode
2514 #define StoreXNode   StoreLNode
2515 // Opcodes
2516 #define Op_LShiftX   Op_LShiftL
2517 #define Op_AndX      Op_AndL
2518 #define Op_AddX      Op_AddL
2519 #define Op_SubX      Op_SubL
2520 #define Op_XorX      Op_XorL
2521 #define Op_URShiftX  Op_URShiftL
2522 #define Op_LoadX     Op_LoadL

2523 // conversions
2524 #define ConvI2X(x)   ConvI2L(x)
2525 #define ConvL2X(x)   (x)
2526 #define ConvX2I(x)   ConvL2I(x)
2527 #define ConvX2L(x)   (x)
2528 #define ConvX2UL(x)  (x)
2529 
2530 #else
2531 
2532 // For type queries and asserts
2533 #define is_intptr_t  is_int
2534 #define isa_intptr_t isa_int
2535 #define find_intptr_t_type find_int_type
2536 #define find_intptr_t_con  find_int_con
2537 #define TypeX        TypeInt
2538 #define Type_X       Type::Int
2539 #define TypeX_X      TypeInt::INT
2540 #define TypeX_ZERO   TypeInt::ZERO
2541 // For 'ideal_reg' machine registers
2542 #define Op_RegX      Op_RegI
2543 // For phase->intcon variants
2544 #define MakeConX     intcon
2545 #define ConXNode     ConINode
2546 // For array index arithmetic
2547 #define MulXNode     MulINode
2548 #define AndXNode     AndINode
2549 #define OrXNode      OrINode
2550 #define CmpXNode     CmpINode

2551 #define SubXNode     SubINode
2552 #define LShiftXNode  LShiftINode
2553 // For object size computation:
2554 #define AddXNode     AddINode
2555 #define RShiftXNode  RShiftINode
2556 // For card marks and hashcodes
2557 #define URShiftXNode URShiftINode
2558 // For shenandoahSupport
2559 #define LoadXNode    LoadINode
2560 #define StoreXNode   StoreINode
2561 // Opcodes
2562 #define Op_LShiftX   Op_LShiftI
2563 #define Op_AndX      Op_AndI
2564 #define Op_AddX      Op_AddI
2565 #define Op_SubX      Op_SubI
2566 #define Op_XorX      Op_XorI
2567 #define Op_URShiftX  Op_URShiftI
2568 #define Op_LoadX     Op_LoadI

2569 // conversions
2570 #define ConvI2X(x)   (x)
2571 #define ConvL2X(x)   ConvL2I(x)
2572 #define ConvX2I(x)   (x)
2573 #define ConvX2L(x)   ConvI2L(x)
2574 #define ConvX2UL(x)  ConvI2UL(x)
2575 
2576 #endif
2577 
2578 #endif // SHARE_OPTO_TYPE_HPP

   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:

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

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

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

1506     return make_from_klass_common(klass, true, false, interface_handling);
1507   }
1508   // Same as before, but will produce an exact type, even if
1509   // the klass is not final, as long as it has exactly one implementation.
1510   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass, InterfaceHandling interface_handling= ignore_interfaces) {
1511     return make_from_klass_common(klass, true, true, interface_handling);
1512   }
1513   // Same as before, but does not respects UseUniqueSubclasses.
1514   // Use this only for creating array element types.
1515   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass, InterfaceHandling interface_handling = ignore_interfaces) {
1516     return make_from_klass_common(klass, false, false, interface_handling);
1517   }
1518   // Creates a singleton type given an object.
1519   // If the object cannot be rendered as a constant,
1520   // may return a non-singleton type.
1521   // If require_constant, produce a null if a singleton is not possible.
1522   static const TypeOopPtr* make_from_constant(ciObject* o,
1523                                               bool require_constant = false);
1524 
1525   // Make a generic (unclassed) pointer to an oop.
1526   static const TypeOopPtr* make(PTR ptr, Offset offset, int instance_id,
1527                                 const TypePtr* speculative = nullptr,
1528                                 int inline_depth = InlineDepthBottom);
1529 
1530   ciObject* const_oop()    const { return _const_oop; }
1531   // Exact klass, possibly an interface or an array of interface
1532   ciKlass* exact_klass(bool maybe_null = false) const { assert(klass_is_exact(), ""); ciKlass* k = exact_klass_helper(); assert(k != nullptr || maybe_null, ""); return k;  }
1533   ciKlass* unloaded_klass() const { assert(!is_loaded(), "only for unloaded types"); return klass(); }
1534 
1535   virtual bool  is_loaded() const { return klass()->is_loaded(); }
1536   virtual bool klass_is_exact()    const { return _klass_is_exact; }
1537 
1538   // Returns true if this pointer points at memory which contains a
1539   // compressed oop references.
1540   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1541   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1542   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }
1543   bool is_ptr_to_strict_final_field() const { return _is_ptr_to_strict_final_field; }
1544   bool is_known_instance()       const { return _instance_id > 0; }
1545   int  instance_id()             const { return _instance_id; }
1546   bool is_known_instance_field() const { return is_known_instance() && _offset.get() >= 0; }
1547 
1548   virtual bool can_be_inline_type() const { return (_klass == nullptr || _klass->can_be_inline_klass(_klass_is_exact)); }
1549   virtual bool can_be_inline_array() const { ShouldNotReachHere(); return false; }
1550 
1551   virtual intptr_t get_con() const;
1552 
1553   virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1554 
1555   virtual const TypeOopPtr* cast_to_exactness(bool klass_is_exact) const;
1556 
1557   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1558 
1559   // corresponding pointer to klass, for a given instance
1560   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1561 
1562   virtual const TypeOopPtr* with_offset(intptr_t offset) const;
1563   virtual const TypePtr* add_offset(intptr_t offset) const;
1564 
1565   // Speculative type helper methods.
1566   virtual const TypeOopPtr* remove_speculative() const;
1567   virtual const Type* cleanup_speculative() const;
1568   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1569   virtual const TypePtr* with_inline_depth(int depth) const;

1592     return _interfaces;
1593   };
1594 
1595   const TypeOopPtr* is_reference_type(const Type* other) const {
1596     return other->isa_oopptr();
1597   }
1598 
1599   const TypeAryPtr* is_array_type(const TypeOopPtr* other) const {
1600     return other->isa_aryptr();
1601   }
1602 
1603   const TypeInstPtr* is_instance_type(const TypeOopPtr* other) const {
1604     return other->isa_instptr();
1605   }
1606 };
1607 
1608 //------------------------------TypeInstPtr------------------------------------
1609 // Class of Java object pointers, pointing either to non-array Java instances
1610 // or to a Klass* (including array klasses).
1611 class TypeInstPtr : public TypeOopPtr {
1612   // Can this instance be in a flat array?
1613   FlatInArray _flat_in_array;
1614 
1615   TypeInstPtr(PTR ptr, ciKlass* k, const TypeInterfaces* interfaces, bool xk, ciObject* o, Offset offset,
1616               FlatInArray flat_in_array, int instance_id, const TypePtr* speculative,
1617               int inline_depth);
1618   virtual bool eq( const Type *t ) const;
1619   virtual uint hash() const;             // Type specific hashing

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

1988 
1989   virtual bool  is_loaded() const { return _klass->is_loaded(); }
1990 
1991   virtual const TypeKlassPtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return nullptr; }
1992 
1993   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return nullptr; }
1994 
1995   // corresponding pointer to instance, for a given class
1996   virtual const TypeOopPtr* as_instance_type(bool klass_change = true) const { ShouldNotReachHere(); return nullptr; }
1997 
1998   virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return nullptr; }
1999   virtual const Type    *xmeet( const Type *t ) const { ShouldNotReachHere(); return nullptr; }
2000   virtual const Type    *xdual() const { ShouldNotReachHere(); return nullptr; }
2001 
2002   virtual intptr_t get_con() const;
2003 
2004   virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return nullptr; }
2005 
2006   virtual bool can_be_inline_array() const { ShouldNotReachHere(); return false; }
2007 
2008   virtual const TypeKlassPtr* try_improve() const { return this; }
2009 
2010 private:
2011   virtual bool is_meet_subtype_of(const TypePtr* other) const {
2012     return is_meet_subtype_of_helper(other->is_klassptr(), klass_is_exact(), other->is_klassptr()->klass_is_exact());
2013   }
2014 
2015   virtual bool is_meet_subtype_of_helper(const TypeKlassPtr* other, bool this_xk, bool other_xk) const {
2016     ShouldNotReachHere(); return false;
2017   }
2018 
2019   virtual const TypeInterfaces* interfaces() const {
2020     return _interfaces;
2021   };
2022 
2023   const TypeKlassPtr* is_reference_type(const Type* other) const {
2024     return other->isa_klassptr();
2025   }
2026 
2027   const TypeAryKlassPtr* is_array_type(const TypeKlassPtr* other) const {
2028     return other->isa_aryklassptr();
2029   }
2030 
2031   const TypeInstKlassPtr* is_instance_type(const TypeKlassPtr* other) const {
2032     return other->isa_instklassptr();
2033   }
2034 };
2035 
2036 // Instance klass pointer, mirrors TypeInstPtr
2037 class TypeInstKlassPtr : public TypeKlassPtr {
2038   // Can an instance of this class be in a flat array?
2039   const FlatInArray _flat_in_array;
2040 
2041   TypeInstKlassPtr(PTR ptr, ciKlass* klass, const TypeInterfaces* interfaces, Offset offset, FlatInArray flat_in_array)
2042     : TypeKlassPtr(InstKlassPtr, ptr, klass, interfaces, offset), _flat_in_array(flat_in_array) {
2043     assert(flat_in_array != Uninitialized, "must be set now");
2044     assert(klass->is_instance_klass() && (!klass->is_loaded() || !klass->is_interface()), "");
2045   }
2046 
2047   virtual bool must_be_exact() const;
2048 
2049 public:
2050   // Instance klass ignoring any interface
2051   ciInstanceKlass* instance_klass() const {
2052     assert(!klass()->is_interface(), "");
2053     return klass()->as_instance_klass();
2054   }
2055 
2056   bool might_be_an_array() const;
2057 
2058   bool is_same_java_type_as_helper(const TypeKlassPtr* other) const;
2059   bool is_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
2060   bool maybe_java_subtype_of_helper(const TypeKlassPtr* other, bool this_exact, bool other_exact) const;
2061 
2062   virtual bool can_be_inline_type() const { return (_klass == nullptr || _klass->can_be_inline_klass(klass_is_exact())); }
2063 
2064   static const TypeInstKlassPtr *make(ciKlass* k, InterfaceHandling interface_handling) {
2065     const TypeInterfaces* interfaces = TypePtr::interfaces(k, true, true, false, interface_handling);
2066     return make(TypePtr::Constant, k, interfaces, Offset(0));
2067   }

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

2329   }
2330 
2331   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
2332     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
2333   }
2334 
2335 public:
2336   static const TypeNarrowKlass *make( const TypePtr* type);
2337 
2338   // static const TypeNarrowKlass *BOTTOM;
2339   static const TypeNarrowKlass *NULL_PTR;
2340 
2341 #ifndef PRODUCT
2342   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
2343 #endif
2344 };
2345 
2346 //------------------------------TypeFunc---------------------------------------
2347 // Class of Array Types
2348 class TypeFunc : public Type {
2349   TypeFunc(const TypeTuple *domain_sig, const TypeTuple *domain_cc, const TypeTuple *range_sig, const TypeTuple *range_cc)
2350     : Type(Function), _domain_sig(domain_sig), _domain_cc(domain_cc), _range_sig(range_sig), _range_cc(range_cc) {}
2351   virtual bool eq( const Type *t ) const;
2352   virtual uint hash() const;             // Type specific hashing
2353   virtual bool singleton(void) const;    // TRUE if type is a singleton
2354   virtual bool empty(void) const;        // TRUE if type is vacuous
2355 
2356   // Domains of inputs: inline type arguments are not passed by
2357   // reference, instead each field of the inline type is passed as an
2358   // argument. We maintain 2 views of the argument list here: one
2359   // based on the signature (with an inline type argument as a single
2360   // slot), one based on the actual calling convention (with a value
2361   // type argument as a list of its fields).
2362   const TypeTuple* const _domain_sig;
2363   const TypeTuple* const _domain_cc;
2364   // Range of results. Similar to domains: an inline type result can be
2365   // returned in registers in which case range_cc lists all fields and
2366   // is the actual calling convention.
2367   const TypeTuple* const _range_sig;
2368   const TypeTuple* const _range_cc;
2369 
2370 public:
2371   // Constants are shared among ADLC and VM
2372   enum { Control    = AdlcVMDeps::Control,
2373          I_O        = AdlcVMDeps::I_O,
2374          Memory     = AdlcVMDeps::Memory,
2375          FramePtr   = AdlcVMDeps::FramePtr,
2376          ReturnAdr  = AdlcVMDeps::ReturnAdr,
2377          Parms      = AdlcVMDeps::Parms
2378   };
2379 
2380 
2381   // Accessors:
2382   const TypeTuple* domain_sig() const { return _domain_sig; }
2383   const TypeTuple* domain_cc()  const { return _domain_cc; }
2384   const TypeTuple* range_sig()  const { return _range_sig; }
2385   const TypeTuple* range_cc()   const { return _range_cc; }
2386 
2387   static const TypeFunc* make(ciMethod* method, bool is_osr_compilation = false);
2388   static const TypeFunc *make(const TypeTuple* domain_sig, const TypeTuple* domain_cc,
2389                               const TypeTuple* range_sig, const TypeTuple* range_cc);
2390   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
2391 
2392   virtual const Type *xmeet( const Type *t ) const;
2393   virtual const Type *xdual() const;    // Compute dual right now.
2394 
2395   BasicType return_type() const;
2396 
2397   bool returns_inline_type_as_fields() const { return range_sig() != range_cc(); }
2398 
2399 #ifndef PRODUCT
2400   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
2401 #endif
2402   // Convenience common pre-built types.
2403 };
2404 
2405 //------------------------------accessors--------------------------------------
2406 inline bool Type::is_ptr_to_narrowoop() const {
2407 #ifdef _LP64
2408   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowoop_nv());
2409 #else
2410   return false;
2411 #endif
2412 }
2413 
2414 inline bool Type::is_ptr_to_narrowklass() const {
2415 #ifdef _LP64
2416   return (isa_oopptr() != nullptr && is_oopptr()->is_ptr_to_narrowklass_nv());
2417 #else
2418   return false;

2655 }
2656 
2657 inline const TypeNarrowOop* Type::make_narrowoop() const {
2658   return (_base == NarrowOop) ? is_narrowoop() :
2659                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : nullptr);
2660 }
2661 
2662 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2663   return (_base == NarrowKlass) ? is_narrowklass() :
2664                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : nullptr);
2665 }
2666 
2667 inline bool Type::is_floatingpoint() const {
2668   if( (_base == HalfFloatCon)  || (_base == HalfFloatBot) ||
2669       (_base == FloatCon)  || (_base == FloatBot) ||
2670       (_base == DoubleCon) || (_base == DoubleBot) )
2671     return true;
2672   return false;
2673 }
2674 
2675 inline bool Type::is_inlinetypeptr() const {
2676   return isa_instptr() != nullptr && is_instptr()->instance_klass()->is_inlinetype();
2677 }
2678 
2679 inline ciInlineKlass* Type::inline_klass() const {
2680   return make_ptr()->is_instptr()->instance_klass()->as_inline_klass();
2681 }
2682 
2683 template <>
2684 inline const TypeInt* Type::cast<TypeInt>() const {
2685   return is_int();
2686 }
2687 
2688 template <>
2689 inline const TypeLong* Type::cast<TypeLong>() const {
2690   return is_long();
2691 }
2692 
2693 template <>
2694 inline const TypeInt* Type::try_cast<TypeInt>() const {
2695   return isa_int();
2696 }
2697 
2698 template <>
2699 inline const TypeLong* Type::try_cast<TypeLong>() const {
2700   return isa_long();
2701 }
2702 

2708 
2709 // For type queries and asserts
2710 #define is_intptr_t  is_long
2711 #define isa_intptr_t isa_long
2712 #define find_intptr_t_type find_long_type
2713 #define find_intptr_t_con  find_long_con
2714 #define TypeX        TypeLong
2715 #define Type_X       Type::Long
2716 #define TypeX_X      TypeLong::LONG
2717 #define TypeX_ZERO   TypeLong::ZERO
2718 // For 'ideal_reg' machine registers
2719 #define Op_RegX      Op_RegL
2720 // For phase->intcon variants
2721 #define MakeConX     longcon
2722 #define ConXNode     ConLNode
2723 // For array index arithmetic
2724 #define MulXNode     MulLNode
2725 #define AndXNode     AndLNode
2726 #define OrXNode      OrLNode
2727 #define CmpXNode     CmpLNode
2728 #define CmpUXNode    CmpULNode
2729 #define SubXNode     SubLNode
2730 #define LShiftXNode  LShiftLNode
2731 // For object size computation:
2732 #define AddXNode     AddLNode
2733 #define RShiftXNode  RShiftLNode
2734 // For card marks and hashcodes
2735 #define URShiftXNode URShiftLNode
2736 // For shenandoahSupport
2737 #define LoadXNode    LoadLNode
2738 #define StoreXNode   StoreLNode
2739 // Opcodes
2740 #define Op_LShiftX   Op_LShiftL
2741 #define Op_AndX      Op_AndL
2742 #define Op_AddX      Op_AddL
2743 #define Op_SubX      Op_SubL
2744 #define Op_XorX      Op_XorL
2745 #define Op_URShiftX  Op_URShiftL
2746 #define Op_LoadX     Op_LoadL
2747 #define Op_StoreX    Op_StoreL
2748 // conversions
2749 #define ConvI2X(x)   ConvI2L(x)
2750 #define ConvL2X(x)   (x)
2751 #define ConvX2I(x)   ConvL2I(x)
2752 #define ConvX2L(x)   (x)
2753 #define ConvX2UL(x)  (x)
2754 
2755 #else
2756 
2757 // For type queries and asserts
2758 #define is_intptr_t  is_int
2759 #define isa_intptr_t isa_int
2760 #define find_intptr_t_type find_int_type
2761 #define find_intptr_t_con  find_int_con
2762 #define TypeX        TypeInt
2763 #define Type_X       Type::Int
2764 #define TypeX_X      TypeInt::INT
2765 #define TypeX_ZERO   TypeInt::ZERO
2766 // For 'ideal_reg' machine registers
2767 #define Op_RegX      Op_RegI
2768 // For phase->intcon variants
2769 #define MakeConX     intcon
2770 #define ConXNode     ConINode
2771 // For array index arithmetic
2772 #define MulXNode     MulINode
2773 #define AndXNode     AndINode
2774 #define OrXNode      OrINode
2775 #define CmpXNode     CmpINode
2776 #define CmpUXNode    CmpUNode
2777 #define SubXNode     SubINode
2778 #define LShiftXNode  LShiftINode
2779 // For object size computation:
2780 #define AddXNode     AddINode
2781 #define RShiftXNode  RShiftINode
2782 // For card marks and hashcodes
2783 #define URShiftXNode URShiftINode
2784 // For shenandoahSupport
2785 #define LoadXNode    LoadINode
2786 #define StoreXNode   StoreINode
2787 // Opcodes
2788 #define Op_LShiftX   Op_LShiftI
2789 #define Op_AndX      Op_AndI
2790 #define Op_AddX      Op_AddI
2791 #define Op_SubX      Op_SubI
2792 #define Op_XorX      Op_XorI
2793 #define Op_URShiftX  Op_URShiftI
2794 #define Op_LoadX     Op_LoadI
2795 #define Op_StoreX    Op_StoreI
2796 // conversions
2797 #define ConvI2X(x)   (x)
2798 #define ConvL2X(x)   ConvL2I(x)
2799 #define ConvX2I(x)   (x)
2800 #define ConvX2L(x)   ConvI2L(x)
2801 #define ConvX2UL(x)  ConvI2UL(x)
2802 
2803 #endif
2804 
2805 #endif // SHARE_OPTO_TYPE_HPP
< prev index next >