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

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

  56 class   TypeVect;
  57 class     TypeVectA;
  58 class     TypeVectS;
  59 class     TypeVectD;
  60 class     TypeVectX;
  61 class     TypeVectY;
  62 class     TypeVectZ;
  63 class     TypeVectMask;
  64 class   TypePtr;
  65 class     TypeRawPtr;
  66 class     TypeOopPtr;
  67 class       TypeInstPtr;
  68 class       TypeAryPtr;
  69 class     TypeKlassPtr;
  70 class       TypeInstKlassPtr;
  71 class       TypeAryKlassPtr;
  72 class     TypeMetadataPtr;
  73 
  74 //------------------------------Type-------------------------------------------
  75 // Basic Type object, represents a set of primitive Values.

  83   enum TYPES {
  84     Bad=0,                      // Type check
  85     Control,                    // Control of code (not in lattice)
  86     Top,                        // Top of the lattice
  87     Int,                        // Integer range (lo-hi)
  88     Long,                       // Long integer range (lo-hi)
  89     Half,                       // Placeholder half of doubleword
  90     NarrowOop,                  // Compressed oop pointer
  91     NarrowKlass,                // Compressed klass pointer
  92 
  93     Tuple,                      // Method signature or object layout
  94     Array,                      // Array types
  95 
  96     VectorMask,                 // Vector predicate/mask type
  97     VectorA,                    // (Scalable) Vector types for vector length agnostic
  98     VectorS,                    //  32bit Vector types
  99     VectorD,                    //  64bit Vector types
 100     VectorX,                    // 128bit Vector types
 101     VectorY,                    // 256bit Vector types
 102     VectorZ,                    // 512bit Vector types

 103 
 104     AnyPtr,                     // Any old raw, klass, inst, or array pointer
 105     RawPtr,                     // Raw (non-oop) pointers
 106     OopPtr,                     // Any and all Java heap entities
 107     InstPtr,                    // Instance pointers (non-array objects)
 108     AryPtr,                     // Array pointers
 109     // (Ptr order matters:  See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
 110 
 111     MetadataPtr,                // Generic metadata
 112     KlassPtr,                   // Klass pointers
 113     InstKlassPtr,
 114     AryKlassPtr,
 115 
 116     Function,                   // Function signature
 117     Abio,                       // Abstract I/O
 118     Return_Address,             // Subroutine return address
 119     Memory,                     // Abstract store
 120     FloatTop,                   // No float value
 121     FloatCon,                   // Floating point constant
 122     FloatBot,                   // Any float value
 123     DoubleTop,                  // No double value
 124     DoubleCon,                  // Double precision constant
 125     DoubleBot,                  // Any double value
 126     Bottom,                     // Bottom of lattice
 127     lastype                     // Bogus ending type (not in lattice)
 128   };
 129 
 130   // Signal values for offsets from a base pointer
 131   enum OFFSET_SIGNALS {
 132     OffsetTop = -2000000000,    // undefined offset
 133     OffsetBot = -2000000001     // any possible offset
 134   };
 135 
























 136   // Min and max WIDEN values.
 137   enum WIDEN {
 138     WidenMin = 0,
 139     WidenMax = 3
 140   };
 141 
 142 private:
 143   typedef struct {
 144     TYPES                dual_type;
 145     BasicType            basic_type;
 146     const char*          msg;
 147     bool                 isa_oop;
 148     uint                 ideal_reg;
 149     relocInfo::relocType reloc;
 150   } TypeInfo;
 151 
 152   // Dictionary of types shared among compilations.
 153   static Dict* _shared_type_dict;
 154   static const TypeInfo _type_info[];
 155 

 263   // Currently, it also works around limitations involving interface types.
 264   // Variant that drops the speculative part of the types
 265   const Type *filter(const Type *kills) const {
 266     return filter_helper(kills, false);
 267   }
 268   // Variant that keeps the speculative part of the types
 269   const Type *filter_speculative(const Type *kills) const {
 270     return filter_helper(kills, true)->cleanup_speculative();
 271   }
 272 
 273 #ifdef ASSERT
 274   // One type is interface, the other is oop
 275   virtual bool interface_vs_oop(const Type *t) const;
 276 #endif
 277 
 278   // Returns true if this pointer points at memory which contains a
 279   // compressed oop references.
 280   bool is_ptr_to_narrowoop() const;
 281   bool is_ptr_to_narrowklass() const;
 282 
 283   bool is_ptr_to_boxing_obj() const;
 284 
 285 
 286   // Convenience access
 287   float getf() const;
 288   double getd() const;
 289 
 290   const TypeInt    *is_int() const;
 291   const TypeInt    *isa_int() const;             // Returns NULL if not an Int
 292   const TypeInteger* is_integer(BasicType bt) const;
 293   const TypeInteger* isa_integer(BasicType bt) const;
 294   const TypeLong   *is_long() const;
 295   const TypeLong   *isa_long() const;            // Returns NULL if not a Long
 296   const TypeD      *isa_double() const;          // Returns NULL if not a Double{Top,Con,Bot}
 297   const TypeD      *is_double_constant() const;  // Asserts it is a DoubleCon
 298   const TypeD      *isa_double_constant() const; // Returns NULL if not a DoubleCon
 299   const TypeF      *isa_float() const;           // Returns NULL if not a Float{Top,Con,Bot}
 300   const TypeF      *is_float_constant() const;   // Asserts it is a FloatCon
 301   const TypeF      *isa_float_constant() const;  // Returns NULL if not a FloatCon
 302   const TypeTuple  *is_tuple() const;            // Collection of fields, NOT a pointer
 303   const TypeAry    *is_ary() const;              // Array, NOT array pointer
 304   const TypeAry    *isa_ary() const;             // Returns NULL of not ary
 305   const TypeVect   *is_vect() const;             // Vector
 306   const TypeVect   *isa_vect() const;            // Returns NULL if not a Vector
 307   const TypeVectMask *is_vectmask() const;       // Predicate/Mask Vector
 308   const TypeVectMask *isa_vectmask() const;      // Returns NULL if not a Vector Predicate/Mask
 309   const TypePtr    *is_ptr() const;              // Asserts it is a ptr type
 310   const TypePtr    *isa_ptr() const;             // Returns NULL if not ptr type
 311   const TypeRawPtr *isa_rawptr() const;          // NOT Java oop
 312   const TypeRawPtr *is_rawptr() const;           // Asserts is rawptr
 313   const TypeNarrowOop  *is_narrowoop() const;    // Java-style GC'd pointer
 314   const TypeNarrowOop  *isa_narrowoop() const;   // Returns NULL if not oop ptr type
 315   const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer
 316   const TypeNarrowKlass *isa_narrowklass() const;// Returns NULL if not oop ptr type
 317   const TypeOopPtr   *isa_oopptr() const;        // Returns NULL if not oop ptr type
 318   const TypeOopPtr   *is_oopptr() const;         // Java-style GC'd pointer
 319   const TypeInstPtr  *isa_instptr() const;       // Returns NULL if not InstPtr
 320   const TypeInstPtr  *is_instptr() const;        // Instance
 321   const TypeAryPtr   *isa_aryptr() const;        // Returns NULL if not AryPtr
 322   const TypeAryPtr   *is_aryptr() const;         // Array oop


 323 
 324   const TypeMetadataPtr   *isa_metadataptr() const;   // Returns NULL if not oop ptr type
 325   const TypeMetadataPtr   *is_metadataptr() const;    // Java-style GC'd pointer
 326   const TypeKlassPtr      *isa_klassptr() const;      // Returns NULL if not KlassPtr
 327   const TypeKlassPtr      *is_klassptr() const;       // assert if not KlassPtr
 328   const TypeInstKlassPtr  *isa_instklassptr() const;  // Returns NULL if not IntKlassPtr
 329   const TypeInstKlassPtr  *is_instklassptr() const;   // assert if not IntKlassPtr
 330   const TypeAryKlassPtr   *isa_aryklassptr() const;   // Returns NULL if not AryKlassPtr
 331   const TypeAryKlassPtr   *is_aryklassptr() const;    // assert if not AryKlassPtr
 332 
 333   virtual bool      is_finite() const;           // Has a finite value
 334   virtual bool      is_nan()    const;           // Is not a number (NaN)
 335 



 336   // Returns this ptr type or the equivalent ptr type for this compressed pointer.
 337   const TypePtr* make_ptr() const;
 338 
 339   // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
 340   // Asserts if the underlying type is not an oopptr or narrowoop.
 341   const TypeOopPtr* make_oopptr() const;
 342 
 343   // Returns this compressed pointer or the equivalent compressed version
 344   // of this pointer type.
 345   const TypeNarrowOop* make_narrowoop() const;
 346 
 347   // Returns this compressed klass pointer or the equivalent
 348   // compressed version of this pointer type.
 349   const TypeNarrowKlass* make_narrowklass() const;
 350 
 351   // Special test for register pressure heuristic
 352   bool is_floatingpoint() const;        // True if Float or Double base type
 353 
 354   // Do you have memory, directly or through a tuple?
 355   bool has_memory( ) const;

 707   const Type ** const _fields;           // Array of field types
 708 
 709 public:
 710   virtual bool eq( const Type *t ) const;
 711   virtual int  hash() const;             // Type specific hashing
 712   virtual bool singleton(void) const;    // TRUE if type is a singleton
 713   virtual bool empty(void) const;        // TRUE if type is vacuous
 714 
 715   // Accessors:
 716   uint cnt() const { return _cnt; }
 717   const Type* field_at(uint i) const {
 718     assert(i < _cnt, "oob");
 719     return _fields[i];
 720   }
 721   void set_field_at(uint i, const Type* t) {
 722     assert(i < _cnt, "oob");
 723     _fields[i] = t;
 724   }
 725 
 726   static const TypeTuple *make( uint cnt, const Type **fields );
 727   static const TypeTuple *make_range(ciSignature *sig);
 728   static const TypeTuple *make_domain(ciInstanceKlass* recv, ciSignature *sig);
 729 
 730   // Subroutine call type with space allocated for argument types
 731   // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
 732   static const Type **fields( uint arg_cnt );
 733 
 734   virtual const Type *xmeet( const Type *t ) const;
 735   virtual const Type *xdual() const;    // Compute dual right now.
 736   // Convenience common pre-built types.
 737   static const TypeTuple *IFBOTH;
 738   static const TypeTuple *IFFALSE;
 739   static const TypeTuple *IFTRUE;
 740   static const TypeTuple *IFNEITHER;
 741   static const TypeTuple *LOOPBODY;
 742   static const TypeTuple *MEMBAR;
 743   static const TypeTuple *STORECONDITIONAL;
 744   static const TypeTuple *START_I2C;
 745   static const TypeTuple *INT_PAIR;
 746   static const TypeTuple *LONG_PAIR;
 747   static const TypeTuple *INT_CC_PAIR;
 748   static const TypeTuple *LONG_CC_PAIR;
 749 #ifndef PRODUCT
 750   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 751 #endif
 752 };
 753 
 754 //------------------------------TypeAry----------------------------------------
 755 // Class of Array Types
 756 class TypeAry : public Type {
 757   TypeAry(const Type* elem, const TypeInt* size, bool stable) : Type(Array),
 758       _elem(elem), _size(size), _stable(stable) {}
 759 public:
 760   virtual bool eq( const Type *t ) const;
 761   virtual int  hash() const;             // Type specific hashing
 762   virtual bool singleton(void) const;    // TRUE if type is a singleton
 763   virtual bool empty(void) const;        // TRUE if type is vacuous
 764 
 765 private:
 766   const Type *_elem;            // Element type of array
 767   const TypeInt *_size;         // Elements in array
 768   const bool _stable;           // Are elements @Stable?





 769   friend class TypeAryPtr;
 770 
 771 public:
 772   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);

 773 
 774   virtual const Type *xmeet( const Type *t ) const;
 775   virtual const Type *xdual() const;    // Compute dual right now.
 776   bool ary_must_be_exact() const;  // true if arrays of such are never generic
 777   virtual const Type* remove_speculative() const;
 778   virtual const Type* cleanup_speculative() const;

 779 #ifdef ASSERT
 780   // One type is interface, the other is oop
 781   virtual bool interface_vs_oop(const Type *t) const;
 782 #endif
 783 #ifndef PRODUCT
 784   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 785 #endif
 786 };
 787 







































 788 //------------------------------TypeVect---------------------------------------
 789 // Class of Vector Types
 790 class TypeVect : public Type {
 791   const Type*   _elem;  // Vector's element type
 792   const uint  _length;  // Elements in vector (power of 2)
 793 
 794 protected:
 795   TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
 796     _elem(elem), _length(length) {}
 797 
 798 public:
 799   const Type* element_type() const { return _elem; }
 800   BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
 801   uint length() const { return _length; }
 802   uint length_in_bytes() const {
 803    return _length * type2aelembytes(element_basic_type());
 804   }
 805 
 806   virtual bool eq(const Type *t) const;
 807   virtual int  hash() const;             // Type specific hashing

 871 class TypeVectMask : public TypeVect {
 872 public:
 873   friend class TypeVect;
 874   TypeVectMask(const Type* elem, uint length) : TypeVect(VectorMask, elem, length) {}
 875   virtual bool eq(const Type *t) const;
 876   virtual const Type *xdual() const;
 877   static const TypeVectMask* make(const BasicType elem_bt, uint length);
 878   static const TypeVectMask* make(const Type* elem, uint length);
 879 };
 880 
 881 //------------------------------TypePtr----------------------------------------
 882 // Class of machine Pointer Types: raw data, instances or arrays.
 883 // If the _base enum is AnyPtr, then this refers to all of the above.
 884 // Otherwise the _base will indicate which subset of pointers is affected,
 885 // and the class will be inherited from.
 886 class TypePtr : public Type {
 887   friend class TypeNarrowPtr;
 888 public:
 889   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
 890 protected:
 891   TypePtr(TYPES t, PTR ptr, int offset,
 892           const TypePtr* speculative = NULL,
 893           int inline_depth = InlineDepthBottom) :
 894     Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
 895     _ptr(ptr) {}
 896   static const PTR ptr_meet[lastPTR][lastPTR];
 897   static const PTR ptr_dual[lastPTR];
 898   static const char * const ptr_msg[lastPTR];
 899 
 900   enum {
 901     InlineDepthBottom = INT_MAX,
 902     InlineDepthTop = -InlineDepthBottom
 903   };
 904 
 905   // Extra type information profiling gave us. We propagate it the
 906   // same way the rest of the type info is propagated. If we want to
 907   // use it, then we have to emit a guard: this part of the type is
 908   // not something we know but something we speculate about the type.
 909   const TypePtr*   _speculative;
 910   // For speculative types, we record at what inlining depth the
 911   // profiling point that provided the data is. We want to favor

 927   int dual_inline_depth() const;
 928   int meet_inline_depth(int depth) const;
 929 #ifndef PRODUCT
 930   void dump_inline_depth(outputStream *st) const;
 931 #endif
 932 
 933   // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
 934   // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
 935   // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
 936   // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
 937   // encountered so the right logic specific to klasses or oops can be executed.,
 938   enum MeetResult {
 939     QUICK,
 940     UNLOADED,
 941     SUBTYPE,
 942     NOT_SUBTYPE,
 943     LCA
 944   };
 945   static MeetResult
 946   meet_instptr(PTR &ptr, ciKlass* this_klass, ciKlass* tinst_klass, bool this_xk, bool tinst_xk, PTR this_ptr,
 947                PTR tinst_ptr, ciKlass*&res_klass, bool &res_xk);
 948   static MeetResult
 949   meet_aryptr(PTR& ptr, const Type*& elem, ciKlass* this_klass, ciKlass* tap_klass, bool this_xk, bool tap_xk, PTR this_ptr, PTR tap_ptr, ciKlass*& res_klass, bool& res_xk);




 950 
 951 public:
 952   const int _offset;            // Offset into oop, with TOP & BOT
 953   const PTR _ptr;               // Pointer equivalence class
 954 
 955   const int offset() const { return _offset; }
 956   const PTR ptr()    const { return _ptr; }
 957 
 958   static const TypePtr *make(TYPES t, PTR ptr, int offset,
 959                              const TypePtr* speculative = NULL,
 960                              int inline_depth = InlineDepthBottom);
 961 
 962   // Return a 'ptr' version of this type
 963   virtual const Type *cast_to_ptr_type(PTR ptr) const;
 964 
 965   virtual intptr_t get_con() const;
 966 
 967   int xadd_offset( intptr_t offset ) const;
 968   virtual const TypePtr *add_offset( intptr_t offset ) const;


 969   virtual bool eq(const Type *t) const;
 970   virtual int  hash() const;             // Type specific hashing
 971 
 972   virtual bool singleton(void) const;    // TRUE if type is a singleton
 973   virtual bool empty(void) const;        // TRUE if type is vacuous
 974   virtual const Type *xmeet( const Type *t ) const;
 975   virtual const Type *xmeet_helper( const Type *t ) const;
 976   int meet_offset( int offset ) const;
 977   int dual_offset( ) const;
 978   virtual const Type *xdual() const;    // Compute dual right now.
 979 
 980   // meet, dual and join over pointer equivalence sets
 981   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
 982   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
 983 
 984   // This is textually confusing unless one recalls that
 985   // join(t) == dual()->meet(t->dual())->dual().
 986   PTR join_ptr( const PTR in_ptr ) const {
 987     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
 988   }
 989 
 990   // Speculative type helper methods.
 991   virtual const TypePtr* speculative() const { return _speculative; }
 992   int inline_depth() const                   { return _inline_depth; }
 993   virtual ciKlass* speculative_type() const;
 994   virtual ciKlass* speculative_type_not_null() const;
 995   virtual bool speculative_maybe_null() const;
 996   virtual bool speculative_always_null() const;
 997   virtual const Type* remove_speculative() const;
 998   virtual const Type* cleanup_speculative() const;
 999   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1000   virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1001   virtual const TypePtr* with_inline_depth(int depth) const;
1002 
1003   virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1004 







1005   // Tests for relation to centerline of type lattice:
1006   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1007   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1008   // Convenience common pre-built types.
1009   static const TypePtr *NULL_PTR;
1010   static const TypePtr *NOTNULL;
1011   static const TypePtr *BOTTOM;
1012 #ifndef PRODUCT
1013   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1014 #endif
1015 };
1016 
1017 //------------------------------TypeRawPtr-------------------------------------
1018 // Class of raw pointers, pointers to things other than Oops.  Examples
1019 // include the stack pointer, top of heap, card-marking area, handles, etc.
1020 class TypeRawPtr : public TypePtr {
1021 protected:
1022   TypeRawPtr( PTR ptr, address bits ) : TypePtr(RawPtr,ptr,0), _bits(bits){}
1023 public:
1024   virtual bool eq( const Type *t ) const;
1025   virtual int  hash() const;     // Type specific hashing
1026 
1027   const address _bits;          // Constant value, if applicable
1028 
1029   static const TypeRawPtr *make( PTR ptr );
1030   static const TypeRawPtr *make( address bits );
1031 
1032   // Return a 'ptr' version of this type
1033   virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1034 
1035   virtual intptr_t get_con() const;
1036 
1037   virtual const TypePtr *add_offset( intptr_t offset ) const;
1038 
1039   virtual const Type *xmeet( const Type *t ) const;
1040   virtual const Type *xdual() const;    // Compute dual right now.
1041   // Convenience common pre-built types.
1042   static const TypeRawPtr *BOTTOM;
1043   static const TypeRawPtr *NOTNULL;
1044 #ifndef PRODUCT
1045   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1046 #endif
1047 };
1048 
1049 //------------------------------TypeOopPtr-------------------------------------
1050 // Some kind of oop (Java pointer), either instance or array.
1051 class TypeOopPtr : public TypePtr {
1052 protected:
1053   TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id,
1054              const TypePtr* speculative, int inline_depth);
1055 public:
1056   virtual bool eq( const Type *t ) const;
1057   virtual int  hash() const;             // Type specific hashing
1058   virtual bool singleton(void) const;    // TRUE if type is a singleton
1059   enum {
1060    InstanceTop = -1,   // undefined instance
1061    InstanceBot = 0     // any possible instance
1062   };
1063 protected:
1064 
1065   // Oop is NULL, unless this is a constant oop.
1066   ciObject*     _const_oop;   // Constant oop
1067   // If _klass is NULL, then so is _sig.  This is an unloaded klass.
1068   ciKlass*      _klass;       // Klass object
1069   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1070   bool          _klass_is_exact;
1071   bool          _is_ptr_to_narrowoop;
1072   bool          _is_ptr_to_narrowklass;
1073   bool          _is_ptr_to_boxed_value;
1074 

1093     return make_from_klass_common(klass, true, false);
1094   }
1095   // Same as before, but will produce an exact type, even if
1096   // the klass is not final, as long as it has exactly one implementation.
1097   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
1098     return make_from_klass_common(klass, true, true);
1099   }
1100   // Same as before, but does not respects UseUniqueSubclasses.
1101   // Use this only for creating array element types.
1102   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
1103     return make_from_klass_common(klass, false, false);
1104   }
1105   // Creates a singleton type given an object.
1106   // If the object cannot be rendered as a constant,
1107   // may return a non-singleton type.
1108   // If require_constant, produce a NULL if a singleton is not possible.
1109   static const TypeOopPtr* make_from_constant(ciObject* o,
1110                                               bool require_constant = false);
1111 
1112   // Make a generic (unclassed) pointer to an oop.
1113   static const TypeOopPtr* make(PTR ptr, int offset, int instance_id,
1114                                 const TypePtr* speculative = NULL,
1115                                 int inline_depth = InlineDepthBottom);
1116 
1117   ciObject* const_oop()    const { return _const_oop; }
1118   virtual ciKlass* klass() const { return _klass;     }
1119   bool klass_is_exact()    const { return _klass_is_exact; }
1120 
1121   // Returns true if this pointer points at memory which contains a
1122   // compressed oop references.
1123   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1124   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1125   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }
1126   bool is_known_instance()       const { return _instance_id > 0; }
1127   int  instance_id()             const { return _instance_id; }
1128   bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }


