< 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;

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





 765   friend class TypeAryPtr;
 766 
 767 public:
 768   static const TypeAry* make(const Type* elem, const TypeInt* size, bool stable = false);

 769 
 770   virtual const Type *xmeet( const Type *t ) const;
 771   virtual const Type *xdual() const;    // Compute dual right now.
 772   bool ary_must_be_exact() const;  // true if arrays of such are never generic
 773   virtual const Type* remove_speculative() const;
 774   virtual const Type* cleanup_speculative() const;

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







































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

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

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




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


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





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

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


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

1162   virtual bool eq( const Type *t ) const;
1163   virtual int  hash() const;             // Type specific hashing
1164 
1165   ciSymbol*  _name;        // class name

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

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



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

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






1272 
1273   ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
1274 
1275 public:
1276   // Accessors
1277   ciKlass* klass() const;
1278   const TypeAry* ary() const  { return _ary; }
1279   const Type*    elem() const { return _ary->_elem; }
1280   const TypeInt* size() const { return _ary->_size; }
1281   bool      is_stable() const { return _ary->_stable; }
1282 






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

1286                                 int instance_id = InstanceBot,
1287                                 const TypePtr* speculative = NULL,
1288                                 int inline_depth = InlineDepthBottom);
1289   // Constant pointer to array
1290   static const TypeAryPtr *make(PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset,

1291                                 int instance_id = InstanceBot,
1292                                 const TypePtr* speculative = NULL,
1293                                 int inline_depth = InlineDepthBottom, bool is_autobox_cache = false);

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

1310   virtual const TypePtr* with_inline_depth(int depth) const;
1311   virtual const TypePtr* with_instance_id(int instance_id) const;
1312 
1313   // the core of the computation of the meet of 2 types
1314   virtual const Type *xmeet_helper(const Type *t) const;
1315   virtual const Type *xdual() const;    // Compute dual right now.
1316 





1317   const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1318   int stable_dimension() const;
1319 
1320   const TypeAryPtr* cast_to_autobox_cache() const;
1321 
1322   static jint max_array_length(BasicType etype) ;







1323   virtual const TypeKlassPtr* as_klass_type(bool try_for_exact = false) const;
1324 
1325   // Convenience common pre-built types.
1326   static const TypeAryPtr *RANGE;
1327   static const TypeAryPtr *OOPS;
1328   static const TypeAryPtr *NARROWOOPS;
1329   static const TypeAryPtr *BYTES;
1330   static const TypeAryPtr *SHORTS;
1331   static const TypeAryPtr *CHARS;
1332   static const TypeAryPtr *INTS;
1333   static const TypeAryPtr *LONGS;
1334   static const TypeAryPtr *FLOATS;
1335   static const TypeAryPtr *DOUBLES;

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


1449 public:
1450   // Instance klass ignoring any interface
1451   ciInstanceKlass* instance_klass() const { return klass()->as_instance_klass();     }
1452 


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


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




1475 };
1476 
1477 // Array klass pointer, mirrors TypeAryPtr
1478 class TypeAryKlassPtr : public TypeKlassPtr {
1479   const Type *_elem;



1480 
1481   TypeAryKlassPtr(PTR ptr, const Type *elem, ciKlass* klass, int offset)
1482     : TypeKlassPtr(AryKlassPtr, ptr, klass, offset), _elem(elem) {
1483   }
1484 
1485   virtual bool must_be_exact() const;
1486 








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




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

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

1653   virtual bool eq( const Type *t ) const;
1654   virtual int  hash() const;             // Type specific hashing
1655   virtual bool singleton(void) const;    // TRUE if type is a singleton
1656   virtual bool empty(void) const;        // TRUE if type is vacuous
1657 
1658   const TypeTuple* const _domain;     // Domain of inputs
1659   const TypeTuple* const _range;      // Range of results











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



1678   static const TypeFunc *make(const TypeTuple* domain, const TypeTuple* range);
1679 
1680   virtual const Type *xmeet( const Type *t ) const;
1681   virtual const Type *xdual() const;    // Compute dual right now.
1682 
1683   BasicType return_type() const;
1684 


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

1836 }
1837 
1838 inline const TypeInstPtr *Type::isa_instptr() const {
1839   return (_base == InstPtr) ? (TypeInstPtr*)this : NULL;
1840 }
1841 
1842 inline const TypeInstPtr *Type::is_instptr() const {
1843   assert( _base == InstPtr, "Not an object pointer" );
1844   return (TypeInstPtr*)this;
1845 }
1846 
1847 inline const TypeAryPtr *Type::isa_aryptr() const {
1848   return (_base == AryPtr) ? (TypeAryPtr*)this : NULL;
1849 }
1850 
1851 inline const TypeAryPtr *Type::is_aryptr() const {
1852   assert( _base == AryPtr, "Not an array pointer" );
1853   return (TypeAryPtr*)this;
1854 }
1855 









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

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



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

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

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

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

2037 // conversions
2038 #define ConvI2X(x)   (x)
2039 #define ConvL2X(x)   ConvL2I(x)
2040 #define ConvX2I(x)   (x)
2041 #define ConvX2L(x)   ConvI2L(x)
2042 #define ConvX2UL(x)  ConvI2UL(x)
2043 
2044 #endif
2045 
2046 #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;

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

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

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

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




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

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

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

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