comparison src/share/vm/opto/type.hpp @ 12966:b2ee5dc63353

8024070: C2 needs some form of type speculation Summary: record unused type profile information with type system, propagate and use it. Reviewed-by: kvn, twisti
author roland
date Wed, 23 Oct 2013 12:40:23 +0200
parents c9ccd7b85f20
children 59e8ad757e19
comparison
equal deleted inserted replaced
12965:8b4bbba322d3 12966:b2ee5dc63353
156 // join to ensure my lattice is symmetric up and down. Dual is computed 156 // join to ensure my lattice is symmetric up and down. Dual is computed
157 // lazily, on demand, and cached in _dual. 157 // lazily, on demand, and cached in _dual.
158 const Type *_dual; // Cached dual value 158 const Type *_dual; // Cached dual value
159 // Table for efficient dualing of base types 159 // Table for efficient dualing of base types
160 static const TYPES dual_type[lastype]; 160 static const TYPES dual_type[lastype];
161
162 #ifdef ASSERT
163 // One type is interface, the other is oop
164 virtual bool interface_vs_oop_helper(const Type *t) const;
165 #endif
161 166
162 protected: 167 protected:
163 // Each class of type is also identified by its base. 168 // Each class of type is also identified by its base.
164 const TYPES _base; // Enum of Types type 169 const TYPES _base; // Enum of Types type
165 170
374 379
375 static const Type* make_from_constant(ciConstant constant, 380 static const Type* make_from_constant(ciConstant constant,
376 bool require_constant = false, 381 bool require_constant = false,
377 bool is_autobox_cache = false); 382 bool is_autobox_cache = false);
378 383
384 // Speculative type. See TypeInstPtr
385 virtual ciKlass* speculative_type() const { return NULL; }
386
379 private: 387 private:
380 // support arrays 388 // support arrays
381 static const BasicType _basic_type[]; 389 static const BasicType _basic_type[];
382 static const Type* _zero_type[T_CONFLICT+1]; 390 static const Type* _zero_type[T_CONFLICT+1];
383 static const Type* _const_basic_type[T_CONFLICT+1]; 391 static const Type* _const_basic_type[T_CONFLICT+1];
782 790
783 //------------------------------TypeOopPtr------------------------------------- 791 //------------------------------TypeOopPtr-------------------------------------
784 // Some kind of oop (Java pointer), either klass or instance or array. 792 // Some kind of oop (Java pointer), either klass or instance or array.
785 class TypeOopPtr : public TypePtr { 793 class TypeOopPtr : public TypePtr {
786 protected: 794 protected:
787 TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id ); 795 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative);
788 public: 796 public:
789 virtual bool eq( const Type *t ) const; 797 virtual bool eq( const Type *t ) const;
790 virtual int hash() const; // Type specific hashing 798 virtual int hash() const; // Type specific hashing
791 virtual bool singleton(void) const; // TRUE if type is a singleton 799 virtual bool singleton(void) const; // TRUE if type is a singleton
792 enum { 800 enum {
808 // If not InstanceTop or InstanceBot, indicates that this is 816 // If not InstanceTop or InstanceBot, indicates that this is
809 // a particular instance of this type which is distinct. 817 // a particular instance of this type which is distinct.
810 // This is the the node index of the allocation node creating this instance. 818 // This is the the node index of the allocation node creating this instance.
811 int _instance_id; 819 int _instance_id;
812 820
821 // Extra type information profiling gave us. We propagate it the
822 // same way the rest of the type info is propagated. If we want to
823 // use it, then we have to emit a guard: this part of the type is
824 // not something we know but something we speculate about the type.
825 const TypeOopPtr* _speculative;
826
813 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact); 827 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
814 828
815 int dual_instance_id() const; 829 int dual_instance_id() const;
816 int meet_instance_id(int uid) const; 830 int meet_instance_id(int uid) const;
831
832 // utility methods to work on the speculative part of the type
833 const TypeOopPtr* dual_speculative() const;
834 const TypeOopPtr* meet_speculative(const TypeOopPtr* other) const;
835 bool eq_speculative(const TypeOopPtr* other) const;
836 int hash_speculative() const;
837 const TypeOopPtr* add_offset_speculative(intptr_t offset) const;
838 #ifndef PRODUCT
839 void dump_speculative(outputStream *st) const;
840 #endif
817 841
818 public: 842 public:
819 // Creates a type given a klass. Correctly handles multi-dimensional arrays 843 // Creates a type given a klass. Correctly handles multi-dimensional arrays
820 // Respects UseUniqueSubclasses. 844 // Respects UseUniqueSubclasses.
821 // If the klass is final, the resulting type will be exact. 845 // If the klass is final, the resulting type will be exact.
839 static const TypeOopPtr* make_from_constant(ciObject* o, 863 static const TypeOopPtr* make_from_constant(ciObject* o,
840 bool require_constant = false, 864 bool require_constant = false,
841 bool not_null_elements = false); 865 bool not_null_elements = false);
842 866
843 // Make a generic (unclassed) pointer to an oop. 867 // Make a generic (unclassed) pointer to an oop.
844 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id); 868 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id, const TypeOopPtr* speculative);
845 869
846 ciObject* const_oop() const { return _const_oop; } 870 ciObject* const_oop() const { return _const_oop; }
847 virtual ciKlass* klass() const { return _klass; } 871 virtual ciKlass* klass() const { return _klass; }
848 bool klass_is_exact() const { return _klass_is_exact; } 872 bool klass_is_exact() const { return _klass_is_exact; }
849 873
853 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; } 877 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
854 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; } 878 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; }
855 bool is_known_instance() const { return _instance_id > 0; } 879 bool is_known_instance() const { return _instance_id > 0; }
856 int instance_id() const { return _instance_id; } 880 int instance_id() const { return _instance_id; }
857 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; } 881 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
882 const TypeOopPtr* speculative() const { return _speculative; }
858 883
859 virtual intptr_t get_con() const; 884 virtual intptr_t get_con() const;
860 885
861 virtual const Type *cast_to_ptr_type(PTR ptr) const; 886 virtual const Type *cast_to_ptr_type(PTR ptr) const;
862 887
866 891
867 // corresponding pointer to klass, for a given instance 892 // corresponding pointer to klass, for a given instance
868 const TypeKlassPtr* as_klass_type() const; 893 const TypeKlassPtr* as_klass_type() const;
869 894
870 virtual const TypePtr *add_offset( intptr_t offset ) const; 895 virtual const TypePtr *add_offset( intptr_t offset ) const;
871 896 // Return same type without a speculative part
872 virtual const Type *xmeet( const Type *t ) const; 897 virtual const TypeOopPtr* remove_speculative() const;
898
899 virtual const Type *xmeet(const Type *t) const;
873 virtual const Type *xdual() const; // Compute dual right now. 900 virtual const Type *xdual() const; // Compute dual right now.
901 // the core of the computation of the meet for TypeOopPtr and for its subclasses
902 virtual const Type *xmeet_helper(const Type *t) const;
874 903
875 // Do not allow interface-vs.-noninterface joins to collapse to top. 904 // Do not allow interface-vs.-noninterface joins to collapse to top.
876 virtual const Type *filter( const Type *kills ) const; 905 virtual const Type *filter( const Type *kills ) const;
877 906
878 // Convenience common pre-built type. 907 // Convenience common pre-built type.
879 static const TypeOopPtr *BOTTOM; 908 static const TypeOopPtr *BOTTOM;
880 #ifndef PRODUCT 909 #ifndef PRODUCT
881 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; 910 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
882 #endif 911 #endif
912
913 // Return the speculative type if any
914 ciKlass* speculative_type() const {
915 if (_speculative != NULL) {
916 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
917 if (speculative->klass_is_exact()) {
918 return speculative->klass();
919 }
920 }
921 return NULL;
922 }
883 }; 923 };
884 924
885 //------------------------------TypeInstPtr------------------------------------ 925 //------------------------------TypeInstPtr------------------------------------
886 // Class of Java object pointers, pointing either to non-array Java instances 926 // Class of Java object pointers, pointing either to non-array Java instances
887 // or to a Klass* (including array klasses). 927 // or to a Klass* (including array klasses).
888 class TypeInstPtr : public TypeOopPtr { 928 class TypeInstPtr : public TypeOopPtr {
889 TypeInstPtr( PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id ); 929 TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative);
890 virtual bool eq( const Type *t ) const; 930 virtual bool eq( const Type *t ) const;
891 virtual int hash() const; // Type specific hashing 931 virtual int hash() const; // Type specific hashing
892 932
893 ciSymbol* _name; // class name 933 ciSymbol* _name; // class name
894 934
897 937
898 bool is_loaded() const { return _klass->is_loaded(); } 938 bool is_loaded() const { return _klass->is_loaded(); }
899 939
900 // Make a pointer to a constant oop. 940 // Make a pointer to a constant oop.
901 static const TypeInstPtr *make(ciObject* o) { 941 static const TypeInstPtr *make(ciObject* o) {
902 return make(TypePtr::Constant, o->klass(), true, o, 0); 942 return make(TypePtr::Constant, o->klass(), true, o, 0, InstanceBot);
903 } 943 }
904 // Make a pointer to a constant oop with offset. 944 // Make a pointer to a constant oop with offset.
905 static const TypeInstPtr *make(ciObject* o, int offset) { 945 static const TypeInstPtr *make(ciObject* o, int offset) {
906 return make(TypePtr::Constant, o->klass(), true, o, offset); 946 return make(TypePtr::Constant, o->klass(), true, o, offset, InstanceBot);
907 } 947 }
908 948
909 // Make a pointer to some value of type klass. 949 // Make a pointer to some value of type klass.
910 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) { 950 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
911 return make(ptr, klass, false, NULL, 0); 951 return make(ptr, klass, false, NULL, 0, InstanceBot);
912 } 952 }
913 953
914 // Make a pointer to some non-polymorphic value of exactly type klass. 954 // Make a pointer to some non-polymorphic value of exactly type klass.
915 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) { 955 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
916 return make(ptr, klass, true, NULL, 0); 956 return make(ptr, klass, true, NULL, 0, InstanceBot);
917 } 957 }
918 958
919 // Make a pointer to some value of type klass with offset. 959 // Make a pointer to some value of type klass with offset.
920 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) { 960 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
921 return make(ptr, klass, false, NULL, offset); 961 return make(ptr, klass, false, NULL, offset, InstanceBot);
922 } 962 }
923 963
924 // Make a pointer to an oop. 964 // Make a pointer to an oop.
925 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot ); 965 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL);
926 966
927 /** Create constant type for a constant boxed value */ 967 /** Create constant type for a constant boxed value */
928 const Type* get_const_boxed_value() const; 968 const Type* get_const_boxed_value() const;
929 969
930 // If this is a java.lang.Class constant, return the type for it or NULL. 970 // If this is a java.lang.Class constant, return the type for it or NULL.
937 virtual const Type *cast_to_exactness(bool klass_is_exact) const; 977 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
938 978
939 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const; 979 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
940 980
941 virtual const TypePtr *add_offset( intptr_t offset ) const; 981 virtual const TypePtr *add_offset( intptr_t offset ) const;
942 982 // Return same type without a speculative part
943 virtual const Type *xmeet( const Type *t ) const; 983 virtual const TypeOopPtr* remove_speculative() const;
984
985 // the core of the computation of the meet of 2 types
986 virtual const Type *xmeet_helper(const Type *t) const;
944 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const; 987 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
945 virtual const Type *xdual() const; // Compute dual right now. 988 virtual const Type *xdual() const; // Compute dual right now.
946 989
947 // Convenience common pre-built types. 990 // Convenience common pre-built types.
948 static const TypeInstPtr *NOTNULL; 991 static const TypeInstPtr *NOTNULL;
957 1000
958 //------------------------------TypeAryPtr------------------------------------- 1001 //------------------------------TypeAryPtr-------------------------------------
959 // Class of Java array pointers 1002 // Class of Java array pointers
960 class TypeAryPtr : public TypeOopPtr { 1003 class TypeAryPtr : public TypeOopPtr {
961 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, 1004 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
962 int offset, int instance_id, bool is_autobox_cache ) 1005 int offset, int instance_id, bool is_autobox_cache, const TypeOopPtr* speculative)
963 : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id), 1006 : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id, speculative),
964 _ary(ary), 1007 _ary(ary),
965 _is_autobox_cache(is_autobox_cache) 1008 _is_autobox_cache(is_autobox_cache)
966 { 1009 {
967 #ifdef ASSERT 1010 #ifdef ASSERT
968 if (k != NULL) { 1011 if (k != NULL) {
996 const TypeInt* size() const { return _ary->_size; } 1039 const TypeInt* size() const { return _ary->_size; }
997 bool is_stable() const { return _ary->_stable; } 1040 bool is_stable() const { return _ary->_stable; }
998 1041
999 bool is_autobox_cache() const { return _is_autobox_cache; } 1042 bool is_autobox_cache() const { return _is_autobox_cache; }
1000 1043
1001 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot); 1044 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL);
1002 // Constant pointer to array 1045 // Constant pointer to array
1003 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); 1046 static const TypeAryPtr *make( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL, bool is_autobox_cache = false);
1004 1047
1005 // Return a 'ptr' version of this type 1048 // Return a 'ptr' version of this type
1006 virtual const Type *cast_to_ptr_type(PTR ptr) const; 1049 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1007 1050
1008 virtual const Type *cast_to_exactness(bool klass_is_exact) const; 1051 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1012 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const; 1055 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1013 virtual const TypeInt* narrow_size_type(const TypeInt* size) const; 1056 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1014 1057
1015 virtual bool empty(void) const; // TRUE if type is vacuous 1058 virtual bool empty(void) const; // TRUE if type is vacuous
1016 virtual const TypePtr *add_offset( intptr_t offset ) const; 1059 virtual const TypePtr *add_offset( intptr_t offset ) const;
1017 1060 // Return same type without a speculative part
1018 virtual const Type *xmeet( const Type *t ) const; 1061 virtual const TypeOopPtr* remove_speculative() const;
1062
1063 // the core of the computation of the meet of 2 types
1064 virtual const Type *xmeet_helper(const Type *t) const;
1019 virtual const Type *xdual() const; // Compute dual right now. 1065 virtual const Type *xdual() const; // Compute dual right now.
1020 1066
1021 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const; 1067 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1022 int stable_dimension() const; 1068 int stable_dimension() const;
1023 1069