1129 
1130   virtual intptr_t get_con() const;
1131 
1132   virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1133 
1134   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1135 
1136   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1137 
1138   // corresponding pointer to klass, for a given instance
1139   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1140 
1141   virtual const TypePtr *add_offset( intptr_t offset ) const;
1142 
1143   // Speculative type helper methods.
1144   virtual const Type* remove_speculative() const;
1145   virtual const Type* cleanup_speculative() const;
1146   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1147   virtual const TypePtr* with_inline_depth(int depth) const;
1148 
1149   virtual const TypePtr* with_instance_id(int instance_id) const;
1150 
1151   virtual const Type *xdual() const;    // Compute dual right now.
1152   // the core of the computation of the meet for TypeOopPtr and for its subclasses
1153   virtual const Type *xmeet_helper(const Type *t) const;
1154 
1155   // Convenience common pre-built type.
1156   static const TypeOopPtr *BOTTOM;
1157 #ifndef PRODUCT
1158   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1159 #endif
1160 };
1161 
1162 //------------------------------TypeInstPtr------------------------------------
1163 // Class of Java object pointers, pointing either to non-array Java instances
1164 // or to a Klass* (including array klasses).
1165 class TypeInstPtr : public TypeOopPtr {
1166   TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id,
1167               const TypePtr* speculative, int inline_depth);

1168   virtual bool eq( const Type *t ) const;
1169   virtual int  hash() const;             // Type specific hashing
1170 
1171   ciSymbol*  _name;        // class name

1172 
1173  public:
1174   ciSymbol* name()         const { return _name; }
1175 
1176   bool  is_loaded() const { return _klass->is_loaded(); }
1177 
1178   // Make a pointer to a constant oop.
1179   static const TypeInstPtr *make(ciObject* o) {
1180     return make(TypePtr::Constant, o->klass(), true, o, 0, InstanceBot);
1181   }
1182   // Make a pointer to a constant oop with offset.
1183   static const TypeInstPtr *make(ciObject* o, int offset) {
1184     return make(TypePtr::Constant, o->klass(), true, o, offset, InstanceBot);
1185   }
1186 
1187   // Make a pointer to some value of type klass.
1188   static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
1189     return make(ptr, klass, false, NULL, 0, InstanceBot);
1190   }
1191 
1192   // Make a pointer to some non-polymorphic value of exactly type klass.
1193   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1194     return make(ptr, klass, true, NULL, 0, InstanceBot);
1195   }
1196 
1197   // Make a pointer to some value of type klass with offset.
1198   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
1199     return make(ptr, klass, false, NULL, offset, InstanceBot);
1200   }
1201 
1202   // Make a pointer to an oop.
1203   static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset,

1204                                  int instance_id = InstanceBot,
1205                                  const TypePtr* speculative = NULL,
1206                                  int inline_depth = InlineDepthBottom);
1207 
1208   /** Create constant type for a constant boxed value */
1209   const Type* get_const_boxed_value() const;
1210 
1211   // If this is a java.lang.Class constant, return the type for it or NULL.
1212   // Pass to Type::get_const_type to turn it to a type, which will usually
1213   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1214   ciType* java_mirror_type() const;
1215 
1216   virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1217 
1218   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1219 
1220   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1221 
1222   virtual const TypePtr *add_offset( intptr_t offset ) const;
1223 
1224   // Speculative type helper methods.
1225   virtual const Type* remove_speculative() const;
1226   virtual const TypePtr* with_inline_depth(int depth) const;
1227   virtual const TypePtr* with_instance_id(int instance_id) const;
1228 



1229   // the core of the computation of the meet of 2 types
1230   virtual const Type *xmeet_helper(const Type *t) const;
1231   virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
1232   virtual const Type *xdual() const;    // Compute dual right now.
1233 
1234   const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1235 
1236   // Convenience common pre-built types.
1237   static const TypeInstPtr *NOTNULL;
1238   static const TypeInstPtr *BOTTOM;
1239   static const TypeInstPtr *MIRROR;
1240   static const TypeInstPtr *MARK;
1241   static const TypeInstPtr *KLASS;
1242 #ifndef PRODUCT
1243   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1244 #endif
1245 };
1246 
1247 //------------------------------TypeAryPtr-------------------------------------
1248 // Class of Java array pointers
1249 class TypeAryPtr : public TypeOopPtr {
1250   TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1251               int offset, int instance_id, bool is_autobox_cache,
1252               const TypePtr* speculative, int inline_depth)
1253     : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id, speculative, inline_depth),
1254     _ary(ary),
1255     _is_autobox_cache(is_autobox_cache)

