12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_OOPS_METHODDATA_HPP
26 #define SHARE_OOPS_METHODDATA_HPP
27
28 #include "interpreter/bytecodes.hpp"
29 #include "interpreter/invocationCounter.hpp"
30 #include "oops/metadata.hpp"
31 #include "oops/method.hpp"
32 #include "oops/oop.hpp"
33 #include "runtime/atomic.hpp"
34 #include "runtime/deoptimization.hpp"
35 #include "runtime/mutex.hpp"
36 #include "utilities/align.hpp"
37 #include "utilities/copy.hpp"
38
39 class BytecodeStream;
40
41 // The MethodData object collects counts and other profile information
42 // during zeroth-tier (interpreter) and third-tier (C1 with full profiling)
43 // execution.
44 //
45 // The profile is used later by compilation heuristics. Some heuristics
46 // enable use of aggressive (or "heroic") optimizations. An aggressive
47 // optimization often has a down-side, a corner case that it handles
48 // poorly, but which is thought to be rare. The profile provides
49 // evidence of this rarity for a given method or even BCI. It allows
50 // the compiler to back out of the optimization at places where it
51 // has historically been a poor choice. Other heuristics try to use
52 // specific information gathered about types observed at a given site.
185 return Atomic::load_acquire(&_header._struct._flags);
186 }
187
188 u2 bci() const {
189 return _header._struct._bci;
190 }
191
192 void set_header(u8 value) {
193 _header._bits = value;
194 }
195 u8 header() {
196 return _header._bits;
197 }
198 void set_cell_at(int index, intptr_t value) {
199 _cells[index] = value;
200 }
201 void release_set_cell_at(int index, intptr_t value);
202 intptr_t cell_at(int index) const {
203 return _cells[index];
204 }
205
206 bool set_flag_at(u1 flag_number) {
207 const u1 bit = 1 << flag_number;
208 u1 compare_value;
209 do {
210 compare_value = _header._struct._flags;
211 if ((compare_value & bit) == bit) {
212 // already set.
213 return false;
214 }
215 } while (compare_value != Atomic::cmpxchg(&_header._struct._flags, compare_value, static_cast<u1>(compare_value | bit)));
216 return true;
217 }
218
219 bool clear_flag_at(u1 flag_number) {
220 const u1 bit = 1 << flag_number;
221 u1 compare_value;
222 u1 exchange_value;
223 do {
224 compare_value = _header._struct._flags;
328 ShouldNotReachHere();
329 return -1;
330 }
331
332 // Return the size of this data.
333 int size_in_bytes() {
334 return DataLayout::compute_size_in_bytes(cell_count());
335 }
336
337 protected:
338 // Low-level accessors for underlying data
339 void set_intptr_at(int index, intptr_t value) {
340 assert(0 <= index && index < cell_count(), "oob");
341 data()->set_cell_at(index, value);
342 }
343 void release_set_intptr_at(int index, intptr_t value);
344 intptr_t intptr_at(int index) const {
345 assert(0 <= index && index < cell_count(), "oob");
346 return data()->cell_at(index);
347 }
348 void set_uint_at(int index, uint value) {
349 set_intptr_at(index, (intptr_t) value);
350 }
351 void release_set_uint_at(int index, uint value);
352 uint uint_at(int index) const {
353 return (uint)intptr_at(index);
354 }
355 void set_int_at(int index, int value) {
356 set_intptr_at(index, (intptr_t) value);
357 }
358 void release_set_int_at(int index, int value);
359 int int_at(int index) const {
360 return (int)intptr_at(index);
361 }
362 int int_at_unchecked(int index) const {
363 return (int)data()->cell_at(index);
364 }
365 void set_oop_at(int index, oop value) {
366 set_intptr_at(index, cast_from_oop<intptr_t>(value));
367 }
368 oop oop_at(int index) const {
369 return cast_to_oop(intptr_at(index));
370 }
371
372 void set_flag_at(u1 flag_number) {
373 data()->set_flag_at(flag_number);
374 }
375 bool flag_at(u1 flag_number) const {
376 return data()->flag_at(flag_number);
377 }
378
379 // two convenient imports for use by subclasses:
380 static ByteSize cell_offset(int index) {
381 return DataLayout::cell_offset(index);
382 }
383 static u1 flag_number_to_constant(u1 flag_number) {
384 return DataLayout::flag_number_to_constant(flag_number);
385 }
386
387 ProfileData(DataLayout* data) {
388 _data = data;
389 }
390
471 VirtualCallTypeData* as_VirtualCallTypeData() const {
472 assert(is_VirtualCallTypeData(), "wrong type");
473 return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : nullptr;
474 }
475 ParametersTypeData* as_ParametersTypeData() const {
476 assert(is_ParametersTypeData(), "wrong type");
477 return is_ParametersTypeData() ? (ParametersTypeData*)this : nullptr;
478 }
479 SpeculativeTrapData* as_SpeculativeTrapData() const {
480 assert(is_SpeculativeTrapData(), "wrong type");
481 return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : nullptr;
482 }
483
484
485 // Subclass specific initialization
486 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
487
488 // GC support
489 virtual void clean_weak_klass_links(bool always_clean) {}
490
491 // CI translation: ProfileData can represent both MethodDataOop data
492 // as well as CIMethodData data. This function is provided for translating
493 // an oop in a ProfileData to the ci equivalent. Generally speaking,
494 // most ProfileData don't require any translation, so we provide the null
495 // translation here, and the required translators are in the ci subclasses.
496 virtual void translate_from(const ProfileData* data) {}
497
498 virtual void print_data_on(outputStream* st, const char* extra = nullptr) const {
499 ShouldNotReachHere();
500 }
501
502 void print_data_on(outputStream* st, const MethodData* md) const;
503
504 void print_shared(outputStream* st, const char* name, const char* extra) const;
505 void tab(outputStream* st, bool first = false) const;
506 };
507
508 // BitData
509 //
510 // A BitData holds a flag or two in its header.
511 class BitData : public ProfileData {
836 }
837
838 // stack slot for entry i
839 uint stack_slot(int i) const {
840 assert(i >= 0 && i < _number_of_entries, "oob");
841 return _pd->uint_at(stack_slot_offset(i));
842 }
843
844 // set stack slot for entry i
845 void set_stack_slot(int i, uint num) {
846 assert(i >= 0 && i < _number_of_entries, "oob");
847 _pd->set_uint_at(stack_slot_offset(i), num);
848 }
849
850 // type for entry i
851 intptr_t type(int i) const {
852 assert(i >= 0 && i < _number_of_entries, "oob");
853 return _pd->intptr_at(type_offset_in_cells(i));
854 }
855
856 // set type for entry i
857 void set_type(int i, intptr_t k) {
858 assert(i >= 0 && i < _number_of_entries, "oob");
859 _pd->set_intptr_at(type_offset_in_cells(i), k);
860 }
861
862 static ByteSize per_arg_size() {
863 return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
864 }
865
866 static int per_arg_count() {
867 return per_arg_cell_count;
868 }
869
870 ByteSize type_offset(int i) const {
871 return DataLayout::cell_offset(type_offset_in_cells(i));
872 }
873
874 // GC support
875 void clean_weak_klass_links(bool always_clean);
876
877 void print_data_on(outputStream* st) const;
878 };
879
880 // Type entry used for return from a call. A single cell to record the
881 // type.
882 class ReturnTypeEntry : public TypeEntries {
883
884 private:
885 enum {
886 cell_count = 1
887 };
888
889 public:
890 ReturnTypeEntry(int base_off)
891 : TypeEntries(base_off) {}
892
893 void post_initialize() {
894 set_type(type_none());
895 }
896
897 intptr_t type() const {
898 return _pd->intptr_at(_base_off);
899 }
900
901 void set_type(intptr_t k) {
902 _pd->set_intptr_at(_base_off, k);
903 }
904
905 static int static_cell_count() {
906 return cell_count;
907 }
908
909 static ByteSize size() {
910 return in_ByteSize(cell_count * DataLayout::cell_size);
911 }
912
913 ByteSize type_offset() {
914 return DataLayout::cell_offset(_base_off);
915 }
916
917 // GC support
918 void clean_weak_klass_links(bool always_clean);
919
920 void print_data_on(outputStream* st) const;
921 };
922
923 // Entries to collect type information at a call: contains arguments
924 // (TypeStackSlotEntries), a return type (ReturnTypeEntry) and a
925 // number of cells. Because the number of cells for the return type is
926 // smaller than the number of cells for the type of an arguments, the
927 // number of cells is used to tell how many arguments are profiled and
928 // whether a return value is profiled. See has_arguments() and
929 // has_return().
930 class TypeEntriesAtCall {
931 private:
932 static int stack_slot_local_offset(int i) {
933 return header_cell_count() + TypeStackSlotEntries::stack_slot_local_offset(i);
934 }
935
936 static int argument_type_local_offset(int i) {
937 return header_cell_count() + TypeStackSlotEntries::type_local_offset(i);
938 }
939
1091 }
1092
1093 ByteSize argument_type_offset(int i) {
1094 return _args.type_offset(i);
1095 }
1096
1097 ByteSize return_type_offset() {
1098 return _ret.type_offset();
1099 }
1100
1101 // GC support
1102 virtual void clean_weak_klass_links(bool always_clean) {
1103 if (has_arguments()) {
1104 _args.clean_weak_klass_links(always_clean);
1105 }
1106 if (has_return()) {
1107 _ret.clean_weak_klass_links(always_clean);
1108 }
1109 }
1110
1111 virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1112 };
1113
1114 // ReceiverTypeData
1115 //
1116 // A ReceiverTypeData is used to access profiling information about a
1117 // dynamic type check. It consists of a series of (Klass*, count)
1118 // pairs which are used to store a type profile for the receiver of
1119 // the check, the associated count is incremented every time the type
1120 // is seen. A per ReceiverTypeData counter is incremented on type
1121 // overflow (when there's no more room for a not yet profiled Klass*).
1122 //
1123 class ReceiverTypeData : public CounterData {
1124 friend class VMStructs;
1125 friend class JVMCIVMStructs;
1126 protected:
1127 enum {
1128 receiver0_offset = counter_cell_count,
1129 count0_offset,
1130 receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
1201 //
1202 set_count(0);
1203 set_receiver(row, nullptr);
1204 set_receiver_count(row, 0);
1205 }
1206
1207 // Code generation support
1208 static ByteSize receiver_offset(uint row) {
1209 return cell_offset(receiver_cell_index(row));
1210 }
1211 static ByteSize receiver_count_offset(uint row) {
1212 return cell_offset(receiver_count_cell_index(row));
1213 }
1214 static ByteSize receiver_type_data_size() {
1215 return cell_offset(static_cell_count());
1216 }
1217
1218 // GC support
1219 virtual void clean_weak_klass_links(bool always_clean);
1220
1221 void print_receiver_data_on(outputStream* st) const;
1222 void print_data_on(outputStream* st, const char* extra = nullptr) const;
1223 };
1224
1225 // VirtualCallData
1226 //
1227 // A VirtualCallData is used to access profiling information about a
1228 // virtual call. For now, it has nothing more than a ReceiverTypeData.
1229 class VirtualCallData : public ReceiverTypeData {
1230 public:
1231 VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
1232 assert(layout->tag() == DataLayout::virtual_call_data_tag ||
1233 layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1234 }
1235
1236 virtual bool is_VirtualCallData() const { return true; }
1237
1238 static int static_cell_count() {
1239 // At this point we could add more profile state, e.g., for arguments.
1240 // But for now it's the same size as the base record type.
1366
1367 ByteSize argument_type_offset(int i) {
1368 return _args.type_offset(i);
1369 }
1370
1371 ByteSize return_type_offset() {
1372 return _ret.type_offset();
1373 }
1374
1375 // GC support
1376 virtual void clean_weak_klass_links(bool always_clean) {
1377 ReceiverTypeData::clean_weak_klass_links(always_clean);
1378 if (has_arguments()) {
1379 _args.clean_weak_klass_links(always_clean);
1380 }
1381 if (has_return()) {
1382 _ret.clean_weak_klass_links(always_clean);
1383 }
1384 }
1385
1386 virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1387 };
1388
1389 // RetData
1390 //
1391 // A RetData is used to access profiling information for a ret bytecode.
1392 // It is composed of a count of the number of times that the ret has
1393 // been executed, followed by a series of triples of the form
1394 // (bci, count, di) which count the number of times that some bci was the
1395 // target of the ret and cache a corresponding data displacement.
1396 class RetData : public CounterData {
1397 protected:
1398 enum {
1399 bci0_offset = counter_cell_count,
1400 count0_offset,
1401 displacement0_offset,
1402 ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
1403 };
1404
1405 void set_bci(uint row, int bci) {
1549 // and an array start.
1550 class ArrayData : public ProfileData {
1551 friend class VMStructs;
1552 friend class JVMCIVMStructs;
1553 protected:
1554 friend class DataLayout;
1555
1556 enum {
1557 array_len_off_set,
1558 array_start_off_set
1559 };
1560
1561 uint array_uint_at(int index) const {
1562 int aindex = index + array_start_off_set;
1563 return uint_at(aindex);
1564 }
1565 int array_int_at(int index) const {
1566 int aindex = index + array_start_off_set;
1567 return int_at(aindex);
1568 }
1569 oop array_oop_at(int index) const {
1570 int aindex = index + array_start_off_set;
1571 return oop_at(aindex);
1572 }
1573 void array_set_int_at(int index, int value) {
1574 int aindex = index + array_start_off_set;
1575 set_int_at(aindex, value);
1576 }
1577
1578 // Code generation support for subclasses.
1579 static ByteSize array_element_offset(int index) {
1580 return cell_offset(array_start_off_set + index);
1581 }
1582
1583 public:
1584 ArrayData(DataLayout* layout) : ProfileData(layout) {}
1585
1586 virtual bool is_ArrayData() const { return true; }
1587
1588 static int static_cell_count() {
1589 return -1;
1590 }
1591
1592 int array_len() const {
1765
1766 int number_of_parameters() const {
1767 return array_len() / TypeStackSlotEntries::per_arg_count();
1768 }
1769
1770 const TypeStackSlotEntries* parameters() const { return &_parameters; }
1771
1772 uint stack_slot(int i) const {
1773 return _parameters.stack_slot(i);
1774 }
1775
1776 void set_type(int i, Klass* k) {
1777 intptr_t current = _parameters.type(i);
1778 _parameters.set_type(i, TypeEntries::with_status((intptr_t)k, current));
1779 }
1780
1781 virtual void clean_weak_klass_links(bool always_clean) {
1782 _parameters.clean_weak_klass_links(always_clean);
1783 }
1784
1785 virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1786
1787 static ByteSize stack_slot_offset(int i) {
1788 return cell_offset(stack_slot_local_offset(i));
1789 }
1790
1791 static ByteSize type_offset(int i) {
1792 return cell_offset(type_local_offset(i));
1793 }
1794 };
1795
1796 // SpeculativeTrapData
1797 //
1798 // A SpeculativeTrapData is used to record traps due to type
1799 // speculation. It records the root of the compilation: that type
1800 // speculation is wrong in the context of one compilation (for
1801 // method1) doesn't mean it's wrong in the context of another one (for
1802 // method2). Type speculation could have more/different data in the
1803 // context of the compilation of method2 and it's worthwhile to try an
1804 // optimization that failed for compilation of method1 in the context
1835 }
1836
1837 virtual int cell_count() const {
1838 return static_cell_count();
1839 }
1840
1841 // Direct accessor
1842 Method* method() const {
1843 return (Method*)intptr_at(speculative_trap_method);
1844 }
1845
1846 void set_method(Method* m) {
1847 assert(!m->is_old(), "cannot add old methods");
1848 set_intptr_at(speculative_trap_method, (intptr_t)m);
1849 }
1850
1851 static ByteSize method_offset() {
1852 return cell_offset(speculative_trap_method);
1853 }
1854
1855 virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1856 };
1857
1858 // MethodData*
1859 //
1860 // A MethodData* holds information which has been collected about
1861 // a method. Its layout looks like this:
1862 //
1863 // -----------------------------
1864 // | header |
1865 // | klass |
1866 // -----------------------------
1867 // | method |
1868 // | size of the MethodData* |
1869 // -----------------------------
1870 // | Data entries... |
1871 // | (variable size) |
1872 // | |
1873 // . .
1874 // . .
1945 class MethodData : public Metadata {
1946 friend class VMStructs;
1947 friend class JVMCIVMStructs;
1948 friend class ProfileData;
1949 friend class TypeEntriesAtCall;
1950 friend class ciMethodData;
1951 friend class VM_ReinitializeMDO;
1952
1953 // If you add a new field that points to any metaspace object, you
1954 // must add this field to MethodData::metaspace_pointers_do().
1955
1956 // Back pointer to the Method*
1957 Method* _method;
1958
1959 // Size of this oop in bytes
1960 int _size;
1961
1962 // Cached hint for bci_to_dp and bci_to_data
1963 int _hint_di;
1964
1965 Mutex _extra_data_lock;
1966
1967 MethodData(const methodHandle& method);
1968
1969 void initialize();
1970
1971 public:
1972 static MethodData* allocate(ClassLoaderData* loader_data, const methodHandle& method, TRAPS);
1973
1974 virtual bool is_methodData() const { return true; }
1975
1976 // Safely reinitialize the data in the MDO. This is intended as a testing facility as the
1977 // reinitialization is performed at a safepoint so it's isn't cheap and it doesn't ensure that all
1978 // readers will see consistent profile data.
1979 void reinitialize();
1980
1981 // Whole-method sticky bits and flags
1982 enum {
1983 _trap_hist_limit = Deoptimization::Reason_TRAP_HISTORY_LENGTH,
1984 _trap_hist_mask = max_jubyte,
1985 _extra_data_count = 4 // extra DataLayout headers, for trap history
1986 }; // Public flag values
1987
1988 // Compiler-related counters.
1989 class CompilerCounters {
1990 friend class VMStructs;
1991 friend class JVMCIVMStructs;
2249 return _backedge_counter_start;
2250 }
2251
2252 int invocation_count_delta() { return invocation_count() - invocation_count_start(); }
2253 int backedge_count_delta() { return backedge_count() - backedge_count_start(); }
2254
2255 void reset_start_counters() {
2256 _invocation_counter_start = invocation_count();
2257 _backedge_counter_start = backedge_count();
2258 }
2259
2260 InvocationCounter* invocation_counter() { return &_invocation_counter; }
2261 InvocationCounter* backedge_counter() { return &_backedge_counter; }
2262
2263 #if INCLUDE_JVMCI
2264 FailedSpeculation** get_failed_speculations_address() {
2265 return &_failed_speculations;
2266 }
2267 #endif
2268
2269 void set_would_profile(bool p) { _would_profile = p ? profile : no_profile; }
2270 bool would_profile() const { return _would_profile != no_profile; }
2271
2272 int num_loops() const { return _num_loops; }
2273 void set_num_loops(short n) { _num_loops = n; }
2274 int num_blocks() const { return _num_blocks; }
2275 void set_num_blocks(short n) { _num_blocks = n; }
2276
2277 bool is_mature() const;
2278
2279 // Support for interprocedural escape analysis, from Thomas Kotzmann.
2280 enum EscapeFlag {
2281 estimated = 1 << 0,
2282 return_local = 1 << 1,
2283 return_allocated = 1 << 2,
2284 allocated_escapes = 1 << 3,
2285 unknown_modified = 1 << 4
2286 };
2287
2288 intx eflags() { return _eflags; }
2487 void print_value_on(outputStream* st) const;
2488
2489 // printing support for method data
2490 void print_data_on(outputStream* st) const;
2491
2492 const char* internal_name() const { return "{method data}"; }
2493
2494 // verification
2495 void verify_on(outputStream* st);
2496 void verify_data_on(outputStream* st);
2497
2498 static bool profile_parameters_for_method(const methodHandle& m);
2499 static bool profile_arguments();
2500 static bool profile_arguments_jsr292_only();
2501 static bool profile_return();
2502 static bool profile_parameters();
2503 static bool profile_return_jsr292_only();
2504
2505 void clean_method_data(bool always_clean);
2506 void clean_weak_method_links();
2507 Mutex* extra_data_lock() const { return const_cast<Mutex*>(&_extra_data_lock); }
2508 void check_extra_data_locked() const NOT_DEBUG_RETURN;
2509 };
2510
2511 #endif // SHARE_OOPS_METHODDATA_HPP
|
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_OOPS_METHODDATA_HPP
26 #define SHARE_OOPS_METHODDATA_HPP
27
28 #include "interpreter/bytecodes.hpp"
29 #include "interpreter/invocationCounter.hpp"
30 #include "oops/metadata.hpp"
31 #include "oops/method.hpp"
32 #include "runtime/atomic.hpp"
33 #include "runtime/deoptimization.hpp"
34 #include "runtime/mutex.hpp"
35 #include "utilities/align.hpp"
36 #include "utilities/copy.hpp"
37
38 class BytecodeStream;
39
40 // The MethodData object collects counts and other profile information
41 // during zeroth-tier (interpreter) and third-tier (C1 with full profiling)
42 // execution.
43 //
44 // The profile is used later by compilation heuristics. Some heuristics
45 // enable use of aggressive (or "heroic") optimizations. An aggressive
46 // optimization often has a down-side, a corner case that it handles
47 // poorly, but which is thought to be rare. The profile provides
48 // evidence of this rarity for a given method or even BCI. It allows
49 // the compiler to back out of the optimization at places where it
50 // has historically been a poor choice. Other heuristics try to use
51 // specific information gathered about types observed at a given site.
184 return Atomic::load_acquire(&_header._struct._flags);
185 }
186
187 u2 bci() const {
188 return _header._struct._bci;
189 }
190
191 void set_header(u8 value) {
192 _header._bits = value;
193 }
194 u8 header() {
195 return _header._bits;
196 }
197 void set_cell_at(int index, intptr_t value) {
198 _cells[index] = value;
199 }
200 void release_set_cell_at(int index, intptr_t value);
201 intptr_t cell_at(int index) const {
202 return _cells[index];
203 }
204 intptr_t* cell_at_adr(int index) const {
205 return const_cast<intptr_t*>(&_cells[index]);
206 }
207
208 bool set_flag_at(u1 flag_number) {
209 const u1 bit = 1 << flag_number;
210 u1 compare_value;
211 do {
212 compare_value = _header._struct._flags;
213 if ((compare_value & bit) == bit) {
214 // already set.
215 return false;
216 }
217 } while (compare_value != Atomic::cmpxchg(&_header._struct._flags, compare_value, static_cast<u1>(compare_value | bit)));
218 return true;
219 }
220
221 bool clear_flag_at(u1 flag_number) {
222 const u1 bit = 1 << flag_number;
223 u1 compare_value;
224 u1 exchange_value;
225 do {
226 compare_value = _header._struct._flags;
330 ShouldNotReachHere();
331 return -1;
332 }
333
334 // Return the size of this data.
335 int size_in_bytes() {
336 return DataLayout::compute_size_in_bytes(cell_count());
337 }
338
339 protected:
340 // Low-level accessors for underlying data
341 void set_intptr_at(int index, intptr_t value) {
342 assert(0 <= index && index < cell_count(), "oob");
343 data()->set_cell_at(index, value);
344 }
345 void release_set_intptr_at(int index, intptr_t value);
346 intptr_t intptr_at(int index) const {
347 assert(0 <= index && index < cell_count(), "oob");
348 return data()->cell_at(index);
349 }
350 intptr_t* intptr_at_adr(int index) const {
351 assert(0 <= index && index < cell_count(), "oob");
352 return data()->cell_at_adr(index);
353 }
354 void set_uint_at(int index, uint value) {
355 set_intptr_at(index, (intptr_t) value);
356 }
357 void release_set_uint_at(int index, uint value);
358 uint uint_at(int index) const {
359 return (uint)intptr_at(index);
360 }
361 void set_int_at(int index, int value) {
362 set_intptr_at(index, (intptr_t) value);
363 }
364 void release_set_int_at(int index, int value);
365 int int_at(int index) const {
366 return (int)intptr_at(index);
367 }
368 int int_at_unchecked(int index) const {
369 return (int)data()->cell_at(index);
370 }
371
372 void set_flag_at(u1 flag_number) {
373 data()->set_flag_at(flag_number);
374 }
375 bool flag_at(u1 flag_number) const {
376 return data()->flag_at(flag_number);
377 }
378
379 // two convenient imports for use by subclasses:
380 static ByteSize cell_offset(int index) {
381 return DataLayout::cell_offset(index);
382 }
383 static u1 flag_number_to_constant(u1 flag_number) {
384 return DataLayout::flag_number_to_constant(flag_number);
385 }
386
387 ProfileData(DataLayout* data) {
388 _data = data;
389 }
390
471 VirtualCallTypeData* as_VirtualCallTypeData() const {
472 assert(is_VirtualCallTypeData(), "wrong type");
473 return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : nullptr;
474 }
475 ParametersTypeData* as_ParametersTypeData() const {
476 assert(is_ParametersTypeData(), "wrong type");
477 return is_ParametersTypeData() ? (ParametersTypeData*)this : nullptr;
478 }
479 SpeculativeTrapData* as_SpeculativeTrapData() const {
480 assert(is_SpeculativeTrapData(), "wrong type");
481 return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : nullptr;
482 }
483
484
485 // Subclass specific initialization
486 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
487
488 // GC support
489 virtual void clean_weak_klass_links(bool always_clean) {}
490
491 // CDS support
492 virtual void metaspace_pointers_do(MetaspaceClosure* it) {}
493
494 // CI translation: ProfileData can represent both MethodDataOop data
495 // as well as CIMethodData data. This function is provided for translating
496 // an oop in a ProfileData to the ci equivalent. Generally speaking,
497 // most ProfileData don't require any translation, so we provide the null
498 // translation here, and the required translators are in the ci subclasses.
499 virtual void translate_from(const ProfileData* data) {}
500
501 virtual void print_data_on(outputStream* st, const char* extra = nullptr) const {
502 ShouldNotReachHere();
503 }
504
505 void print_data_on(outputStream* st, const MethodData* md) const;
506
507 void print_shared(outputStream* st, const char* name, const char* extra) const;
508 void tab(outputStream* st, bool first = false) const;
509 };
510
511 // BitData
512 //
513 // A BitData holds a flag or two in its header.
514 class BitData : public ProfileData {
839 }
840
841 // stack slot for entry i
842 uint stack_slot(int i) const {
843 assert(i >= 0 && i < _number_of_entries, "oob");
844 return _pd->uint_at(stack_slot_offset(i));
845 }
846
847 // set stack slot for entry i
848 void set_stack_slot(int i, uint num) {
849 assert(i >= 0 && i < _number_of_entries, "oob");
850 _pd->set_uint_at(stack_slot_offset(i), num);
851 }
852
853 // type for entry i
854 intptr_t type(int i) const {
855 assert(i >= 0 && i < _number_of_entries, "oob");
856 return _pd->intptr_at(type_offset_in_cells(i));
857 }
858
859 intptr_t* type_adr(int i) const {
860 assert(i >= 0 && i < _number_of_entries, "oob");
861 return _pd->intptr_at_adr(type_offset_in_cells(i));
862 }
863
864 // set type for entry i
865 void set_type(int i, intptr_t k) {
866 assert(i >= 0 && i < _number_of_entries, "oob");
867 _pd->set_intptr_at(type_offset_in_cells(i), k);
868 }
869
870 static ByteSize per_arg_size() {
871 return in_ByteSize(per_arg_cell_count * DataLayout::cell_size);
872 }
873
874 static int per_arg_count() {
875 return per_arg_cell_count;
876 }
877
878 ByteSize type_offset(int i) const {
879 return DataLayout::cell_offset(type_offset_in_cells(i));
880 }
881
882 // GC support
883 void clean_weak_klass_links(bool always_clean);
884
885 // CDS support
886 virtual void metaspace_pointers_do(MetaspaceClosure* it);
887
888 void print_data_on(outputStream* st) const;
889 };
890
891 // Type entry used for return from a call. A single cell to record the
892 // type.
893 class ReturnTypeEntry : public TypeEntries {
894
895 private:
896 enum {
897 cell_count = 1
898 };
899
900 public:
901 ReturnTypeEntry(int base_off)
902 : TypeEntries(base_off) {}
903
904 void post_initialize() {
905 set_type(type_none());
906 }
907
908 intptr_t type() const {
909 return _pd->intptr_at(_base_off);
910 }
911
912 intptr_t* type_adr() const {
913 return _pd->intptr_at_adr(_base_off);
914 }
915
916 void set_type(intptr_t k) {
917 _pd->set_intptr_at(_base_off, k);
918 }
919
920 static int static_cell_count() {
921 return cell_count;
922 }
923
924 static ByteSize size() {
925 return in_ByteSize(cell_count * DataLayout::cell_size);
926 }
927
928 ByteSize type_offset() {
929 return DataLayout::cell_offset(_base_off);
930 }
931
932 // GC support
933 void clean_weak_klass_links(bool always_clean);
934
935 // CDS support
936 virtual void metaspace_pointers_do(MetaspaceClosure* it);
937
938 void print_data_on(outputStream* st) const;
939 };
940
941 // Entries to collect type information at a call: contains arguments
942 // (TypeStackSlotEntries), a return type (ReturnTypeEntry) and a
943 // number of cells. Because the number of cells for the return type is
944 // smaller than the number of cells for the type of an arguments, the
945 // number of cells is used to tell how many arguments are profiled and
946 // whether a return value is profiled. See has_arguments() and
947 // has_return().
948 class TypeEntriesAtCall {
949 private:
950 static int stack_slot_local_offset(int i) {
951 return header_cell_count() + TypeStackSlotEntries::stack_slot_local_offset(i);
952 }
953
954 static int argument_type_local_offset(int i) {
955 return header_cell_count() + TypeStackSlotEntries::type_local_offset(i);
956 }
957
1109 }
1110
1111 ByteSize argument_type_offset(int i) {
1112 return _args.type_offset(i);
1113 }
1114
1115 ByteSize return_type_offset() {
1116 return _ret.type_offset();
1117 }
1118
1119 // GC support
1120 virtual void clean_weak_klass_links(bool always_clean) {
1121 if (has_arguments()) {
1122 _args.clean_weak_klass_links(always_clean);
1123 }
1124 if (has_return()) {
1125 _ret.clean_weak_klass_links(always_clean);
1126 }
1127 }
1128
1129 // CDS support
1130 virtual void metaspace_pointers_do(MetaspaceClosure* it) {
1131 if (has_arguments()) {
1132 _args.metaspace_pointers_do(it);
1133 }
1134 if (has_return()) {
1135 _ret.metaspace_pointers_do(it);
1136 }
1137 }
1138
1139 virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1140 };
1141
1142 // ReceiverTypeData
1143 //
1144 // A ReceiverTypeData is used to access profiling information about a
1145 // dynamic type check. It consists of a series of (Klass*, count)
1146 // pairs which are used to store a type profile for the receiver of
1147 // the check, the associated count is incremented every time the type
1148 // is seen. A per ReceiverTypeData counter is incremented on type
1149 // overflow (when there's no more room for a not yet profiled Klass*).
1150 //
1151 class ReceiverTypeData : public CounterData {
1152 friend class VMStructs;
1153 friend class JVMCIVMStructs;
1154 protected:
1155 enum {
1156 receiver0_offset = counter_cell_count,
1157 count0_offset,
1158 receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
1229 //
1230 set_count(0);
1231 set_receiver(row, nullptr);
1232 set_receiver_count(row, 0);
1233 }
1234
1235 // Code generation support
1236 static ByteSize receiver_offset(uint row) {
1237 return cell_offset(receiver_cell_index(row));
1238 }
1239 static ByteSize receiver_count_offset(uint row) {
1240 return cell_offset(receiver_count_cell_index(row));
1241 }
1242 static ByteSize receiver_type_data_size() {
1243 return cell_offset(static_cell_count());
1244 }
1245
1246 // GC support
1247 virtual void clean_weak_klass_links(bool always_clean);
1248
1249 // CDS support
1250 virtual void metaspace_pointers_do(MetaspaceClosure* it);
1251
1252 void print_receiver_data_on(outputStream* st) const;
1253 void print_data_on(outputStream* st, const char* extra = nullptr) const;
1254 };
1255
1256 // VirtualCallData
1257 //
1258 // A VirtualCallData is used to access profiling information about a
1259 // virtual call. For now, it has nothing more than a ReceiverTypeData.
1260 class VirtualCallData : public ReceiverTypeData {
1261 public:
1262 VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
1263 assert(layout->tag() == DataLayout::virtual_call_data_tag ||
1264 layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1265 }
1266
1267 virtual bool is_VirtualCallData() const { return true; }
1268
1269 static int static_cell_count() {
1270 // At this point we could add more profile state, e.g., for arguments.
1271 // But for now it's the same size as the base record type.
1397
1398 ByteSize argument_type_offset(int i) {
1399 return _args.type_offset(i);
1400 }
1401
1402 ByteSize return_type_offset() {
1403 return _ret.type_offset();
1404 }
1405
1406 // GC support
1407 virtual void clean_weak_klass_links(bool always_clean) {
1408 ReceiverTypeData::clean_weak_klass_links(always_clean);
1409 if (has_arguments()) {
1410 _args.clean_weak_klass_links(always_clean);
1411 }
1412 if (has_return()) {
1413 _ret.clean_weak_klass_links(always_clean);
1414 }
1415 }
1416
1417 // CDS support
1418 virtual void metaspace_pointers_do(MetaspaceClosure* it) {
1419 ReceiverTypeData::metaspace_pointers_do(it);
1420 if (has_arguments()) {
1421 _args.metaspace_pointers_do(it);
1422 }
1423 if (has_return()) {
1424 _ret.metaspace_pointers_do(it);
1425 }
1426 }
1427
1428 virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1429 };
1430
1431 // RetData
1432 //
1433 // A RetData is used to access profiling information for a ret bytecode.
1434 // It is composed of a count of the number of times that the ret has
1435 // been executed, followed by a series of triples of the form
1436 // (bci, count, di) which count the number of times that some bci was the
1437 // target of the ret and cache a corresponding data displacement.
1438 class RetData : public CounterData {
1439 protected:
1440 enum {
1441 bci0_offset = counter_cell_count,
1442 count0_offset,
1443 displacement0_offset,
1444 ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
1445 };
1446
1447 void set_bci(uint row, int bci) {
1591 // and an array start.
1592 class ArrayData : public ProfileData {
1593 friend class VMStructs;
1594 friend class JVMCIVMStructs;
1595 protected:
1596 friend class DataLayout;
1597
1598 enum {
1599 array_len_off_set,
1600 array_start_off_set
1601 };
1602
1603 uint array_uint_at(int index) const {
1604 int aindex = index + array_start_off_set;
1605 return uint_at(aindex);
1606 }
1607 int array_int_at(int index) const {
1608 int aindex = index + array_start_off_set;
1609 return int_at(aindex);
1610 }
1611 void array_set_int_at(int index, int value) {
1612 int aindex = index + array_start_off_set;
1613 set_int_at(aindex, value);
1614 }
1615
1616 // Code generation support for subclasses.
1617 static ByteSize array_element_offset(int index) {
1618 return cell_offset(array_start_off_set + index);
1619 }
1620
1621 public:
1622 ArrayData(DataLayout* layout) : ProfileData(layout) {}
1623
1624 virtual bool is_ArrayData() const { return true; }
1625
1626 static int static_cell_count() {
1627 return -1;
1628 }
1629
1630 int array_len() const {
1803
1804 int number_of_parameters() const {
1805 return array_len() / TypeStackSlotEntries::per_arg_count();
1806 }
1807
1808 const TypeStackSlotEntries* parameters() const { return &_parameters; }
1809
1810 uint stack_slot(int i) const {
1811 return _parameters.stack_slot(i);
1812 }
1813
1814 void set_type(int i, Klass* k) {
1815 intptr_t current = _parameters.type(i);
1816 _parameters.set_type(i, TypeEntries::with_status((intptr_t)k, current));
1817 }
1818
1819 virtual void clean_weak_klass_links(bool always_clean) {
1820 _parameters.clean_weak_klass_links(always_clean);
1821 }
1822
1823 // CDS support
1824 virtual void metaspace_pointers_do(MetaspaceClosure* it) {
1825 _parameters.metaspace_pointers_do(it);
1826 }
1827
1828 virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1829
1830 static ByteSize stack_slot_offset(int i) {
1831 return cell_offset(stack_slot_local_offset(i));
1832 }
1833
1834 static ByteSize type_offset(int i) {
1835 return cell_offset(type_local_offset(i));
1836 }
1837 };
1838
1839 // SpeculativeTrapData
1840 //
1841 // A SpeculativeTrapData is used to record traps due to type
1842 // speculation. It records the root of the compilation: that type
1843 // speculation is wrong in the context of one compilation (for
1844 // method1) doesn't mean it's wrong in the context of another one (for
1845 // method2). Type speculation could have more/different data in the
1846 // context of the compilation of method2 and it's worthwhile to try an
1847 // optimization that failed for compilation of method1 in the context
1878 }
1879
1880 virtual int cell_count() const {
1881 return static_cell_count();
1882 }
1883
1884 // Direct accessor
1885 Method* method() const {
1886 return (Method*)intptr_at(speculative_trap_method);
1887 }
1888
1889 void set_method(Method* m) {
1890 assert(!m->is_old(), "cannot add old methods");
1891 set_intptr_at(speculative_trap_method, (intptr_t)m);
1892 }
1893
1894 static ByteSize method_offset() {
1895 return cell_offset(speculative_trap_method);
1896 }
1897
1898 // CDS support
1899 virtual void metaspace_pointers_do(MetaspaceClosure* it);
1900
1901 virtual void print_data_on(outputStream* st, const char* extra = nullptr) const;
1902 };
1903
1904 // MethodData*
1905 //
1906 // A MethodData* holds information which has been collected about
1907 // a method. Its layout looks like this:
1908 //
1909 // -----------------------------
1910 // | header |
1911 // | klass |
1912 // -----------------------------
1913 // | method |
1914 // | size of the MethodData* |
1915 // -----------------------------
1916 // | Data entries... |
1917 // | (variable size) |
1918 // | |
1919 // . .
1920 // . .
1991 class MethodData : public Metadata {
1992 friend class VMStructs;
1993 friend class JVMCIVMStructs;
1994 friend class ProfileData;
1995 friend class TypeEntriesAtCall;
1996 friend class ciMethodData;
1997 friend class VM_ReinitializeMDO;
1998
1999 // If you add a new field that points to any metaspace object, you
2000 // must add this field to MethodData::metaspace_pointers_do().
2001
2002 // Back pointer to the Method*
2003 Method* _method;
2004
2005 // Size of this oop in bytes
2006 int _size;
2007
2008 // Cached hint for bci_to_dp and bci_to_data
2009 int _hint_di;
2010
2011 Mutex* volatile _extra_data_lock; // FIXME: CDS support
2012
2013 MethodData(const methodHandle& method);
2014
2015 void initialize();
2016
2017 public:
2018 MethodData();
2019
2020 static MethodData* allocate(ClassLoaderData* loader_data, const methodHandle& method, TRAPS);
2021
2022 virtual bool is_methodData() const { return true; }
2023
2024 // Safely reinitialize the data in the MDO. This is intended as a testing facility as the
2025 // reinitialization is performed at a safepoint so it's isn't cheap and it doesn't ensure that all
2026 // readers will see consistent profile data.
2027 void reinitialize();
2028
2029 // Whole-method sticky bits and flags
2030 enum {
2031 _trap_hist_limit = Deoptimization::Reason_TRAP_HISTORY_LENGTH,
2032 _trap_hist_mask = max_jubyte,
2033 _extra_data_count = 4 // extra DataLayout headers, for trap history
2034 }; // Public flag values
2035
2036 // Compiler-related counters.
2037 class CompilerCounters {
2038 friend class VMStructs;
2039 friend class JVMCIVMStructs;
2297 return _backedge_counter_start;
2298 }
2299
2300 int invocation_count_delta() { return invocation_count() - invocation_count_start(); }
2301 int backedge_count_delta() { return backedge_count() - backedge_count_start(); }
2302
2303 void reset_start_counters() {
2304 _invocation_counter_start = invocation_count();
2305 _backedge_counter_start = backedge_count();
2306 }
2307
2308 InvocationCounter* invocation_counter() { return &_invocation_counter; }
2309 InvocationCounter* backedge_counter() { return &_backedge_counter; }
2310
2311 #if INCLUDE_JVMCI
2312 FailedSpeculation** get_failed_speculations_address() {
2313 return &_failed_speculations;
2314 }
2315 #endif
2316
2317 #if INCLUDE_CDS
2318 void remove_unshareable_info();
2319 void restore_unshareable_info(TRAPS);
2320 #endif
2321
2322 void set_would_profile(bool p) { _would_profile = p ? profile : no_profile; }
2323 bool would_profile() const { return _would_profile != no_profile; }
2324
2325 int num_loops() const { return _num_loops; }
2326 void set_num_loops(short n) { _num_loops = n; }
2327 int num_blocks() const { return _num_blocks; }
2328 void set_num_blocks(short n) { _num_blocks = n; }
2329
2330 bool is_mature() const;
2331
2332 // Support for interprocedural escape analysis, from Thomas Kotzmann.
2333 enum EscapeFlag {
2334 estimated = 1 << 0,
2335 return_local = 1 << 1,
2336 return_allocated = 1 << 2,
2337 allocated_escapes = 1 << 3,
2338 unknown_modified = 1 << 4
2339 };
2340
2341 intx eflags() { return _eflags; }
2540 void print_value_on(outputStream* st) const;
2541
2542 // printing support for method data
2543 void print_data_on(outputStream* st) const;
2544
2545 const char* internal_name() const { return "{method data}"; }
2546
2547 // verification
2548 void verify_on(outputStream* st);
2549 void verify_data_on(outputStream* st);
2550
2551 static bool profile_parameters_for_method(const methodHandle& m);
2552 static bool profile_arguments();
2553 static bool profile_arguments_jsr292_only();
2554 static bool profile_return();
2555 static bool profile_parameters();
2556 static bool profile_return_jsr292_only();
2557
2558 void clean_method_data(bool always_clean);
2559 void clean_weak_method_links();
2560 Mutex* extra_data_lock();
2561 void check_extra_data_locked() const NOT_DEBUG_RETURN;
2562 };
2563
2564 #endif // SHARE_OOPS_METHODDATA_HPP
|