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 5411 : 8026251: New type profiling points: parameters to methods
Summary: x86 interpreter and c1 type profiling for parameters on method entries
Reviewed-by:


 102     counter_increment = 1
 103   };
 104 
 105   enum {
 106     cell_size = sizeof(intptr_t)
 107   };
 108 
 109   // Tag values
 110   enum {
 111     no_tag,
 112     bit_data_tag,
 113     counter_data_tag,
 114     jump_data_tag,
 115     receiver_type_data_tag,
 116     virtual_call_data_tag,
 117     ret_data_tag,
 118     branch_data_tag,
 119     multi_branch_data_tag,
 120     arg_info_data_tag,
 121     call_type_data_tag,
 122     virtual_call_type_data_tag

 123   };
 124 
 125   enum {
 126     // The _struct._flags word is formatted as [trap_state:4 | flags:4].
 127     // The trap state breaks down further as [recompile:1 | reason:3].
 128     // This further breakdown is defined in deoptimization.cpp.
 129     // See Deoptimization::trap_state_reason for an assert that
 130     // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
 131     //
 132     // The trap_state is collected only if ProfileTraps is true.
 133     trap_bits = 1+3,  // 3: enough to distinguish [0..Reason_RECORDED_LIMIT].
 134     trap_shift = BitsPerByte - trap_bits,
 135     trap_mask = right_n_bits(trap_bits),
 136     trap_mask_in_place = (trap_mask << trap_shift),
 137     flag_limit = trap_shift,
 138     flag_mask = right_n_bits(flag_limit),
 139     first_flag = 0
 140   };
 141 
 142   // Size computation


 247 
 248   // GC support
 249   void clean_weak_klass_links(BoolObjectClosure* cl);
 250 };
 251 
 252 
 253 // ProfileData class hierarchy
 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 


 380   int trap_state() const {
 381     return data()->trap_state();
 382   }
 383   void set_trap_state(int new_state) {
 384     data()->set_trap_state(new_state);
 385   }
 386 
 387   // Type checking
 388   virtual bool is_BitData()         const { return false; }
 389   virtual bool is_CounterData()     const { return false; }
 390   virtual bool is_JumpData()        const { return false; }
 391   virtual bool is_ReceiverTypeData()const { return false; }
 392   virtual bool is_VirtualCallData() const { return false; }
 393   virtual bool is_RetData()         const { return false; }
 394   virtual bool is_BranchData()      const { return false; }
 395   virtual bool is_ArrayData()       const { return false; }
 396   virtual bool is_MultiBranchData() const { return false; }
 397   virtual bool is_ArgInfoData()     const { return false; }
 398   virtual bool is_CallTypeData()    const { return false; }
 399   virtual bool is_VirtualCallTypeData()const { return false; }

 400 
 401 
 402   BitData* as_BitData() const {
 403     assert(is_BitData(), "wrong type");
 404     return is_BitData()         ? (BitData*)        this : NULL;
 405   }
 406   CounterData* as_CounterData() const {
 407     assert(is_CounterData(), "wrong type");
 408     return is_CounterData()     ? (CounterData*)    this : NULL;
 409   }
 410   JumpData* as_JumpData() const {
 411     assert(is_JumpData(), "wrong type");
 412     return is_JumpData()        ? (JumpData*)       this : NULL;
 413   }
 414   ReceiverTypeData* as_ReceiverTypeData() const {
 415     assert(is_ReceiverTypeData(), "wrong type");
 416     return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
 417   }
 418   VirtualCallData* as_VirtualCallData() const {
 419     assert(is_VirtualCallData(), "wrong type");


 430   ArrayData* as_ArrayData() const {
 431     assert(is_ArrayData(), "wrong type");
 432     return is_ArrayData()       ? (ArrayData*)      this : NULL;
 433   }
 434   MultiBranchData* as_MultiBranchData() const {
 435     assert(is_MultiBranchData(), "wrong type");
 436     return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
 437   }
 438   ArgInfoData* as_ArgInfoData() const {
 439     assert(is_ArgInfoData(), "wrong type");
 440     return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
 441   }
 442   CallTypeData* as_CallTypeData() const {
 443     assert(is_CallTypeData(), "wrong type");
 444     return is_CallTypeData() ? (CallTypeData*)this : NULL;
 445   }
 446   VirtualCallTypeData* as_VirtualCallTypeData() const {
 447     assert(is_VirtualCallTypeData(), "wrong type");
 448     return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL;
 449   }




 450 
 451 
 452   // Subclass specific initialization
 453   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
 454 
 455   // GC support
 456   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {}
 457 
 458   // CI translation: ProfileData can represent both MethodDataOop data
 459   // as well as CIMethodData data. This function is provided for translating
 460   // an oop in a ProfileData to the ci equivalent. Generally speaking,
 461   // most ProfileData don't require any translation, so we provide the null
 462   // translation here, and the required translators are in the ci subclasses.
 463   virtual void translate_from(const ProfileData* data) {}
 464 
 465   virtual void print_data_on(outputStream* st) const {
 466     ShouldNotReachHere();
 467   }
 468 
 469 #ifndef PRODUCT


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


 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;


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()) {


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;


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


1645   virtual bool is_ArgInfoData() const { return true; }
1646 
1647 
1648   int number_of_args() const {
1649     return array_len();
1650   }
1651 
1652   uint arg_modified(int arg) const {
1653     return array_uint_at(arg);
1654   }
1655 
1656   void set_arg_modified(int arg, uint val) {
1657     array_set_int_at(arg, val);
1658   }
1659 
1660 #ifndef PRODUCT
1661   void print_data_on(outputStream* st) const;
1662 #endif
1663 };
1664 





































































