142 static Dict* _shared_type_dict;
143 static TypeInfo _type_info[];
144
145 static int uhash( const Type *const t );
146 // Structural equality check. Assumes that cmp() has already compared
147 // the _base types and thus knows it can cast 't' appropriately.
148 virtual bool eq( const Type *t ) const;
149
150 // Top-level hash-table of types
151 static Dict *type_dict() {
152 return Compile::current()->type_dict();
153 }
154
155 // DUAL operation: reflect around lattice centerline. Used instead of
156 // join to ensure my lattice is symmetric up and down. Dual is computed
157 // lazily, on demand, and cached in _dual.
158 const Type *_dual; // Cached dual value
159 // Table for efficient dualing of base types
160 static const TYPES dual_type[lastype];
161
162 protected:
163 // Each class of type is also identified by its base.
164 const TYPES _base; // Enum of Types type
165
166 Type( TYPES t ) : _dual(NULL), _base(t) {} // Simple types
167 // ~Type(); // Use fast deallocation
168 const Type *hashcons(); // Hash-cons the type
169
170 public:
171
172 inline void* operator new( size_t x ) throw() {
173 Compile* compile = Compile::current();
174 compile->set_type_last_size(x);
175 void *temp = compile->type_arena()->Amalloc_D(x);
176 compile->set_type_hwm(temp);
177 return temp;
178 }
179 inline void operator delete( void* ptr ) {
180 Compile* compile = Compile::current();
181 compile->type_arena()->Afree(ptr,compile->type_last_size());
359 static const Type *HALF;
360 static const Type *MEMORY;
361 static const Type *MULTI;
362 static const Type *RETURN_ADDRESS;
363 static const Type *TOP;
364
365 // Mapping from compiler type to VM BasicType
366 BasicType basic_type() const { return _type_info[_base].basic_type; }
367 int ideal_reg() const { return _type_info[_base].ideal_reg; }
368 const char* msg() const { return _type_info[_base].msg; }
369 bool isa_oop_ptr() const { return _type_info[_base].isa_oop; }
370 relocInfo::relocType reloc() const { return _type_info[_base].reloc; }
371
372 // Mapping from CI type system to compiler type:
373 static const Type* get_typeflow_type(ciType* type);
374
375 static const Type* make_from_constant(ciConstant constant,
376 bool require_constant = false,
377 bool is_autobox_cache = false);
378
379 private:
380 // support arrays
381 static const BasicType _basic_type[];
382 static const Type* _zero_type[T_CONFLICT+1];
383 static const Type* _const_basic_type[T_CONFLICT+1];
384 };
385
386 //------------------------------TypeF------------------------------------------
387 // Class of Float-Constant Types.
388 class TypeF : public Type {
389 TypeF( float f ) : Type(FloatCon), _f(f) {};
390 public:
391 virtual bool eq( const Type *t ) const;
392 virtual int hash() const; // Type specific hashing
393 virtual bool singleton(void) const; // TRUE if type is a singleton
394 virtual bool empty(void) const; // TRUE if type is vacuous
395 public:
396 const float _f; // Float constant
397
398 static const TypeF *make(float f);
767 virtual const Type *cast_to_ptr_type(PTR ptr) const;
768
769 virtual intptr_t get_con() const;
770
771 virtual const TypePtr *add_offset( intptr_t offset ) const;
772
773 virtual const Type *xmeet( const Type *t ) const;
774 virtual const Type *xdual() const; // Compute dual right now.
775 // Convenience common pre-built types.
776 static const TypeRawPtr *BOTTOM;
777 static const TypeRawPtr *NOTNULL;
778 #ifndef PRODUCT
779 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
780 #endif
781 };
782
783 //------------------------------TypeOopPtr-------------------------------------
784 // Some kind of oop (Java pointer), either klass or instance or array.
785 class TypeOopPtr : public TypePtr {
786 protected:
787 TypeOopPtr( TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
788 public:
789 virtual bool eq( const Type *t ) const;
790 virtual int hash() const; // Type specific hashing
791 virtual bool singleton(void) const; // TRUE if type is a singleton
792 enum {
793 InstanceTop = -1, // undefined instance
794 InstanceBot = 0 // any possible instance
795 };
796 protected:
797
798 // Oop is NULL, unless this is a constant oop.
799 ciObject* _const_oop; // Constant oop
800 // If _klass is NULL, then so is _sig. This is an unloaded klass.
801 ciKlass* _klass; // Klass object
802 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
803 bool _klass_is_exact;
804 bool _is_ptr_to_narrowoop;
805 bool _is_ptr_to_narrowklass;
806 bool _is_ptr_to_boxed_value;
807
808 // If not InstanceTop or InstanceBot, indicates that this is
809 // a particular instance of this type which is distinct.
810 // This is the the node index of the allocation node creating this instance.
811 int _instance_id;
812
813 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
814
815 int dual_instance_id() const;
816 int meet_instance_id(int uid) const;
817
818 public:
819 // Creates a type given a klass. Correctly handles multi-dimensional arrays
820 // Respects UseUniqueSubclasses.
821 // If the klass is final, the resulting type will be exact.
822 static const TypeOopPtr* make_from_klass(ciKlass* klass) {
823 return make_from_klass_common(klass, true, false);
824 }
825 // Same as before, but will produce an exact type, even if
826 // the klass is not final, as long as it has exactly one implementation.
827 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
828 return make_from_klass_common(klass, true, true);
829 }
830 // Same as before, but does not respects UseUniqueSubclasses.
831 // Use this only for creating array element types.
832 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
833 return make_from_klass_common(klass, false, false);
834 }
835 // Creates a singleton type given an object.
836 // If the object cannot be rendered as a constant,
837 // may return a non-singleton type.
838 // If require_constant, produce a NULL if a singleton is not possible.
839 static const TypeOopPtr* make_from_constant(ciObject* o,
840 bool require_constant = false,
841 bool not_null_elements = false);
842
843 // Make a generic (unclassed) pointer to an oop.
844 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id);
845
846 ciObject* const_oop() const { return _const_oop; }
847 virtual ciKlass* klass() const { return _klass; }
848 bool klass_is_exact() const { return _klass_is_exact; }
849
850 // Returns true if this pointer points at memory which contains a
851 // compressed oop references.
852 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
853 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; }
855 bool is_known_instance() const { return _instance_id > 0; }
856 int instance_id() const { return _instance_id; }
857 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
858
859 virtual intptr_t get_con() const;
860
861 virtual const Type *cast_to_ptr_type(PTR ptr) const;
862
863 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
864
865 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
866
867 // corresponding pointer to klass, for a given instance
868 const TypeKlassPtr* as_klass_type() const;
869
870 virtual const TypePtr *add_offset( intptr_t offset ) const;
871
872 virtual const Type *xmeet( const Type *t ) const;
873 virtual const Type *xdual() const; // Compute dual right now.
874
875 // Do not allow interface-vs.-noninterface joins to collapse to top.
876 virtual const Type *filter( const Type *kills ) const;
877
878 // Convenience common pre-built type.
879 static const TypeOopPtr *BOTTOM;
880 #ifndef PRODUCT
881 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
882 #endif
883 };
884
885 //------------------------------TypeInstPtr------------------------------------
886 // Class of Java object pointers, pointing either to non-array Java instances
887 // or to a Klass* (including array klasses).
888 class TypeInstPtr : public TypeOopPtr {
889 TypeInstPtr( PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id );
890 virtual bool eq( const Type *t ) const;
891 virtual int hash() const; // Type specific hashing
892
893 ciSymbol* _name; // class name
894
895 public:
896 ciSymbol* name() const { return _name; }
897
898 bool is_loaded() const { return _klass->is_loaded(); }
899
900 // Make a pointer to a constant oop.
901 static const TypeInstPtr *make(ciObject* o) {
902 return make(TypePtr::Constant, o->klass(), true, o, 0);
903 }
904 // Make a pointer to a constant oop with offset.
905 static const TypeInstPtr *make(ciObject* o, int offset) {
906 return make(TypePtr::Constant, o->klass(), true, o, offset);
907 }
908
909 // Make a pointer to some value of type klass.
910 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
911 return make(ptr, klass, false, NULL, 0);
912 }
913
914 // Make a pointer to some non-polymorphic value of exactly type klass.
915 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
916 return make(ptr, klass, true, NULL, 0);
917 }
918
919 // Make a pointer to some value of type klass with offset.
920 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
921 return make(ptr, klass, false, NULL, offset);
922 }
923
924 // 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 );
926
927 /** Create constant type for a constant boxed value */
928 const Type* get_const_boxed_value() const;
929
930 // If this is a java.lang.Class constant, return the type for it or NULL.
931 // Pass to Type::get_const_type to turn it to a type, which will usually
932 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
933 ciType* java_mirror_type() const;
934
935 virtual const Type *cast_to_ptr_type(PTR ptr) const;
936
937 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
938
939 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
940
941 virtual const TypePtr *add_offset( intptr_t offset ) const;
942
943 virtual const Type *xmeet( const Type *t ) const;
944 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
945 virtual const Type *xdual() const; // Compute dual right now.
946
947 // Convenience common pre-built types.
948 static const TypeInstPtr *NOTNULL;
949 static const TypeInstPtr *BOTTOM;
950 static const TypeInstPtr *MIRROR;
951 static const TypeInstPtr *MARK;
952 static const TypeInstPtr *KLASS;
953 #ifndef PRODUCT
954 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
955 #endif
956 };
957
958 //------------------------------TypeAryPtr-------------------------------------
959 // Class of Java array pointers
960 class TypeAryPtr : public TypeOopPtr {
961 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
962 int offset, int instance_id, bool is_autobox_cache )
963 : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id),
964 _ary(ary),
965 _is_autobox_cache(is_autobox_cache)
966 {
967 #ifdef ASSERT
968 if (k != NULL) {
969 // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
970 ciKlass* ck = compute_klass(true);
971 if (k != ck) {
972 this->dump(); tty->cr();
973 tty->print(" k: ");
974 k->print(); tty->cr();
975 tty->print("ck: ");
976 if (ck != NULL) ck->print();
977 else tty->print("<NULL>");
978 tty->cr();
979 assert(false, "unexpected TypeAryPtr::_klass");
980 }
981 }
982 #endif
983 }
984 virtual bool eq( const Type *t ) const;
985 virtual int hash() const; // Type specific hashing
986 const TypeAry *_ary; // Array we point into
987 const bool _is_autobox_cache;
988
989 ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
990
991 public:
992 // Accessors
993 ciKlass* klass() const;
994 const TypeAry* ary() const { return _ary; }
995 const Type* elem() const { return _ary->_elem; }
996 const TypeInt* size() const { return _ary->_size; }
997 bool is_stable() const { return _ary->_stable; }
998
999 bool is_autobox_cache() const { return _is_autobox_cache; }
1000
1001 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot);
1002 // 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);
1004
1005 // Return a 'ptr' version of this type
1006 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1007
1008 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1009
1010 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1011
1012 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1013 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1014
1015 virtual bool empty(void) const; // TRUE if type is vacuous
1016 virtual const TypePtr *add_offset( intptr_t offset ) const;
1017
1018 virtual const Type *xmeet( const Type *t ) const;
1019 virtual const Type *xdual() const; // Compute dual right now.
1020
1021 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1022 int stable_dimension() const;
1023
1024 // Convenience common pre-built types.
1025 static const TypeAryPtr *RANGE;
1026 static const TypeAryPtr *OOPS;
1027 static const TypeAryPtr *NARROWOOPS;
1028 static const TypeAryPtr *BYTES;
1029 static const TypeAryPtr *SHORTS;
1030 static const TypeAryPtr *CHARS;
1031 static const TypeAryPtr *INTS;
1032 static const TypeAryPtr *LONGS;
1033 static const TypeAryPtr *FLOATS;
1034 static const TypeAryPtr *DOUBLES;
1035 // selects one of the above:
1036 static const TypeAryPtr *get_array_body_type(BasicType elem) {
1037 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1038 return _array_body_type[elem];
|
142 static Dict* _shared_type_dict;
143 static TypeInfo _type_info[];
144
145 static int uhash( const Type *const t );
146 // Structural equality check. Assumes that cmp() has already compared
147 // the _base types and thus knows it can cast 't' appropriately.
148 virtual bool eq( const Type *t ) const;
149
150 // Top-level hash-table of types
151 static Dict *type_dict() {
152 return Compile::current()->type_dict();
153 }
154
155 // DUAL operation: reflect around lattice centerline. Used instead of
156 // join to ensure my lattice is symmetric up and down. Dual is computed
157 // lazily, on demand, and cached in _dual.
158 const Type *_dual; // Cached dual value
159 // Table for efficient dualing of base types
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
166
167 protected:
168 // Each class of type is also identified by its base.
169 const TYPES _base; // Enum of Types type
170
171 Type( TYPES t ) : _dual(NULL), _base(t) {} // Simple types
172 // ~Type(); // Use fast deallocation
173 const Type *hashcons(); // Hash-cons the type
174
175 public:
176
177 inline void* operator new( size_t x ) throw() {
178 Compile* compile = Compile::current();
179 compile->set_type_last_size(x);
180 void *temp = compile->type_arena()->Amalloc_D(x);
181 compile->set_type_hwm(temp);
182 return temp;
183 }
184 inline void operator delete( void* ptr ) {
185 Compile* compile = Compile::current();
186 compile->type_arena()->Afree(ptr,compile->type_last_size());
364 static const Type *HALF;
365 static const Type *MEMORY;
366 static const Type *MULTI;
367 static const Type *RETURN_ADDRESS;
368 static const Type *TOP;
369
370 // Mapping from compiler type to VM BasicType
371 BasicType basic_type() const { return _type_info[_base].basic_type; }
372 int ideal_reg() const { return _type_info[_base].ideal_reg; }
373 const char* msg() const { return _type_info[_base].msg; }
374 bool isa_oop_ptr() const { return _type_info[_base].isa_oop; }
375 relocInfo::relocType reloc() const { return _type_info[_base].reloc; }
376
377 // Mapping from CI type system to compiler type:
378 static const Type* get_typeflow_type(ciType* type);
379
380 static const Type* make_from_constant(ciConstant constant,
381 bool require_constant = false,
382 bool is_autobox_cache = false);
383
384 // Speculative type. See TypeInstPtr
385 virtual ciKlass* speculative_type() const { return NULL; }
386
387 private:
388 // support arrays
389 static const BasicType _basic_type[];
390 static const Type* _zero_type[T_CONFLICT+1];
391 static const Type* _const_basic_type[T_CONFLICT+1];
392 };
393
394 //------------------------------TypeF------------------------------------------
395 // Class of Float-Constant Types.
396 class TypeF : public Type {
397 TypeF( float f ) : Type(FloatCon), _f(f) {};
398 public:
399 virtual bool eq( const Type *t ) const;
400 virtual int hash() const; // Type specific hashing
401 virtual bool singleton(void) const; // TRUE if type is a singleton
402 virtual bool empty(void) const; // TRUE if type is vacuous
403 public:
404 const float _f; // Float constant
405
406 static const TypeF *make(float f);
775 virtual const Type *cast_to_ptr_type(PTR ptr) const;
776
777 virtual intptr_t get_con() const;
778
779 virtual const TypePtr *add_offset( intptr_t offset ) const;
780
781 virtual const Type *xmeet( const Type *t ) const;
782 virtual const Type *xdual() const; // Compute dual right now.
783 // Convenience common pre-built types.
784 static const TypeRawPtr *BOTTOM;
785 static const TypeRawPtr *NOTNULL;
786 #ifndef PRODUCT
787 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
788 #endif
789 };
790
791 //------------------------------TypeOopPtr-------------------------------------
792 // Some kind of oop (Java pointer), either klass or instance or array.
793 class TypeOopPtr : public TypePtr {
794 protected:
795 TypeOopPtr(TYPES t, PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative);
796 public:
797 virtual bool eq( const Type *t ) const;
798 virtual int hash() const; // Type specific hashing
799 virtual bool singleton(void) const; // TRUE if type is a singleton
800 enum {
801 InstanceTop = -1, // undefined instance
802 InstanceBot = 0 // any possible instance
803 };
804 protected:
805
806 // Oop is NULL, unless this is a constant oop.
807 ciObject* _const_oop; // Constant oop
808 // If _klass is NULL, then so is _sig. This is an unloaded klass.
809 ciKlass* _klass; // Klass object
810 // Does the type exclude subclasses of the klass? (Inexact == polymorphic.)
811 bool _klass_is_exact;
812 bool _is_ptr_to_narrowoop;
813 bool _is_ptr_to_narrowklass;
814 bool _is_ptr_to_boxed_value;
815
816 // If not InstanceTop or InstanceBot, indicates that this is
817 // a particular instance of this type which is distinct.
818 // This is the the node index of the allocation node creating this instance.
819 int _instance_id;
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
827 static const TypeOopPtr* make_from_klass_common(ciKlass* klass, bool klass_change, bool try_for_exact);
828
829 int dual_instance_id() const;
830 int meet_instance_id(int uid) const;
831
832 // dual of the speculative part of the type
833 const TypeOopPtr* dual_speculative() const;
834 // meet of the speculative parts of 2 types
835 const TypeOopPtr* meet_speculative(const TypeOopPtr* other) const;
836 // Are the speculative parts of 2 types equal?
837 bool eq_speculative(const TypeOopPtr* other) const;
838 // Hash of the speculative part of the type
839 int hash_speculative() const;
840 // add offset to the speculative part of the type
841 const TypeOopPtr* add_offset_speculative(intptr_t offset) const;
842 #ifndef PRODUCT
843 // dump the speculative part of the type
844 void dump_speculative(outputStream *st) const;
845 #endif
846
847 public:
848 // Creates a type given a klass. Correctly handles multi-dimensional arrays
849 // Respects UseUniqueSubclasses.
850 // If the klass is final, the resulting type will be exact.
851 static const TypeOopPtr* make_from_klass(ciKlass* klass) {
852 return make_from_klass_common(klass, true, false);
853 }
854 // Same as before, but will produce an exact type, even if
855 // the klass is not final, as long as it has exactly one implementation.
856 static const TypeOopPtr* make_from_klass_unique(ciKlass* klass) {
857 return make_from_klass_common(klass, true, true);
858 }
859 // Same as before, but does not respects UseUniqueSubclasses.
860 // Use this only for creating array element types.
861 static const TypeOopPtr* make_from_klass_raw(ciKlass* klass) {
862 return make_from_klass_common(klass, false, false);
863 }
864 // Creates a singleton type given an object.
865 // If the object cannot be rendered as a constant,
866 // may return a non-singleton type.
867 // If require_constant, produce a NULL if a singleton is not possible.
868 static const TypeOopPtr* make_from_constant(ciObject* o,
869 bool require_constant = false,
870 bool not_null_elements = false);
871
872 // Make a generic (unclassed) pointer to an oop.
873 static const TypeOopPtr* make(PTR ptr, int offset, int instance_id, const TypeOopPtr* speculative);
874
875 ciObject* const_oop() const { return _const_oop; }
876 virtual ciKlass* klass() const { return _klass; }
877 bool klass_is_exact() const { return _klass_is_exact; }
878
879 // Returns true if this pointer points at memory which contains a
880 // compressed oop references.
881 bool is_ptr_to_narrowoop_nv() const { return _is_ptr_to_narrowoop; }
882 bool is_ptr_to_narrowklass_nv() const { return _is_ptr_to_narrowklass; }
883 bool is_ptr_to_boxed_value() const { return _is_ptr_to_boxed_value; }
884 bool is_known_instance() const { return _instance_id > 0; }
885 int instance_id() const { return _instance_id; }
886 bool is_known_instance_field() const { return is_known_instance() && _offset >= 0; }
887 const TypeOopPtr* speculative() const { return _speculative; }
888
889 virtual intptr_t get_con() const;
890
891 virtual const Type *cast_to_ptr_type(PTR ptr) const;
892
893 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
894
895 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
896
897 // corresponding pointer to klass, for a given instance
898 const TypeKlassPtr* as_klass_type() const;
899
900 virtual const TypePtr *add_offset( intptr_t offset ) const;
901 // Return same type without a speculative part
902 virtual const TypeOopPtr* remove_speculative() const;
903
904 virtual const Type *xmeet(const Type *t) const;
905 virtual const Type *xdual() const; // Compute dual right now.
906 // the core of the computation of the meet for TypeOopPtr and for its subclasses
907 virtual const Type *xmeet_helper(const Type *t) const;
908
909 // Do not allow interface-vs.-noninterface joins to collapse to top.
910 virtual const Type *filter( const Type *kills ) const;
911
912 // Convenience common pre-built type.
913 static const TypeOopPtr *BOTTOM;
914 #ifndef PRODUCT
915 virtual void dump2( Dict &d, uint depth, outputStream *st ) const;
916 #endif
917
918 // The speculative type if any: what klass we believe this is but a
919 // guard must be emitted
920 ciKlass* speculative_type() const {
921 if (_speculative != NULL) {
922 const TypeOopPtr* speculative = _speculative->join(this)->is_oopptr();
923 if (speculative->klass_is_exact()) {
924 return speculative->klass();
925 }
926 }
927 return NULL;
928 }
929 };
930
931 //------------------------------TypeInstPtr------------------------------------
932 // Class of Java object pointers, pointing either to non-array Java instances
933 // or to a Klass* (including array klasses).
934 class TypeInstPtr : public TypeOopPtr {
935 TypeInstPtr(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id, const TypeOopPtr* speculative);
936 virtual bool eq( const Type *t ) const;
937 virtual int hash() const; // Type specific hashing
938
939 ciSymbol* _name; // class name
940
941 public:
942 ciSymbol* name() const { return _name; }
943
944 bool is_loaded() const { return _klass->is_loaded(); }
945
946 // Make a pointer to a constant oop.
947 static const TypeInstPtr *make(ciObject* o) {
948 return make(TypePtr::Constant, o->klass(), true, o, 0, InstanceBot);
949 }
950 // Make a pointer to a constant oop with offset.
951 static const TypeInstPtr *make(ciObject* o, int offset) {
952 return make(TypePtr::Constant, o->klass(), true, o, offset, InstanceBot);
953 }
954
955 // Make a pointer to some value of type klass.
956 static const TypeInstPtr *make(PTR ptr, ciKlass* klass) {
957 return make(ptr, klass, false, NULL, 0, InstanceBot);
958 }
959
960 // Make a pointer to some non-polymorphic value of exactly type klass.
961 static const TypeInstPtr *make_exact(PTR ptr, ciKlass* klass) {
962 return make(ptr, klass, true, NULL, 0, InstanceBot);
963 }
964
965 // Make a pointer to some value of type klass with offset.
966 static const TypeInstPtr *make(PTR ptr, ciKlass* klass, int offset) {
967 return make(ptr, klass, false, NULL, offset, InstanceBot);
968 }
969
970 // Make a pointer to an oop.
971 static const TypeInstPtr *make(PTR ptr, ciKlass* k, bool xk, ciObject* o, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL);
972
973 /** Create constant type for a constant boxed value */
974 const Type* get_const_boxed_value() const;
975
976 // If this is a java.lang.Class constant, return the type for it or NULL.
977 // Pass to Type::get_const_type to turn it to a type, which will usually
978 // be a TypeInstPtr, but may also be a TypeInt::INT for int.class, etc.
979 ciType* java_mirror_type() const;
980
981 virtual const Type *cast_to_ptr_type(PTR ptr) const;
982
983 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
984
985 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
986
987 virtual const TypePtr *add_offset( intptr_t offset ) const;
988 // Return same type without a speculative part
989 virtual const TypeOopPtr* remove_speculative() const;
990
991 // the core of the computation of the meet of 2 types
992 virtual const Type *xmeet_helper(const Type *t) const;
993 virtual const TypeInstPtr *xmeet_unloaded( const TypeInstPtr *t ) const;
994 virtual const Type *xdual() const; // Compute dual right now.
995
996 // Convenience common pre-built types.
997 static const TypeInstPtr *NOTNULL;
998 static const TypeInstPtr *BOTTOM;
999 static const TypeInstPtr *MIRROR;
1000 static const TypeInstPtr *MARK;
1001 static const TypeInstPtr *KLASS;
1002 #ifndef PRODUCT
1003 virtual void dump2( Dict &d, uint depth, outputStream *st ) const; // Specialized per-Type dumping
1004 #endif
1005 };
1006
1007 //------------------------------TypeAryPtr-------------------------------------
1008 // Class of Java array pointers
1009 class TypeAryPtr : public TypeOopPtr {
1010 TypeAryPtr( PTR ptr, ciObject* o, const TypeAry *ary, ciKlass* k, bool xk,
1011 int offset, int instance_id, bool is_autobox_cache, const TypeOopPtr* speculative)
1012 : TypeOopPtr(AryPtr,ptr,k,xk,o,offset, instance_id, speculative),
1013 _ary(ary),
1014 _is_autobox_cache(is_autobox_cache)
1015 {
1016 #ifdef ASSERT
1017 if (k != NULL) {
1018 // Verify that specified klass and TypeAryPtr::klass() follow the same rules.
1019 ciKlass* ck = compute_klass(true);
1020 if (k != ck) {
1021 this->dump(); tty->cr();
1022 tty->print(" k: ");
1023 k->print(); tty->cr();
1024 tty->print("ck: ");
1025 if (ck != NULL) ck->print();
1026 else tty->print("<NULL>");
1027 tty->cr();
1028 assert(false, "unexpected TypeAryPtr::_klass");
1029 }
1030 }
1031 #endif
1032 }
1033 virtual bool eq( const Type *t ) const;
1034 virtual int hash() const; // Type specific hashing
1035 const TypeAry *_ary; // Array we point into
1036 const bool _is_autobox_cache;
1037
1038 ciKlass* compute_klass(DEBUG_ONLY(bool verify = false)) const;
1039
1040 public:
1041 // Accessors
1042 ciKlass* klass() const;
1043 const TypeAry* ary() const { return _ary; }
1044 const Type* elem() const { return _ary->_elem; }
1045 const TypeInt* size() const { return _ary->_size; }
1046 bool is_stable() const { return _ary->_stable; }
1047
1048 bool is_autobox_cache() const { return _is_autobox_cache; }
1049
1050 static const TypeAryPtr *make( PTR ptr, const TypeAry *ary, ciKlass* k, bool xk, int offset, int instance_id = InstanceBot, const TypeOopPtr* speculative = NULL);
1051 // Constant pointer to array
1052 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);
1053
1054 // Return a 'ptr' version of this type
1055 virtual const Type *cast_to_ptr_type(PTR ptr) const;
1056
1057 virtual const Type *cast_to_exactness(bool klass_is_exact) const;
1058
1059 virtual const TypeOopPtr *cast_to_instance_id(int instance_id) const;
1060
1061 virtual const TypeAryPtr* cast_to_size(const TypeInt* size) const;
1062 virtual const TypeInt* narrow_size_type(const TypeInt* size) const;
1063
1064 virtual bool empty(void) const; // TRUE if type is vacuous
1065 virtual const TypePtr *add_offset( intptr_t offset ) const;
1066 // Return same type without a speculative part
1067 virtual const TypeOopPtr* remove_speculative() const;
1068
1069 // the core of the computation of the meet of 2 types
1070 virtual const Type *xmeet_helper(const Type *t) const;
1071 virtual const Type *xdual() const; // Compute dual right now.
1072
1073 const TypeAryPtr* cast_to_stable(bool stable, int stable_dimension = 1) const;
1074 int stable_dimension() const;
1075
1076 // Convenience common pre-built types.
1077 static const TypeAryPtr *RANGE;
1078 static const TypeAryPtr *OOPS;
1079 static const TypeAryPtr *NARROWOOPS;
1080 static const TypeAryPtr *BYTES;
1081 static const TypeAryPtr *SHORTS;
1082 static const TypeAryPtr *CHARS;
1083 static const TypeAryPtr *INTS;
1084 static const TypeAryPtr *LONGS;
1085 static const TypeAryPtr *FLOATS;
1086 static const TypeAryPtr *DOUBLES;
1087 // selects one of the above:
1088 static const TypeAryPtr *get_array_body_type(BasicType elem) {
1089 assert((uint)elem <= T_CONFLICT && _array_body_type[elem] != NULL, "bad elem type");
1090 return _array_body_type[elem];
|