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
172 return ((_header._struct._flags >> trap_shift) & trap_mask);
173 }
174
175 void set_trap_state(int new_state) {
176 assert(ProfileTraps, "used only under +ProfileTraps");
177 uint old_flags = (_header._struct._flags & flag_mask);
178 _header._struct._flags = (new_state << trap_shift) | old_flags;
179 }
180
181 u1 flags() const {
182 return _header._struct._flags;
183 }
184
185 u2 bci() const {
186 return _header._struct._bci;
187 }
188
189 void set_header(intptr_t value) {
190 _header._bits = value;
191 }
192 void release_set_header(intptr_t value) {
193 OrderAccess::release_store_ptr(&_header._bits, value);
194 }
195 intptr_t 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 OrderAccess::release_store_ptr(&_cells[index], value);
203 }
204 intptr_t cell_at(int index) const {
205 return _cells[index];
206 }
207
208 void set_flag_at(int flag_number) {
209 assert(flag_number < flag_limit, "oob");
210 _header._struct._flags |= (0x1 << flag_number);
211 }
212 bool flag_at(int flag_number) const {
213 assert(flag_number < flag_limit, "oob");
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
289 protected:
290 DataLayout* data() { return _data; }
291 const DataLayout* data() const { return _data; }
292
293 enum {
294 cell_size = DataLayout::cell_size
295 };
296
297 public:
298 // How many cells are in this?
299 virtual int cell_count() const {
300 ShouldNotReachHere();
301 return -1;
302 }
303
304 // Return the size of this data.
305 int size_in_bytes() {
306 return DataLayout::compute_size_in_bytes(cell_count());
307 }
308
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");
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
477 void print_shared(outputStream* st, const char* name) const;
478 void tab(outputStream* st, bool first = false) const;
479 #endif
480 };
481
482 // BitData
483 //
484 // A BitData holds a flag or two in its header.
485 class BitData : public ProfileData {
486 protected:
487 enum {
488 // null_seen:
489 // saw a null operand (cast/aastore/instanceof)
490 null_seen_flag = DataLayout::first_flag + 0
491 };
492 enum { bit_cell_count = 0 }; // no additional data fields needed.
493 public:
494 BitData(DataLayout* layout) : ProfileData(layout) {
495 }
496
497 virtual bool is_BitData() const { return true; }
505 }
506
507 // Accessor
508
509 // The null_seen flag bit is specially known to the interpreter.
510 // Consulting it allows the compiler to avoid setting up null_check traps.
511 bool null_seen() { return flag_at(null_seen_flag); }
512 void set_null_seen() { set_flag_at(null_seen_flag); }
513
514
515 // Code generation support
516 static int null_seen_byte_constant() {
517 return flag_number_to_byte_constant(null_seen_flag);
518 }
519
520 static ByteSize bit_data_size() {
521 return cell_offset(bit_cell_count);
522 }
523
524 #ifndef PRODUCT
525 void print_data_on(outputStream* st) const;
526 #endif
527 };
528
529 // CounterData
530 //
531 // A CounterData corresponds to a simple counter.
532 class CounterData : public BitData {
533 protected:
534 enum {
535 count_off,
536 counter_cell_count
537 };
538 public:
539 CounterData(DataLayout* layout) : BitData(layout) {}
540
541 virtual bool is_CounterData() const { return true; }
542
543 static int static_cell_count() {
544 return counter_cell_count;
545 }
549 }
550
551 // Direct accessor
552 uint count() const {
553 return uint_at(count_off);
554 }
555
556 // Code generation support
557 static ByteSize count_offset() {
558 return cell_offset(count_off);
559 }
560 static ByteSize counter_data_size() {
561 return cell_offset(counter_cell_count);
562 }
563
564 void set_count(uint count) {
565 set_uint_at(count_off, count);
566 }
567
568 #ifndef PRODUCT
569 void print_data_on(outputStream* st) const;
570 #endif
571 };
572
573 // JumpData
574 //
575 // A JumpData is used to access profiling information for a direct
576 // branch. It is a counter, used for counting the number of branches,
577 // plus a data displacement, used for realigning the data pointer to
578 // the corresponding target bci.
579 class JumpData : public ProfileData {
580 protected:
581 enum {
582 taken_off_set,
583 displacement_off_set,
584 jump_cell_count
585 };
586
587 void set_displacement(int displacement) {
588 set_int_at(displacement_off_set, displacement);
589 }
622 return cnt;
623 }
624
625 int displacement() const {
626 return int_at(displacement_off_set);
627 }
628
629 // Code generation support
630 static ByteSize taken_offset() {
631 return cell_offset(taken_off_set);
632 }
633
634 static ByteSize displacement_offset() {
635 return cell_offset(displacement_off_set);
636 }
637
638 // Specific initialization.
639 void post_initialize(BytecodeStream* stream, MethodData* mdo);
640
641 #ifndef PRODUCT
642 void print_data_on(outputStream* st) const;
643 #endif
644 };
645
646 // Entries in a ProfileData object to record types: it can either be
647 // none (no profile), unknown (conflicting profile data) or a klass if
648 // a single one is seen. Whether a null reference was seen is also
649 // recorded. No counter is associated with the type and a single type
650 // is tracked (unlike VirtualCallData).
651 class TypeEntries {
652
653 public:
654
655 // A single cell is used to record information for a type:
656 // - the cell is initialized to 0
657 // - when a type is discovered it is stored in the cell
658 // - bit zero of the cell is used to record whether a null reference
659 // was encountered or not
660 // - bit 1 is set to record a conflict in the type information
661
662 enum {
1033 assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values");
1034 return res;
1035 }
1036
1037 // Code generation support
1038 static ByteSize args_data_offset() {
1039 return cell_offset(CounterData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
1040 }
1041
1042 // GC support
1043 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1044 if (has_arguments()) {
1045 _args.clean_weak_klass_links(is_alive_closure);
1046 }
1047 if (has_return()) {
1048 _ret.clean_weak_klass_links(is_alive_closure);
1049 }
1050 }
1051
1052 #ifndef PRODUCT
1053 virtual void print_data_on(outputStream* st) const;
1054 #endif
1055 };
1056
1057 // ReceiverTypeData
1058 //
1059 // A ReceiverTypeData is used to access profiling information about a
1060 // dynamic type check. It consists of a counter which counts the total times
1061 // that the check is reached, and a series of (Klass*, count) pairs
1062 // which are used to store a type profile for the receiver of the check.
1063 class ReceiverTypeData : public CounterData {
1064 protected:
1065 enum {
1066 receiver0_offset = counter_cell_count,
1067 count0_offset,
1068 receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
1069 };
1070
1071 public:
1072 ReceiverTypeData(DataLayout* layout) : CounterData(layout) {
1073 assert(layout->tag() == DataLayout::receiver_type_data_tag ||
1141 set_receiver(row, NULL);
1142 set_receiver_count(row, 0);
1143 }
1144
1145 // Code generation support
1146 static ByteSize receiver_offset(uint row) {
1147 return cell_offset(receiver_cell_index(row));
1148 }
1149 static ByteSize receiver_count_offset(uint row) {
1150 return cell_offset(receiver_count_cell_index(row));
1151 }
1152 static ByteSize receiver_type_data_size() {
1153 return cell_offset(static_cell_count());
1154 }
1155
1156 // GC support
1157 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
1158
1159 #ifndef PRODUCT
1160 void print_receiver_data_on(outputStream* st) const;
1161 void print_data_on(outputStream* st) const;
1162 #endif
1163 };
1164
1165 // VirtualCallData
1166 //
1167 // A VirtualCallData is used to access profiling information about a
1168 // virtual call. For now, it has nothing more than a ReceiverTypeData.
1169 class VirtualCallData : public ReceiverTypeData {
1170 public:
1171 VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
1172 assert(layout->tag() == DataLayout::virtual_call_data_tag ||
1173 layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1174 }
1175
1176 virtual bool is_VirtualCallData() const { return true; }
1177
1178 static int static_cell_count() {
1179 // At this point we could add more profile state, e.g., for arguments.
1180 // But for now it's the same size as the base record type.
1181 return ReceiverTypeData::static_cell_count();
1182 }
1183
1184 virtual int cell_count() const {
1185 return static_cell_count();
1186 }
1187
1188 // Direct accessors
1189 static ByteSize virtual_call_data_size() {
1190 return cell_offset(static_cell_count());
1191 }
1192
1193 #ifndef PRODUCT
1194 void print_data_on(outputStream* st) const;
1195 #endif
1196 };
1197
1198 // VirtualCallTypeData
1199 //
1200 // A VirtualCallTypeData is used to access profiling information about
1201 // a virtual call for which we collect type information about
1202 // arguments and return value.
1203 class VirtualCallTypeData : public VirtualCallData {
1204 private:
1205 // entries for arguments if any
1206 TypeStackSlotEntries _args;
1207 // entry for return type if any
1208 ReturnTypeEntry _ret;
1209
1210 int cell_count_global_offset() const {
1211 return VirtualCallData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
1212 }
1213
1214 // number of cells not counting the header
1300 return res;
1301 }
1302
1303 // Code generation support
1304 static ByteSize args_data_offset() {
1305 return cell_offset(VirtualCallData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
1306 }
1307
1308 // GC support
1309 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1310 ReceiverTypeData::clean_weak_klass_links(is_alive_closure);
1311 if (has_arguments()) {
1312 _args.clean_weak_klass_links(is_alive_closure);
1313 }
1314 if (has_return()) {
1315 _ret.clean_weak_klass_links(is_alive_closure);
1316 }
1317 }
1318
1319 #ifndef PRODUCT
1320 virtual void print_data_on(outputStream* st) const;
1321 #endif
1322 };
1323
1324 // RetData
1325 //
1326 // A RetData is used to access profiling information for a ret bytecode.
1327 // It is composed of a count of the number of times that the ret has
1328 // been executed, followed by a series of triples of the form
1329 // (bci, count, di) which count the number of times that some bci was the
1330 // target of the ret and cache a corresponding data displacement.
1331 class RetData : public CounterData {
1332 protected:
1333 enum {
1334 bci0_offset = counter_cell_count,
1335 count0_offset,
1336 displacement0_offset,
1337 ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
1338 };
1339
1340 void set_bci(uint row, int bci) {
1399 }
1400
1401 // Interpreter Runtime support
1402 address fixup_ret(int return_bci, MethodData* mdo);
1403
1404 // Code generation support
1405 static ByteSize bci_offset(uint row) {
1406 return cell_offset(bci_cell_index(row));
1407 }
1408 static ByteSize bci_count_offset(uint row) {
1409 return cell_offset(bci_count_cell_index(row));
1410 }
1411 static ByteSize bci_displacement_offset(uint row) {
1412 return cell_offset(bci_displacement_cell_index(row));
1413 }
1414
1415 // Specific initialization.
1416 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1417
1418 #ifndef PRODUCT
1419 void print_data_on(outputStream* st) const;
1420 #endif
1421 };
1422
1423 // BranchData
1424 //
1425 // A BranchData is used to access profiling data for a two-way branch.
1426 // It consists of taken and not_taken counts as well as a data displacement
1427 // for the taken case.
1428 class BranchData : public JumpData {
1429 protected:
1430 enum {
1431 not_taken_off_set = jump_cell_count,
1432 branch_cell_count
1433 };
1434
1435 void set_displacement(int displacement) {
1436 set_int_at(displacement_off_set, displacement);
1437 }
1438
1439 public:
1463 uint inc_not_taken() {
1464 uint cnt = not_taken() + 1;
1465 // Did we wrap? Will compiler screw us??
1466 if (cnt == 0) cnt--;
1467 set_uint_at(not_taken_off_set, cnt);
1468 return cnt;
1469 }
1470
1471 // Code generation support
1472 static ByteSize not_taken_offset() {
1473 return cell_offset(not_taken_off_set);
1474 }
1475 static ByteSize branch_data_size() {
1476 return cell_offset(branch_cell_count);
1477 }
1478
1479 // Specific initialization.
1480 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1481
1482 #ifndef PRODUCT
1483 void print_data_on(outputStream* st) const;
1484 #endif
1485 };
1486
1487 // ArrayData
1488 //
1489 // A ArrayData is a base class for accessing profiling data which does
1490 // not have a statically known size. It consists of an array length
1491 // and an array start.
1492 class ArrayData : public ProfileData {
1493 protected:
1494 friend class DataLayout;
1495
1496 enum {
1497 array_len_off_set,
1498 array_start_off_set
1499 };
1500
1501 uint array_uint_at(int index) const {
1502 int aindex = index + array_start_off_set;
1503 return uint_at(aindex);
1620 (per_case_size() * index) +
1621 relative_count_offset();
1622 }
1623 static ByteSize case_array_offset() {
1624 return array_element_offset(case_array_start);
1625 }
1626 static ByteSize per_case_size() {
1627 return in_ByteSize(per_case_cell_count) * cell_size;
1628 }
1629 static ByteSize relative_count_offset() {
1630 return in_ByteSize(relative_count_off_set) * cell_size;
1631 }
1632 static ByteSize relative_displacement_offset() {
1633 return in_ByteSize(relative_displacement_off_set) * cell_size;
1634 }
1635
1636 // Specific initialization.
1637 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1638
1639 #ifndef PRODUCT
1640 void print_data_on(outputStream* st) const;
1641 #endif
1642 };
1643
1644 class ArgInfoData : public ArrayData {
1645
1646 public:
1647 ArgInfoData(DataLayout* layout) : ArrayData(layout) {
1648 assert(layout->tag() == DataLayout::arg_info_data_tag, "wrong type");
1649 }
1650
1651 virtual bool is_ArgInfoData() const { return true; }
1652
1653
1654 int number_of_args() const {
1655 return array_len();
1656 }
1657
1658 uint arg_modified(int arg) const {
1659 return array_uint_at(arg);
1660 }
1661
1662 void set_arg_modified(int arg, uint val) {
1663 array_set_int_at(arg, val);
1664 }
1665
1666 #ifndef PRODUCT
1667 void print_data_on(outputStream* st) const;
1668 #endif
1669 };
1670
1671 // ParametersTypeData
1672 //
1673 // A ParametersTypeData is used to access profiling information about
1674 // types of parameters to a method
1675 class ParametersTypeData : public ArrayData {
1676
1677 private:
1678 TypeStackSlotEntries _parameters;
1679
1680 static int stack_slot_local_offset(int i) {
1681 assert_profiling_enabled();
1682 return array_start_off_set + TypeStackSlotEntries::stack_slot_local_offset(i);
1683 }
1684
1685 static int type_local_offset(int i) {
1686 assert_profiling_enabled();
1687 return array_start_off_set + TypeStackSlotEntries::type_local_offset(i);
1708 int number_of_parameters() const {
1709 return array_len() / TypeStackSlotEntries::per_arg_count();
1710 }
1711
1712 const TypeStackSlotEntries* parameters() const { return &_parameters; }
1713
1714 uint stack_slot(int i) const {
1715 return _parameters.stack_slot(i);
1716 }
1717
1718 void set_type(int i, Klass* k) {
1719 intptr_t current = _parameters.type(i);
1720 _parameters.set_type(i, TypeEntries::with_status((intptr_t)k, current));
1721 }
1722
1723 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1724 _parameters.clean_weak_klass_links(is_alive_closure);
1725 }
1726
1727 #ifndef PRODUCT
1728 virtual void print_data_on(outputStream* st) const;
1729 #endif
1730
1731 static ByteSize stack_slot_offset(int i) {
1732 return cell_offset(stack_slot_local_offset(i));
1733 }
1734
1735 static ByteSize type_offset(int i) {
1736 return cell_offset(type_local_offset(i));
1737 }
1738 };
1739
1740 // MethodData*
1741 //
1742 // A MethodData* holds information which has been collected about
1743 // a method. Its layout looks like this:
1744 //
1745 // -----------------------------
1746 // | header |
1747 // | klass |
1748 // -----------------------------
1749 // | method |
1750 // | size of the MethodData* |
1751 // -----------------------------
1752 // | Data entries... |
1753 // | (variable size) |
1754 // | |
1755 // . .
1756 // . .
1757 // . .
1758 // | |
1759 // -----------------------------
1786 friend class ProfileData;
1787
1788 // Back pointer to the Method*
1789 Method* _method;
1790
1791 // Size of this oop in bytes
1792 int _size;
1793
1794 // Cached hint for bci_to_dp and bci_to_data
1795 int _hint_di;
1796
1797 MethodData(methodHandle method, int size, TRAPS);
1798 public:
1799 static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS);
1800 MethodData() {}; // For ciMethodData
1801
1802 bool is_methodData() const volatile { return true; }
1803
1804 // Whole-method sticky bits and flags
1805 enum {
1806 _trap_hist_limit = 17, // decoupled from Deoptimization::Reason_LIMIT
1807 _trap_hist_mask = max_jubyte,
1808 _extra_data_count = 4 // extra DataLayout headers, for trap history
1809 }; // Public flag values
1810 private:
1811 uint _nof_decompiles; // count of all nmethod removals
1812 uint _nof_overflow_recompiles; // recompile count, excluding recomp. bits
1813 uint _nof_overflow_traps; // trap count, excluding _trap_hist
1814 union {
1815 intptr_t _align;
1816 u1 _array[_trap_hist_limit];
1817 } _trap_hist;
1818
1819 // Support for interprocedural escape analysis, from Thomas Kotzmann.
1820 intx _eflags; // flags on escape information
1821 intx _arg_local; // bit set of non-escaping arguments
1822 intx _arg_stack; // bit set of stack-allocatable arguments
1823 intx _arg_returned; // bit set of returned arguments
1824
1825 int _creation_mileage; // method mileage at MDO creation
1826
1841 // Highest compile level this method has ever seen.
1842 u1 _highest_comp_level;
1843 // Same for OSR level
1844 u1 _highest_osr_comp_level;
1845 // Does this method contain anything worth profiling?
1846 bool _would_profile;
1847
1848 // Size of _data array in bytes. (Excludes header and extra_data fields.)
1849 int _data_size;
1850
1851 // data index for the area dedicated to parameters. -1 if no
1852 // parameter profiling.
1853 int _parameters_type_data_di;
1854
1855 // Beginning of the data entries
1856 intptr_t _data[1];
1857
1858 // Helper for size computation
1859 static int compute_data_size(BytecodeStream* stream);
1860 static int bytecode_cell_count(Bytecodes::Code code);
1861 enum { no_profile_data = -1, variable_cell_count = -2 };
1862
1863 // Helper for initialization
1864 DataLayout* data_layout_at(int data_index) const {
1865 assert(data_index % sizeof(intptr_t) == 0, "unaligned");
1866 return (DataLayout*) (((address)_data) + data_index);
1867 }
1868
1869 // Initialize an individual data segment. Returns the size of
1870 // the segment in bytes.
1871 int initialize_data(BytecodeStream* stream, int data_index);
1872
1873 // Helper for data_at
1874 DataLayout* limit_data_position() const {
1875 return (DataLayout*)((address)data_base() + _data_size);
1876 }
1877 bool out_of_bounds(int data_index) const {
1878 return data_index >= data_size();
1879 }
1880
1884
1885 // hint accessors
1886 int hint_di() const { return _hint_di; }
1887 void set_hint_di(int di) {
1888 assert(!out_of_bounds(di), "hint_di out of bounds");
1889 _hint_di = di;
1890 }
1891 ProfileData* data_before(int bci) {
1892 // avoid SEGV on this edge case
1893 if (data_size() == 0)
1894 return NULL;
1895 int hint = hint_di();
1896 if (data_layout_at(hint)->bci() <= bci)
1897 return data_at(hint);
1898 return first_data();
1899 }
1900
1901 // What is the index of the first data entry?
1902 int first_di() const { return 0; }
1903
1904 // Find or create an extra ProfileData:
1905 ProfileData* bci_to_extra_data(int bci, bool create_if_missing);
1906
1907 // return the argument info cell
1908 ArgInfoData *arg_info();
1909
1910 enum {
1911 no_type_profile = 0,
1912 type_profile_jsr292 = 1,
1913 type_profile_all = 2
1914 };
1915
1916 static bool profile_jsr292(methodHandle m, int bci);
1917 static int profile_arguments_flag();
1918 static bool profile_arguments_jsr292_only();
1919 static bool profile_all_arguments();
1920 static bool profile_arguments_for_invoke(methodHandle m, int bci);
1921 static int profile_return_flag();
1922 static bool profile_all_return();
1923 static bool profile_return_for_invoke(methodHandle m, int bci);
1924 static int profile_parameters_flag();
1925 static bool profile_parameters_jsr292_only();
1926 static bool profile_all_parameters();
1927
1928 public:
1929 static int header_size() {
1930 return sizeof(MethodData)/wordSize;
1931 }
1932
1933 // Compute the size of a MethodData* before it is created.
1934 static int compute_allocation_size_in_bytes(methodHandle method);
1935 static int compute_allocation_size_in_words(methodHandle method);
1936 static int compute_extra_data_count(int data_size, int empty_bc_count);
1937
1938 // Determine if a given bytecode can have profile information.
1939 static bool bytecode_has_profile(Bytecodes::Code code) {
1940 return bytecode_cell_count(code) != no_profile_data;
1941 }
1942
1943 // reset into original state
1944 void init();
1945
1946 // My size
1947 int size_in_bytes() const { return _size; }
1948 int size() const { return align_object_size(align_size_up(_size, BytesPerWord)/BytesPerWord); }
1949 #if INCLUDE_SERVICES
1950 void collect_statistics(KlassSizeStats *sz) const;
1951 #endif
1952
1953 int creation_mileage() const { return _creation_mileage; }
1954 void set_creation_mileage(int x) { _creation_mileage = x; }
1955
1956 int invocation_count() {
2057
2058 // Convert a dp (data pointer) to a di (data index).
2059 int dp_to_di(address dp) const {
2060 return dp - ((address)_data);
2061 }
2062
2063 address di_to_dp(int di) {
2064 return (address)data_layout_at(di);
2065 }
2066
2067 // bci to di/dp conversion.
2068 address bci_to_dp(int bci);
2069 int bci_to_di(int bci) {
2070 return dp_to_di(bci_to_dp(bci));
2071 }
2072
2073 // Get the data at an arbitrary bci, or NULL if there is none.
2074 ProfileData* bci_to_data(int bci);
2075
2076 // Same, but try to create an extra_data record if one is needed:
2077 ProfileData* allocate_bci_to_data(int bci) {
2078 ProfileData* data = bci_to_data(bci);
2079 return (data != NULL) ? data : bci_to_extra_data(bci, true);
2080 }
2081
2082 // Add a handful of extra data records, for trap tracking.
2083 DataLayout* extra_data_base() const { return limit_data_position(); }
2084 DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); }
2085 int extra_data_size() const { return (address)extra_data_limit()
2086 - (address)extra_data_base(); }
2087 static DataLayout* next_extra(DataLayout* dp) { return (DataLayout*)((address)dp + in_bytes(DataLayout::cell_offset(0))); }
2088
2089 // Return (uint)-1 for overflow.
2090 uint trap_count(int reason) const {
2091 assert((uint)reason < _trap_hist_limit, "oob");
2092 return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1;
2093 }
2094 // For loops:
2095 static uint trap_reason_limit() { return _trap_hist_limit; }
2096 static uint trap_count_limit() { return _trap_hist_mask; }
2097 uint inc_trap_count(int reason) {
2098 // Count another trap, anywhere in this method.
2099 assert(reason >= 0, "must be single trap");
2100 if ((uint)reason < _trap_hist_limit) {
2101 uint cnt1 = 1 + _trap_hist._array[reason];
2102 if ((cnt1 & _trap_hist_mask) != 0) { // if no counter overflow...
2103 _trap_hist._array[reason] = cnt1;
2104 return cnt1;
2105 } else {
2106 return _trap_hist_mask + (++_nof_overflow_traps);
2107 }
2167 void print_on (outputStream* st) const;
2168 #endif
2169 void print_value_on(outputStream* st) const;
2170
2171 #ifndef PRODUCT
2172 // printing support for method data
2173 void print_data_on(outputStream* st) const;
2174 #endif
2175
2176 const char* internal_name() const { return "{method data}"; }
2177
2178 // verification
2179 void verify_on(outputStream* st);
2180 void verify_data_on(outputStream* st);
2181
2182 static bool profile_parameters_for_method(methodHandle m);
2183 static bool profile_arguments();
2184 static bool profile_return();
2185 static bool profile_parameters();
2186 static bool profile_return_jsr292_only();
2187 };
2188
2189 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP
|
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 speculative_trap_data_tag
125 };
126
127 enum {
128 // The _struct._flags word is formatted as [trap_state:4 | flags:4].
129 // The trap state breaks down further as [recompile:1 | reason:3].
130 // This further breakdown is defined in deoptimization.cpp.
131 // See Deoptimization::trap_state_reason for an assert that
132 // trap_bits is big enough to hold reasons < Reason_RECORDED_LIMIT.
133 //
134 // The trap_state is collected only if ProfileTraps is true.
135 trap_bits = 1+3, // 3: enough to distinguish [0..Reason_RECORDED_LIMIT].
136 trap_shift = BitsPerByte - trap_bits,
137 trap_mask = right_n_bits(trap_bits),
138 trap_mask_in_place = (trap_mask << trap_shift),
139 flag_limit = trap_shift,
140 flag_mask = right_n_bits(flag_limit),
141 first_flag = 0
142 };
143
144 // Size computation
173 return ((_header._struct._flags >> trap_shift) & trap_mask);
174 }
175
176 void set_trap_state(int new_state) {
177 assert(ProfileTraps, "used only under +ProfileTraps");
178 uint old_flags = (_header._struct._flags & flag_mask);
179 _header._struct._flags = (new_state << trap_shift) | old_flags;
180 }
181
182 u1 flags() const {
183 return _header._struct._flags;
184 }
185
186 u2 bci() const {
187 return _header._struct._bci;
188 }
189
190 void set_header(intptr_t value) {
191 _header._bits = value;
192 }
193 bool atomic_set_header(intptr_t value) {
194 if (Atomic::cmpxchg_ptr(value, (volatile intptr_t*)&_header._bits, 0) == 0) {
195 return true;
196 }
197 return false;
198 }
199 intptr_t header() {
200 return _header._bits;
201 }
202 void set_cell_at(int index, intptr_t value) {
203 _cells[index] = value;
204 }
205 void release_set_cell_at(int index, intptr_t value) {
206 OrderAccess::release_store_ptr(&_cells[index], value);
207 }
208 intptr_t cell_at(int index) const {
209 return _cells[index];
210 }
211
212 void set_flag_at(int flag_number) {
213 assert(flag_number < flag_limit, "oob");
214 _header._struct._flags |= (0x1 << flag_number);
215 }
216 bool flag_at(int flag_number) const {
217 assert(flag_number < flag_limit, "oob");
253 // GC support
254 void clean_weak_klass_links(BoolObjectClosure* cl);
255 };
256
257
258 // ProfileData class hierarchy
259 class ProfileData;
260 class BitData;
261 class CounterData;
262 class ReceiverTypeData;
263 class VirtualCallData;
264 class VirtualCallTypeData;
265 class RetData;
266 class CallTypeData;
267 class JumpData;
268 class BranchData;
269 class ArrayData;
270 class MultiBranchData;
271 class ArgInfoData;
272 class ParametersTypeData;
273 class SpeculativeTrapData;
274
275 // ProfileData
276 //
277 // A ProfileData object is created to refer to a section of profiling
278 // data in a structured way.
279 class ProfileData : public ResourceObj {
280 friend class TypeEntries;
281 friend class ReturnTypeEntry;
282 friend class TypeStackSlotEntries;
283 private:
284 #ifndef PRODUCT
285 enum {
286 tab_width_one = 16,
287 tab_width_two = 36
288 };
289 #endif // !PRODUCT
290
291 // This is a pointer to a section of profiling data.
292 DataLayout* _data;
293
294 char* print_data_on_helper(const MethodData* md) const;
295
296 protected:
297 DataLayout* data() { return _data; }
298 const DataLayout* data() const { return _data; }
299
300 enum {
301 cell_size = DataLayout::cell_size
302 };
303
304 public:
305 // How many cells are in this?
306 virtual int cell_count() const {
307 ShouldNotReachHere();
308 return -1;
309 }
310
311 // Return the size of this data.
312 int size_in_bytes() {
313 return DataLayout::compute_size_in_bytes(cell_count());
314 }
315
390 return data()->trap_state();
391 }
392 void set_trap_state(int new_state) {
393 data()->set_trap_state(new_state);
394 }
395
396 // Type checking
397 virtual bool is_BitData() const { return false; }
398 virtual bool is_CounterData() const { return false; }
399 virtual bool is_JumpData() const { return false; }
400 virtual bool is_ReceiverTypeData()const { return false; }
401 virtual bool is_VirtualCallData() const { return false; }
402 virtual bool is_RetData() const { return false; }
403 virtual bool is_BranchData() const { return false; }
404 virtual bool is_ArrayData() const { return false; }
405 virtual bool is_MultiBranchData() const { return false; }
406 virtual bool is_ArgInfoData() const { return false; }
407 virtual bool is_CallTypeData() const { return false; }
408 virtual bool is_VirtualCallTypeData()const { return false; }
409 virtual bool is_ParametersTypeData() const { return false; }
410 virtual bool is_SpeculativeTrapData()const { return false; }
411
412
413 BitData* as_BitData() const {
414 assert(is_BitData(), "wrong type");
415 return is_BitData() ? (BitData*) this : NULL;
416 }
417 CounterData* as_CounterData() const {
418 assert(is_CounterData(), "wrong type");
419 return is_CounterData() ? (CounterData*) this : NULL;
420 }
421 JumpData* as_JumpData() const {
422 assert(is_JumpData(), "wrong type");
423 return is_JumpData() ? (JumpData*) this : NULL;
424 }
425 ReceiverTypeData* as_ReceiverTypeData() const {
426 assert(is_ReceiverTypeData(), "wrong type");
427 return is_ReceiverTypeData() ? (ReceiverTypeData*)this : NULL;
428 }
429 VirtualCallData* as_VirtualCallData() const {
430 assert(is_VirtualCallData(), "wrong type");
445 MultiBranchData* as_MultiBranchData() const {
446 assert(is_MultiBranchData(), "wrong type");
447 return is_MultiBranchData() ? (MultiBranchData*)this : NULL;
448 }
449 ArgInfoData* as_ArgInfoData() const {
450 assert(is_ArgInfoData(), "wrong type");
451 return is_ArgInfoData() ? (ArgInfoData*)this : NULL;
452 }
453 CallTypeData* as_CallTypeData() const {
454 assert(is_CallTypeData(), "wrong type");
455 return is_CallTypeData() ? (CallTypeData*)this : NULL;
456 }
457 VirtualCallTypeData* as_VirtualCallTypeData() const {
458 assert(is_VirtualCallTypeData(), "wrong type");
459 return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL;
460 }
461 ParametersTypeData* as_ParametersTypeData() const {
462 assert(is_ParametersTypeData(), "wrong type");
463 return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL;
464 }
465 SpeculativeTrapData* as_SpeculativeTrapData() const {
466 assert(is_SpeculativeTrapData(), "wrong type");
467 return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : NULL;
468 }
469
470
471 // Subclass specific initialization
472 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
473
474 // GC support
475 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {}
476
477 // CI translation: ProfileData can represent both MethodDataOop data
478 // as well as CIMethodData data. This function is provided for translating
479 // an oop in a ProfileData to the ci equivalent. Generally speaking,
480 // most ProfileData don't require any translation, so we provide the null
481 // translation here, and the required translators are in the ci subclasses.
482 virtual void translate_from(const ProfileData* data) {}
483
484 virtual void print_data_on(outputStream* st, const char* extra = NULL) const {
485 ShouldNotReachHere();
486 }
487
488 void print_data_on(outputStream* st, const MethodData* md) const;
489
490 #ifndef PRODUCT
491 void print_shared(outputStream* st, const char* name, const char* extra) const;
492 void tab(outputStream* st, bool first = false) const;
493 #endif
494 };
495
496 // BitData
497 //
498 // A BitData holds a flag or two in its header.
499 class BitData : public ProfileData {
500 protected:
501 enum {
502 // null_seen:
503 // saw a null operand (cast/aastore/instanceof)
504 null_seen_flag = DataLayout::first_flag + 0
505 };
506 enum { bit_cell_count = 0 }; // no additional data fields needed.
507 public:
508 BitData(DataLayout* layout) : ProfileData(layout) {
509 }
510
511 virtual bool is_BitData() const { return true; }
519 }
520
521 // Accessor
522
523 // The null_seen flag bit is specially known to the interpreter.
524 // Consulting it allows the compiler to avoid setting up null_check traps.
525 bool null_seen() { return flag_at(null_seen_flag); }
526 void set_null_seen() { set_flag_at(null_seen_flag); }
527
528
529 // Code generation support
530 static int null_seen_byte_constant() {
531 return flag_number_to_byte_constant(null_seen_flag);
532 }
533
534 static ByteSize bit_data_size() {
535 return cell_offset(bit_cell_count);
536 }
537
538 #ifndef PRODUCT
539 void print_data_on(outputStream* st, const char* extra = NULL) const;
540 #endif
541 };
542
543 // CounterData
544 //
545 // A CounterData corresponds to a simple counter.
546 class CounterData : public BitData {
547 protected:
548 enum {
549 count_off,
550 counter_cell_count
551 };
552 public:
553 CounterData(DataLayout* layout) : BitData(layout) {}
554
555 virtual bool is_CounterData() const { return true; }
556
557 static int static_cell_count() {
558 return counter_cell_count;
559 }
563 }
564
565 // Direct accessor
566 uint count() const {
567 return uint_at(count_off);
568 }
569
570 // Code generation support
571 static ByteSize count_offset() {
572 return cell_offset(count_off);
573 }
574 static ByteSize counter_data_size() {
575 return cell_offset(counter_cell_count);
576 }
577
578 void set_count(uint count) {
579 set_uint_at(count_off, count);
580 }
581
582 #ifndef PRODUCT
583 void print_data_on(outputStream* st, const char* extra = NULL) const;
584 #endif
585 };
586
587 // JumpData
588 //
589 // A JumpData is used to access profiling information for a direct
590 // branch. It is a counter, used for counting the number of branches,
591 // plus a data displacement, used for realigning the data pointer to
592 // the corresponding target bci.
593 class JumpData : public ProfileData {
594 protected:
595 enum {
596 taken_off_set,
597 displacement_off_set,
598 jump_cell_count
599 };
600
601 void set_displacement(int displacement) {
602 set_int_at(displacement_off_set, displacement);
603 }
636 return cnt;
637 }
638
639 int displacement() const {
640 return int_at(displacement_off_set);
641 }
642
643 // Code generation support
644 static ByteSize taken_offset() {
645 return cell_offset(taken_off_set);
646 }
647
648 static ByteSize displacement_offset() {
649 return cell_offset(displacement_off_set);
650 }
651
652 // Specific initialization.
653 void post_initialize(BytecodeStream* stream, MethodData* mdo);
654
655 #ifndef PRODUCT
656 void print_data_on(outputStream* st, const char* extra = NULL) const;
657 #endif
658 };
659
660 // Entries in a ProfileData object to record types: it can either be
661 // none (no profile), unknown (conflicting profile data) or a klass if
662 // a single one is seen. Whether a null reference was seen is also
663 // recorded. No counter is associated with the type and a single type
664 // is tracked (unlike VirtualCallData).
665 class TypeEntries {
666
667 public:
668
669 // A single cell is used to record information for a type:
670 // - the cell is initialized to 0
671 // - when a type is discovered it is stored in the cell
672 // - bit zero of the cell is used to record whether a null reference
673 // was encountered or not
674 // - bit 1 is set to record a conflict in the type information
675
676 enum {
1047 assert (!res || TypeEntriesAtCall::return_profiling_enabled(), "no profiling of return values");
1048 return res;
1049 }
1050
1051 // Code generation support
1052 static ByteSize args_data_offset() {
1053 return cell_offset(CounterData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
1054 }
1055
1056 // GC support
1057 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1058 if (has_arguments()) {
1059 _args.clean_weak_klass_links(is_alive_closure);
1060 }
1061 if (has_return()) {
1062 _ret.clean_weak_klass_links(is_alive_closure);
1063 }
1064 }
1065
1066 #ifndef PRODUCT
1067 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
1068 #endif
1069 };
1070
1071 // ReceiverTypeData
1072 //
1073 // A ReceiverTypeData is used to access profiling information about a
1074 // dynamic type check. It consists of a counter which counts the total times
1075 // that the check is reached, and a series of (Klass*, count) pairs
1076 // which are used to store a type profile for the receiver of the check.
1077 class ReceiverTypeData : public CounterData {
1078 protected:
1079 enum {
1080 receiver0_offset = counter_cell_count,
1081 count0_offset,
1082 receiver_type_row_cell_count = (count0_offset + 1) - receiver0_offset
1083 };
1084
1085 public:
1086 ReceiverTypeData(DataLayout* layout) : CounterData(layout) {
1087 assert(layout->tag() == DataLayout::receiver_type_data_tag ||
1155 set_receiver(row, NULL);
1156 set_receiver_count(row, 0);
1157 }
1158
1159 // Code generation support
1160 static ByteSize receiver_offset(uint row) {
1161 return cell_offset(receiver_cell_index(row));
1162 }
1163 static ByteSize receiver_count_offset(uint row) {
1164 return cell_offset(receiver_count_cell_index(row));
1165 }
1166 static ByteSize receiver_type_data_size() {
1167 return cell_offset(static_cell_count());
1168 }
1169
1170 // GC support
1171 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
1172
1173 #ifndef PRODUCT
1174 void print_receiver_data_on(outputStream* st) const;
1175 void print_data_on(outputStream* st, const char* extra = NULL) const;
1176 #endif
1177 };
1178
1179 // VirtualCallData
1180 //
1181 // A VirtualCallData is used to access profiling information about a
1182 // virtual call. For now, it has nothing more than a ReceiverTypeData.
1183 class VirtualCallData : public ReceiverTypeData {
1184 public:
1185 VirtualCallData(DataLayout* layout) : ReceiverTypeData(layout) {
1186 assert(layout->tag() == DataLayout::virtual_call_data_tag ||
1187 layout->tag() == DataLayout::virtual_call_type_data_tag, "wrong type");
1188 }
1189
1190 virtual bool is_VirtualCallData() const { return true; }
1191
1192 static int static_cell_count() {
1193 // At this point we could add more profile state, e.g., for arguments.
1194 // But for now it's the same size as the base record type.
1195 return ReceiverTypeData::static_cell_count();
1196 }
1197
1198 virtual int cell_count() const {
1199 return static_cell_count();
1200 }
1201
1202 // Direct accessors
1203 static ByteSize virtual_call_data_size() {
1204 return cell_offset(static_cell_count());
1205 }
1206
1207 #ifndef PRODUCT
1208 void print_data_on(outputStream* st, const char* extra = NULL) const;
1209 #endif
1210 };
1211
1212 // VirtualCallTypeData
1213 //
1214 // A VirtualCallTypeData is used to access profiling information about
1215 // a virtual call for which we collect type information about
1216 // arguments and return value.
1217 class VirtualCallTypeData : public VirtualCallData {
1218 private:
1219 // entries for arguments if any
1220 TypeStackSlotEntries _args;
1221 // entry for return type if any
1222 ReturnTypeEntry _ret;
1223
1224 int cell_count_global_offset() const {
1225 return VirtualCallData::static_cell_count() + TypeEntriesAtCall::cell_count_local_offset();
1226 }
1227
1228 // number of cells not counting the header
1314 return res;
1315 }
1316
1317 // Code generation support
1318 static ByteSize args_data_offset() {
1319 return cell_offset(VirtualCallData::static_cell_count()) + TypeEntriesAtCall::args_data_offset();
1320 }
1321
1322 // GC support
1323 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1324 ReceiverTypeData::clean_weak_klass_links(is_alive_closure);
1325 if (has_arguments()) {
1326 _args.clean_weak_klass_links(is_alive_closure);
1327 }
1328 if (has_return()) {
1329 _ret.clean_weak_klass_links(is_alive_closure);
1330 }
1331 }
1332
1333 #ifndef PRODUCT
1334 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
1335 #endif
1336 };
1337
1338 // RetData
1339 //
1340 // A RetData is used to access profiling information for a ret bytecode.
1341 // It is composed of a count of the number of times that the ret has
1342 // been executed, followed by a series of triples of the form
1343 // (bci, count, di) which count the number of times that some bci was the
1344 // target of the ret and cache a corresponding data displacement.
1345 class RetData : public CounterData {
1346 protected:
1347 enum {
1348 bci0_offset = counter_cell_count,
1349 count0_offset,
1350 displacement0_offset,
1351 ret_row_cell_count = (displacement0_offset + 1) - bci0_offset
1352 };
1353
1354 void set_bci(uint row, int bci) {
1413 }
1414
1415 // Interpreter Runtime support
1416 address fixup_ret(int return_bci, MethodData* mdo);
1417
1418 // Code generation support
1419 static ByteSize bci_offset(uint row) {
1420 return cell_offset(bci_cell_index(row));
1421 }
1422 static ByteSize bci_count_offset(uint row) {
1423 return cell_offset(bci_count_cell_index(row));
1424 }
1425 static ByteSize bci_displacement_offset(uint row) {
1426 return cell_offset(bci_displacement_cell_index(row));
1427 }
1428
1429 // Specific initialization.
1430 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1431
1432 #ifndef PRODUCT
1433 void print_data_on(outputStream* st, const char* extra = NULL) const;
1434 #endif
1435 };
1436
1437 // BranchData
1438 //
1439 // A BranchData is used to access profiling data for a two-way branch.
1440 // It consists of taken and not_taken counts as well as a data displacement
1441 // for the taken case.
1442 class BranchData : public JumpData {
1443 protected:
1444 enum {
1445 not_taken_off_set = jump_cell_count,
1446 branch_cell_count
1447 };
1448
1449 void set_displacement(int displacement) {
1450 set_int_at(displacement_off_set, displacement);
1451 }
1452
1453 public:
1477 uint inc_not_taken() {
1478 uint cnt = not_taken() + 1;
1479 // Did we wrap? Will compiler screw us??
1480 if (cnt == 0) cnt--;
1481 set_uint_at(not_taken_off_set, cnt);
1482 return cnt;
1483 }
1484
1485 // Code generation support
1486 static ByteSize not_taken_offset() {
1487 return cell_offset(not_taken_off_set);
1488 }
1489 static ByteSize branch_data_size() {
1490 return cell_offset(branch_cell_count);
1491 }
1492
1493 // Specific initialization.
1494 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1495
1496 #ifndef PRODUCT
1497 void print_data_on(outputStream* st, const char* extra = NULL) const;
1498 #endif
1499 };
1500
1501 // ArrayData
1502 //
1503 // A ArrayData is a base class for accessing profiling data which does
1504 // not have a statically known size. It consists of an array length
1505 // and an array start.
1506 class ArrayData : public ProfileData {
1507 protected:
1508 friend class DataLayout;
1509
1510 enum {
1511 array_len_off_set,
1512 array_start_off_set
1513 };
1514
1515 uint array_uint_at(int index) const {
1516 int aindex = index + array_start_off_set;
1517 return uint_at(aindex);
1634 (per_case_size() * index) +
1635 relative_count_offset();
1636 }
1637 static ByteSize case_array_offset() {
1638 return array_element_offset(case_array_start);
1639 }
1640 static ByteSize per_case_size() {
1641 return in_ByteSize(per_case_cell_count) * cell_size;
1642 }
1643 static ByteSize relative_count_offset() {
1644 return in_ByteSize(relative_count_off_set) * cell_size;
1645 }
1646 static ByteSize relative_displacement_offset() {
1647 return in_ByteSize(relative_displacement_off_set) * cell_size;
1648 }
1649
1650 // Specific initialization.
1651 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1652
1653 #ifndef PRODUCT
1654 void print_data_on(outputStream* st, const char* extra = NULL) const;
1655 #endif
1656 };
1657
1658 class ArgInfoData : public ArrayData {
1659
1660 public:
1661 ArgInfoData(DataLayout* layout) : ArrayData(layout) {
1662 assert(layout->tag() == DataLayout::arg_info_data_tag, "wrong type");
1663 }
1664
1665 virtual bool is_ArgInfoData() const { return true; }
1666
1667
1668 int number_of_args() const {
1669 return array_len();
1670 }
1671
1672 uint arg_modified(int arg) const {
1673 return array_uint_at(arg);
1674 }
1675
1676 void set_arg_modified(int arg, uint val) {
1677 array_set_int_at(arg, val);
1678 }
1679
1680 #ifndef PRODUCT
1681 void print_data_on(outputStream* st, const char* extra = NULL) const;
1682 #endif
1683 };
1684
1685 // ParametersTypeData
1686 //
1687 // A ParametersTypeData is used to access profiling information about
1688 // types of parameters to a method
1689 class ParametersTypeData : public ArrayData {
1690
1691 private:
1692 TypeStackSlotEntries _parameters;
1693
1694 static int stack_slot_local_offset(int i) {
1695 assert_profiling_enabled();
1696 return array_start_off_set + TypeStackSlotEntries::stack_slot_local_offset(i);
1697 }
1698
1699 static int type_local_offset(int i) {
1700 assert_profiling_enabled();
1701 return array_start_off_set + TypeStackSlotEntries::type_local_offset(i);
1722 int number_of_parameters() const {
1723 return array_len() / TypeStackSlotEntries::per_arg_count();
1724 }
1725
1726 const TypeStackSlotEntries* parameters() const { return &_parameters; }
1727
1728 uint stack_slot(int i) const {
1729 return _parameters.stack_slot(i);
1730 }
1731
1732 void set_type(int i, Klass* k) {
1733 intptr_t current = _parameters.type(i);
1734 _parameters.set_type(i, TypeEntries::with_status((intptr_t)k, current));
1735 }
1736
1737 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1738 _parameters.clean_weak_klass_links(is_alive_closure);
1739 }
1740
1741 #ifndef PRODUCT
1742 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
1743 #endif
1744
1745 static ByteSize stack_slot_offset(int i) {
1746 return cell_offset(stack_slot_local_offset(i));
1747 }
1748
1749 static ByteSize type_offset(int i) {
1750 return cell_offset(type_local_offset(i));
1751 }
1752 };
1753
1754 // SpeculativeTrapData
1755 //
1756 // A SpeculativeTrapData is used to record traps due to type
1757 // speculation. It records the root of the compilation: that type
1758 // speculation is wrong in the context of one compilation (for
1759 // method1) doesn't mean it's wrong in the context of another one (for
1760 // method2). Type speculation could have more/different data in the
1761 // context of the compilation of method2 and it's worthwhile to try an
1762 // optimization that failed for compilation of method1 in the context
1763 // of compilation of method2.
1764 // Space for SpeculativeTrapData entries is allocated from the extra
1765 // data space in the MDO. If we run out of space, the trap data for
1766 // the ProfileData at that bci is updated.
1767 class SpeculativeTrapData : public ProfileData {
1768 protected:
1769 enum {
1770 method_offset,
1771 speculative_trap_cell_count
1772 };
1773 public:
1774 SpeculativeTrapData(DataLayout* layout) : ProfileData(layout) {
1775 assert(layout->tag() == DataLayout::speculative_trap_data_tag, "wrong type");
1776 }
1777
1778 virtual bool is_SpeculativeTrapData() const { return true; }
1779
1780 static int static_cell_count() {
1781 return speculative_trap_cell_count;
1782 }
1783
1784 virtual int cell_count() const {
1785 return static_cell_count();
1786 }
1787
1788 // Direct accessor
1789 Method* method() const {
1790 return (Method*)intptr_at(method_offset);
1791 }
1792
1793 void set_method(Method* m) {
1794 set_intptr_at(method_offset, (intptr_t)m);
1795 }
1796
1797 #ifndef PRODUCT
1798 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
1799 #endif
1800 };
1801
1802 // MethodData*
1803 //
1804 // A MethodData* holds information which has been collected about
1805 // a method. Its layout looks like this:
1806 //
1807 // -----------------------------
1808 // | header |
1809 // | klass |
1810 // -----------------------------
1811 // | method |
1812 // | size of the MethodData* |
1813 // -----------------------------
1814 // | Data entries... |
1815 // | (variable size) |
1816 // | |
1817 // . .
1818 // . .
1819 // . .
1820 // | |
1821 // -----------------------------
1848 friend class ProfileData;
1849
1850 // Back pointer to the Method*
1851 Method* _method;
1852
1853 // Size of this oop in bytes
1854 int _size;
1855
1856 // Cached hint for bci_to_dp and bci_to_data
1857 int _hint_di;
1858
1859 MethodData(methodHandle method, int size, TRAPS);
1860 public:
1861 static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS);
1862 MethodData() {}; // For ciMethodData
1863
1864 bool is_methodData() const volatile { return true; }
1865
1866 // Whole-method sticky bits and flags
1867 enum {
1868 _trap_hist_limit = 18, // decoupled from Deoptimization::Reason_LIMIT
1869 _trap_hist_mask = max_jubyte,
1870 _extra_data_count = 4 // extra DataLayout headers, for trap history
1871 }; // Public flag values
1872 private:
1873 uint _nof_decompiles; // count of all nmethod removals
1874 uint _nof_overflow_recompiles; // recompile count, excluding recomp. bits
1875 uint _nof_overflow_traps; // trap count, excluding _trap_hist
1876 union {
1877 intptr_t _align;
1878 u1 _array[_trap_hist_limit];
1879 } _trap_hist;
1880
1881 // Support for interprocedural escape analysis, from Thomas Kotzmann.
1882 intx _eflags; // flags on escape information
1883 intx _arg_local; // bit set of non-escaping arguments
1884 intx _arg_stack; // bit set of stack-allocatable arguments
1885 intx _arg_returned; // bit set of returned arguments
1886
1887 int _creation_mileage; // method mileage at MDO creation
1888
1903 // Highest compile level this method has ever seen.
1904 u1 _highest_comp_level;
1905 // Same for OSR level
1906 u1 _highest_osr_comp_level;
1907 // Does this method contain anything worth profiling?
1908 bool _would_profile;
1909
1910 // Size of _data array in bytes. (Excludes header and extra_data fields.)
1911 int _data_size;
1912
1913 // data index for the area dedicated to parameters. -1 if no
1914 // parameter profiling.
1915 int _parameters_type_data_di;
1916
1917 // Beginning of the data entries
1918 intptr_t _data[1];
1919
1920 // Helper for size computation
1921 static int compute_data_size(BytecodeStream* stream);
1922 static int bytecode_cell_count(Bytecodes::Code code);
1923 static bool is_speculative_trap_bytecode(Bytecodes::Code code);
1924 enum { no_profile_data = -1, variable_cell_count = -2 };
1925
1926 // Helper for initialization
1927 DataLayout* data_layout_at(int data_index) const {
1928 assert(data_index % sizeof(intptr_t) == 0, "unaligned");
1929 return (DataLayout*) (((address)_data) + data_index);
1930 }
1931
1932 // Initialize an individual data segment. Returns the size of
1933 // the segment in bytes.
1934 int initialize_data(BytecodeStream* stream, int data_index);
1935
1936 // Helper for data_at
1937 DataLayout* limit_data_position() const {
1938 return (DataLayout*)((address)data_base() + _data_size);
1939 }
1940 bool out_of_bounds(int data_index) const {
1941 return data_index >= data_size();
1942 }
1943
1947
1948 // hint accessors
1949 int hint_di() const { return _hint_di; }
1950 void set_hint_di(int di) {
1951 assert(!out_of_bounds(di), "hint_di out of bounds");
1952 _hint_di = di;
1953 }
1954 ProfileData* data_before(int bci) {
1955 // avoid SEGV on this edge case
1956 if (data_size() == 0)
1957 return NULL;
1958 int hint = hint_di();
1959 if (data_layout_at(hint)->bci() <= bci)
1960 return data_at(hint);
1961 return first_data();
1962 }
1963
1964 // What is the index of the first data entry?
1965 int first_di() const { return 0; }
1966
1967 ProfileData* bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp);
1968 // Find or create an extra ProfileData:
1969 ProfileData* bci_to_extra_data(int bci, Method* m, bool create_if_missing);
1970
1971 // return the argument info cell
1972 ArgInfoData *arg_info();
1973
1974 enum {
1975 no_type_profile = 0,
1976 type_profile_jsr292 = 1,
1977 type_profile_all = 2
1978 };
1979
1980 static bool profile_jsr292(methodHandle m, int bci);
1981 static int profile_arguments_flag();
1982 static bool profile_arguments_jsr292_only();
1983 static bool profile_all_arguments();
1984 static bool profile_arguments_for_invoke(methodHandle m, int bci);
1985 static int profile_return_flag();
1986 static bool profile_all_return();
1987 static bool profile_return_for_invoke(methodHandle m, int bci);
1988 static int profile_parameters_flag();
1989 static bool profile_parameters_jsr292_only();
1990 static bool profile_all_parameters();
1991
1992 public:
1993 static int header_size() {
1994 return sizeof(MethodData)/wordSize;
1995 }
1996
1997 // Compute the size of a MethodData* before it is created.
1998 static int compute_allocation_size_in_bytes(methodHandle method);
1999 static int compute_allocation_size_in_words(methodHandle method);
2000 static int compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps);
2001
2002 // Determine if a given bytecode can have profile information.
2003 static bool bytecode_has_profile(Bytecodes::Code code) {
2004 return bytecode_cell_count(code) != no_profile_data;
2005 }
2006
2007 // reset into original state
2008 void init();
2009
2010 // My size
2011 int size_in_bytes() const { return _size; }
2012 int size() const { return align_object_size(align_size_up(_size, BytesPerWord)/BytesPerWord); }
2013 #if INCLUDE_SERVICES
2014 void collect_statistics(KlassSizeStats *sz) const;
2015 #endif
2016
2017 int creation_mileage() const { return _creation_mileage; }
2018 void set_creation_mileage(int x) { _creation_mileage = x; }
2019
2020 int invocation_count() {
2121
2122 // Convert a dp (data pointer) to a di (data index).
2123 int dp_to_di(address dp) const {
2124 return dp - ((address)_data);
2125 }
2126
2127 address di_to_dp(int di) {
2128 return (address)data_layout_at(di);
2129 }
2130
2131 // bci to di/dp conversion.
2132 address bci_to_dp(int bci);
2133 int bci_to_di(int bci) {
2134 return dp_to_di(bci_to_dp(bci));
2135 }
2136
2137 // Get the data at an arbitrary bci, or NULL if there is none.
2138 ProfileData* bci_to_data(int bci);
2139
2140 // Same, but try to create an extra_data record if one is needed:
2141 ProfileData* allocate_bci_to_data(int bci, Method* m) {
2142 ProfileData* data = NULL;
2143 // If m not NULL, try to allocate a SpeculativeTrapData entry
2144 if (m == NULL) {
2145 data = bci_to_data(bci);
2146 }
2147 if (data != NULL) {
2148 return data;
2149 }
2150 data = bci_to_extra_data(bci, m, true);
2151 if (data != NULL) {
2152 return data;
2153 }
2154 // If SpeculativeTrapData allocation fails try to allocate a
2155 // regular entry
2156 data = bci_to_data(bci);
2157 if (data != NULL) {
2158 return data;
2159 }
2160 return bci_to_extra_data(bci, NULL, true);
2161 }
2162
2163 // Add a handful of extra data records, for trap tracking.
2164 DataLayout* extra_data_base() const { return limit_data_position(); }
2165 DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); }
2166 int extra_data_size() const { return (address)extra_data_limit()
2167 - (address)extra_data_base(); }
2168 static DataLayout* next_extra(DataLayout* dp);
2169
2170 // Return (uint)-1 for overflow.
2171 uint trap_count(int reason) const {
2172 assert((uint)reason < _trap_hist_limit, "oob");
2173 return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1;
2174 }
2175 // For loops:
2176 static uint trap_reason_limit() { return _trap_hist_limit; }
2177 static uint trap_count_limit() { return _trap_hist_mask; }
2178 uint inc_trap_count(int reason) {
2179 // Count another trap, anywhere in this method.
2180 assert(reason >= 0, "must be single trap");
2181 if ((uint)reason < _trap_hist_limit) {
2182 uint cnt1 = 1 + _trap_hist._array[reason];
2183 if ((cnt1 & _trap_hist_mask) != 0) { // if no counter overflow...
2184 _trap_hist._array[reason] = cnt1;
2185 return cnt1;
2186 } else {
2187 return _trap_hist_mask + (++_nof_overflow_traps);
2188 }
2248 void print_on (outputStream* st) const;
2249 #endif
2250 void print_value_on(outputStream* st) const;
2251
2252 #ifndef PRODUCT
2253 // printing support for method data
2254 void print_data_on(outputStream* st) const;
2255 #endif
2256
2257 const char* internal_name() const { return "{method data}"; }
2258
2259 // verification
2260 void verify_on(outputStream* st);
2261 void verify_data_on(outputStream* st);
2262
2263 static bool profile_parameters_for_method(methodHandle m);
2264 static bool profile_arguments();
2265 static bool profile_return();
2266 static bool profile_parameters();
2267 static bool profile_return_jsr292_only();
2268
2269 void clean_method_data(BoolObjectClosure* is_alive);
2270 };
2271
2272 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP
|