1256  {
1257 #ifdef ASSERT
1258     if (k != NULL) {
1259       // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
1260       ciKlass* ck = compute_klass(true);
1261       if (k != ck) {
1262         this->dump(); tty->cr();
1263         tty->print(" k: ");
1264         k->print(); tty->cr();
1265         tty->print("ck: ");
1266         if (ck != NULL) ck->print();
1267         else tty->print("<NULL>");
1268         tty->cr();
1269         assert(false, "unexpected TypeAryPtr::_klass");
1270       }
1271     }
1272 #endif
1273   }
1274   virtual bool eq( const Type *t ) const;
1275   virtual int hash() const;     // Type specific hashing
1276   const TypeAry *_ary;          // Array we point into
1277   const bool     _is_autobox_cache;






1278 
1279   ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
1280 
1281 public:
1282   // Accessors
1283   ciKlass* klass() const;
1284   const TypeAry* ary() const  { return _ary; }
1285   const Type*    elem() const { return _ary->_elem; }
1286   const TypeInt* size() const { return _ary->_size; }
1287   bool      is_stable() const { return _ary->_stable; }
1288 






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

1292                                 int instance_id = InstanceBot,
1293                                 const TypePtr* speculative = NULL,
1294                                 int inline_depth = InlineDepthBottom);
1295   // Constant pointer to array
1296   static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,

1297                                 int instance_id = InstanceBot,
1298                                 const TypePtr* speculative = NULL,
1299                                 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false);

1300 
1301   // Return a 'ptr' version of this type
1302   virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1303 
1304   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1305 
1306   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1307 
1308   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1309   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1310 
1311   virtual bool empty(void) const;        // TRUE if type is vacuous
1312   virtual const TypePtr *add_offset( intptr_t offset ) const;
1313 
1314   // Speculative type helper methods.
1315   virtual const Type* remove_speculative() const;

1316   virtual const TypePtr* with_inline_depth(int depth) const;
1317   virtual const TypePtr* with_instance_id(int instance_id) const;
1318 
1319   // the core of the computation of the meet of 2 types
1320   virtual const Type *xmeet_helper(const Type *t) const;
1321   virtual const Type *xdual() const;    // Compute dual right now.
1322 





1323   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1324   int stable_dimension() const;
1325 
1326   const TypeAryPtr* cast_to_autobox_cache() const;
1327 
1328   static jint max_array_length(BasicType etype) ;







1329   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1330 
1331   // Convenience common pre-built types.
1332   static const TypeAryPtr *RANGE;
1333   static const TypeAryPtr *OOPS;
1334   static const TypeAryPtr *NARROWOOPS;
1335   static const TypeAryPtr *BYTES;
1336   static const TypeAryPtr *SHORTS;
1337   static const TypeAryPtr *CHARS;
1338   static const TypeAryPtr *INTS;
1339   static const TypeAryPtr *LONGS;
1340   static const TypeAryPtr *FLOATS;
1341   static const TypeAryPtr *DOUBLES;

1342   // selects one of the above:
1343   static const TypeAryPtr *get_array_body_type(BasicType elem) {
1344     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1345     return _array_body_type[elem];
1346   }
1347   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1348   // sharpen the type of an int which is used as an array size
1349 #ifdef ASSERT
1350   // One type is interface, the other is oop
1351   virtual bool interface_vs_oop(const Type *t) const;
1352 #endif
1353 #ifndef PRODUCT
1354   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1355 #endif
1356 };
1357 
1358 //------------------------------TypeMetadataPtr-------------------------------------
1359 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1360 class TypeMetadataPtr : public TypePtr {
1361 protected:
1362   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, int offset);
1363   // Do not allow interface-vs.-noninterface joins to collapse to top.
1364   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1365 public:
1366   virtual bool eq( const Type *t ) const;
1367   virtual int  hash() const;             // Type specific hashing
1368   virtual bool singleton(void) const;    // TRUE if type is a singleton
1369 
1370 private:
1371   ciMetadata*   _metadata;
1372 
1373 public:
1374   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, int offset);
1375 
1376   static const TypeMetadataPtr* make(ciMethod* m);
1377   static const TypeMetadataPtr* make(ciMethodData* m);
1378 
1379   ciMetadata* metadata() const { return _metadata; }
1380 
1381   virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1382 
1383   virtual const TypePtr *add_offset( intptr_t offset ) const;
1384 
1385   virtual const Type *xmeet( const Type *t ) const;
1386   virtual const Type *xdual() const;    // Compute dual right now.
1387 
1388   virtual intptr_t get_con() const;
1389 
1390   // Convenience common pre-built types.
1391   static const TypeMetadataPtr *BOTTOM;
1392 
1393 #ifndef PRODUCT
1394   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1395 #endif
1396 };
1397 
1398 //------------------------------TypeKlassPtr-----------------------------------
1399 // Class of Java Klass pointers
1400 class TypeKlassPtr : public TypePtr {
1401 protected:
1402   TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, int offset);
1403 
1404   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1405 
1406 public:
1407   virtual bool eq( const Type *t ) const;
1408   virtual int hash() const;
1409   virtual bool singleton(void) const;    // TRUE if type is a singleton
1410   virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1411 
1412 protected:
1413 
1414   ciKlass* _klass;
1415 
1416 public:
1417 
1418   virtual ciKlass* klass() const { return  _klass; }
1419   bool klass_is_exact()    const { return _ptr == Constant; }
1420   bool  is_loaded() const { return klass()->is_loaded(); }
1421 
1422   static const TypeKlassPtr* make(ciKlass* klass);
1423   static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, int offset);
1424 
1425 
1426   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return NULL; }
1427 
1428   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return NULL; }
1429 
1430   // corresponding pointer to instance, for a given class
1431   virtual const TypeOopPtr* as_instance_type() const { ShouldNotReachHere(); return NULL; }
1432 
1433   virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return NULL; }
1434   virtual const Type    *xmeet( const Type *t ) const { ShouldNotReachHere(); return NULL; }
1435   virtual const Type    *xdual() const { ShouldNotReachHere(); return NULL; }
1436 
1437   virtual intptr_t get_con() const;
1438 
1439   virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return NULL; }
1440 
1441 #ifndef PRODUCT
1442   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1443 #endif
1444 };
1445 
1446 // Instance klass pointer, mirrors TypeInstPtr
1447 class TypeInstKlassPtr : public TypeKlassPtr {
1448 
1449   TypeInstKlassPtr(PTR ptr, ciKlass* klass, int offset)
1450     : TypeKlassPtr(InstKlassPtr, ptr, klass, offset) {
1451   }
1452 
1453   virtual bool must_be_exact() const;
1454 


1455 public:
1456   // Instance klass ignoring any interface
1457   ciInstanceKlass* instance_klass() const { return klass()->as_instance_klass();     }
1458 


1459   static const TypeInstKlassPtr *make(ciKlass* k) {
1460     return make(TypePtr::Constant, k, 0);
1461   }
1462   static const TypeInstKlassPtr *make(PTR ptr, ciKlass* k, int offset);
1463 
1464   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1465 
1466   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1467 
1468   // corresponding pointer to instance, for a given class
1469   virtual const TypeOopPtr* as_instance_type() const;
1470   virtual int hash() const;
1471   virtual bool eq(const Type *t) const;
1472 
1473   virtual const TypePtr *add_offset( intptr_t offset ) const;
1474   virtual const Type    *xmeet( const Type *t ) const;
1475   virtual const Type    *xdual() const;
1476   virtual const TypeKlassPtr* with_offset(intptr_t offset) const;
1477 


1478   // Convenience common pre-built types.
1479   static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
1480   static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same




1481 };
1482 
1483 // Array klass pointer, mirrors TypeAryPtr
1484 class TypeAryKlassPtr : public TypeKlassPtr {
1485   const Type *_elem;



1486 
1487   TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, int offset)
1488     : TypeKlassPtr(AryKlassPtr, ptr, klass, offset), _elem(elem) {
1489   }
1490 
1491   virtual bool must_be_exact() const;
1492 








1493 public:
1494   virtual ciKlass* klass() const;
1495 
1496   // returns base element type, an instance klass (and not interface) for object arrays
1497   const Type* base_element_type(int& dims) const;
1498 
1499   static const TypeAryKlassPtr *make(PTR ptr, ciKlass* k, int offset);
1500   static const TypeAryKlassPtr *make(PTR ptr, const Type *elem, ciKlass* k, int offset);
1501   static const TypeAryKlassPtr* make(ciKlass* klass);
1502 
1503   const Type *elem() const { return _elem; }
1504 
1505   virtual bool eq(const Type *t) const;
1506   virtual int hash() const;             // Type specific hashing
1507 
1508   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1509 
1510   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1511 
1512   // corresponding pointer to instance, for a given class
1513   virtual const TypeOopPtr* as_instance_type() const;
1514 
1515   virtual const TypePtr *add_offset( intptr_t offset ) const;
1516   virtual const Type    *xmeet( const Type *t ) const;
1517   virtual const Type    *xdual() const;      // Compute dual right now.
1518 
1519   virtual const TypeKlassPtr* with_offset(intptr_t offset) const;
1520 
1521   virtual bool empty(void) const {
1522     return TypeKlassPtr::empty() || _elem->empty();
1523   }
1524 





1525 #ifndef PRODUCT
1526   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1527 #endif
1528 };
1529 
1530 class TypeNarrowPtr : public Type {
1531 protected:
1532   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1533 
1534   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
1535                                                   _ptrtype(ptrtype) {
1536     assert(ptrtype->offset() == 0 ||
1537            ptrtype->offset() == OffsetBot ||
1538            ptrtype->offset() == OffsetTop, "no real offsets");
1539   }
1540 
1541   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1542   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1543   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1544   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;

1638   }
1639 
1640   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1641     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1642   }
1643 
1644 public:
1645   static const TypeNarrowKlass *make( const TypePtr* type);
1646 
1647   // static const TypeNarrowKlass *BOTTOM;
1648   static const TypeNarrowKlass *NULL_PTR;
1649 
1650 #ifndef PRODUCT
1651   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1652 #endif
1653 };
1654 
1655 //------------------------------TypeFunc---------------------------------------
1656 // Class of Array Types
1657 class TypeFunc : public Type {
1658   TypeFunc( const TypeTuple *domain, const TypeTuple *range ) : Type(Function),  _domain(domain), _range(range) {}

1659   virtual bool eq( const Type *t ) const;
1660   virtual int  hash() const;             // Type specific hashing
1661   virtual bool singleton(void) const;    // TRUE if type is a singleton
1662   virtual bool empty(void) const;        // TRUE if type is vacuous
1663 
1664   const TypeTuple* const _domain;     // Domain of inputs
1665   const TypeTuple* const _range;      // Range of results











1666 
1667 public:
1668   // Constants are shared among ADLC and VM
1669   enum { Control    = AdlcVMDeps::Control,
1670          I_O        = AdlcVMDeps::I_O,
1671          Memory     = AdlcVMDeps::Memory,
1672          FramePtr   = AdlcVMDeps::FramePtr,
1673          ReturnAdr  = AdlcVMDeps::ReturnAdr,
1674          Parms      = AdlcVMDeps::Parms
1675   };
1676 
1677 
1678   // Accessors:
1679   const TypeTuple* domain() const { return _domain; }
1680   const TypeTuple* range()  const { return _range; }
1681 
1682   static const TypeFunc *make(ciMethod* method);
1683   static const TypeFunc *make(ciSignature signature, const Type* extra);



1684   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1685 
1686   virtual const Type *xmeet( const Type *t ) const;
1687   virtual const Type *xdual() const;    // Compute dual right now.
1688 
1689   BasicType return_type() const;
1690 


1691 #ifndef PRODUCT
1692   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1693 #endif
1694   // Convenience common pre-built types.
1695 };
1696 
1697 //------------------------------accessors--------------------------------------
1698 inline bool Type::is_ptr_to_narrowoop() const {
1699 #ifdef _LP64
1700   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1701 #else
1702   return false;
1703 #endif
1704 }
1705 
1706 inline bool Type::is_ptr_to_narrowklass() const {
1707 #ifdef _LP64
1708   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1709 #else
1710   return false;

1842 }
1843 
1844 inline const TypeInstPtr *Type::isa_instptr() const {
1845   return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1846 }
1847 
1848 inline const TypeInstPtr *Type::is_instptr() const {
1849   assert( _base == InstPtr, "Not an object pointer" );
1850   return (TypeInstPtr*)this;
1851 }
1852 
1853 inline const TypeAryPtr *Type::isa_aryptr() const {
1854   return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1855 }
1856 
1857 inline const TypeAryPtr *Type::is_aryptr() const {
1858   assert( _base == AryPtr, "Not an array pointer" );
1859   return (TypeAryPtr*)this;
1860 }
1861 