1665 // MethodData*
1666 //
1667 // A MethodData* holds information which has been collected about
1668 // a method.  Its layout looks like this:
1669 //
1670 // -----------------------------
1671 // | header                    |
1672 // | klass                     |
1673 // -----------------------------
1674 // | method                    |
1675 // | size of the MethodData* |
1676 // -----------------------------
1677 // | Data entries...           |
1678 // |   (variable size)         |
1679 // |                           |
1680 // .                           .
1681 // .                           .
1682 // .                           .
1683 // |                           |
1684 // -----------------------------


1756   InvocationCounter _invocation_counter;
1757   // Same for backedges.
1758   InvocationCounter _backedge_counter;
1759   // Counter values at the time profiling started.
1760   int               _invocation_counter_start;
1761   int               _backedge_counter_start;
1762   // Number of loops and blocks is computed when compiling the first
1763   // time with C1. It is used to determine if method is trivial.
1764   short             _num_loops;
1765   short             _num_blocks;
1766   // Highest compile level this method has ever seen.
1767   u1                _highest_comp_level;
1768   // Same for OSR level
1769   u1                _highest_osr_comp_level;
1770   // Does this method contain anything worth profiling?
1771   bool              _would_profile;
1772 
1773   // Size of _data array in bytes.  (Excludes header and extra_data fields.)
1774   int _data_size;
1775 


