217 // JOIN operation; higher in lattice. Done by finding the dual of the 218 // meet of the dual of the 2 inputs. 219 const Type *join( const Type *t ) const { 220 return dual()->meet(t->dual())->dual(); } 221 222 // Modified version of JOIN adapted to the needs Node::Value. 223 // Normalizes all empty values to TOP. Does not kill _widen bits. 224 // Currently, it also works around limitations involving interface types. 225 virtual const Type *filter( const Type *kills ) const; 226 227 #ifdef ASSERT 228 // One type is interface, the other is oop 229 virtual bool interface_vs_oop(const Type *t) const; 230 #endif 231 232 // Returns true if this pointer points at memory which contains a 233 // compressed oop references. 234 bool is_ptr_to_narrowoop() const; 235 bool is_ptr_to_narrowklass() const; 236 237 // Convenience access 238 float getf() const; 239 double getd() const; 240 241 const TypeInt *is_int() const; 242 const TypeInt *isa_int() const; // Returns NULL if not an Int 243 const TypeLong *is_long() const; 244 const TypeLong *isa_long() const; // Returns NULL if not a Long 245 const TypeD *isa_double() const; // Returns NULL if not a Double{Top,Con,Bot} 246 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon 247 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon 248 const TypeF *isa_float() const; // Returns NULL if not a Float{Top,Con,Bot} 249 const TypeF *is_float_constant() const; // Asserts it is a FloatCon 250 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon 251 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer 252 const TypeAry *is_ary() const; // Array, NOT array pointer 253 const TypeVect *is_vect() const; // Vector 254 const TypeVect *isa_vect() const; // Returns NULL if not a Vector 255 const TypePtr *is_ptr() const; // Asserts it is a ptr type 256 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type 777 protected: 778 TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id ); 779 public: 780 virtual bool eq( const Type *t ) const; 781 virtual int hash() const; // Type specific hashing 782 virtual bool singleton(void) const; // TRUE if type is a singleton 783 enum { 784 InstanceTop = -1, // undefined instance 785 InstanceBot = 0 // any possible instance 786 }; 787 protected: 788 789 // Oop is NULL, unless this is a constant oop. 790 ciObject* _const_oop; // Constant oop 791 // If _klass is NULL, then so is _sig. This is an unloaded klass. 792 ciKlass* _klass; // Klass object 793 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.) 794 bool _klass_is_exact; 795 bool _is_ptr_to_narrowoop; 796 bool _is_ptr_to_narrowklass; 797 798 // If not InstanceTop or InstanceBot, indicates that this is 799 // a particular instance of this type which is distinct. 800 // This is the the node index of the allocation node creating this instance. 801 int _instance_id; 802 803 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact); 804 805 int dual_instance_id() const; 806 int meet_instance_id(int uid) const; 807 808 public: 809 // Creates a type given a klass. Correctly handles multi-dimensional arrays 810 // Respects UseUniqueSubclasses. 811 // If the klass is final, the resulting type will be exact. 812 static const TypeOopPtr* make_from_klass(ciKlass* klass) { 813 return make_from_klass_common(klass, true, false); 814 } 815 // Same as before, but will produce an exact type, even if 816 // the klass is not final, as long as it has exactly one implementation. 817 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) { 818 return make_from_klass_common(klass, true, true); 819 } 820 // Same as before, but does not respects UseUniqueSubclasses. 821 // Use this only for creating array element types. 822 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) { 823 return make_from_klass_common(klass, false, false); 824 } 825 // Creates a singleton type given an object. 826 // If the object cannot be rendered as a constant, 827 // may return a non-singleton type. 828 // If require_constant, produce a NULL if a singleton is not possible. 829 static const TypeOopPtr* make_from_constant(ciObject* o, bool require_constant = false); 830 831 // Make a generic (unclassed) pointer to an oop. 832 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id); 833 834 ciObject* const_oop() const { return _const_oop; } 835 virtual ciKlass* klass() const { return _klass; } 836 bool klass_is_exact() const { return _klass_is_exact; } 837 838 // Returns true if this pointer points at memory which contains a 839 // compressed oop references. 840 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; } 841 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; } 842 843 bool is_known_instance() const { return _instance_id > 0; } 844 int instance_id() const { return _instance_id; } 845 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; } 846 847 virtual intptr_t get_con() const; 848 849 virtual const Type *cast_to_ptr_type(PTR ptr) const; 850 851 virtual const Type *cast_to_exactness(bool klass_is_exact) const; 852 853 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const; 854 855 // corresponding pointer to klass, for a given instance 856 const TypeKlassPtr* as_klass_type() const; 857 858 virtual const TypePtr *add_offset( intptr_t offset ) const; 859 860 virtual const Type *xmeet( const Type *t ) const; 861 virtual const Type *xdual() const; // Compute dual right now. 862 926 virtual const TypePtr *add_offset( intptr_t offset ) const; 927 928 virtual const Type *xmeet( const Type *t ) const; 929 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const; 930 virtual const Type *xdual() const; // Compute dual right now. 931 932 // Convenience common pre-built types. 933 static const TypeInstPtr *NOTNULL; 934 static const TypeInstPtr *BOTTOM; 935 static const TypeInstPtr *MIRROR; 936 static const TypeInstPtr *MARK; 937 static const TypeInstPtr *KLASS; 938 #ifndef PRODUCT 939 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 940 #endif 941 }; 942 943 //------------------------------TypeAryPtr------------------------------------- 944 // Class of Java array pointers 945 class TypeAryPtr : public TypeOopPtr { 946 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id ) : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id), _ary(ary) { 947 #ifdef ASSERT 948 if (k != NULL) { 949 // Verify that specified klass and TypeAryPtr::klass() follow the same rules. 950 ciKlass* ck = compute_klass(true); 951 if (k != ck) { 952 this->dump(); tty->cr(); 953 tty->print(" k: "); 954 k->print(); tty->cr(); 955 tty->print("ck: "); 956 if (ck != NULL) ck->print(); 957 else tty->print("<NULL>"); 958 tty->cr(); 959 assert(false, "unexpected TypeAryPtr::_klass"); 960 } 961 } 962 #endif 963 } 964 virtual bool eq( const Type *t ) const; 965 virtual int hash() const; // Type specific hashing 966 const TypeAry *_ary; // Array we point into 967 968 ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const; 969 970 public: 971 // Accessors 972 ciKlass* klass() const; 973 const TypeAry* ary() const { return _ary; } 974 const Type* elem() const { return _ary->_elem; } 975 const TypeInt* size() const { return _ary->_size; } 976 977 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot); 978 // Constant pointer to array 979 static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot); 980 981 // Return a 'ptr' version of this type 982 virtual const Type *cast_to_ptr_type(PTR ptr) const; 983 984 virtual const Type *cast_to_exactness(bool klass_is_exact) const; 985 986 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const; 987 988 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const; 989 virtual const TypeInt* narrow_size_type(const TypeInt* size) const; 990 991 virtual bool empty(void) const; // TRUE if type is vacuous 992 virtual const TypePtr *add_offset( intptr_t offset ) const; 993 994 virtual const Type *xmeet( const Type *t ) const; 995 virtual const Type *xdual() const; // Compute dual right now. 996 997 // Convenience common pre-built types. 998 static const TypeAryPtr *RANGE; 999 static const TypeAryPtr *OOPS; 1487 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr(); 1488 } 1489 1490 inline const TypeNarrowOop* Type::make_narrowoop() const { 1491 return (_base == NarrowOop) ? is_narrowoop() : 1492 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL); 1493 } 1494 1495 inline const TypeNarrowKlass* Type::make_narrowklass() const { 1496 return (_base == NarrowKlass) ? is_narrowklass() : 1497 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL); 1498 } 1499 1500 inline bool Type::is_floatingpoint() const { 1501 if( (_base == FloatCon) || (_base == FloatBot) || 1502 (_base == DoubleCon) || (_base == DoubleBot) ) 1503 return true; 1504 return false; 1505 } 1506 1507 1508 // =============================================================== 1509 // Things that need to be 64-bits in the 64-bit build but 1510 // 32-bits in the 32-bit build. Done this way to get full 1511 // optimization AND strong typing. 1512 #ifdef _LP64 1513 1514 // For type queries and asserts 1515 #define is_intptr_t is_long 1516 #define isa_intptr_t isa_long 1517 #define find_intptr_t_type find_long_type 1518 #define find_intptr_t_con find_long_con 1519 #define TypeX TypeLong 1520 #define Type_X Type::Long 1521 #define TypeX_X TypeLong::LONG 1522 #define TypeX_ZERO TypeLong::ZERO 1523 // For 'ideal_reg' machine registers 1524 #define Op_RegX Op_RegL 1525 // For phase->intcon variants 1526 #define MakeConX longcon | 217 // JOIN operation; higher in lattice. Done by finding the dual of the 218 // meet of the dual of the 2 inputs. 219 const Type *join( const Type *t ) const { 220 return dual()->meet(t->dual())->dual(); } 221 222 // Modified version of JOIN adapted to the needs Node::Value. 223 // Normalizes all empty values to TOP. Does not kill _widen bits. 224 // Currently, it also works around limitations involving interface types. 225 virtual const Type *filter( const Type *kills ) const; 226 227 #ifdef ASSERT 228 // One type is interface, the other is oop 229 virtual bool interface_vs_oop(const Type *t) const; 230 #endif 231 232 // Returns true if this pointer points at memory which contains a 233 // compressed oop references. 234 bool is_ptr_to_narrowoop() const; 235 bool is_ptr_to_narrowklass() const; 236 237 bool is_ptr_to_boxing_obj() const; 238 239 240 // Convenience access 241 float getf() const; 242 double getd() const; 243 244 const TypeInt *is_int() const; 245 const TypeInt *isa_int() const; // Returns NULL if not an Int 246 const TypeLong *is_long() const; 247 const TypeLong *isa_long() const; // Returns NULL if not a Long 248 const TypeD *isa_double() const; // Returns NULL if not a Double{Top,Con,Bot} 249 const TypeD *is_double_constant() const; // Asserts it is a DoubleCon 250 const TypeD *isa_double_constant() const; // Returns NULL if not a DoubleCon 251 const TypeF *isa_float() const; // Returns NULL if not a Float{Top,Con,Bot} 252 const TypeF *is_float_constant() const; // Asserts it is a FloatCon 253 const TypeF *isa_float_constant() const; // Returns NULL if not a FloatCon 254 const TypeTuple *is_tuple() const; // Collection of fields, NOT a pointer 255 const TypeAry *is_ary() const; // Array, NOT array pointer 256 const TypeVect *is_vect() const; // Vector 257 const TypeVect *isa_vect() const; // Returns NULL if not a Vector 258 const TypePtr *is_ptr() const; // Asserts it is a ptr type 259 const TypePtr *isa_ptr() const; // Returns NULL if not ptr type 780 protected: 781 TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id ); 782 public: 783 virtual bool eq( const Type *t ) const; 784 virtual int hash() const; // Type specific hashing 785 virtual bool singleton(void) const; // TRUE if type is a singleton 786 enum { 787 InstanceTop = -1, // undefined instance 788 InstanceBot = 0 // any possible instance 789 }; 790 protected: 791 792 // Oop is NULL, unless this is a constant oop. 793 ciObject* _const_oop; // Constant oop 794 // If _klass is NULL, then so is _sig. This is an unloaded klass. 795 ciKlass* _klass; // Klass object 796 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.) 797 bool _klass_is_exact; 798 bool _is_ptr_to_narrowoop; 799 bool _is_ptr_to_narrowklass; 800 bool _is_ptr_to_boxed_value; 801 802 // If not InstanceTop or InstanceBot, indicates that this is 803 // a particular instance of this type which is distinct. 804 // This is the the node index of the allocation node creating this instance. 805 int _instance_id; 806 807 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact); 808 809 int dual_instance_id() const; 810 int meet_instance_id(int uid) const; 811 812 public: 813 // Creates a type given a klass. Correctly handles multi-dimensional arrays 814 // Respects UseUniqueSubclasses. 815 // If the klass is final, the resulting type will be exact. 816 static const TypeOopPtr* make_from_klass(ciKlass* klass) { 817 return make_from_klass_common(klass, true, false); 818 } 819 // Same as before, but will produce an exact type, even if 820 // the klass is not final, as long as it has exactly one implementation. 821 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) { 822 return make_from_klass_common(klass, true, true); 823 } 824 // Same as before, but does not respects UseUniqueSubclasses. 825 // Use this only for creating array element types. 826 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) { 827 return make_from_klass_common(klass, false, false); 828 } 829 // Creates a singleton type given an object. 830 // If the object cannot be rendered as a constant, 831 // may return a non-singleton type. 832 // If require_constant, produce a NULL if a singleton is not possible. 833 static const TypeOopPtr* make_from_constant(ciObject* o, 834 bool require_constant = false, 835 bool not_null_elements = false); 836 837 // Make a generic (unclassed) pointer to an oop. 838 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id); 839 840 ciObject* const_oop() const { return _const_oop; } 841 virtual ciKlass* klass() const { return _klass; } 842 bool klass_is_exact() const { return _klass_is_exact; } 843 844 // Returns true if this pointer points at memory which contains a 845 // compressed oop references. 846 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; } 847 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; } 848 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; } 849 bool is_known_instance() const { return _instance_id > 0; } 850 int instance_id() const { return _instance_id; } 851 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; } 852 853 virtual intptr_t get_con() const; 854 855 virtual const Type *cast_to_ptr_type(PTR ptr) const; 856 857 virtual const Type *cast_to_exactness(bool klass_is_exact) const; 858 859 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const; 860 861 // corresponding pointer to klass, for a given instance 862 const TypeKlassPtr* as_klass_type() const; 863 864 virtual const TypePtr *add_offset( intptr_t offset ) const; 865 866 virtual const Type *xmeet( const Type *t ) const; 867 virtual const Type *xdual() const; // Compute dual right now. 868 932 virtual const TypePtr *add_offset( intptr_t offset ) const; 933 934 virtual const Type *xmeet( const Type *t ) const; 935 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const; 936 virtual const Type *xdual() const; // Compute dual right now. 937 938 // Convenience common pre-built types. 939 static const TypeInstPtr *NOTNULL; 940 static const TypeInstPtr *BOTTOM; 941 static const TypeInstPtr *MIRROR; 942 static const TypeInstPtr *MARK; 943 static const TypeInstPtr *KLASS; 944 #ifndef PRODUCT 945 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping 946 #endif 947 }; 948 949 //------------------------------TypeAryPtr------------------------------------- 950 // Class of Java array pointers 951 class TypeAryPtr : public TypeOopPtr { 952 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, 953 int offset, int instance_id, bool is_autobox_cache ) 954 : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id), 955 _ary(ary), 956 _is_autobox_cache(is_autobox_cache) 957 { 958 #ifdef ASSERT 959 if (k != NULL) { 960 // Verify that specified klass and TypeAryPtr::klass() follow the same rules. 961 ciKlass* ck = compute_klass(true); 962 if (k != ck) { 963 this->dump(); tty->cr(); 964 tty->print(" k: "); 965 k->print(); tty->cr(); 966 tty->print("ck: "); 967 if (ck != NULL) ck->print(); 968 else tty->print("<NULL>"); 969 tty->cr(); 970 assert(false, "unexpected TypeAryPtr::_klass"); 971 } 972 } 973 #endif 974 } 975 virtual bool eq( const Type *t ) const; 976 virtual int hash() const; // Type specific hashing 977 const TypeAry *_ary; // Array we point into 978 const bool _is_autobox_cache; 979 980 ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const; 981 982 public: 983 // Accessors 984 ciKlass* klass() const; 985 const TypeAry* ary() const { return _ary; } 986 const Type* elem() const { return _ary->_elem; } 987 const TypeInt* size() const { return _ary->_size; } 988 989 bool is_autobox_cache() const { return _is_autobox_cache; } 990 991 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot); 992 // Constant pointer to array 993 static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot, bool is_autobox_cache = false); 994 995 // Return a 'ptr' version of this type 996 virtual const Type *cast_to_ptr_type(PTR ptr) const; 997 998 virtual const Type *cast_to_exactness(bool klass_is_exact) const; 999 1000 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const; 1001 1002 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const; 1003 virtual const TypeInt* narrow_size_type(const TypeInt* size) const; 1004 1005 virtual bool empty(void) const; // TRUE if type is vacuous 1006 virtual const TypePtr *add_offset( intptr_t offset ) const; 1007 1008 virtual const Type *xmeet( const Type *t ) const; 1009 virtual const Type *xdual() const; // Compute dual right now. 1010 1011 // Convenience common pre-built types. 1012 static const TypeAryPtr *RANGE; 1013 static const TypeAryPtr *OOPS; 1501 return (_base == NarrowOop) ? is_narrowoop()->get_ptrtype()->is_oopptr() : is_oopptr(); 1502 } 1503 1504 inline const TypeNarrowOop* Type::make_narrowoop() const { 1505 return (_base == NarrowOop) ? is_narrowoop() : 1506 (isa_ptr() ? TypeNarrowOop::make(is_ptr()) : NULL); 1507 } 1508 1509 inline const TypeNarrowKlass* Type::make_narrowklass() const { 1510 return (_base == NarrowKlass) ? is_narrowklass() : 1511 (isa_ptr() ? TypeNarrowKlass::make(is_ptr()) : NULL); 1512 } 1513 1514 inline bool Type::is_floatingpoint() const { 1515 if( (_base == FloatCon) || (_base == FloatBot) || 1516 (_base == DoubleCon) || (_base == DoubleBot) ) 1517 return true; 1518 return false; 1519 } 1520 1521 inline bool Type::is_ptr_to_boxing_obj() const { 1522 const TypeInstPtr* tp = isa_instptr(); 1523 return (tp != NULL) && (tp->offset() == 0) && 1524 tp->klass()->is_instance_klass() && 1525 tp->klass()->as_instance_klass()->is_box_klass(); 1526 } 1527 1528 1529 // =============================================================== 1530 // Things that need to be 64-bits in the 64-bit build but 1531 // 32-bits in the 32-bit build. Done this way to get full 1532 // optimization AND strong typing. 1533 #ifdef _LP64 1534 1535 // For type queries and asserts 1536 #define is_intptr_t is_long 1537 #define isa_intptr_t isa_long 1538 #define find_intptr_t_type find_long_type 1539 #define find_intptr_t_con find_long_con 1540 #define TypeX TypeLong 1541 #define Type_X Type::Long 1542 #define TypeX_X TypeLong::LONG 1543 #define TypeX_ZERO TypeLong::ZERO 1544 // For 'ideal_reg' machine registers 1545 #define Op_RegX Op_RegL 1546 // For phase->intcon variants 1547 #define MakeConX longcon |