1862 inline const TypeNarrowOop *Type::is_narrowoop() const {
1863   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1864   assert(_base == NarrowOop, "Not a narrow oop" ) ;
1865   return (TypeNarrowOop*)this;
1866 }
1867 
1868 inline const TypeNarrowOop *Type::isa_narrowoop() const {
1869   // OopPtr is the first and KlassPtr the last, with no non-oops between.
1870   return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
1871 }
1872 
1873 inline const TypeNarrowKlass *Type::is_narrowklass() const {
1874   assert(_base == NarrowKlass, "Not a narrow oop" ) ;
1875   return (TypeNarrowKlass*)this;
1876 }
1877 
1878 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
1879   return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL;
1880 }
1881 

1926   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr();
1927 }
1928 
1929 inline const TypeNarrowOop* Type::make_narrowoop() const {
1930   return (_base == NarrowOop) ? is_narrowoop() :
1931                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
1932 }
1933 
1934 inline const TypeNarrowKlass* Type::make_narrowklass() const {
1935   return (_base == NarrowKlass) ? is_narrowklass() :
1936                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL);
1937 }
1938 
1939 inline bool Type::is_floatingpoint() const {
1940   if( (_base == FloatCon)  || (_base == FloatBot) ||
1941       (_base == DoubleCon) || (_base == DoubleBot) )
1942     return true;
1943   return false;
1944 }
1945 
1946 inline bool Type::is_ptr_to_boxing_obj() const {
1947   const TypeInstPtr* tp = isa_instptr();
1948   return (tp != NULL) && (tp->offset() == 0) &&
1949          tp->klass()->is_instance_klass()  &&
1950          tp->klass()->as_instance_klass()->is_box_klass();



1951 }
1952 
1953 
1954 // ===============================================================
1955 // Things that need to be 64-bits in the 64-bit build but
1956 // 32-bits in the 32-bit build.  Done this way to get full
1957 // optimization AND strong typing.
1958 #ifdef _LP64
1959 
1960 // For type queries and asserts
1961 #define is_intptr_t  is_long
1962 #define isa_intptr_t isa_long
1963 #define find_intptr_t_type find_long_type
1964 #define find_intptr_t_con  find_long_con
1965 #define TypeX        TypeLong
1966 #define Type_X       Type::Long
1967 #define TypeX_X      TypeLong::LONG
1968 #define TypeX_ZERO   TypeLong::ZERO
1969 // For 'ideal_reg' machine registers
1970 #define Op_RegX      Op_RegL
1971 // For phase->intcon variants
1972 #define MakeConX     longcon
1973 #define ConXNode     ConLNode
1974 // For array index arithmetic
1975 #define MulXNode     MulLNode
1976 #define AndXNode     AndLNode
1977 #define OrXNode      OrLNode
1978 #define CmpXNode     CmpLNode

1979 #define SubXNode     SubLNode
1980 #define LShiftXNode  LShiftLNode
1981 // For object size computation:
1982 #define AddXNode     AddLNode
1983 #define RShiftXNode  RShiftLNode
1984 // For card marks and hashcodes
1985 #define URShiftXNode URShiftLNode
1986 // For shenandoahSupport
1987 #define LoadXNode    LoadLNode
1988 #define StoreXNode   StoreLNode
1989 // Opcodes
1990 #define Op_LShiftX   Op_LShiftL
1991 #define Op_AndX      Op_AndL
1992 #define Op_AddX      Op_AddL
1993 #define Op_SubX      Op_SubL
1994 #define Op_XorX      Op_XorL
1995 #define Op_URShiftX  Op_URShiftL
1996 #define Op_LoadX     Op_LoadL

1997 // conversions
1998 #define ConvI2X(x)   ConvI2L(x)
1999 #define ConvL2X(x)   (x)
2000 #define ConvX2I(x)   ConvL2I(x)
2001 #define ConvX2L(x)   (x)
2002 #define ConvX2UL(x)  (x)
2003 
2004 #else
2005 
2006 // For type queries and asserts
2007 #define is_intptr_t  is_int
2008 #define isa_intptr_t isa_int
2009 #define find_intptr_t_type find_int_type
2010 #define find_intptr_t_con  find_int_con
2011 #define TypeX        TypeInt
2012 #define Type_X       Type::Int
2013 #define TypeX_X      TypeInt::INT
2014 #define TypeX_ZERO   TypeInt::ZERO
2015 // For 'ideal_reg' machine registers
2016 #define Op_RegX      Op_RegI
2017 // For phase->intcon variants
2018 #define MakeConX     intcon
2019 #define ConXNode     ConINode
2020 // For array index arithmetic
2021 #define MulXNode     MulINode
2022 #define AndXNode     AndINode
2023 #define OrXNode      OrINode
2024 #define CmpXNode     CmpINode

2025 #define SubXNode     SubINode
2026 #define LShiftXNode  LShiftINode
2027 // For object size computation:
2028 #define AddXNode     AddINode
2029 #define RShiftXNode  RShiftINode
2030 // For card marks and hashcodes
2031 #define URShiftXNode URShiftINode
2032 // For shenandoahSupport
2033 #define LoadXNode    LoadINode
2034 #define StoreXNode   StoreINode
2035 // Opcodes
2036 #define Op_LShiftX   Op_LShiftI
2037 #define Op_AndX      Op_AndI
2038 #define Op_AddX      Op_AddI
2039 #define Op_SubX      Op_SubI
2040 #define Op_XorX      Op_XorI
2041 #define Op_URShiftX  Op_URShiftI
2042 #define Op_LoadX     Op_LoadI