1776   // Beginning of the data entries
1777   intptr_t _data[1];
1778 
1779   // Helper for size computation
1780   static int compute_data_size(BytecodeStream* stream);
1781   static int bytecode_cell_count(Bytecodes::Code code);
1782   enum { no_profile_data = -1, variable_cell_count = -2 };
1783 
1784   // Helper for initialization
1785   DataLayout* data_layout_at(int data_index) const {
1786     assert(data_index % sizeof(intptr_t) == 0, "unaligned");
1787     return (DataLayout*) (((address)_data) + data_index);
1788   }
1789 
1790   // Initialize an individual data segment.  Returns the size of
1791   // the segment in bytes.
1792   int initialize_data(BytecodeStream* stream, int data_index);
1793 
1794   // Helper for data_at
1795   DataLayout* limit_data_position() const {


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


2031 
2032   uint overflow_trap_count() const {
2033     return _nof_overflow_traps;
2034   }
2035   uint overflow_recompile_count() const {
2036     return _nof_overflow_recompiles;
2037   }
2038   void inc_overflow_recompile_count() {
2039     _nof_overflow_recompiles += 1;
2040   }
2041   uint decompile_count() const {
2042     return _nof_decompiles;
2043   }
2044   void inc_decompile_count() {
2045     _nof_decompiles += 1;
2046     if (decompile_count() > (uint)PerMethodRecompilationCutoff) {
2047       method()->set_not_compilable(CompLevel_full_optimization, true, "decompile_count > PerMethodRecompilationCutoff");
2048     }
2049   }
2050 









2051   // Support for code generation
2052   static ByteSize data_offset() {
2053     return byte_offset_of(MethodData, _data[0]);
2054   }
2055 
2056   static ByteSize invocation_counter_offset() {
2057     return byte_offset_of(MethodData, _invocation_counter);
2058   }
2059   static ByteSize backedge_counter_offset() {
2060     return byte_offset_of(MethodData, _backedge_counter);
2061   }
2062 




2063   // Deallocation support - no pointer fields to deallocate
2064   void deallocate_contents(ClassLoaderData* loader_data) {}
2065 
2066   // GC support
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


 102     counter_increment = 1
 103   };
 104 
 105   enum {
 106     cell_size = sizeof(intptr_t)
 107   };
 108 
 109   // Tag values
 110   enum {
 111     no_tag,
 112     bit_data_tag,
 113     counter_data_tag,
 114     jump_data_tag,
 115     receiver_type_data_tag,
 116     virtual_call_data_tag,
 117     ret_data_tag,
 118     branch_data_tag,
 119     multi_branch_data_tag,
 120     arg_info_data_tag,
 121     call_type_data_tag,
 122     virtual_call_type_data_tag,
 123     parameters_type_data_tag
 124   };
 125 
 126   enum {
 127     // The _struct._flags word is formatted as [trap_state:4 | flags:4].
 128     // The trap state breaks down further as [recompile:1 | reason:3].
 129     // This further breakdown is defined in deoptimization.cpp.
 130     // See Deoptimization::trap_state_reason for an assert that
 131     // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
 132     //
 133     // The trap_state is collected only if ProfileTraps is true.
 134     trap_bits = 1+3,  // 3: enough to distinguish [0..Reason_RECORDED_LIMIT].
 135     trap_shift = BitsPerByte - trap_bits,
 136     trap_mask = right_n_bits(trap_bits),
 137     trap_mask_in_place = (trap_mask << trap_shift),
 138     flag_limit = trap_shift,
 139     flag_mask = right_n_bits(flag_limit),
 140     first_flag = 0
 141   };
 142 
 143   // Size computation


 248 
 249   // GC support
 250   void clean_weak_klass_links(BoolObjectClosure* cl);
 251 };
 252 
 253 
 254 // ProfileData class hierarchy
 255 class ProfileData;
 256 class   BitData;
 257 class     CounterData;
 258 class       ReceiverTypeData;
 259 class         VirtualCallData;
 260 class           VirtualCallTypeData;
 261 class       RetData;
 262 class       CallTypeData;
 263 class   JumpData;
 264 class     BranchData;
 265 class   ArrayData;
 266 class     MultiBranchData;
 267 class     ArgInfoData;
 268 class     ParametersTypeData;
 269 
 270 // ProfileData
 271 //
 272 // A ProfileData object is created to refer to a section of profiling
 273 // data in a structured way.
 274 class ProfileData : public ResourceObj {
 275   friend class TypeEntries;
 276   friend class ReturnTypeEntry;
 277   friend class TypeStackSlotEntries;
 278 private:
 279 #ifndef PRODUCT
 280   enum {
 281     tab_width_one = 16,
 282     tab_width_two = 36
 283   };
 284 #endif // !PRODUCT
 285 
 286   // This is a pointer to a section of profiling data.
 287   DataLayout* _data;
 288 


 382   int trap_state() const {
 383     return data()->trap_state();
 384   }
 385   void set_trap_state(int new_state) {
 386     data()->set_trap_state(new_state);
 387   }
 388 
 389   // Type checking
 390   virtual bool is_BitData()         const { return false; }
 391   virtual bool is_CounterData()     const { return false; }
 392   virtual bool is_JumpData()        const { return false; }
 393   virtual bool is_ReceiverTypeData()const { return false; }
 394   virtual bool is_VirtualCallData() const { return false; }
 395   virtual bool is_RetData()         const { return false; }
 396   virtual bool is_BranchData()      const { return false; }
 397   virtual bool is_ArrayData()       const { return false; }
 398   virtual bool is_MultiBranchData() const { return false; }
 399   virtual bool is_ArgInfoData()     const { return false; }
 400   virtual bool is_CallTypeData()    const { return false; }
 401   virtual bool is_VirtualCallTypeData()const { return false; }
 402   virtual bool is_ParametersTypeData() const { return false; }
 403 
 404 
 405   BitData* as_BitData() const {
 406     assert(is_BitData(), "wrong type");
 407     return is_BitData()         ? (BitData*)        this : NULL;
 408   }
 409   CounterData* as_CounterData() const {
 410     assert(is_CounterData(), "wrong type");
 411     return is_CounterData()     ? (CounterData*)    this : NULL;
 412   }
 413   JumpData* as_JumpData() const {
 414     assert(is_JumpData(), "wrong type");
 415     return is_JumpData()        ? (JumpData*)       this : NULL;
 416   }
 417   ReceiverTypeData* as_ReceiverTypeData() const {
 418     assert(is_ReceiverTypeData(), "wrong type");
 419     return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
 420   }
 421   VirtualCallData* as_VirtualCallData() const {
 422     assert(is_VirtualCallData(), "wrong type");


 433   ArrayData* as_ArrayData() const {
 434     assert(is_ArrayData(), "wrong type");
 435     return is_ArrayData()       ? (ArrayData*)      this : NULL;
 436   }
 437   MultiBranchData* as_MultiBranchData() const {
 438     assert(is_MultiBranchData(), "wrong type");
 439     return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
 440   }
 441   ArgInfoData* as_ArgInfoData() const {
 442     assert(is_ArgInfoData(), "wrong type");
 443     return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
 444   }
 445   CallTypeData* as_CallTypeData() const {
 446     assert(is_CallTypeData(), "wrong type");
 447     return is_CallTypeData() ? (CallTypeData*)this : NULL;
 448   }
 449   VirtualCallTypeData* as_VirtualCallTypeData() const {
 450     assert(is_VirtualCallTypeData(), "wrong type");
 451     return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL;
 452   }
 453   ParametersTypeData* as_ParametersTypeData() const {
 454     assert(is_ParametersTypeData(), "wrong type");
 455     return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL;
 456   }
 457 
 458 
 459   // Subclass specific initialization
 460   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
 461 
 462   // GC support
 463   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {}
 464 
 465   // CI translation: ProfileData can represent both MethodDataOop data
 466   // as well as CIMethodData data. This function is provided for translating
 467   // an oop in a ProfileData to the ci equivalent. Generally speaking,
 468   // most ProfileData don't require any translation, so we provide the null
 469   // translation here, and the required translators are in the ci subclasses.
 470   virtual void translate_from(const ProfileData* data) {}
 471 
 472   virtual void print_data_on(outputStream* st) const {
 473     ShouldNotReachHere();
 474   }
 475 
 476 #ifndef PRODUCT


 757   };
 758 
 759   // offset of cell for stack slot for entry i within ProfileData object
 760   int stack_slot_offset(int i) const {
 761     return _base_off + stack_slot_local_offset(i);
 762   }
 763 
 764 protected:
 765   const int _number_of_entries;
 766 
 767   // offset of cell for type for entry i within ProfileData object
 768   int type_offset(int i) const {
 769     return _base_off + type_local_offset(i);
 770   }
 771 
 772 public:
 773 
 774   TypeStackSlotEntries(int base_off, int nb_entries)
 775     : TypeEntries(base_off), _number_of_entries(nb_entries) {}
 776 
 777   static int compute_cell_count(Symbol* signature, bool include_receiver, int max);
 778 
 779   void post_initialize(Symbol* signature, bool has_receiver, bool include_receiver);
 780 
 781   // offset of cell for stack slot for entry i within this block of cells for a TypeStackSlotEntries
 782   static int stack_slot_local_offset(int i) {
 783     return i * per_arg_cell_count + stack_slot_entry;
 784   }
 785 
 786   // offset of cell for type for entry i within this block of cells for a TypeStackSlotEntries
 787   static int type_local_offset(int i) {
 788     return i * per_arg_cell_count + type_entry;
 789   }
 790 
 791   // stack slot for entry i
 792   uint stack_slot(int i) const {
 793     assert(i >= 0 && i < _number_of_entries, "oob");
 794     return _pd->uint_at(stack_slot_offset(i));
 795   }
 796 
 797   // set stack slot for entry i
 798   void set_stack_slot(int i, uint num) {
 799     assert(i >= 0 && i < _number_of_entries, "oob");


 936 class CallTypeData : public CounterData {
 937 private:
 938   // entries for arguments if any
 939   TypeStackSlotEntries _args;
 940   // entry for return type if any
 941   ReturnTypeEntry _ret;
 942 
 943   int cell_count_global_offset() const {
 944     return CounterData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
 945   }
 946 
 947   // number of cells not counting the header
 948   int cell_count_no_header() const {
 949     return uint_at(cell_count_global_offset());
 950   }
 951 
 952   void check_number_of_arguments(int total) {
 953     assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
 954   }
 955 











 956 public:
 957   CallTypeData(DataLayout* layout) :
 958     CounterData(layout),
 959     _args(CounterData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
 960     _ret(cell_count() - ReturnTypeEntry::static_cell_count())
 961   {
 962     assert(layout->tag() == DataLayout::call_type_data_tag, "wrong type");
 963     // Some compilers (VC++) don't want this passed in member initialization list
 964     _args.set_profile_data(this);
 965     _ret.set_profile_data(this);
 966   }
 967 
 968   const TypeStackSlotEntries* args() const {
 969     assert(has_arguments(), "no profiling of arguments");
 970     return &_args;
 971   }
 972 
 973   const ReturnTypeEntry* ret() const {
 974     assert(has_return(), "no profiling of return value");
 975     return &_ret;


 997       int_at_unchecked(cell_count_global_offset());
 998   }
 999 
1000   int number_of_arguments() const {
1001     return cell_count_no_header() / TypeStackSlotEntries::per_arg_count();
1002   }
1003 
1004   void set_argument_type(int i, Klass* k) {
1005     assert(has_arguments(), "no arguments!");
1006     intptr_t current = _args.type(i);
1007     _args.set_type(i, TypeEntries::with_status(k, current));
1008   }
1009 
1010   void set_return_type(Klass* k) {
1011     assert(has_return(), "no return!");
1012     intptr_t current = _ret.type();
1013     _ret.set_type(TypeEntries::with_status(k, current));
1014   }
1015 
1016   // An entry for a return value takes less space than an entry for an
1017   // argument so if the number of cells exceeds the number of cells
1018   // needed for an argument, this object contains type information for
1019   // at least one argument.
1020   bool has_arguments() const {
1021     bool res = cell_count_no_header() >= TypeStackSlotEntries::per_arg_count();
1022     assert (!res || TypeEntriesAtCall::arguments_profiling_enabled(), "no profiling of arguments");
1023     return res;
1024   }
1025 
1026   // An entry for a return value takes less space than an entry for an
1027   // argument, so if the remainder of the number of cells divided by
1028   // the number of cells for an argument is not null, a return value
1029   // is profiled in this object.
1030   bool has_return() const {
1031     bool res = (cell_count_no_header() % TypeStackSlotEntries::per_arg_count()) != 0;
1032     assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values");
1033     return res;
1034   }
1035 
1036   // Code generation support
1037   static ByteSize args_data_offset() {
1038     return cell_offset(CounterData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
1039   }
1040 
1041   // GC support
1042   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1043     if (has_arguments()) {
1044       _args.clean_weak_klass_links(is_alive_closure);
1045     }
1046     if (has_return()) {


1202 class VirtualCallTypeData : public VirtualCallData {
1203 private:
1204   // entries for arguments if any
1205   TypeStackSlotEntries _args;
1206   // entry for return type if any
1207   ReturnTypeEntry _ret;
1208 
1209   int cell_count_global_offset() const {
1210     return VirtualCallData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
1211   }
1212 
1213   // number of cells not counting the header
1214   int cell_count_no_header() const {
1215     return uint_at(cell_count_global_offset());
1216   }
1217 
1218   void check_number_of_arguments(int total) {
1219     assert(number_of_arguments() == total, "should be set in DataLayout::initialize");
1220   }
1221 











1222 public:
1223   VirtualCallTypeData(DataLayout* layout) :
1224     VirtualCallData(layout),
1225     _args(VirtualCallData::static_cell_count()+TypeEntriesAtCall::header_cell_count(), number_of_arguments()),
1226     _ret(cell_count() - ReturnTypeEntry::static_cell_count())
1227   {
1228     assert(layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1229     // Some compilers (VC++) don't want this passed in member initialization list
1230     _args.set_profile_data(this);
1231     _ret.set_profile_data(this);
1232   }
1233 
1234   const TypeStackSlotEntries* args() const {
1235     assert(has_arguments(), "no profiling of arguments");
1236     return &_args;
1237   }
1238 
1239   const ReturnTypeEntry* ret() const {
1240     assert(has_return(), "no profiling of return value");
1241     return &_ret;


1272     intptr_t current = _args.type(i);
1273     _args.set_type(i, TypeEntries::with_status(k, current));
1274   }
1275 
1276   void set_return_type(Klass* k) {
1277     assert(has_return(), "no return!");
1278     intptr_t current = _ret.type();
1279     _ret.set_type(TypeEntries::with_status(k, current));
1280   }
1281 
1282   // An entry for a return value takes less space than an entry for an
1283   // argument, so if the remainder of the number of cells divided by
1284   // the number of cells for an argument is not null, a return value
1285   // is profiled in this object.
1286   bool has_return() const {
1287     bool res = (cell_count_no_header() % TypeStackSlotEntries::per_arg_count()) != 0;
1288     assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values");
1289     return res;
1290   }
1291 
1292   // An entry for a return value takes less space than an entry for an
1293   // argument so if the number of cells exceeds the number of cells
1294   // needed for an argument, this object contains type information for
1295   // at least one argument.
1296   bool has_arguments() const {
1297     bool res = cell_count_no_header() >= TypeStackSlotEntries::per_arg_count();
1298     assert (!res || TypeEntriesAtCall::arguments_profiling_enabled(), "no profiling of arguments");
1299     return res;
1300   }
1301 
1302   // Code generation support
1303   static ByteSize args_data_offset() {
1304     return cell_offset(VirtualCallData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
1305   }
1306 
1307   // GC support
1308   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1309     ReceiverTypeData::clean_weak_klass_links(is_alive_closure);
1310     if (has_arguments()) {
1311       _args.clean_weak_klass_links(is_alive_closure);
1312     }
1313     if (has_return()) {
1314       _ret.clean_weak_klass_links(is_alive_closure);
1315     }
1316   }
1317 
1318 #ifndef PRODUCT
1319   virtual void print_data_on(outputStream* st) const;
1320 #endif
1321 };


1650   virtual bool is_ArgInfoData() const { return true; }
1651 
1652 
1653   int number_of_args() const {
1654     return array_len();
1655   }
1656 
1657   uint arg_modified(int arg) const {
1658     return array_uint_at(arg);
1659   }
1660 
1661   void set_arg_modified(int arg, uint val) {
1662     array_set_int_at(arg, val);
1663   }
1664 
1665 #ifndef PRODUCT
1666   void print_data_on(outputStream* st) const;
1667 #endif
1668 };
1669 
1670 // ParametersTypeData
1671 //
1672 // A ParametersTypeData is used to access profiling information about
1673 // types of parameters to a method
1674 class ParametersTypeData : public ArrayData {
1675 
1676 private:
1677   TypeStackSlotEntries _parameters;
1678 
1679   static int stack_slot_local_offset(int i) {
1680     assert_profiling_enabled();
1681     return array_start_off_set + TypeStackSlotEntries::stack_slot_local_offset(i);
1682   }
1683 
1684   static int type_local_offset(int i) {
1685     assert_profiling_enabled();
1686     return array_start_off_set + TypeStackSlotEntries::type_local_offset(i);
1687   }
1688 
1689   static bool profiling_enabled();
1690   static void assert_profiling_enabled() {
1691     assert(profiling_enabled(), "method parameters profiling should be on");
1692   }
1693 
1694 public:
1695   ParametersTypeData(DataLayout* layout) : ArrayData(layout), _parameters(1, number_of_parameters()) {
1696     assert(layout->tag() == DataLayout::parameters_type_data_tag, "wrong type");
1697     // Some compilers (VC++) don't want this passed in member initialization list
1698     _parameters.set_profile_data(this);
1699   }
1700 
1701   static int compute_cell_count(Method* m);
1702 
1703   virtual bool is_ParametersTypeData() const { return true; }
1704 
1705   virtual void post_initialize(BytecodeStream* stream, MethodData* mdo);
1706 
1707   int number_of_parameters() const {
1708     return array_len() / TypeStackSlotEntries::per_arg_count();
1709   }
1710 
1711   const TypeStackSlotEntries* parameters() const { return &_parameters; }
1712 
1713   uint stack_slot(int i) const {
1714     return _parameters.stack_slot(i);
1715   }
1716 
1717   void set_type(int i, Klass* k) {
1718     intptr_t current = _parameters.type(i);
1719     _parameters.set_type(i, TypeEntries::with_status((intptr_t)k, current));
1720   }
1721 
1722   virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1723     _parameters.clean_weak_klass_links(is_alive_closure);
1724   }
1725 
1726 #ifndef PRODUCT
1727   virtual void print_data_on(outputStream* st) const;
1728 #endif
1729 
1730   static ByteSize stack_slot_offset(int i) {
1731     return cell_offset(stack_slot_local_offset(i));
1732   }
1733 
1734   static ByteSize type_offset(int i) {
1735     return cell_offset(type_local_offset(i));
1736   }
1737 };
1738 
1739 // MethodData*
1740 //
1741 // A MethodData* holds information which has been collected about
1742 // a method.  Its layout looks like this:
1743 //
1744 // -----------------------------
1745 // | header                    |
1746 // | klass                     |
1747 // -----------------------------
1748 // | method                    |
1749 // | size of the MethodData* |
1750 // -----------------------------
1751 // | Data entries...           |
1752 // |   (variable size)         |
1753 // |                           |
1754 // .                           .
1755 // .                           .
1756 // .                           .
1757 // |                           |
1758 // -----------------------------


1830   InvocationCounter _invocation_counter;
1831   // Same for backedges.
1832   InvocationCounter _backedge_counter;
1833   // Counter values at the time profiling started.
1834   int               _invocation_counter_start;
1835   int               _backedge_counter_start;
1836   // Number of loops and blocks is computed when compiling the first
1837   // time with C1. It is used to determine if method is trivial.
1838   short             _num_loops;
1839   short             _num_blocks;
1840   // Highest compile level this method has ever seen.
1841   u1                _highest_comp_level;
1842   // Same for OSR level
1843   u1                _highest_osr_comp_level;
1844   // Does this method contain anything worth profiling?
1845   bool              _would_profile;
1846 
1847   // Size of _data array in bytes.  (Excludes header and extra_data fields.)
1848   int _data_size;
1849 
1850   int _parameters_type_data_di;
1851 
1852   // Beginning of the data entries
1853   intptr_t _data[1];
1854 
1855   // Helper for size computation
1856   static int compute_data_size(BytecodeStream* stream);
1857   static int bytecode_cell_count(Bytecodes::Code code);
1858   enum { no_profile_data = -1, variable_cell_count = -2 };
1859 
1860   // Helper for initialization
1861   DataLayout* data_layout_at(int data_index) const {
1862     assert(data_index % sizeof(intptr_t) == 0, "unaligned");
1863     return (DataLayout*) (((address)_data) + data_index);
1864   }
1865 
1866   // Initialize an individual data segment.  Returns the size of
1867   // the segment in bytes.
1868   int initialize_data(BytecodeStream* stream, int data_index);
1869 
1870   // Helper for data_at
1871   DataLayout* limit_data_position() const {


1901   // Find or create an extra ProfileData:
1902   ProfileData* bci_to_extra_data(int bci, bool create_if_missing);
1903 
1904   // return the argument info cell
1905   ArgInfoData *arg_info();
1906 
1907   enum {
1908     no_type_profile = 0,
1909     type_profile_jsr292 = 1,
1910     type_profile_all = 2
1911   };
1912 
1913   static bool profile_jsr292(methodHandle m, int bci);
1914   static int profile_arguments_flag();
1915   static bool profile_arguments_jsr292_only();
1916   static bool profile_all_arguments();
1917   static bool profile_arguments_for_invoke(methodHandle m, int bci);
1918   static int profile_return_flag();
1919   static bool profile_all_return();
1920   static bool profile_return_for_invoke(methodHandle m, int bci);
1921   static int profile_parameters_flag();
1922   static bool profile_parameters_jsr292_only();
1923   static bool profile_all_parameters();
1924 
1925 public:
1926   static int header_size() {
1927     return sizeof(MethodData)/wordSize;
1928   }
1929 
1930   // Compute the size of a MethodData* before it is created.
1931   static int compute_allocation_size_in_bytes(methodHandle method);
1932   static int compute_allocation_size_in_words(methodHandle method);
1933   static int compute_extra_data_count(int data_size, int empty_bc_count);
1934 
1935   // Determine if a given bytecode can have profile information.
1936   static bool bytecode_has_profile(Bytecodes::Code code) {
1937     return bytecode_cell_count(code) != no_profile_data;
1938   }
1939 
1940   // reset into original state
1941   void init();
1942 
1943   // My size


2110 
2111   uint overflow_trap_count() const {
2112     return _nof_overflow_traps;
2113   }
2114   uint overflow_recompile_count() const {
2115     return _nof_overflow_recompiles;
2116   }
2117   void inc_overflow_recompile_count() {
2118     _nof_overflow_recompiles += 1;
2119   }
2120   uint decompile_count() const {
2121     return _nof_decompiles;
2122   }
2123   void inc_decompile_count() {
2124     _nof_decompiles += 1;
2125     if (decompile_count() > (uint)PerMethodRecompilationCutoff) {
2126       method()->set_not_compilable(CompLevel_full_optimization, true, "decompile_count > PerMethodRecompilationCutoff");
2127     }
2128   }
2129 
2130   ParametersTypeData* parameters_type_data() const {
2131     return _parameters_type_data_di != -1 ? data_layout_at(_parameters_type_data_di)->data_in()->as_ParametersTypeData() : NULL;
2132   }
2133 
2134   int parameters_type_data_di() const {
2135     assert(_parameters_type_data_di != -1, "no args type data");
2136     return _parameters_type_data_di;
2137   }
2138 
2139   // Support for code generation
2140   static ByteSize data_offset() {
2141     return byte_offset_of(MethodData, _data[0]);
2142   }
2143 
2144   static ByteSize invocation_counter_offset() {
2145     return byte_offset_of(MethodData, _invocation_counter);
2146   }
2147   static ByteSize backedge_counter_offset() {
2148     return byte_offset_of(MethodData, _backedge_counter);
2149   }
2150 
2151   static ByteSize parameters_type_data_di_offset() {
2152     return byte_offset_of(MethodData, _parameters_type_data_di);
2153   }
2154 
2155   // Deallocation support - no pointer fields to deallocate
2156   void deallocate_contents(ClassLoaderData* loader_data) {}
2157 
2158   // GC support
2159   void set_size(int object_size_in_bytes) { _size = object_size_in_bytes; }
2160 
2161   // Printing
2162 #ifndef PRODUCT
2163   void print_on      (outputStream* st) const;
2164 #endif
2165   void print_value_on(outputStream* st) const;
2166 
2167 #ifndef PRODUCT
2168   // printing support for method data
2169   void print_data_on(outputStream* st) const;
2170 #endif
2171 
2172   const char* internal_name() const { return "{method data}"; }
2173 
2174   // verification
2175   void verify_on(outputStream* st);
2176   void verify_data_on(outputStream* st);
2177 
2178   static bool profile_parameters_for_method(methodHandle m);
2179   static bool profile_arguments();
2180   static bool profile_return();
2181   static bool profile_parameters();
2182   static bool profile_return_jsr292_only();
2183 };
2184 
2185 #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