src/share/vm/oops/methodData.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/oops

src/share/vm/oops/methodData.hpp

Print this page
rev 5403 : 8023657: New type profiling points: arguments to call
Summary: x86 interpreter and c1 type profiling for arguments at calls
Reviewed-by: kvn, twisti
rev 5404 : 8026054: New type profiling points: type of return values at calls
Summary: x86 interpreter and c1 type profiling for return values at calls
Reviewed-by:
rev 5405 : imported patch kvn
rev 5406 : imported patch twisti
rev 5407 : imported patch fixreturn


 254 class ProfileData;
 255 class   BitData;
 256 class     CounterData;
 257 class       ReceiverTypeData;
 258 class         VirtualCallData;
 259 class           VirtualCallTypeData;
 260 class       RetData;
 261 class       CallTypeData;
 262 class   JumpData;
 263 class     BranchData;
 264 class   ArrayData;
 265 class     MultiBranchData;
 266 class     ArgInfoData;
 267 
 268 // ProfileData
 269 //
 270 // A ProfileData object is created to refer to a section of profiling
 271 // data in a structured way.
 272 class ProfileData : public ResourceObj {
 273   friend class TypeEntries;

 274   friend class TypeStackSlotEntries;
 275 private:
 276 #ifndef PRODUCT
 277   enum {
 278     tab_width_one = 16,
 279     tab_width_two = 36
 280   };
 281 #endif // !PRODUCT
 282 
 283   // This is a pointer to a section of profiling data.
 284   DataLayout* _data;
 285 
 286 protected:
 287   DataLayout* data() { return _data; }
 288   const DataLayout* data() const { return _data; }
 289 
 290   enum {
 291     cell_size = DataLayout::cell_size
 292   };
 293 


 731 public:
 732   void set_profile_data(ProfileData* pd) {
 733     _pd = pd;
 734   }
 735 };
 736 
 737 // Type entries used for arguments passed at a call and parameters on
 738 // method entry. 2 cells per entry: one for the type encoded as in
 739 // TypeEntries and one initialized with the stack slot where the
 740 // profiled object is to be found so that the interpreter can locate
 741 // it quickly.
 742 class TypeStackSlotEntries : public TypeEntries {
 743 
 744 private:
 745   enum {
 746     stack_slot_entry,
 747     type_entry,
 748     per_arg_cell_count
 749   };
 750 
 751   // Start with a header if needed. It stores the number of cells used
 752   // for this call type information. Unless we collect only profiling
 753   // for a single argument the number of cells is unknown statically.
 754   static int header_cell_count() {
 755     return (TypeProfileArgsLimit > 1) ? 1 : 0;
 756   }
 757 
 758   static int cell_count_local_offset() {
 759      assert(arguments_profiling_enabled() && TypeProfileArgsLimit > 1, "no cell count");
 760      return 0;
 761    }
 762 
 763   int cell_count_global_offset() const {
 764     return _base_off + cell_count_local_offset();
 765   }
 766 
 767   // offset of cell for stack slot for entry i within ProfileData object
 768   int stack_slot_global_offset(int i) const {
 769     return _base_off + stack_slot_local_offset(i);
 770   }
 771 
 772   void check_number_of_arguments(int total) {
 773     assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
 774   }
 775 
 776   // number of cells not counting the header
 777   int cell_count_no_header() const {
 778     return _pd->uint_at(cell_count_global_offset());
 779   }
 780 
 781   static bool arguments_profiling_enabled();
 782   static void assert_arguments_profiling_enabled() {
 783     assert(arguments_profiling_enabled(), "args profiling should be on");
 784   }
 785 
 786 protected:

 787 
 788   // offset of cell for type for entry i within ProfileData object
 789   int type_global_offset(int i) const {
 790     return _base_off + type_local_offset(i);
 791   }
 792 
 793 public:
 794 
 795   TypeStackSlotEntries(int base_off)
 796     : TypeEntries(base_off) {}
 797 
 798   static int compute_cell_count(BytecodeStream* stream);
 799 
 800   static void initialize(DataLayout* dl, int base, int cell_count) {
 801     if (TypeProfileArgsLimit > 1) {
 802       int off = base + cell_count_local_offset();
 803       dl->set_cell_at(off, cell_count - base - header_cell_count());
 804     }
 805   }
 806 
 807   void post_initialize(BytecodeStream* stream);
 808 
 809   int number_of_arguments() const {
 810     assert_arguments_profiling_enabled();
 811     if (TypeProfileArgsLimit > 1) {
 812       int cell_count = cell_count_no_header();
 813       int nb = cell_count / TypeStackSlotEntries::per_arg_count();
 814       assert(nb > 0 && nb <= TypeProfileArgsLimit , "only when we profile args");
 815       return nb;
 816     } else {
 817       assert(TypeProfileArgsLimit == 1, "at least one arg");
 818       return 1;
 819     }
 820   }
 821 
 822   int cell_count() const {
 823     assert_arguments_profiling_enabled();
 824     if (TypeProfileArgsLimit > 1) {
 825       return _base_off + header_cell_count() + _pd->int_at_unchecked(cell_count_global_offset());
 826     } else {
 827       return _base_off + TypeStackSlotEntries::per_arg_count();
 828     }
 829   }
 830 
 831   // offset of cell for stack slot for entry i within this block of cells for a TypeStackSlotEntries
 832   static int stack_slot_local_offset(int i) {
 833     assert_arguments_profiling_enabled();
 834     return header_cell_count() + i * per_arg_cell_count + stack_slot_entry;
 835   }
 836 
 837   // offset of cell for type for entry i within this block of cells for a TypeStackSlotEntries
 838   static int type_local_offset(int i) {
 839     return header_cell_count() + i * per_arg_cell_count + type_entry;
 840   }
 841 
 842   // stack slot for entry i
 843   uint stack_slot(int i) const {
 844     assert(i >= 0 && i < number_of_arguments(), "oob");
 845     return _pd->uint_at(stack_slot_global_offset(i));
 846   }
 847 
 848   // set stack slot for entry i
 849   void set_stack_slot(int i, uint num) {
 850     assert(i >= 0 && i < number_of_arguments(), "oob");
 851     _pd->set_uint_at(stack_slot_global_offset(i), num);
 852   }
 853 
 854   // type for entry i
 855   intptr_t type(int i) const {
 856     assert(i >= 0 && i < number_of_arguments(), "oob");
 857     return _pd->intptr_at(type_global_offset(i));
 858   }
 859 
 860   // set type for entry i
 861   void set_type(int i, intptr_t k) {
 862     assert(i >= 0 && i < number_of_arguments(), "oob");
 863     _pd->set_intptr_at(type_global_offset(i), k);
 864   }
 865 
 866   static ByteSize per_arg_size() {
 867     return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
 868   }
 869 
 870   static int per_arg_count() {
 871     return per_arg_cell_count ;
 872   }
 873 
 874   // Code generation support
 875    static ByteSize cell_count_offset() {
 876      return in_ByteSize(cell_count_local_offset() * DataLayout::cell_size);




















 877    }
 878 
 879    static ByteSize args_data_offset() {
 880      return in_ByteSize(header_cell_count() * DataLayout::cell_size);
 881    }
 882 
 883    static ByteSize stack_slot_offset(int i) {
 884      return in_ByteSize(stack_slot_local_offset(i) * DataLayout::cell_size);








 885    }
 886 
 887    static ByteSize type_offset(int i) {
 888      return in_ByteSize(type_local_offset(i) * DataLayout::cell_size);
 889    }
 890 
 891   // GC support
 892   void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
 893 
 894 #ifndef PRODUCT
 895   void print_data_on(outputStream* st) const;
 896 #endif
 897 };
 898 























































 899 // CallTypeData
 900 //
 901 // A CallTypeData is used to access profiling information about a non
 902 // virtual call for which we collect type information about arguments.

 903 class CallTypeData : public CounterData {
 904 private:

 905   TypeStackSlotEntries _args;


























 906 
 907 public:
 908   CallTypeData(DataLayout* layout) :
 909     CounterData(layout), _args(CounterData::static_cell_count())  {



 910     assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type");
 911     // Some compilers (VC++) don't want this passed in member initialization list
 912     _args.set_profile_data(this);






 913   }
 914 
 915   const TypeStackSlotEntries* args() const { return &_args; }



 916 
 917   virtual bool is_CallTypeData() const { return true; }
 918 
 919   static int static_cell_count() {
 920     return -1;
 921   }
 922 
 923   static int compute_cell_count(BytecodeStream* stream) {
 924     return CounterData::static_cell_count() + TypeStackSlotEntries::compute_cell_count(stream);
 925   }
 926 
 927   static void initialize(DataLayout* dl, int cell_count) {
 928     TypeStackSlotEntries::initialize(dl, CounterData::static_cell_count(), cell_count);
 929   }
 930 
 931   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {
 932     _args.post_initialize(stream);
 933   }
 934 
 935   virtual int cell_count() const {
 936     return _args.cell_count();


 937   }
 938 
 939   uint number_of_arguments() const {
 940     return args()->number_of_arguments();
 941   }
 942 
 943   void set_argument_type(int i, Klass* k) {

 944     intptr_t current = _args.type(i);
 945     _args.set_type(i, TypeEntries::with_status(k, current));
 946   }
 947 
















 948   // Code generation support
 949   static ByteSize args_data_offset() {
 950     return cell_offset(CounterData::static_cell_count()) + TypeStackSlotEntries::args_data_offset();
 951   }
 952 
 953   // GC support
 954   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {

 955     _args.clean_weak_klass_links(is_alive_closure);
 956   }




 957 
 958 #ifndef PRODUCT
 959   virtual void print_data_on(outputStream* st) const;
 960 #endif
 961 };
 962 
 963 // ReceiverTypeData
 964 //
 965 // A ReceiverTypeData is used to access profiling information about a
 966 // dynamic type check.  It consists of a counter which counts the total times
 967 // that the check is reached, and a series of (Klass*, count) pairs
 968 // which are used to store a type profile for the receiver of the check.
 969 class ReceiverTypeData : public CounterData {
 970 protected:
 971   enum {
 972     receiver0_offset = counter_cell_count,
 973     count0_offset,
 974     receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
 975   };
 976 


1088   }
1089 
1090   virtual int cell_count() const {
1091     return static_cell_count();
1092   }
1093 
1094   // Direct accessors
1095   static ByteSize virtual_call_data_size() {
1096     return cell_offset(static_cell_count());
1097   }
1098 
1099 #ifndef PRODUCT
1100   void print_data_on(outputStream* st) const;
1101 #endif
1102 };
1103 
1104 // VirtualCallTypeData
1105 //
1106 // A VirtualCallTypeData is used to access profiling information about
1107 // a virtual call for which we collect type information about
1108 // arguments.
1109 class VirtualCallTypeData : public VirtualCallData {
1110 private:

1111   TypeStackSlotEntries _args;


























1112 
1113 public:
1114   VirtualCallTypeData(DataLayout* layout) :
1115     VirtualCallData(layout), _args(VirtualCallData::static_cell_count())  {



1116     assert(layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1117     // Some compilers (VC++) don't want this passed in member initialization list
1118     _args.set_profile_data(this);

1119   }
1120 
1121   const TypeStackSlotEntries* args() const { return &_args; }








1122 
1123   virtual bool is_VirtualCallTypeData() const { return true; }
1124 
1125   static int static_cell_count() {
1126     return -1;
1127   }
1128 
1129   static int compute_cell_count(BytecodeStream* stream) {
1130     return VirtualCallData::static_cell_count() + TypeStackSlotEntries::compute_cell_count(stream);
1131   }
1132 
1133   static void initialize(DataLayout* dl, int cell_count) {
1134     TypeStackSlotEntries::initialize(dl, VirtualCallData::static_cell_count(), cell_count);
1135   }
1136 
1137   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {
1138     _args.post_initialize(stream);
1139   }
1140 
1141   virtual int cell_count() const {
1142     return _args.cell_count();


1143   }
1144 
1145   uint number_of_arguments() const {
1146     return args()->number_of_arguments();
1147   }
1148 
1149   void set_argument_type(int i, Klass* k) {

1150     intptr_t current = _args.type(i);
1151     _args.set_type(i, TypeEntries::with_status(k, current));
1152   }
1153 
















1154   // Code generation support
1155   static ByteSize args_data_offset() {
1156     return cell_offset(VirtualCallData::static_cell_count()) + TypeStackSlotEntries::args_data_offset();
1157   }
1158 
1159   // GC support
1160   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1161     ReceiverTypeData::clean_weak_klass_links(is_alive_closure);

1162     _args.clean_weak_klass_links(is_alive_closure);
1163   }




1164 
1165 #ifndef PRODUCT
1166   virtual void print_data_on(outputStream* st) const;
1167 #endif
1168 };
1169 
1170 // RetData
1171 //
1172 // A RetData is used to access profiling information for a ret bytecode.
1173 // It is composed of a count of the number of times that the ret has
1174 // been executed, followed by a series of triples of the form
1175 // (bci, count, di) which count the number of times that some bci was the
1176 // target of the ret and cache a corresponding data displacement.
1177 class RetData : public CounterData {
1178 protected:
1179   enum {
1180     bci0_offset = counter_cell_count,
1181     count0_offset,
1182     displacement0_offset,
1183     ret_row_cell_count = (displacement0_offset + 1) - bci0_offset


1674   // What is the index of the first data entry?
1675   int first_di() const { return 0; }
1676 
1677   // Find or create an extra ProfileData:
1678   ProfileData* bci_to_extra_data(int bci, bool create_if_missing);
1679 
1680   // return the argument info cell
1681   ArgInfoData *arg_info();
1682 
1683   enum {
1684     no_type_profile = 0,
1685     type_profile_jsr292 = 1,
1686     type_profile_all = 2
1687   };
1688 
1689   static bool profile_jsr292(methodHandle m, int bci);
1690   static int profile_arguments_flag();
1691   static bool profile_arguments_jsr292_only();
1692   static bool profile_all_arguments();
1693   static bool profile_arguments_for_invoke(methodHandle m, int bci);



1694 
1695 public:
1696   static int header_size() {
1697     return sizeof(MethodData)/wordSize;
1698   }
1699 
1700   // Compute the size of a MethodData* before it is created.
1701   static int compute_allocation_size_in_bytes(methodHandle method);
1702   static int compute_allocation_size_in_words(methodHandle method);
1703   static int compute_extra_data_count(int data_size, int empty_bc_count);
1704 
1705   // Determine if a given bytecode can have profile information.
1706   static bool bytecode_has_profile(Bytecodes::Code code) {
1707     return bytecode_cell_count(code) != no_profile_data;
1708   }
1709 
1710   // reset into original state
1711   void init();
1712 
1713   // My size


1916   void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; }
1917 
1918   // Printing
1919 #ifndef PRODUCT
1920   void print_on      (outputStream* st) const;
1921 #endif
1922   void print_value_on(outputStream* st) const;
1923 
1924 #ifndef PRODUCT
1925   // printing support for method data
1926   void print_data_on(outputStream* st) const;
1927 #endif
1928 
1929   const char* internal_name() const { return "{method data}"; }
1930 
1931   // verification
1932   void verify_on(outputStream* st);
1933   void verify_data_on(outputStream* st);
1934 
1935   static bool profile_arguments();


1936 };
1937 
1938 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP


 254 class ProfileData;
 255 class   BitData;
 256 class     CounterData;
 257 class       ReceiverTypeData;
 258 class         VirtualCallData;
 259 class           VirtualCallTypeData;
 260 class       RetData;
 261 class       CallTypeData;
 262 class   JumpData;
 263 class     BranchData;
 264 class   ArrayData;
 265 class     MultiBranchData;
 266 class     ArgInfoData;
 267 
 268 // ProfileData
 269 //
 270 // A ProfileData object is created to refer to a section of profiling
 271 // data in a structured way.
 272 class ProfileData : public ResourceObj {
 273   friend class TypeEntries;
 274   friend class ReturnTypeEntry;
 275   friend class TypeStackSlotEntries;
 276 private:
 277 #ifndef PRODUCT
 278   enum {
 279     tab_width_one = 16,
 280     tab_width_two = 36
 281   };
 282 #endif // !PRODUCT
 283 
 284   // This is a pointer to a section of profiling data.
 285   DataLayout* _data;
 286 
 287 protected:
 288   DataLayout* data() { return _data; }
 289   const DataLayout* data() const { return _data; }
 290 
 291   enum {
 292     cell_size = DataLayout::cell_size
 293   };
 294 


 732 public:
 733   void set_profile_data(ProfileData* pd) {
 734     _pd = pd;
 735   }
 736 };
 737 
 738 // Type entries used for arguments passed at a call and parameters on
 739 // method entry. 2 cells per entry: one for the type encoded as in
 740 // TypeEntries and one initialized with the stack slot where the
 741 // profiled object is to be found so that the interpreter can locate
 742 // it quickly.
 743 class TypeStackSlotEntries : public TypeEntries {
 744 
 745 private:
 746   enum {
 747     stack_slot_entry,
 748     type_entry,
 749     per_arg_cell_count
 750   };
 751 
















 752   // offset of cell for stack slot for entry i within ProfileData object
 753   int stack_slot_offset(int i) const {
 754     return _base_off + stack_slot_local_offset(i);
 755   }
 756 














 757 protected:
 758   const int _number_of_entries;
 759 
 760   // offset of cell for type for entry i within ProfileData object
 761   int type_offset(int i) const {
 762     return _base_off + type_local_offset(i);
 763   }
 764 
 765 public:
 766 
 767   TypeStackSlotEntries(int base_off, int nb_entries)
 768     : TypeEntries(base_off), _number_of_entries(nb_entries) {}











 769 
 770   static int compute_cell_count(Symbol* signature, int max);











 771 
 772   void post_initialize(Symbol* signature, bool has_receiver);







 773 
 774   // offset of cell for stack slot for entry i within this block of cells for a TypeStackSlotEntries
 775   static int stack_slot_local_offset(int i) {
 776     return i * per_arg_cell_count + stack_slot_entry;

 777   }
 778 
 779   // offset of cell for type for entry i within this block of cells for a TypeStackSlotEntries
 780   static int type_local_offset(int i) {
 781     return i * per_arg_cell_count + type_entry;
 782   }
 783 
 784   // stack slot for entry i
 785   uint stack_slot(int i) const {
 786     assert(i >= 0 && i < _number_of_entries, "oob");
 787     return _pd->uint_at(stack_slot_offset(i));
 788   }
 789 
 790   // set stack slot for entry i
 791   void set_stack_slot(int i, uint num) {
 792     assert(i >= 0 && i < _number_of_entries, "oob");
 793     _pd->set_uint_at(stack_slot_offset(i), num);
 794   }
 795 
 796   // type for entry i
 797   intptr_t type(int i) const {
 798     assert(i >= 0 && i < _number_of_entries, "oob");
 799     return _pd->intptr_at(type_offset(i));
 800   }
 801 
 802   // set type for entry i
 803   void set_type(int i, intptr_t k) {
 804     assert(i >= 0 && i < _number_of_entries, "oob");
 805     _pd->set_intptr_at(type_offset(i), k);
 806   }
 807 
 808   static ByteSize per_arg_size() {
 809     return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
 810   }
 811 
 812   static int per_arg_count() {
 813     return per_arg_cell_count ;
 814   }
 815 
 816   // GC support
 817   void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
 818 
 819 #ifndef PRODUCT
 820   void print_data_on(outputStream* st) const;
 821 #endif
 822 };
 823 
 824 // Type entry used for return from a call. A single cell to record the
 825 // type.
 826 class ReturnTypeEntry : public TypeEntries {
 827 
 828 private:
 829   enum {
 830     cell_count = 1
 831   };
 832 
 833 public:
 834   ReturnTypeEntry(int base_off)
 835     : TypeEntries(base_off) {}
 836 
 837   void post_initialize() {
 838     set_type(type_none());
 839   }
 840 
 841   intptr_t type() const {
 842     return _pd->intptr_at(_base_off);
 843   }
 844 
 845   void set_type(intptr_t k) {
 846     _pd->set_intptr_at(_base_off, k);
 847   }
 848 
 849   static int static_cell_count() {
 850     return cell_count;
 851   }
 852 
 853   static ByteSize size() {
 854     return in_ByteSize(cell_count * DataLayout::cell_size);
 855   }
 856 
 857   ByteSize type_offset() {
 858     return DataLayout::cell_offset(_base_off);
 859   }
 860 
 861   // GC support
 862   void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
 863 
 864 #ifndef PRODUCT
 865   void print_data_on(outputStream* st) const;
 866 #endif
 867 };
 868 
 869 // Entries to collect type information at a call: contains arguments
 870 // (TypeStackSlotEntries), a return type (ReturnTypeEntry) and a
 871 // number of cells. Because the number of cells for the return type is
 872 // smaller than the number of cells for the type of an arguments, the
 873 // number of cells is used to tell how many arguments are profiled and
 874 // whether a return value is profiled. See has_arguments() and
 875 // has_return().
 876 class TypeEntriesAtCall {
 877 private:
 878   static int stack_slot_local_offset(int i) {
 879     return header_cell_count() + TypeStackSlotEntries::stack_slot_local_offset(i);
 880   }
 881 
 882   static int argument_type_local_offset(int i) {
 883     return header_cell_count() + TypeStackSlotEntries::type_local_offset(i);;
 884   }
 885 
 886 public:
 887 
 888   static int header_cell_count() {
 889     return 1;
 890   }
 891 
 892   static int cell_count_local_offset() {
 893     return 0;
 894   }
 895 
 896   static int compute_cell_count(BytecodeStream* stream);
 897 
 898   static void initialize(DataLayout* dl, int base, int cell_count) {
 899     int off = base + cell_count_local_offset();
 900     dl->set_cell_at(off, cell_count - base - header_cell_count());
 901   }
 902 
 903   static bool arguments_profiling_enabled();
 904   static bool return_profiling_enabled();
 905 
 906   // Code generation support
 907   static ByteSize cell_count_offset() {
 908     return in_ByteSize(cell_count_local_offset() * DataLayout::cell_size);
 909   }
 910 
 911   static ByteSize args_data_offset() {
 912     return in_ByteSize(header_cell_count() * DataLayout::cell_size);
 913   }
 914 
 915   static ByteSize stack_slot_offset(int i) {
 916     return in_ByteSize(stack_slot_local_offset(i) * DataLayout::cell_size);
 917   }
 918 
 919   static ByteSize argument_type_offset(int i) {
 920     return in_ByteSize(argument_type_local_offset(i) * DataLayout::cell_size);
 921   }
 922 };
 923 
 924 // CallTypeData
 925 //
 926 // A CallTypeData is used to access profiling information about a non
 927 // virtual call for which we collect type information about arguments
 928 // and return value.
 929 class CallTypeData : public CounterData {
 930 private:
 931   // entries for arguments if any
 932   TypeStackSlotEntries _args;
 933   // entry for return type if any
 934   ReturnTypeEntry _ret;
 935 
 936   int cell_count_global_offset() const {
 937     return CounterData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
 938   }
 939 
 940   // number of cells not counting the header
 941   int cell_count_no_header() const {
 942     return uint_at(cell_count_global_offset());
 943   }
 944 
 945   void check_number_of_arguments(int total) {
 946     assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
 947   }
 948 
 949 protected:
 950   // An entry for a return value takes less space than an entry for an
 951   // argument so if the number of cells exceeds the number of cells
 952   // needed for an argument, this object contains type information for
 953   // at least one argument.
 954   bool has_arguments() const {
 955     bool res = cell_count_no_header() >= TypeStackSlotEntries::per_arg_count();
 956     assert (!res || TypeEntriesAtCall::arguments_profiling_enabled(), "no profiling of arguments");
 957     return res;
 958   }
 959 
 960 public:
 961   CallTypeData(DataLayout* layout) :
 962     CounterData(layout),
 963     _args(CounterData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
 964     _ret(cell_count() - ReturnTypeEntry::static_cell_count())
 965   {
 966     assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type");
 967     // Some compilers (VC++) don't want this passed in member initialization list
 968     _args.set_profile_data(this);
 969     _ret.set_profile_data(this);
 970   }
 971 
 972   const TypeStackSlotEntries* args() const {
 973     assert(has_arguments(), "no profiling of arguments");
 974     return &_args;
 975   }
 976 
 977   const ReturnTypeEntry* ret() const {
 978     assert(has_return(), "no profiling of return value");
 979     return &_ret;
 980   }
 981 
 982   virtual bool is_CallTypeData() const { return true; }
 983 
 984   static int static_cell_count() {
 985     return -1;
 986   }
 987 
 988   static int compute_cell_count(BytecodeStream* stream) {
 989     return CounterData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
 990   }
 991 
 992   static void initialize(DataLayout* dl, int cell_count) {
 993     TypeEntriesAtCall::initialize(dl, CounterData::static_cell_count(), cell_count);
 994   }
 995 
 996   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);


 997 
 998   virtual int cell_count() const {
 999     return CounterData::static_cell_count() +
1000       TypeEntriesAtCall::header_cell_count() +
1001       int_at_unchecked(cell_count_global_offset());
1002   }
1003 
1004   int number_of_arguments() const {
1005     return cell_count_no_header() / TypeStackSlotEntries::per_arg_count();
1006   }
1007 
1008   void set_argument_type(int i, Klass* k) {
1009     assert(has_arguments(), "no arguments!");
1010     intptr_t current = _args.type(i);
1011     _args.set_type(i, TypeEntries::with_status(k, current));
1012   }
1013 
1014   void set_return_type(Klass* k) {
1015     assert(has_return(), "no return!");
1016     intptr_t current = _ret.type();
1017     _ret.set_type(TypeEntries::with_status(k, current));
1018   }
1019 
1020   // An entry for a return value takes less space than an entry for an
1021   // argument, so if the remainder of the number of cells divided by
1022   // the number of cells for an argument is not null, a return value
1023   // is profiled in this object.
1024   bool has_return() const {
1025     bool res = (cell_count_no_header() % TypeStackSlotEntries::per_arg_count()) != 0;
1026     assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values");
1027     return res;
1028   }
1029 
1030   // Code generation support
1031   static ByteSize args_data_offset() {
1032     return cell_offset(CounterData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
1033   }
1034 
1035   // GC support
1036   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1037     if (has_arguments()) {
1038       _args.clean_weak_klass_links(is_alive_closure);
1039     }
1040     if (has_return()) {
1041       _ret.clean_weak_klass_links(is_alive_closure);
1042     }
1043   }
1044 
1045 #ifndef PRODUCT
1046   virtual void print_data_on(outputStream* st) const;
1047 #endif
1048 };
1049 
1050 // ReceiverTypeData
1051 //
1052 // A ReceiverTypeData is used to access profiling information about a
1053 // dynamic type check.  It consists of a counter which counts the total times
1054 // that the check is reached, and a series of (Klass*, count) pairs
1055 // which are used to store a type profile for the receiver of the check.
1056 class ReceiverTypeData : public CounterData {
1057 protected:
1058   enum {
1059     receiver0_offset = counter_cell_count,
1060     count0_offset,
1061     receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
1062   };
1063 


1175   }
1176 
1177   virtual int cell_count() const {
1178     return static_cell_count();
1179   }
1180 
1181   // Direct accessors
1182   static ByteSize virtual_call_data_size() {
1183     return cell_offset(static_cell_count());
1184   }
1185 
1186 #ifndef PRODUCT
1187   void print_data_on(outputStream* st) const;
1188 #endif
1189 };
1190 
1191 // VirtualCallTypeData
1192 //
1193 // A VirtualCallTypeData is used to access profiling information about
1194 // a virtual call for which we collect type information about
1195 // arguments and return value.
1196 class VirtualCallTypeData : public VirtualCallData {
1197 private:
1198   // entries for arguments if any
1199   TypeStackSlotEntries _args;
1200   // entry for return type if any
1201   ReturnTypeEntry _ret;
1202 
1203   int cell_count_global_offset() const {
1204     return VirtualCallData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
1205   }
1206 
1207   // number of cells not counting the header
1208   int cell_count_no_header() const {
1209     return uint_at(cell_count_global_offset());
1210   }
1211 
1212   void check_number_of_arguments(int total) {
1213     assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
1214   }
1215 
1216 protected:
1217   // An entry for a return value takes less space than an entry for an
1218   // argument so if the number of cells exceeds the number of cells
1219   // needed for an argument, this object contains type information for
1220   // at least one argument.
1221   bool has_arguments() const {
1222     bool res = cell_count_no_header() >= TypeStackSlotEntries::per_arg_count();
1223     assert (!res || TypeEntriesAtCall::arguments_profiling_enabled(), "no profiling of arguments");
1224     return res;
1225   }
1226 
1227 public:
1228   VirtualCallTypeData(DataLayout* layout) :
1229     VirtualCallData(layout),
1230     _args(VirtualCallData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
1231     _ret(cell_count() - ReturnTypeEntry::static_cell_count())
1232   {
1233     assert(layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1234     // Some compilers (VC++) don't want this passed in member initialization list
1235     _args.set_profile_data(this);
1236     _ret.set_profile_data(this);
1237   }
1238 
1239   const TypeStackSlotEntries* args() const {
1240     assert(has_arguments(), "no profiling of arguments");
1241     return &_args;
1242   }
1243 
1244   const ReturnTypeEntry* ret() const {
1245     assert(has_return(), "no profiling of return value");
1246     return &_ret;
1247   }
1248 
1249   virtual bool is_VirtualCallTypeData() const { return true; }
1250 
1251   static int static_cell_count() {
1252     return -1;
1253   }
1254 
1255   static int compute_cell_count(BytecodeStream* stream) {
1256     return VirtualCallData::static_cell_count() + TypeEntriesAtCall::compute_cell_count(stream);
1257   }
1258 
1259   static void initialize(DataLayout* dl, int cell_count) {
1260     TypeEntriesAtCall::initialize(dl, VirtualCallData::static_cell_count(), cell_count);
1261   }
1262 
1263   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);


1264 
1265   virtual int cell_count() const {
1266     return VirtualCallData::static_cell_count() +
1267       TypeEntriesAtCall::header_cell_count() +
1268       int_at_unchecked(cell_count_global_offset());
1269   }
1270 
1271   int number_of_arguments() const {
1272     return cell_count_no_header() / TypeStackSlotEntries::per_arg_count();
1273   }
1274 
1275   void set_argument_type(int i, Klass* k) {
1276     assert(has_arguments(), "no arguments!");
1277     intptr_t current = _args.type(i);
1278     _args.set_type(i, TypeEntries::with_status(k, current));
1279   }
1280 
1281   void set_return_type(Klass* k) {
1282     assert(has_return(), "no return!");
1283     intptr_t current = _ret.type();
1284     _ret.set_type(TypeEntries::with_status(k, current));
1285   }
1286 
1287   // An entry for a return value takes less space than an entry for an
1288   // argument, so if the remainder of the number of cells divided by
1289   // the number of cells for an argument is not null, a return value
1290   // is profiled in this object.
1291   bool has_return() const {
1292     bool res = (cell_count_no_header() % TypeStackSlotEntries::per_arg_count()) != 0;
1293     assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values");
1294     return res;
1295   }
1296 
1297   // Code generation support
1298   static ByteSize args_data_offset() {
1299     return cell_offset(VirtualCallData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
1300   }
1301 
1302   // GC support
1303   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1304     ReceiverTypeData::clean_weak_klass_links(is_alive_closure);
1305     if (has_arguments()) {
1306       _args.clean_weak_klass_links(is_alive_closure);
1307     }
1308     if (has_return()) {
1309       _ret.clean_weak_klass_links(is_alive_closure);
1310     }
1311   }
1312 
1313 #ifndef PRODUCT
1314   virtual void print_data_on(outputStream* st) const;
1315 #endif
1316 };
1317 
1318 // RetData
1319 //
1320 // A RetData is used to access profiling information for a ret bytecode.
1321 // It is composed of a count of the number of times that the ret has
1322 // been executed, followed by a series of triples of the form
1323 // (bci, count, di) which count the number of times that some bci was the
1324 // target of the ret and cache a corresponding data displacement.
1325 class RetData : public CounterData {
1326 protected:
1327   enum {
1328     bci0_offset = counter_cell_count,
1329     count0_offset,
1330     displacement0_offset,
1331     ret_row_cell_count = (displacement0_offset + 1) - bci0_offset


1822   // What is the index of the first data entry?
1823   int first_di() const { return 0; }
1824 
1825   // Find or create an extra ProfileData:
1826   ProfileData* bci_to_extra_data(int bci, bool create_if_missing);
1827 
1828   // return the argument info cell
1829   ArgInfoData *arg_info();
1830 
1831   enum {
1832     no_type_profile = 0,
1833     type_profile_jsr292 = 1,
1834     type_profile_all = 2
1835   };
1836 
1837   static bool profile_jsr292(methodHandle m, int bci);
1838   static int profile_arguments_flag();
1839   static bool profile_arguments_jsr292_only();
1840   static bool profile_all_arguments();
1841   static bool profile_arguments_for_invoke(methodHandle m, int bci);
1842   static int profile_return_flag();
1843   static bool profile_all_return();
1844   static bool profile_return_for_invoke(methodHandle m, int bci);
1845 
1846 public:
1847   static int header_size() {
1848     return sizeof(MethodData)/wordSize;
1849   }
1850 
1851   // Compute the size of a MethodData* before it is created.
1852   static int compute_allocation_size_in_bytes(methodHandle method);
1853   static int compute_allocation_size_in_words(methodHandle method);
1854   static int compute_extra_data_count(int data_size, int empty_bc_count);
1855 
1856   // Determine if a given bytecode can have profile information.
1857   static bool bytecode_has_profile(Bytecodes::Code code) {
1858     return bytecode_cell_count(code) != no_profile_data;
1859   }
1860 
1861   // reset into original state
1862   void init();
1863 
1864   // My size


2067   void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; }
2068 
2069   // Printing
2070 #ifndef PRODUCT
2071   void print_on      (outputStream* st) const;
2072 #endif
2073   void print_value_on(outputStream* st) const;
2074 
2075 #ifndef PRODUCT
2076   // printing support for method data
2077   void print_data_on(outputStream* st) const;
2078 #endif
2079 
2080   const char* internal_name() const { return "{method data}"; }
2081 
2082   // verification
2083   void verify_on(outputStream* st);
2084   void verify_data_on(outputStream* st);
2085 
2086   static bool profile_arguments();
2087   static bool profile_return();
2088   static bool profile_return_jsr292_only();
2089 };
2090 
2091 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP
src/share/vm/oops/methodData.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File