2043 // conversions
2044 #define ConvI2X(x)   (x)
2045 #define ConvL2X(x)   ConvL2I(x)
2046 #define ConvX2I(x)   (x)
2047 #define ConvX2L(x)   ConvI2L(x)
2048 #define ConvX2UL(x)  ConvI2UL(x)
2049 
2050 #endif
2051 
2052 #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 "runtime/handles.hpp"
  31 #include "runtime/sharedRuntime.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   TypeInteger;
  51 class     TypeInt;
  52 class     TypeLong;
  53 class   TypeNarrowPtr;
  54 class     TypeNarrowOop;
  55 class     TypeNarrowKlass;
  56 class   TypeAry;
  57 class   TypeTuple;
  58 class   TypeInlineType;
  59 class   TypeVect;
  60 class     TypeVectA;
  61 class     TypeVectS;
  62 class     TypeVectD;
  63 class     TypeVectX;
  64 class     TypeVectY;
  65 class     TypeVectZ;
  66 class     TypeVectMask;
  67 class   TypePtr;
  68 class     TypeRawPtr;
  69 class     TypeOopPtr;
  70 class       TypeInstPtr;
  71 class       TypeAryPtr;
  72 class     TypeKlassPtr;
  73 class       TypeInstKlassPtr;
  74 class       TypeAryKlassPtr;
  75 class     TypeMetadataPtr;
  76 
  77 //------------------------------Type-------------------------------------------
  78 // Basic Type object, represents a set of primitive Values.

  86   enum TYPES {
  87     Bad=0,                      // Type check
  88     Control,                    // Control of code (not in lattice)
  89     Top,                        // Top of the lattice
  90     Int,                        // Integer range (lo-hi)
  91     Long,                       // Long integer range (lo-hi)
  92     Half,                       // Placeholder half of doubleword
  93     NarrowOop,                  // Compressed oop pointer
  94     NarrowKlass,                // Compressed klass pointer
  95 
  96     Tuple,                      // Method signature or object layout
  97     Array,                      // Array types
  98 
  99     VectorMask,                 // Vector predicate/mask type
 100     VectorA,                    // (Scalable) Vector types for vector length agnostic
 101     VectorS,                    //  32bit Vector types
 102     VectorD,                    //  64bit Vector types
 103     VectorX,                    // 128bit Vector types
 104     VectorY,                    // 256bit Vector types
 105     VectorZ,                    // 512bit Vector types
 106     InlineType,                 // Inline type
 107 
 108     AnyPtr,                     // Any old raw, klass, inst, or array pointer
 109     RawPtr,                     // Raw (non-oop) pointers
 110     OopPtr,                     // Any and all Java heap entities
 111     InstPtr,                    // Instance pointers (non-array objects)
 112     AryPtr,                     // Array pointers
 113     // (Ptr order matters:  See is_ptr, isa_ptr, is_oopptr, isa_oopptr.)
 114 
 115     MetadataPtr,                // Generic metadata
 116     KlassPtr,                   // Klass pointers
 117     InstKlassPtr,
 118     AryKlassPtr,
 119 
 120     Function,                   // Function signature
 121     Abio,                       // Abstract I/O
 122     Return_Address,             // Subroutine return address
 123     Memory,                     // Abstract store
 124     FloatTop,                   // No float value
 125     FloatCon,                   // Floating point constant
 126     FloatBot,                   // Any float value
 127     DoubleTop,                  // No double value
 128     DoubleCon,                  // Double precision constant
 129     DoubleBot,                  // Any double value
 130     Bottom,                     // Bottom of lattice
 131     lastype                     // Bogus ending type (not in lattice)
 132   };
 133 
 134   // Signal values for offsets from a base pointer
 135   enum OFFSET_SIGNALS {
 136     OffsetTop = -2000000000,    // undefined offset
 137     OffsetBot = -2000000001     // any possible offset
 138   };
 139 
 140   class Offset {
 141   private:
 142     int _offset;
 143 
 144   public:
 145     explicit Offset(int offset) : _offset(offset) {}
 146 
 147     const Offset meet(const Offset other) const;
 148     const Offset dual() const;
 149     const Offset add(intptr_t offset) const;
 150     bool operator==(const Offset& other) const {
 151       return _offset == other._offset;
 152     }
 153     bool operator!=(const Offset& other) const {
 154       return _offset != other._offset;
 155     }
 156     int get() const { return _offset; }
 157 
 158     void dump2(outputStream *st) const;
 159 
 160     static const Offset top;
 161     static const Offset bottom;
 162   };
 163 
 164   // Min and max WIDEN values.
 165   enum WIDEN {
 166     WidenMin = 0,
 167     WidenMax = 3
 168   };
 169 
 170 private:
 171   typedef struct {
 172     TYPES                dual_type;
 173     BasicType            basic_type;
 174     const char*          msg;
 175     bool                 isa_oop;
 176     uint                 ideal_reg;
 177     relocInfo::relocType reloc;
 178   } TypeInfo;
 179 
 180   // Dictionary of types shared among compilations.
 181   static Dict* _shared_type_dict;
 182   static const TypeInfo _type_info[];
 183 

 291   // Currently, it also works around limitations involving interface types.
 292   // Variant that drops the speculative part of the types
 293   const Type *filter(const Type *kills) const {
 294     return filter_helper(kills, false);
 295   }
 296   // Variant that keeps the speculative part of the types
 297   const Type *filter_speculative(const Type *kills) const {
 298     return filter_helper(kills, true)->cleanup_speculative();
 299   }
 300 
 301 #ifdef ASSERT
 302   // One type is interface, the other is oop
 303   virtual bool interface_vs_oop(const Type *t) const;
 304 #endif
 305 
 306   // Returns true if this pointer points at memory which contains a
 307   // compressed oop references.
 308   bool is_ptr_to_narrowoop() const;
 309   bool is_ptr_to_narrowklass() const;
 310 



 311   // Convenience access
 312   float getf() const;
 313   double getd() const;
 314 
 315   const TypeInt    *is_int() const;
 316   const TypeInt    *isa_int() const;             // Returns NULL if not an Int
 317   const TypeInteger* is_integer(BasicType bt) const;
 318   const TypeInteger* isa_integer(BasicType bt) const;
 319   const TypeLong   *is_long() const;
 320   const TypeLong   *isa_long() const;            // Returns NULL if not a Long
 321   const TypeD      *isa_double() const;          // Returns NULL if not a Double{Top,Con,Bot}
 322   const TypeD      *is_double_constant() const;  // Asserts it is a DoubleCon
 323   const TypeD      *isa_double_constant() const; // Returns NULL if not a DoubleCon
 324   const TypeF      *isa_float() const;           // Returns NULL if not a Float{Top,Con,Bot}
 325   const TypeF      *is_float_constant() const;   // Asserts it is a FloatCon
 326   const TypeF      *isa_float_constant() const;  // Returns NULL if not a FloatCon
 327   const TypeTuple  *is_tuple() const;            // Collection of fields, NOT a pointer
 328   const TypeAry    *is_ary() const;              // Array, NOT array pointer
 329   const TypeAry    *isa_ary() const;             // Returns NULL of not ary
 330   const TypeVect   *is_vect() const;             // Vector
 331   const TypeVect   *isa_vect() const;            // Returns NULL if not a Vector
 332   const TypeVectMask *is_vectmask() const;       // Predicate/Mask Vector
 333   const TypeVectMask *isa_vectmask() const;      // Returns NULL if not a Vector Predicate/Mask
 334   const TypePtr    *is_ptr() const;              // Asserts it is a ptr type
 335   const TypePtr    *isa_ptr() const;             // Returns NULL if not ptr type
 336   const TypeRawPtr *isa_rawptr() const;          // NOT Java oop
 337   const TypeRawPtr *is_rawptr() const;           // Asserts is rawptr
 338   const TypeNarrowOop  *is_narrowoop() const;    // Java-style GC'd pointer
 339   const TypeNarrowOop  *isa_narrowoop() const;   // Returns NULL if not oop ptr type
 340   const TypeNarrowKlass *is_narrowklass() const; // compressed klass pointer
 341   const TypeNarrowKlass *isa_narrowklass() const;// Returns NULL if not oop ptr type
 342   const TypeOopPtr   *isa_oopptr() const;        // Returns NULL if not oop ptr type
 343   const TypeOopPtr   *is_oopptr() const;         // Java-style GC'd pointer
 344   const TypeInstPtr  *isa_instptr() const;       // Returns NULL if not InstPtr
 345   const TypeInstPtr  *is_instptr() const;        // Instance
 346   const TypeAryPtr   *isa_aryptr() const;        // Returns NULL if not AryPtr
 347   const TypeAryPtr   *is_aryptr() const;         // Array oop
 348   const TypeInlineType* isa_inlinetype() const;  // Returns NULL if not Inline Type
 349   const TypeInlineType* is_inlinetype() const;   // Inline Type
 350 
 351   const TypeMetadataPtr   *isa_metadataptr() const;   // Returns NULL if not oop ptr type
 352   const TypeMetadataPtr   *is_metadataptr() const;    // Java-style GC'd pointer
 353   const TypeKlassPtr      *isa_klassptr() const;      // Returns NULL if not KlassPtr
 354   const TypeKlassPtr      *is_klassptr() const;       // assert if not KlassPtr
 355   const TypeInstKlassPtr  *isa_instklassptr() const;  // Returns NULL if not IntKlassPtr
 356   const TypeInstKlassPtr  *is_instklassptr() const;   // assert if not IntKlassPtr
 357   const TypeAryKlassPtr   *isa_aryklassptr() const;   // Returns NULL if not AryKlassPtr
 358   const TypeAryKlassPtr   *is_aryklassptr() const;    // assert if not AryKlassPtr
 359 
 360   virtual bool      is_finite() const;           // Has a finite value
 361   virtual bool      is_nan()    const;           // Is not a number (NaN)
 362 
 363   bool is_inlinetypeptr() const;
 364   virtual ciInlineKlass* inline_klass() const;
 365 
 366   // Returns this ptr type or the equivalent ptr type for this compressed pointer.
 367   const TypePtr* make_ptr() const;
 368 
 369   // Returns this oopptr type or the equivalent oopptr type for this compressed pointer.
 370   // Asserts if the underlying type is not an oopptr or narrowoop.
 371   const TypeOopPtr* make_oopptr() const;
 372 
 373   // Returns this compressed pointer or the equivalent compressed version
 374   // of this pointer type.
 375   const TypeNarrowOop* make_narrowoop() const;
 376 
 377   // Returns this compressed klass pointer or the equivalent
 378   // compressed version of this pointer type.
 379   const TypeNarrowKlass* make_narrowklass() const;
 380 
 381   // Special test for register pressure heuristic
 382   bool is_floatingpoint() const;        // True if Float or Double base type
 383 
 384   // Do you have memory, directly or through a tuple?
 385   bool has_memory( ) const;

 737   const Type ** const _fields;           // Array of field types
 738 
 739 public:
 740   virtual bool eq( const Type *t ) const;
 741   virtual int  hash() const;             // Type specific hashing
 742   virtual bool singleton(void) const;    // TRUE if type is a singleton
 743   virtual bool empty(void) const;        // TRUE if type is vacuous
 744 
 745   // Accessors:
 746   uint cnt() const { return _cnt; }
 747   const Type* field_at(uint i) const {
 748     assert(i < _cnt, "oob");
 749     return _fields[i];
 750   }
 751   void set_field_at(uint i, const Type* t) {
 752     assert(i < _cnt, "oob");
 753     _fields[i] = t;
 754   }
 755 
 756   static const TypeTuple *make( uint cnt, const Type **fields );
 757   static const TypeTuple *make_range(ciSignature* sig, bool ret_vt_fields = false);
 758   static const TypeTuple *make_domain(ciMethod* method, bool vt_fields_as_args = false);
 759 
 760   // Subroutine call type with space allocated for argument types
 761   // Memory for Control, I_O, Memory, FramePtr, and ReturnAdr is allocated implicitly
 762   static const Type **fields( uint arg_cnt );
 763 
 764   virtual const Type *xmeet( const Type *t ) const;
 765   virtual const Type *xdual() const;    // Compute dual right now.
 766   // Convenience common pre-built types.
 767   static const TypeTuple *IFBOTH;
 768   static const TypeTuple *IFFALSE;
 769   static const TypeTuple *IFTRUE;
 770   static const TypeTuple *IFNEITHER;
 771   static const TypeTuple *LOOPBODY;
 772   static const TypeTuple *MEMBAR;
 773   static const TypeTuple *STORECONDITIONAL;
 774   static const TypeTuple *START_I2C;
 775   static const TypeTuple *INT_PAIR;
 776   static const TypeTuple *LONG_PAIR;
 777   static const TypeTuple *INT_CC_PAIR;
 778   static const TypeTuple *LONG_CC_PAIR;
 779 #ifndef PRODUCT
 780   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 781 #endif
 782 };
 783 
 784 //------------------------------TypeAry----------------------------------------
 785 // Class of Array Types
 786 class TypeAry : public Type {
 787   TypeAry(const Type* elem, const TypeInt* size, bool stable, bool not_flat, bool not_null_free) : Type(Array),
 788       _elem(elem), _size(size), _stable(stable), _not_flat(not_flat), _not_null_free(not_null_free) {}
 789 public:
 790   virtual bool eq( const Type *t ) const;
 791   virtual int  hash() const;             // Type specific hashing
 792   virtual bool singleton(void) const;    // TRUE if type is a singleton
 793   virtual bool empty(void) const;        // TRUE if type is vacuous
 794 
 795 private:
 796   const Type *_elem;            // Element type of array
 797   const TypeInt *_size;         // Elements in array
 798   const bool _stable;           // Are elements @Stable?
 799 
 800   // Inline type array properties
 801   const bool _not_flat;         // Array is never flattened
 802   const bool _not_null_free;    // Array is never null-free
 803 
 804   friend class TypeAryPtr;
 805 
 806 public:
 807   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false,
 808                              bool not_flat = false, bool not_null_free = false);
 809 
 810   virtual const Type *xmeet( const Type *t ) const;
 811   virtual const Type *xdual() const;    // Compute dual right now.
 812   bool ary_must_be_exact() const;  // true if arrays of such are never generic
 813   virtual const Type* remove_speculative() const;
 814   virtual const Type* cleanup_speculative() const;
 815 
 816 #ifdef ASSERT
 817   // One type is interface, the other is oop
 818   virtual bool interface_vs_oop(const Type *t) const;
 819 #endif
 820 #ifndef PRODUCT
 821   virtual void dump2( Dict &d, uint, outputStream *st  ) const; // Specialized per-Type dumping
 822 #endif
 823 };
 824 
 825 
 826 //------------------------------TypeValue---------------------------------------
 827 // Class of Inline Type Types
 828 class TypeInlineType : public Type {
 829 private:
 830   ciInlineKlass* _vk;
 831   bool _larval;
 832 
 833 protected:
 834   TypeInlineType(ciInlineKlass* vk, bool larval)
 835     : Type(InlineType),
 836       _vk(vk), _larval(larval) {
 837   }
 838 
 839 public:
 840   static const TypeInlineType* make(ciInlineKlass* vk, bool larval = false);
 841   virtual ciInlineKlass* inline_klass() const { return _vk; }
 842   bool larval() const { return _larval; }
 843 
 844   virtual bool eq(const Type* t) const;
 845   virtual int  hash() const;             // Type specific hashing
 846   virtual bool singleton(void) const;    // TRUE if type is a singleton
 847   virtual bool empty(void) const;        // TRUE if type is vacuous
 848 
 849   virtual const Type* xmeet(const Type* t) const;
 850   virtual const Type* xdual() const;     // Compute dual right now.
 851 
 852   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const { return false; }
 853   virtual bool would_improve_ptr(ProfilePtrKind ptr_kind) const { return false; }
 854 
 855   virtual bool maybe_null() const { return false; }
 856 
 857   static const TypeInlineType* BOTTOM;
 858 
 859 #ifndef PRODUCT
 860   virtual void dump2(Dict &d, uint, outputStream* st) const; // Specialized per-Type dumping
 861 #endif
 862 };
 863 
 864 //------------------------------TypeVect---------------------------------------
 865 // Class of Vector Types
 866 class TypeVect : public Type {
 867   const Type*   _elem;  // Vector's element type
 868   const uint  _length;  // Elements in vector (power of 2)
 869 
 870 protected:
 871   TypeVect(TYPES t, const Type* elem, uint length) : Type(t),
 872     _elem(elem), _length(length) {}
 873 
 874 public:
 875   const Type* element_type() const { return _elem; }
 876   BasicType element_basic_type() const { return _elem->array_element_basic_type(); }
 877   uint length() const { return _length; }
 878   uint length_in_bytes() const {
 879    return _length * type2aelembytes(element_basic_type());
 880   }
 881 
 882   virtual bool eq(const Type *t) const;
 883   virtual int  hash() const;             // Type specific hashing

 947 class TypeVectMask : public TypeVect {
 948 public:
 949   friend class TypeVect;
 950   TypeVectMask(const Type* elem, uint length) : TypeVect(VectorMask, elem, length) {}
 951   virtual bool eq(const Type *t) const;
 952   virtual const Type *xdual() const;
 953   static const TypeVectMask* make(const BasicType elem_bt, uint length);
 954   static const TypeVectMask* make(const Type* elem, uint length);
 955 };
 956 
 957 //------------------------------TypePtr----------------------------------------
 958 // Class of machine Pointer Types: raw data, instances or arrays.
 959 // If the _base enum is AnyPtr, then this refers to all of the above.
 960 // Otherwise the _base will indicate which subset of pointers is affected,
 961 // and the class will be inherited from.
 962 class TypePtr : public Type {
 963   friend class TypeNarrowPtr;
 964 public:
 965   enum PTR { TopPTR, AnyNull, Constant, Null, NotNull, BotPTR, lastPTR };
 966 protected:
 967   TypePtr(TYPES t, PTR ptr, Offset offset,
 968           const TypePtr* speculative = NULL,
 969           int inline_depth = InlineDepthBottom) :
 970     Type(t), _speculative(speculative), _inline_depth(inline_depth), _offset(offset),
 971     _ptr(ptr) {}
 972   static const PTR ptr_meet[lastPTR][lastPTR];
 973   static const PTR ptr_dual[lastPTR];
 974   static const char * const ptr_msg[lastPTR];
 975 
 976   enum {
 977     InlineDepthBottom = INT_MAX,
 978     InlineDepthTop = -InlineDepthBottom
 979   };
 980 
 981   // Extra type information profiling gave us. We propagate it the
 982   // same way the rest of the type info is propagated. If we want to
 983   // use it, then we have to emit a guard: this part of the type is
 984   // not something we know but something we speculate about the type.
 985   const TypePtr*   _speculative;
 986   // For speculative types, we record at what inlining depth the
 987   // profiling point that provided the data is. We want to favor

1003   int dual_inline_depth() const;
1004   int meet_inline_depth(int depth) const;
1005 #ifndef PRODUCT
1006   void dump_inline_depth(outputStream *st) const;
1007 #endif
1008 
1009   // TypeInstPtr (TypeAryPtr resp.) and TypeInstKlassPtr (TypeAryKlassPtr resp.) implement very similar meet logic.
1010   // The logic for meeting 2 instances (2 arrays resp.) is shared in the 2 utility methods below. However the logic for
1011   // the oop and klass versions can be slightly different and extra logic may have to be executed depending on what
1012   // exact case the meet falls into. The MeetResult struct is used by the utility methods to communicate what case was
1013   // encountered so the right logic specific to klasses or oops can be executed.,
1014   enum MeetResult {
1015     QUICK,
1016     UNLOADED,
1017     SUBTYPE,
1018     NOT_SUBTYPE,
1019     LCA
1020   };
1021   static MeetResult
1022   meet_instptr(PTR &ptr, ciKlass* this_klass, ciKlass* tinst_klass, bool this_xk, bool tinst_xk, PTR this_ptr,
1023                PTR tinst_ptr, bool this_flatten_array, bool tinst_flatten_array, ciKlass*&res_klass, bool &res_xk,
1024                bool& res_flatten_array);
1025 
1026   static MeetResult meet_aryptr(PTR &ptr, const Type* this_elem, const Type* tap_elem, ciKlass* this_klass, ciKlass* tap_klass,
1027                                 bool this_xk, bool tap_xk, PTR this_ptr, PTR tap_ptr, bool this_not_flat, bool tap_not_flat,
1028                                 bool this_not_null_free, bool tap_not_null_free, const Type*& res_elem, ciKlass*&res_klass,
1029                                 bool &res_xk, bool &res_not_flat, bool &res_not_null_free);
1030 
1031 public:
1032   const Offset _offset;         // Offset into oop, with TOP & BOT
1033   const PTR _ptr;               // Pointer equivalence class
1034 
1035   const int offset() const { return _offset.get(); }
1036   const PTR ptr()    const { return _ptr; }
1037 
1038   static const TypePtr* make(TYPES t, PTR ptr, Offset offset,
1039                              const TypePtr* speculative = NULL,
1040                              int inline_depth = InlineDepthBottom);
1041 
1042   // Return a 'ptr' version of this type
1043   virtual const Type *cast_to_ptr_type(PTR ptr) const;
1044 
1045   virtual intptr_t get_con() const;
1046 
1047   Offset xadd_offset(intptr_t offset) const;
1048   virtual const TypePtr *add_offset( intptr_t offset ) const;
1049   virtual const int flattened_offset() const { return offset(); }
1050 
1051   virtual bool eq(const Type *t) const;
1052   virtual int  hash() const;             // Type specific hashing
1053 
1054   virtual bool singleton(void) const;    // TRUE if type is a singleton
1055   virtual bool empty(void) const;        // TRUE if type is vacuous
1056   virtual const Type *xmeet( const Type *t ) const;
1057   virtual const Type *xmeet_helper( const Type *t ) const;
1058   Offset meet_offset(int offset) const;
1059   Offset dual_offset() const;
1060   virtual const Type *xdual() const;    // Compute dual right now.
1061 
1062   // meet, dual and join over pointer equivalence sets
1063   PTR meet_ptr( const PTR in_ptr ) const { return ptr_meet[in_ptr][ptr()]; }
1064   PTR dual_ptr()                   const { return ptr_dual[ptr()];      }
1065 
1066   // This is textually confusing unless one recalls that
1067   // join(t) == dual()->meet(t->dual())->dual().
1068   PTR join_ptr( const PTR in_ptr ) const {
1069     return ptr_dual[ ptr_meet[ ptr_dual[in_ptr] ] [ dual_ptr() ] ];
1070   }
1071 
1072   // Speculative type helper methods.
1073   virtual const TypePtr* speculative() const { return _speculative; }
1074   int inline_depth() const                   { return _inline_depth; }
1075   virtual ciKlass* speculative_type() const;
1076   virtual ciKlass* speculative_type_not_null() const;
1077   virtual bool speculative_maybe_null() const;
1078   virtual bool speculative_always_null() const;
1079   virtual const Type* remove_speculative() const;
1080   virtual const Type* cleanup_speculative() const;
1081   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1082   virtual bool would_improve_ptr(ProfilePtrKind maybe_null) const;
1083   virtual const TypePtr* with_inline_depth(int depth) const;
1084 
1085   virtual bool maybe_null() const { return meet_ptr(Null) == ptr(); }
1086 
1087   virtual bool can_be_inline_type() const { return false; }
1088   virtual bool flatten_array()      const { return false; }
1089   virtual bool is_flat()            const { return false; }
1090   virtual bool is_not_flat()        const { return false; }
1091   virtual bool is_null_free()       const { return false; }
1092   virtual bool is_not_null_free()   const { return false; }
1093 
1094   // Tests for relation to centerline of type lattice:
1095   static bool above_centerline(PTR ptr) { return (ptr <= AnyNull); }
1096   static bool below_centerline(PTR ptr) { return (ptr >= NotNull); }
1097   // Convenience common pre-built types.
1098   static const TypePtr *NULL_PTR;
1099   static const TypePtr *NOTNULL;
1100   static const TypePtr *BOTTOM;
1101 #ifndef PRODUCT
1102   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1103 #endif
1104 };
1105 
1106 //------------------------------TypeRawPtr-------------------------------------
1107 // Class of raw pointers, pointers to things other than Oops.  Examples
1108 // include the stack pointer, top of heap, card-marking area, handles, etc.
1109 class TypeRawPtr : public TypePtr {
1110 protected:
1111   TypeRawPtr(PTR ptr, address bits) : TypePtr(RawPtr,ptr,Offset(0)), _bits(bits){}
1112 public:
1113   virtual bool eq( const Type *t ) const;
1114   virtual int  hash() const;     // Type specific hashing
1115 
1116   const address _bits;          // Constant value, if applicable
1117 
1118   static const TypeRawPtr *make( PTR ptr );
1119   static const TypeRawPtr *make( address bits );
1120 
1121   // Return a 'ptr' version of this type
1122   virtual const TypeRawPtr* cast_to_ptr_type(PTR ptr) const;
1123 
1124   virtual intptr_t get_con() const;
1125 
1126   virtual const TypePtr *add_offset( intptr_t offset ) const;
1127 
1128   virtual const Type *xmeet( const Type *t ) const;
1129   virtual const Type *xdual() const;    // Compute dual right now.
1130   // Convenience common pre-built types.
1131   static const TypeRawPtr *BOTTOM;
1132   static const TypeRawPtr *NOTNULL;
1133 #ifndef PRODUCT
1134   virtual void dump2( Dict &d, uint depth, outputStream *st  ) const;
1135 #endif
1136 };
1137 
1138 //------------------------------TypeOopPtr-------------------------------------
1139 // Some kind of oop (Java pointer), either instance or array.
1140 class TypeOopPtr : public TypePtr {
1141 protected:
1142   TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset, Offset field_offset,
1143              int instance_id, const TypePtr* speculative, int inline_depth);
1144 public:
1145   virtual bool eq( const Type *t ) const;
1146   virtual int  hash() const;             // Type specific hashing
1147   virtual bool singleton(void) const;    // TRUE if type is a singleton
1148   enum {
1149    InstanceTop = -1,   // undefined instance
1150    InstanceBot = 0     // any possible instance
1151   };
1152 protected:
1153 
1154   // Oop is NULL, unless this is a constant oop.
1155   ciObject*     _const_oop;   // Constant oop
1156   // If _klass is NULL, then so is _sig.  This is an unloaded klass.
1157   ciKlass*      _klass;       // Klass object
1158   // Does the type exclude subclasses of the klass?  (Inexact == polymorphic.)
1159   bool          _klass_is_exact;
1160   bool          _is_ptr_to_narrowoop;
1161   bool          _is_ptr_to_narrowklass;
1162   bool          _is_ptr_to_boxed_value;
1163 

1182     return make_from_klass_common(klass, true, false);
1183   }
1184   // Same as before, but will produce an exact type, even if
1185   // the klass is not final, as long as it has exactly one implementation.
1186   static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
1187     return make_from_klass_common(klass, true, true);
1188   }
1189   // Same as before, but does not respects UseUniqueSubclasses.
1190   // Use this only for creating array element types.
1191   static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
1192     return make_from_klass_common(klass, false, false);
1193   }
1194   // Creates a singleton type given an object.
1195   // If the object cannot be rendered as a constant,
1196   // may return a non-singleton type.
1197   // If require_constant, produce a NULL if a singleton is not possible.
1198   static const TypeOopPtr* make_from_constant(ciObject* o,
1199                                               bool require_constant = false);
1200 
1201   // Make a generic (unclassed) pointer to an oop.
1202   static const TypeOopPtr* make(PTR ptr, Offset offset, int instance_id,
1203                                 const TypePtr* speculative = NULL,
1204                                 int inline_depth = InlineDepthBottom);
1205 
1206   ciObject* const_oop()    const { return _const_oop; }
1207   virtual ciKlass* klass() const { return _klass;     }
1208   bool klass_is_exact()    const { return _klass_is_exact; }
1209 
1210   // Returns true if this pointer points at memory which contains a
1211   // compressed oop references.
1212   bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
1213   bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
1214   bool is_ptr_to_boxed_value()   const { return _is_ptr_to_boxed_value; }
1215   bool is_known_instance()       const { return _instance_id > 0; }
1216   int  instance_id()             const { return _instance_id; }
1217   bool is_known_instance_field() const { return is_known_instance() && _offset.get() >= 0; }
1218 
1219   virtual bool can_be_inline_type() const { return EnableValhalla && (_klass == NULL || _klass->can_be_inline_klass(_klass_is_exact)); }
1220 
1221   virtual intptr_t get_con() const;
1222 
1223   virtual const TypeOopPtr* cast_to_ptr_type(PTR ptr) const;
1224 
1225   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1226 
1227   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1228 
1229   // corresponding pointer to klass, for a given instance
1230   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1231 
1232   virtual const TypePtr *add_offset( intptr_t offset ) const;
1233 
1234   // Speculative type helper methods.
1235   virtual const Type* remove_speculative() const;
1236   virtual const Type* cleanup_speculative() const;
1237   virtual bool would_improve_type(ciKlass* exact_kls, int inline_depth) const;
1238   virtual const TypePtr* with_inline_depth(int depth) const;
1239 
1240   virtual const TypePtr* with_instance_id(int instance_id) const;
1241 
1242   virtual const Type *xdual() const;    // Compute dual right now.
1243   // the core of the computation of the meet for TypeOopPtr and for its subclasses
1244   virtual const Type *xmeet_helper(const Type *t) const;
1245 
1246   // Convenience common pre-built type.
1247   static const TypeOopPtr *BOTTOM;
1248 #ifndef PRODUCT
1249   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1250 #endif
1251 };
1252 
1253 //------------------------------TypeInstPtr------------------------------------
1254 // Class of Java object pointers, pointing either to non-array Java instances
1255 // or to a Klass* (including array klasses).
1256 class TypeInstPtr : public TypeOopPtr {
1257   TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset,
1258               bool flatten_array, int instance_id, const TypePtr* speculative,
1259               int inline_depth);
1260   virtual bool eq( const Type *t ) const;
1261   virtual int  hash() const;             // Type specific hashing
1262 
1263   ciSymbol*  _name;        // class name
1264   bool _flatten_array;     // Type is flat in arrays
1265 
1266  public:
1267   ciSymbol* name()         const { return _name; }
1268 
1269   bool  is_loaded() const { return _klass->is_loaded(); }
1270 
1271   // Make a pointer to a constant oop.
1272   static const TypeInstPtr *make(ciObject* o) {
1273     return make(TypePtr::Constant, o->klass(), true, o, Offset(0));
1274   }
1275   // Make a pointer to a constant oop with offset.
1276   static const TypeInstPtr* make(ciObject* o, Offset offset) {
1277     return make(TypePtr::Constant, o->klass(), true, o, offset);
1278   }
1279 
1280   // Make a pointer to some value of type klass.
1281   static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
1282     return make(ptr, klass, false, NULL, Offset(0));
1283   }
1284 
1285   // Make a pointer to some non-polymorphic value of exactly type klass.
1286   static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
1287     return make(ptr, klass, true, NULL, Offset(0));
1288   }
1289 
1290   // Make a pointer to some value of type klass with offset.
1291   static const TypeInstPtr *make(PTR ptr, ciKlass* klass, Offset offset) {
1292     return make(ptr, klass, false, NULL, offset);
1293   }
1294 
1295   // Make a pointer to an oop.
1296   static const TypeInstPtr* make(PTR ptr, ciKlass* k, bool xk, ciObject* o, Offset offset,
1297                                  bool flatten_array = false,
1298                                  int instance_id = InstanceBot,
1299                                  const TypePtr* speculative = NULL,
1300                                  int inline_depth = InlineDepthBottom);
1301 
1302   /** Create constant type for a constant boxed value */
1303   const Type* get_const_boxed_value() const;
1304 
1305   // If this is a java.lang.Class constant, return the type for it or NULL.
1306   // Pass to Type::get_const_type to turn it to a type, which will usually
1307   // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
1308   ciType* java_mirror_type(bool* is_val_mirror = NULL) const;
1309 
1310   virtual const TypeInstPtr* cast_to_ptr_type(PTR ptr) const;
1311 
1312   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1313 
1314   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1315 
1316   virtual const TypePtr *add_offset( intptr_t offset ) const;
1317 
1318   // Speculative type helper methods.
1319   virtual const Type* remove_speculative() const;
1320   virtual const TypePtr* with_inline_depth(int depth) const;
1321   virtual const TypePtr* with_instance_id(int instance_id) const;
1322 
1323   virtual const TypeInstPtr* cast_to_flatten_array() const;
1324   virtual bool flatten_array() const { return _flatten_array; }
1325 
1326   // the core of the computation of the meet of 2 types
1327   virtual const Type *xmeet_helper(const Type *t) const;
1328   virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
1329   virtual const Type *xdual() const;    // Compute dual right now.
1330 
1331   const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1332 
1333   // Convenience common pre-built types.
1334   static const TypeInstPtr *NOTNULL;
1335   static const TypeInstPtr *BOTTOM;
1336   static const TypeInstPtr *MIRROR;
1337   static const TypeInstPtr *MARK;
1338   static const TypeInstPtr *KLASS;
1339 #ifndef PRODUCT
1340   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1341 #endif
1342 };
1343 
1344 //------------------------------TypeAryPtr-------------------------------------
1345 // Class of Java array pointers
1346 class TypeAryPtr : public TypeOopPtr {
1347   TypeAryPtr(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1348              Offset offset, Offset field_offset, int instance_id, bool is_autobox_cache,
1349              const TypePtr* speculative, int inline_depth)
1350     : TypeOopPtr(AryPtr, ptr, k, xk, o, offset, field_offset, instance_id, speculative, inline_depth),
1351     _ary(ary),
1352     _is_autobox_cache(is_autobox_cache),
1353     _field_offset(field_offset)
1354  {
1355 #ifdef ASSERT
1356     if (k != NULL) {
1357       // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
1358       ciKlass* ck = compute_klass(true);
1359       if (k != ck) {
1360         this->dump(); tty->cr();
1361         tty->print(" k: ");
1362         k->print(); tty->cr();
1363         tty->print("ck: ");
1364         if (ck != NULL) ck->print();
1365         else tty->print("<NULL>");
1366         tty->cr();
1367         assert(false, "unexpected TypeAryPtr::_klass");
1368       }
1369     }
1370 #endif
1371   }
1372   virtual bool eq( const Type *t ) const;
1373   virtual int hash() const;     // Type specific hashing
1374   const TypeAry *_ary;          // Array we point into
1375   const bool     _is_autobox_cache;
1376   // For flattened inline type arrays, each field of the inline type in
1377   // the array has its own memory slice so we need to keep track of
1378   // which field is accessed
1379   const Offset _field_offset;
1380   Offset meet_field_offset(const Type::Offset offset) const;
1381   Offset dual_field_offset() const;
1382 
1383   ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
1384 
1385 public:
1386   // Accessors
1387   ciKlass* klass() const;
1388   const TypeAry* ary() const  { return _ary; }
1389   const Type*    elem() const { return _ary->_elem; }
1390   const TypeInt* size() const { return _ary->_size; }
1391   bool      is_stable() const { return _ary->_stable; }
1392 
1393   // Inline type array properties
1394   bool is_flat()          const { return _ary->_elem->isa_inlinetype() != NULL; }
1395   bool is_not_flat()      const { return _ary->_not_flat; }
1396   bool is_null_free()     const { return is_flat() || (_ary->_elem->make_ptr() != NULL && _ary->_elem->make_ptr()->is_inlinetypeptr() && !_ary->_elem->make_ptr()->maybe_null()); }
1397   bool is_not_null_free() const { return _ary->_not_null_free; }
1398 
1399   bool is_autobox_cache() const { return _is_autobox_cache; }
1400 
1401   static const TypeAryPtr* make(PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, Offset offset,
1402                                 Offset field_offset = Offset::bottom,
1403                                 int instance_id = InstanceBot,
1404                                 const TypePtr* speculative = NULL,
1405                                 int inline_depth = InlineDepthBottom);
1406   // Constant pointer to array
1407   static const TypeAryPtr* make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, Offset offset,
1408                                 Offset field_offset = Offset::bottom,
1409                                 int instance_id = InstanceBot,
1410                                 const TypePtr* speculative = NULL,
1411                                 int inline_depth = InlineDepthBottom,
1412                                 bool is_autobox_cache = false);
1413 
1414   // Return a 'ptr' version of this type
1415   virtual const TypeAryPtr* cast_to_ptr_type(PTR ptr) const;
1416 
1417   virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1418 
1419   virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1420 
1421   virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1422   virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1423 
1424   virtual bool empty(void) const;        // TRUE if type is vacuous
1425   virtual const TypePtr *add_offset( intptr_t offset ) const;
1426 
1427   // Speculative type helper methods.
1428   virtual const Type* remove_speculative() const;
1429   virtual const Type* cleanup_speculative() const;
1430   virtual const TypePtr* with_inline_depth(int depth) const;
1431   virtual const TypePtr* with_instance_id(int instance_id) const;
1432 
1433   // the core of the computation of the meet of 2 types
1434   virtual const Type *xmeet_helper(const Type *t) const;
1435   virtual const Type *xdual() const;    // Compute dual right now.
1436 
1437   // Inline type array properties
1438   const TypeAryPtr* cast_to_not_flat(bool not_flat = true) const;
1439   const TypeAryPtr* cast_to_not_null_free(bool not_null_free = true) const;
1440   const TypeAryPtr* update_properties(const TypeAryPtr* new_type) const;
1441 
1442   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1443   int stable_dimension() const;
1444 
1445   const TypeAryPtr* cast_to_autobox_cache() const;
1446 
1447   static jint max_array_length(BasicType etype);
1448 
1449   const int flattened_offset() const;
1450   const Offset field_offset() const { return _field_offset; }
1451   const TypeAryPtr* with_field_offset(int offset) const;
1452   const TypePtr* add_field_offset_and_offset(intptr_t offset) const;
1453 
1454   virtual bool can_be_inline_type() const { return false; }
1455   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1456 
1457   // Convenience common pre-built types.
1458   static const TypeAryPtr *RANGE;
1459   static const TypeAryPtr *OOPS;
1460   static const TypeAryPtr *NARROWOOPS;
1461   static const TypeAryPtr *BYTES;
1462   static const TypeAryPtr *SHORTS;
1463   static const TypeAryPtr *CHARS;
1464   static const TypeAryPtr *INTS;
1465   static const TypeAryPtr *LONGS;
1466   static const TypeAryPtr *FLOATS;
1467   static const TypeAryPtr *DOUBLES;
1468   static const TypeAryPtr *INLINES;
1469   // selects one of the above:
1470   static const TypeAryPtr *get_array_body_type(BasicType elem) {
1471     assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1472     return _array_body_type[elem];
1473   }
1474   static const TypeAryPtr *_array_body_type[T_CONFLICT+1];
1475   // sharpen the type of an int which is used as an array size
1476 #ifdef ASSERT
1477   // One type is interface, the other is oop
1478   virtual bool interface_vs_oop(const Type *t) const;
1479 #endif
1480 #ifndef PRODUCT
1481   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1482 #endif
1483 };
1484 
1485 //------------------------------TypeMetadataPtr-------------------------------------
1486 // Some kind of metadata, either Method*, MethodData* or CPCacheOop
1487 class TypeMetadataPtr : public TypePtr {
1488 protected:
1489   TypeMetadataPtr(PTR ptr, ciMetadata* metadata, Offset offset);
1490   // Do not allow interface-vs.-noninterface joins to collapse to top.
1491   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1492 public:
1493   virtual bool eq( const Type *t ) const;
1494   virtual int  hash() const;             // Type specific hashing
1495   virtual bool singleton(void) const;    // TRUE if type is a singleton
1496 
1497 private:
1498   ciMetadata*   _metadata;
1499 
1500 public:
1501   static const TypeMetadataPtr* make(PTR ptr, ciMetadata* m, Offset offset);
1502 
1503   static const TypeMetadataPtr* make(ciMethod* m);
1504   static const TypeMetadataPtr* make(ciMethodData* m);
1505 
1506   ciMetadata* metadata() const { return _metadata; }
1507 
1508   virtual const TypeMetadataPtr* cast_to_ptr_type(PTR ptr) const;
1509 
1510   virtual const TypePtr *add_offset( intptr_t offset ) const;
1511 
1512   virtual const Type *xmeet( const Type *t ) const;
1513   virtual const Type *xdual() const;    // Compute dual right now.
1514 
1515   virtual intptr_t get_con() const;
1516 
1517   // Convenience common pre-built types.
1518   static const TypeMetadataPtr *BOTTOM;
1519 
1520 #ifndef PRODUCT
1521   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1522 #endif
1523 };
1524 
1525 //------------------------------TypeKlassPtr-----------------------------------
1526 // Class of Java Klass pointers
1527 class TypeKlassPtr : public TypePtr {
1528 protected:
1529   TypeKlassPtr(TYPES t, PTR ptr, ciKlass* klass, Offset offset);
1530 
1531   virtual const Type *filter_helper(const Type *kills, bool include_speculative) const;
1532 
1533 public:
1534   virtual bool eq( const Type *t ) const;
1535   virtual int hash() const;
1536   virtual bool singleton(void) const;    // TRUE if type is a singleton
1537   virtual bool must_be_exact() const { ShouldNotReachHere(); return false; }
1538 
1539 protected:
1540 
1541   ciKlass* _klass;
1542 
1543 public:
1544 
1545   virtual ciKlass* klass() const { return  _klass; }
1546   bool klass_is_exact()    const { return _ptr == Constant; }
1547   bool  is_loaded() const { return klass()->is_loaded(); }
1548 
1549   static const TypeKlassPtr* make(ciKlass* klass);
1550   static const TypeKlassPtr *make(PTR ptr, ciKlass* klass, Offset offset);
1551 
1552 
1553   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const { ShouldNotReachHere(); return NULL; }
1554 
1555   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const { ShouldNotReachHere(); return NULL; }
1556 
1557   // corresponding pointer to instance, for a given class
1558   virtual const TypeOopPtr* as_instance_type() const { ShouldNotReachHere(); return NULL; }
1559 
1560   virtual const TypePtr *add_offset( intptr_t offset ) const { ShouldNotReachHere(); return NULL; }
1561   virtual const Type    *xmeet( const Type *t ) const { ShouldNotReachHere(); return NULL; }
1562   virtual const Type    *xdual() const { ShouldNotReachHere(); return NULL; }
1563 
1564   virtual intptr_t get_con() const;
1565 
1566   virtual const TypeKlassPtr* with_offset(intptr_t offset) const { ShouldNotReachHere(); return NULL; }




1567 };
1568 
1569 // Instance klass pointer, mirrors TypeInstPtr
1570 class TypeInstKlassPtr : public TypeKlassPtr {
1571 
1572   TypeInstKlassPtr(PTR ptr, ciKlass* klass, Offset offset, bool flatten_array)
1573     : TypeKlassPtr(InstKlassPtr, ptr, klass, offset), _flatten_array(flatten_array) {
1574   }
1575 
1576   virtual bool must_be_exact() const;
1577 
1578   const bool _flatten_array; // Type is flat in arrays
1579 
1580 public:
1581   // Instance klass ignoring any interface
1582   ciInstanceKlass* instance_klass() const { return klass()->as_instance_klass();     }
1583 
1584   virtual bool can_be_inline_type() const { return EnableValhalla && (_klass == NULL || _klass->can_be_inline_klass(klass_is_exact())); }
1585 
1586   static const TypeInstKlassPtr *make(ciKlass* k) {
1587     return make(TypePtr::Constant, k, Offset(0), false);
1588   }
1589   static const TypeInstKlassPtr *make(PTR ptr, ciKlass* k, Offset offset, bool flatten_array = false);
1590 
1591   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1592 
1593   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1594 
1595   // corresponding pointer to instance, for a given class
1596   virtual const TypeOopPtr* as_instance_type() const;
1597   virtual int hash() const;
1598   virtual bool eq(const Type *t) const;
1599 
1600   virtual const TypePtr *add_offset( intptr_t offset ) const;
1601   virtual const Type    *xmeet( const Type *t ) const;
1602   virtual const Type    *xdual() const;
1603   virtual const TypeKlassPtr* with_offset(intptr_t offset) const;
1604 
1605   virtual bool flatten_array() const { return _flatten_array; }
1606 
1607   // Convenience common pre-built types.
1608   static const TypeInstKlassPtr* OBJECT; // Not-null object klass or below
1609   static const TypeInstKlassPtr* OBJECT_OR_NULL; // Maybe-null version of same
1610 
1611 #ifndef PRODUCT
1612   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1613 #endif
1614 };
1615 
1616 // Array klass pointer, mirrors TypeAryPtr
1617 class TypeAryKlassPtr : public TypeKlassPtr {
1618   const Type *_elem;
1619   const bool _not_flat;      // Array is never flattened
1620   const bool _not_null_free; // Array is never null-free
1621   const bool _null_free;
1622 
1623   TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, Offset offset, bool not_flat, int not_null_free, bool null_free)
1624     : TypeKlassPtr(AryKlassPtr, ptr, klass, offset), _elem(elem), _not_flat(not_flat), _not_null_free(not_null_free), _null_free(null_free) {
1625   }
1626 
1627   virtual bool must_be_exact() const;
1628 
1629   bool dual_null_free() const {
1630     return _null_free;
1631   }
1632 
1633   bool meet_null_free(bool other) const {
1634     return _null_free && other;
1635   }
1636 
1637 public:
1638   virtual ciKlass* klass() const;
1639 
1640   // returns base element type, an instance klass (and not interface) for object arrays
1641   const Type* base_element_type(int& dims) const;
1642 
1643   static const TypeAryKlassPtr *make(PTR ptr, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free);
1644   static const TypeAryKlassPtr *make(PTR ptr, const Type *elem, ciKlass* k, Offset offset, bool not_flat, bool not_null_free, bool null_free);
1645   static const TypeAryKlassPtr* make(ciKlass* klass, PTR ptr = Constant, Offset offset= Offset(0));
1646 
1647   const Type *elem() const { return _elem; }
1648 
1649   virtual bool eq(const Type *t) const;
1650   virtual int hash() const;             // Type specific hashing
1651 
1652   virtual const TypePtr* cast_to_ptr_type(PTR ptr) const;
1653 
1654   virtual const TypeKlassPtr *cast_to_exactness(bool klass_is_exact) const;
1655 
1656   // corresponding pointer to instance, for a given class
1657   virtual const TypeOopPtr* as_instance_type() const;
1658 
1659   virtual const TypePtr *add_offset( intptr_t offset ) const;
1660   virtual const Type    *xmeet( const Type *t ) const;
1661   virtual const Type    *xdual() const;      // Compute dual right now.
1662 
1663   virtual const TypeKlassPtr* with_offset(intptr_t offset) const;
1664 
1665   virtual bool empty(void) const {
1666     return TypeKlassPtr::empty() || _elem->empty();
1667   }
1668 
1669   bool is_flat()          const { return klass()->is_flat_array_klass(); }
1670   bool is_not_flat()      const { return _not_flat; }
1671   bool is_null_free()     const { return _null_free; }
1672   bool is_not_null_free() const { return _not_null_free; }
1673 
1674 #ifndef PRODUCT
1675   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1676 #endif
1677 };
1678 
1679 class TypeNarrowPtr : public Type {
1680 protected:
1681   const TypePtr* _ptrtype; // Could be TypePtr::NULL_PTR
1682 
1683   TypeNarrowPtr(TYPES t, const TypePtr* ptrtype): Type(t),
1684                                                   _ptrtype(ptrtype) {
1685     assert(ptrtype->offset() == 0 ||
1686            ptrtype->offset() == OffsetBot ||
1687            ptrtype->offset() == OffsetTop, "no real offsets");
1688   }
1689 
1690   virtual const TypeNarrowPtr *isa_same_narrowptr(const Type *t) const = 0;
1691   virtual const TypeNarrowPtr *is_same_narrowptr(const Type *t) const = 0;
1692   virtual const TypeNarrowPtr *make_same_narrowptr(const TypePtr *t) const = 0;
1693   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const = 0;

1787   }
1788 
1789   virtual const TypeNarrowPtr *make_hash_same_narrowptr(const TypePtr *t) const {
1790     return (const TypeNarrowPtr*)((new TypeNarrowKlass(t))->hashcons());
1791   }
1792 
1793 public:
1794   static const TypeNarrowKlass *make( const TypePtr* type);
1795 
1796   // static const TypeNarrowKlass *BOTTOM;
1797   static const TypeNarrowKlass *NULL_PTR;
1798 
1799 #ifndef PRODUCT
1800   virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
1801 #endif
1802 };
1803 
1804 //------------------------------TypeFunc---------------------------------------
1805 // Class of Array Types
1806 class TypeFunc : public Type {
1807   TypeFunc(const TypeTuple *domain_sig, const TypeTuple *domain_cc, const TypeTuple *range_sig, const TypeTuple *range_cc)
1808     : Type(Function), _domain_sig(domain_sig), _domain_cc(domain_cc), _range_sig(range_sig), _range_cc(range_cc) {}
1809   virtual bool eq( const Type *t ) const;
1810   virtual int  hash() const;             // Type specific hashing
1811   virtual bool singleton(void) const;    // TRUE if type is a singleton
1812   virtual bool empty(void) const;        // TRUE if type is vacuous
1813 
1814   // Domains of inputs: inline type arguments are not passed by
1815   // reference, instead each field of the inline type is passed as an
1816   // argument. We maintain 2 views of the argument list here: one
1817   // based on the signature (with an inline type argument as a single
1818   // slot), one based on the actual calling convention (with a value
1819   // type argument as a list of its fields).
1820   const TypeTuple* const _domain_sig;
1821   const TypeTuple* const _domain_cc;
1822   // Range of results. Similar to domains: an inline type result can be
1823   // returned in registers in which case range_cc lists all fields and
1824   // is the actual calling convention.
1825   const TypeTuple* const _range_sig;
1826   const TypeTuple* const _range_cc;
1827 
1828 public:
1829   // Constants are shared among ADLC and VM
1830   enum { Control    = AdlcVMDeps::Control,
1831          I_O        = AdlcVMDeps::I_O,
1832          Memory     = AdlcVMDeps::Memory,
1833          FramePtr   = AdlcVMDeps::FramePtr,
1834          ReturnAdr  = AdlcVMDeps::ReturnAdr,
1835          Parms      = AdlcVMDeps::Parms
1836   };
1837 
1838 
1839   // Accessors:
1840   const TypeTuple* domain_sig() const { return _domain_sig; }
1841   const TypeTuple* domain_cc()  const { return _domain_cc; }
1842   const TypeTuple* range_sig()  const { return _range_sig; }
1843   const TypeTuple* range_cc()   const { return _range_cc; }
1844 
1845   static const TypeFunc* make(ciMethod* method, bool is_osr_compilation = false);
1846   static const TypeFunc *make(const TypeTuple* domain_sig, const TypeTuple* domain_cc,
1847                               const TypeTuple* range_sig, const TypeTuple* range_cc);
1848   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1849 
1850   virtual const Type *xmeet( const Type *t ) const;
1851   virtual const Type *xdual() const;    // Compute dual right now.
1852 
1853   BasicType return_type() const;
1854 
1855   bool returns_inline_type_as_fields() const { return range_sig() != range_cc(); }
1856 
1857 #ifndef PRODUCT
1858   virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1859 #endif
1860   // Convenience common pre-built types.
1861 };
1862 
1863 //------------------------------accessors--------------------------------------
1864 inline bool Type::is_ptr_to_narrowoop() const {
1865 #ifdef _LP64
1866   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowoop_nv());
1867 #else
1868   return false;
1869 #endif
1870 }
1871 
1872 inline bool Type::is_ptr_to_narrowklass() const {
1873 #ifdef _LP64
1874   return (isa_oopptr() != NULL && is_oopptr()->is_ptr_to_narrowklass_nv());
1875 #else
1876   return false;

2008 }
2009 
2010 inline const TypeInstPtr *Type::isa_instptr() const {
2011   return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
2012 }
2013 
2014 inline const TypeInstPtr *Type::is_instptr() const {
2015   assert( _base == InstPtr, "Not an object pointer" );
2016   return (TypeInstPtr*)this;
2017 }
2018 
2019 inline const TypeAryPtr *Type::isa_aryptr() const {
2020   return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
2021 }
2022 
2023 inline const TypeAryPtr *Type::is_aryptr() const {
2024   assert( _base == AryPtr, "Not an array pointer" );
2025   return (TypeAryPtr*)this;
2026 }
2027 
2028 inline const TypeInlineType* Type::isa_inlinetype() const {
2029   return (_base == InlineType) ? (TypeInlineType*)this : NULL;
2030 }
2031 
2032 inline const TypeInlineType* Type::is_inlinetype() const {
2033   assert(_base == InlineType, "Not an inline type");
2034   return (TypeInlineType*)this;
2035 }
2036 
2037 inline const TypeNarrowOop *Type::is_narrowoop() const {
2038   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2039   assert(_base == NarrowOop, "Not a narrow oop" ) ;
2040   return (TypeNarrowOop*)this;
2041 }
2042 
2043 inline const TypeNarrowOop *Type::isa_narrowoop() const {
2044   // OopPtr is the first and KlassPtr the last, with no non-oops between.
2045   return (_base == NarrowOop) ? (TypeNarrowOop*)this : NULL;
2046 }
2047 
2048 inline const TypeNarrowKlass *Type::is_narrowklass() const {
2049   assert(_base == NarrowKlass, "Not a narrow oop" ) ;
2050   return (TypeNarrowKlass*)this;
2051 }
2052 
2053 inline const TypeNarrowKlass *Type::isa_narrowklass() const {
2054   return (_base == NarrowKlass) ? (TypeNarrowKlass*)this : NULL;
2055 }
2056 

2101   return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->isa_oopptr() : isa_oopptr();
2102 }
2103 
2104 inline const TypeNarrowOop* Type::make_narrowoop() const {
2105   return (_base == NarrowOop) ? is_narrowoop() :
2106                                 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL);
2107 }
2108 
2109 inline const TypeNarrowKlass* Type::make_narrowklass() const {
2110   return (_base == NarrowKlass) ? is_narrowklass() :
2111                                   (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL);
2112 }
2113 
2114 inline bool Type::is_floatingpoint() const {
2115   if( (_base == FloatCon)  || (_base == FloatBot) ||
2116       (_base == DoubleCon) || (_base == DoubleBot) )
2117     return true;
2118   return false;
2119 }
2120 
2121 inline bool Type::is_inlinetypeptr() const {
2122   return isa_instptr() != NULL && is_instptr()->klass()->is_inlinetype();
2123 }
2124 
2125 
2126 inline ciInlineKlass* Type::inline_klass() const {
2127   assert(is_inlinetypeptr(), "must be an inline type ptr");
2128   return is_instptr()->klass()->as_inline_klass();
2129 }
2130 
2131 
2132 // ===============================================================
2133 // Things that need to be 64-bits in the 64-bit build but
2134 // 32-bits in the 32-bit build.  Done this way to get full
2135 // optimization AND strong typing.
2136 #ifdef _LP64
2137 
2138 // For type queries and asserts
2139 #define is_intptr_t  is_long
2140 #define isa_intptr_t isa_long
2141 #define find_intptr_t_type find_long_type
2142 #define find_intptr_t_con  find_long_con
2143 #define TypeX        TypeLong
2144 #define Type_X       Type::Long
2145 #define TypeX_X      TypeLong::LONG
2146 #define TypeX_ZERO   TypeLong::ZERO
2147 // For 'ideal_reg' machine registers
2148 #define Op_RegX      Op_RegL
2149 // For phase->intcon variants
2150 #define MakeConX     longcon
2151 #define ConXNode     ConLNode
2152 // For array index arithmetic
2153 #define MulXNode     MulLNode
2154 #define AndXNode     AndLNode
2155 #define OrXNode      OrLNode
2156 #define CmpXNode     CmpLNode
2157 #define CmpUXNode    CmpULNode
2158 #define SubXNode     SubLNode
2159 #define LShiftXNode  LShiftLNode
2160 // For object size computation:
2161 #define AddXNode     AddLNode
2162 #define RShiftXNode  RShiftLNode
2163 // For card marks and hashcodes
2164 #define URShiftXNode URShiftLNode
2165 // For shenandoahSupport
2166 #define LoadXNode    LoadLNode
2167 #define StoreXNode   StoreLNode
2168 // Opcodes
2169 #define Op_LShiftX   Op_LShiftL
2170 #define Op_AndX      Op_AndL
2171 #define Op_AddX      Op_AddL
2172 #define Op_SubX      Op_SubL
2173 #define Op_XorX      Op_XorL
2174 #define Op_URShiftX  Op_URShiftL
2175 #define Op_LoadX     Op_LoadL
2176 #define Op_StoreX    Op_StoreL
2177 // conversions
2178 #define ConvI2X(x)   ConvI2L(x)
2179 #define ConvL2X(x)   (x)
2180 #define ConvX2I(x)   ConvL2I(x)
2181 #define ConvX2L(x)   (x)
2182 #define ConvX2UL(x)  (x)
2183 
2184 #else
2185 
2186 // For type queries and asserts
2187 #define is_intptr_t  is_int
2188 #define isa_intptr_t isa_int
2189 #define find_intptr_t_type find_int_type
2190 #define find_intptr_t_con  find_int_con
2191 #define TypeX        TypeInt
2192 #define Type_X       Type::Int
2193 #define TypeX_X      TypeInt::INT
2194 #define TypeX_ZERO   TypeInt::ZERO
2195 // For 'ideal_reg' machine registers
2196 #define Op_RegX      Op_RegI
2197 // For phase->intcon variants
2198 #define MakeConX     intcon
2199 #define ConXNode     ConINode
2200 // For array index arithmetic
2201 #define MulXNode     MulINode
2202 #define AndXNode     AndINode
2203 #define OrXNode      OrINode
2204 #define CmpXNode     CmpINode
2205 #define CmpUXNode    CmpUNode
2206 #define SubXNode     SubINode
2207 #define LShiftXNode  LShiftINode
2208 // For object size computation:
2209 #define AddXNode     AddINode
2210 #define RShiftXNode  RShiftINode
2211 // For card marks and hashcodes
2212 #define URShiftXNode URShiftINode
2213 // For shenandoahSupport
2214 #define LoadXNode    LoadINode
2215 #define StoreXNode   StoreINode
2216 // Opcodes
2217 #define Op_LShiftX   Op_LShiftI
2218 #define Op_AndX      Op_AndI
2219 #define Op_AddX      Op_AddI
2220 #define Op_SubX      Op_SubI
2221 #define Op_XorX      Op_XorI
2222 #define Op_URShiftX  Op_URShiftI
2223 #define Op_LoadX     Op_LoadI
2224 #define Op_StoreX    Op_StoreI
2225 // conversions
2226 #define ConvI2X(x)   (x)
2227 #define ConvL2X(x)   ConvL2I(x)
2228 #define ConvX2I(x)   (x)
2229 #define ConvX2L(x)   ConvI2L(x)
2230 #define ConvX2UL(x)  ConvI2UL(x)
2231 
2232 #endif
2233 
2234 #endif // SHARE_OPTO_TYPE_HPP
< prev index next >