comparison src/share/vm/oops/methodData.hpp @ 18041:52b4284cb496

Merge with jdk8u20-b26
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 15 Oct 2014 16:02:50 +0200
parents e165f4223650 ce9fd31ffd14
children 94faadc823ea
comparison
equal deleted inserted replaced
17606:45d7b2c7029d 18041:52b4284cb496
118 branch_data_tag, 118 branch_data_tag,
119 multi_branch_data_tag, 119 multi_branch_data_tag,
120 arg_info_data_tag, 120 arg_info_data_tag,
121 call_type_data_tag, 121 call_type_data_tag,
122 virtual_call_type_data_tag, 122 virtual_call_type_data_tag,
123 parameters_type_data_tag 123 parameters_type_data_tag,
124 speculative_trap_data_tag
124 }; 125 };
125 126
126 enum { 127 enum {
127 // The _struct._flags word is formatted as [trap_state:4 | flags:4]. 128 // 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 // The trap state breaks down further as [recompile:1 | reason:3].
187 } 188 }
188 189
189 void set_header(intptr_t value) { 190 void set_header(intptr_t value) {
190 _header._bits = value; 191 _header._bits = value;
191 } 192 }
192 void release_set_header(intptr_t value) {
193 OrderAccess::release_store_ptr(&_header._bits, value);
194 }
195 intptr_t header() { 193 intptr_t header() {
196 return _header._bits; 194 return _header._bits;
197 } 195 }
198 void set_cell_at(int index, intptr_t value) { 196 void set_cell_at(int index, intptr_t value) {
199 _cells[index] = value; 197 _cells[index] = value;
228 return byte_offset_of(DataLayout, _header._struct._bci); 226 return byte_offset_of(DataLayout, _header._struct._bci);
229 } 227 }
230 static ByteSize cell_offset(int index) { 228 static ByteSize cell_offset(int index) {
231 return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size); 229 return byte_offset_of(DataLayout, _cells) + in_ByteSize(index * cell_size);
232 } 230 }
231 #ifdef CC_INTERP
232 static int cell_offset_in_bytes(int index) {
233 return (int)offset_of(DataLayout, _cells[index]);
234 }
235 #endif // CC_INTERP
233 // Return a value which, when or-ed as a byte into _flags, sets the flag. 236 // Return a value which, when or-ed as a byte into _flags, sets the flag.
234 static int flag_number_to_byte_constant(int flag_number) { 237 static int flag_number_to_byte_constant(int flag_number) {
235 assert(0 <= flag_number && flag_number < flag_limit, "oob"); 238 assert(0 <= flag_number && flag_number < flag_limit, "oob");
236 DataLayout temp; temp.set_header(0); 239 DataLayout temp; temp.set_header(0);
237 temp.set_flag_at(flag_number); 240 temp.set_flag_at(flag_number);
267 class BranchData; 270 class BranchData;
268 class ArrayData; 271 class ArrayData;
269 class MultiBranchData; 272 class MultiBranchData;
270 class ArgInfoData; 273 class ArgInfoData;
271 class ParametersTypeData; 274 class ParametersTypeData;
275 class SpeculativeTrapData;
272 276
273 // ProfileData 277 // ProfileData
274 // 278 //
275 // A ProfileData object is created to refer to a section of profiling 279 // A ProfileData object is created to refer to a section of profiling
276 // data in a structured way. 280 // data in a structured way.
287 #endif // !PRODUCT 291 #endif // !PRODUCT
288 292
289 // This is a pointer to a section of profiling data. 293 // This is a pointer to a section of profiling data.
290 DataLayout* _data; 294 DataLayout* _data;
291 295
296 char* print_data_on_helper(const MethodData* md) const;
297
292 protected: 298 protected:
293 DataLayout* data() { return _data; } 299 DataLayout* data() { return _data; }
294 const DataLayout* data() const { return _data; } 300 const DataLayout* data() const { return _data; }
295 301
296 enum { 302 enum {
367 } 373 }
368 374
369 ProfileData(DataLayout* data) { 375 ProfileData(DataLayout* data) {
370 _data = data; 376 _data = data;
371 } 377 }
378
379 #ifdef CC_INTERP
380 // Static low level accessors for DataLayout with ProfileData's semantics.
381
382 static int cell_offset_in_bytes(int index) {
383 return DataLayout::cell_offset_in_bytes(index);
384 }
385
386 static void increment_uint_at_no_overflow(DataLayout* layout, int index,
387 int inc = DataLayout::counter_increment) {
388 uint count = ((uint)layout->cell_at(index)) + inc;
389 if (count == 0) return;
390 layout->set_cell_at(index, (intptr_t) count);
391 }
392
393 static int int_at(DataLayout* layout, int index) {
394 return (int)layout->cell_at(index);
395 }
396
397 static int uint_at(DataLayout* layout, int index) {
398 return (uint)layout->cell_at(index);
399 }
400
401 static oop oop_at(DataLayout* layout, int index) {
402 return cast_to_oop(layout->cell_at(index));
403 }
404
405 static void set_intptr_at(DataLayout* layout, int index, intptr_t value) {
406 layout->set_cell_at(index, (intptr_t) value);
407 }
408
409 static void set_flag_at(DataLayout* layout, int flag_number) {
410 layout->set_flag_at(flag_number);
411 }
412 #endif // CC_INTERP
372 413
373 public: 414 public:
374 // Constructor for invalid ProfileData. 415 // Constructor for invalid ProfileData.
375 ProfileData(); 416 ProfileData();
376 417
401 virtual bool is_MultiBranchData() const { return false; } 442 virtual bool is_MultiBranchData() const { return false; }
402 virtual bool is_ArgInfoData() const { return false; } 443 virtual bool is_ArgInfoData() const { return false; }
403 virtual bool is_CallTypeData() const { return false; } 444 virtual bool is_CallTypeData() const { return false; }
404 virtual bool is_VirtualCallTypeData()const { return false; } 445 virtual bool is_VirtualCallTypeData()const { return false; }
405 virtual bool is_ParametersTypeData() const { return false; } 446 virtual bool is_ParametersTypeData() const { return false; }
447 virtual bool is_SpeculativeTrapData()const { return false; }
406 448
407 449
408 BitData* as_BitData() const { 450 BitData* as_BitData() const {
409 assert(is_BitData(), "wrong type"); 451 assert(is_BitData(), "wrong type");
410 return is_BitData() ? (BitData*) this : NULL; 452 return is_BitData() ? (BitData*) this : NULL;
454 return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL; 496 return is_VirtualCallTypeData() ? (VirtualCallTypeData*)this : NULL;
455 } 497 }
456 ParametersTypeData* as_ParametersTypeData() const { 498 ParametersTypeData* as_ParametersTypeData() const {
457 assert(is_ParametersTypeData(), "wrong type"); 499 assert(is_ParametersTypeData(), "wrong type");
458 return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL; 500 return is_ParametersTypeData() ? (ParametersTypeData*)this : NULL;
501 }
502 SpeculativeTrapData* as_SpeculativeTrapData() const {
503 assert(is_SpeculativeTrapData(), "wrong type");
504 return is_SpeculativeTrapData() ? (SpeculativeTrapData*)this : NULL;
459 } 505 }
460 506
461 507
462 // Subclass specific initialization 508 // Subclass specific initialization
463 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {} 509 virtual void post_initialize(BytecodeStream* stream, MethodData* mdo) {}
473 // an oop in a ProfileData to the ci equivalent. Generally speaking, 519 // an oop in a ProfileData to the ci equivalent. Generally speaking,
474 // most ProfileData don't require any translation, so we provide the null 520 // most ProfileData don't require any translation, so we provide the null
475 // translation here, and the required translators are in the ci subclasses. 521 // translation here, and the required translators are in the ci subclasses.
476 virtual void translate_from(const ProfileData* data) {} 522 virtual void translate_from(const ProfileData* data) {}
477 523
478 virtual void print_data_on(outputStream* st) const { 524 virtual void print_data_on(outputStream* st, const char* extra = NULL) const {
479 ShouldNotReachHere(); 525 ShouldNotReachHere();
480 } 526 }
481 527
528 void print_data_on(outputStream* st, const MethodData* md) const;
529
482 #ifndef PRODUCT 530 #ifndef PRODUCT
483 void print_shared(outputStream* st, const char* name) const; 531 void print_shared(outputStream* st, const char* name, const char* extra) const;
484 void tab(outputStream* st, bool first = false) const; 532 void tab(outputStream* st, bool first = false) const;
485 #endif 533 #endif
486 }; 534 };
487 535
488 // BitData 536 // BitData
533 581
534 static ByteSize bit_data_size() { 582 static ByteSize bit_data_size() {
535 return cell_offset(bit_cell_count); 583 return cell_offset(bit_cell_count);
536 } 584 }
537 585
586 #ifdef CC_INTERP
587 static int bit_data_size_in_bytes() {
588 return cell_offset_in_bytes(bit_cell_count);
589 }
590
591 static void set_null_seen(DataLayout* layout) {
592 set_flag_at(layout, null_seen_flag);
593 }
594
595 static DataLayout* advance(DataLayout* layout) {
596 return (DataLayout*) (((address)layout) + (ssize_t)BitData::bit_data_size_in_bytes());
597 }
598 #endif // CC_INTERP
599
538 #ifndef PRODUCT 600 #ifndef PRODUCT
539 void print_data_on(outputStream* st) const; 601 void print_data_on(outputStream* st, const char* extra = NULL) const;
540 #endif 602 #endif
541 }; 603 };
542 604
543 // CounterData 605 // CounterData
544 // 606 //
577 639
578 void set_count(uint count) { 640 void set_count(uint count) {
579 set_uint_at(count_off, count); 641 set_uint_at(count_off, count);
580 } 642 }
581 643
644 #ifdef CC_INTERP
645 static int counter_data_size_in_bytes() {
646 return cell_offset_in_bytes(counter_cell_count);
647 }
648
649 static void increment_count_no_overflow(DataLayout* layout) {
650 increment_uint_at_no_overflow(layout, count_off);
651 }
652
653 // Support counter decrementation at checkcast / subtype check failed.
654 static void decrement_count(DataLayout* layout) {
655 increment_uint_at_no_overflow(layout, count_off, -1);
656 }
657
658 static DataLayout* advance(DataLayout* layout) {
659 return (DataLayout*) (((address)layout) + (ssize_t)CounterData::counter_data_size_in_bytes());
660 }
661 #endif // CC_INTERP
662
582 #ifndef PRODUCT 663 #ifndef PRODUCT
583 void print_data_on(outputStream* st) const; 664 void print_data_on(outputStream* st, const char* extra = NULL) const;
584 #endif 665 #endif
585 }; 666 };
586 667
587 // JumpData 668 // JumpData
588 // 669 //
647 728
648 static ByteSize displacement_offset() { 729 static ByteSize displacement_offset() {
649 return cell_offset(displacement_off_set); 730 return cell_offset(displacement_off_set);
650 } 731 }
651 732
733 #ifdef CC_INTERP
734 static void increment_taken_count_no_overflow(DataLayout* layout) {
735 increment_uint_at_no_overflow(layout, taken_off_set);
736 }
737
738 static DataLayout* advance_taken(DataLayout* layout) {
739 return (DataLayout*) (((address)layout) + (ssize_t)int_at(layout, displacement_off_set));
740 }
741
742 static uint taken_count(DataLayout* layout) {
743 return (uint) uint_at(layout, taken_off_set);
744 }
745 #endif // CC_INTERP
746
652 // Specific initialization. 747 // Specific initialization.
653 void post_initialize(BytecodeStream* stream, MethodData* mdo); 748 void post_initialize(BytecodeStream* stream, MethodData* mdo);
654 749
655 #ifndef PRODUCT 750 #ifndef PRODUCT
656 void print_data_on(outputStream* st) const; 751 void print_data_on(outputStream* st, const char* extra = NULL) const;
657 #endif 752 #endif
658 }; 753 };
659 754
660 // Entries in a ProfileData object to record types: it can either be 755 // Entries in a ProfileData object to record types: it can either be
661 // none (no profile), unknown (conflicting profile data) or a klass if 756 // none (no profile), unknown (conflicting profile data) or a klass if
939 } 1034 }
940 1035
941 static ByteSize argument_type_offset(int i) { 1036 static ByteSize argument_type_offset(int i) {
942 return in_ByteSize(argument_type_local_offset(i) * DataLayout::cell_size); 1037 return in_ByteSize(argument_type_local_offset(i) * DataLayout::cell_size);
943 } 1038 }
1039
1040 static ByteSize return_only_size() {
1041 return ReturnTypeEntry::size() + in_ByteSize(header_cell_count() * DataLayout::cell_size);
1042 }
1043
944 }; 1044 };
945 1045
946 // CallTypeData 1046 // CallTypeData
947 // 1047 //
948 // A CallTypeData is used to access profiling information about a non 1048 // A CallTypeData is used to access profiling information about a non
1062 _ret.clean_weak_klass_links(is_alive_closure); 1162 _ret.clean_weak_klass_links(is_alive_closure);
1063 } 1163 }
1064 } 1164 }
1065 1165
1066 #ifndef PRODUCT 1166 #ifndef PRODUCT
1067 virtual void print_data_on(outputStream* st) const; 1167 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
1068 #endif 1168 #endif
1069 }; 1169 };
1070 1170
1071 // ReceiverTypeData 1171 // ReceiverTypeData
1072 // 1172 //
1201 } 1301 }
1202 1302
1203 // GC support 1303 // GC support
1204 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure); 1304 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure);
1205 1305
1306 #ifdef CC_INTERP
1307 static int receiver_type_data_size_in_bytes() {
1308 return cell_offset_in_bytes(static_cell_count());
1309 }
1310
1311 static Klass *receiver_unchecked(DataLayout* layout, uint row) {
1312 Klass* recv = (Klass*)layout->cell_at(receiver_cell_index(row));
1313 return recv;
1314 }
1315
1316 static void increment_receiver_count_no_overflow(DataLayout* layout, Klass *rcvr) {
1317 const int num_rows = row_limit();
1318 // Receiver already exists?
1319 for (int row = 0; row < num_rows; row++) {
1320 if (receiver_unchecked(layout, row) == rcvr) {
1321 increment_uint_at_no_overflow(layout, receiver_count_cell_index(row));
1322 return;
1323 }
1324 }
1325 // New receiver, find a free slot.
1326 for (int row = 0; row < num_rows; row++) {
1327 if (receiver_unchecked(layout, row) == NULL) {
1328 set_intptr_at(layout, receiver_cell_index(row), (intptr_t)rcvr);
1329 increment_uint_at_no_overflow(layout, receiver_count_cell_index(row));
1330 return;
1331 }
1332 }
1333 // Receiver did not match any saved receiver and there is no empty row for it.
1334 // Increment total counter to indicate polymorphic case.
1335 increment_count_no_overflow(layout);
1336 }
1337
1338 static DataLayout* advance(DataLayout* layout) {
1339 return (DataLayout*) (((address)layout) + (ssize_t)ReceiverTypeData::receiver_type_data_size_in_bytes());
1340 }
1341 #endif // CC_INTERP
1342
1206 #ifndef PRODUCT 1343 #ifndef PRODUCT
1207 void print_receiver_data_on(outputStream* st) const; 1344 void print_receiver_data_on(outputStream* st) const;
1208 void print_data_on(outputStream* st) const; 1345 void print_data_on(outputStream* st, const char* extra = NULL) const;
1209 #endif 1346 #endif
1210 }; 1347 };
1211 1348
1212 // VirtualCallData 1349 // VirtualCallData
1213 // 1350 //
1235 // Direct accessors 1372 // Direct accessors
1236 static ByteSize virtual_call_data_size() { 1373 static ByteSize virtual_call_data_size() {
1237 return cell_offset(static_cell_count()); 1374 return cell_offset(static_cell_count());
1238 } 1375 }
1239 1376
1377 #ifdef CC_INTERP
1378 static int virtual_call_data_size_in_bytes() {
1379 return cell_offset_in_bytes(static_cell_count());
1380 }
1381
1382 static DataLayout* advance(DataLayout* layout) {
1383 return (DataLayout*) (((address)layout) + (ssize_t)VirtualCallData::virtual_call_data_size_in_bytes());
1384 }
1385 #endif // CC_INTERP
1386
1240 #ifdef GRAAL 1387 #ifdef GRAAL
1241 static ByteSize method_offset(uint row) { 1388 static ByteSize method_offset(uint row) {
1242 return cell_offset(method_cell_index(row)); 1389 return cell_offset(method_cell_index(row));
1243 } 1390 }
1244 static ByteSize method_count_offset(uint row) { 1391 static ByteSize method_count_offset(uint row) {
1294 1441
1295 #ifndef PRODUCT 1442 #ifndef PRODUCT
1296 #ifdef GRAAL 1443 #ifdef GRAAL
1297 void print_method_data_on(outputStream* st) const; 1444 void print_method_data_on(outputStream* st) const;
1298 #endif 1445 #endif
1299 void print_data_on(outputStream* st) const; 1446 void print_data_on(outputStream* st, const char* extra = NULL) const;
1300 #endif 1447 #endif
1301 }; 1448 };
1302 1449
1303 // VirtualCallTypeData 1450 // VirtualCallTypeData
1304 // 1451 //
1420 _ret.clean_weak_klass_links(is_alive_closure); 1567 _ret.clean_weak_klass_links(is_alive_closure);
1421 } 1568 }
1422 } 1569 }
1423 1570
1424 #ifndef PRODUCT 1571 #ifndef PRODUCT
1425 virtual void print_data_on(outputStream* st) const; 1572 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
1426 #endif 1573 #endif
1427 }; 1574 };
1428 1575
1429 // RetData 1576 // RetData
1430 // 1577 //
1515 } 1662 }
1516 static ByteSize bci_displacement_offset(uint row) { 1663 static ByteSize bci_displacement_offset(uint row) {
1517 return cell_offset(bci_displacement_cell_index(row)); 1664 return cell_offset(bci_displacement_cell_index(row));
1518 } 1665 }
1519 1666
1667 #ifdef CC_INTERP
1668 static DataLayout* advance(MethodData *md, int bci);
1669 #endif // CC_INTERP
1670
1520 // Specific initialization. 1671 // Specific initialization.
1521 void post_initialize(BytecodeStream* stream, MethodData* mdo); 1672 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1522 1673
1523 #ifndef PRODUCT 1674 #ifndef PRODUCT
1524 void print_data_on(outputStream* st) const; 1675 void print_data_on(outputStream* st, const char* extra = NULL) const;
1525 #endif 1676 #endif
1526 }; 1677 };
1527 1678
1528 // BranchData 1679 // BranchData
1529 // 1680 //
1579 } 1730 }
1580 static ByteSize branch_data_size() { 1731 static ByteSize branch_data_size() {
1581 return cell_offset(branch_cell_count); 1732 return cell_offset(branch_cell_count);
1582 } 1733 }
1583 1734
1735 #ifdef CC_INTERP
1736 static int branch_data_size_in_bytes() {
1737 return cell_offset_in_bytes(branch_cell_count);
1738 }
1739
1740 static void increment_not_taken_count_no_overflow(DataLayout* layout) {
1741 increment_uint_at_no_overflow(layout, not_taken_off_set);
1742 }
1743
1744 static DataLayout* advance_not_taken(DataLayout* layout) {
1745 return (DataLayout*) (((address)layout) + (ssize_t)BranchData::branch_data_size_in_bytes());
1746 }
1747 #endif // CC_INTERP
1748
1584 // Specific initialization. 1749 // Specific initialization.
1585 void post_initialize(BytecodeStream* stream, MethodData* mdo); 1750 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1586 1751
1587 #ifndef PRODUCT 1752 #ifndef PRODUCT
1588 void print_data_on(outputStream* st) const; 1753 void print_data_on(outputStream* st, const char* extra = NULL) const;
1589 #endif 1754 #endif
1590 }; 1755 };
1591 1756
1592 // ArrayData 1757 // ArrayData
1593 // 1758 //
1617 } 1782 }
1618 void array_set_int_at(int index, int value) { 1783 void array_set_int_at(int index, int value) {
1619 int aindex = index + array_start_off_set; 1784 int aindex = index + array_start_off_set;
1620 set_int_at(aindex, value); 1785 set_int_at(aindex, value);
1621 } 1786 }
1787
1788 #ifdef CC_INTERP
1789 // Static low level accessors for DataLayout with ArrayData's semantics.
1790
1791 static void increment_array_uint_at_no_overflow(DataLayout* layout, int index) {
1792 int aindex = index + array_start_off_set;
1793 increment_uint_at_no_overflow(layout, aindex);
1794 }
1795
1796 static int array_int_at(DataLayout* layout, int index) {
1797 int aindex = index + array_start_off_set;
1798 return int_at(layout, aindex);
1799 }
1800 #endif // CC_INTERP
1622 1801
1623 // Code generation support for subclasses. 1802 // Code generation support for subclasses.
1624 static ByteSize array_element_offset(int index) { 1803 static ByteSize array_element_offset(int index) {
1625 return cell_offset(array_start_off_set + index); 1804 return cell_offset(array_start_off_set + index);
1626 } 1805 }
1736 } 1915 }
1737 static ByteSize relative_displacement_offset() { 1916 static ByteSize relative_displacement_offset() {
1738 return in_ByteSize(relative_displacement_off_set) * cell_size; 1917 return in_ByteSize(relative_displacement_off_set) * cell_size;
1739 } 1918 }
1740 1919
1920 #ifdef CC_INTERP
1921 static void increment_count_no_overflow(DataLayout* layout, int index) {
1922 if (index == -1) {
1923 increment_array_uint_at_no_overflow(layout, default_count_off_set);
1924 } else {
1925 increment_array_uint_at_no_overflow(layout, case_array_start +
1926 index * per_case_cell_count +
1927 relative_count_off_set);
1928 }
1929 }
1930
1931 static DataLayout* advance(DataLayout* layout, int index) {
1932 if (index == -1) {
1933 return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, default_disaplacement_off_set));
1934 } else {
1935 return (DataLayout*) (((address)layout) + (ssize_t)array_int_at(layout, case_array_start +
1936 index * per_case_cell_count +
1937 relative_displacement_off_set));
1938 }
1939 }
1940 #endif // CC_INTERP
1941
1741 // Specific initialization. 1942 // Specific initialization.
1742 void post_initialize(BytecodeStream* stream, MethodData* mdo); 1943 void post_initialize(BytecodeStream* stream, MethodData* mdo);
1743 1944
1744 #ifndef PRODUCT 1945 #ifndef PRODUCT
1745 void print_data_on(outputStream* st) const; 1946 void print_data_on(outputStream* st, const char* extra = NULL) const;
1746 #endif 1947 #endif
1747 }; 1948 };
1748 1949
1749 class ArgInfoData : public ArrayData { 1950 class ArgInfoData : public ArrayData {
1750 1951
1767 void set_arg_modified(int arg, uint val) { 1968 void set_arg_modified(int arg, uint val) {
1768 array_set_int_at(arg, val); 1969 array_set_int_at(arg, val);
1769 } 1970 }
1770 1971
1771 #ifndef PRODUCT 1972 #ifndef PRODUCT
1772 void print_data_on(outputStream* st) const; 1973 void print_data_on(outputStream* st, const char* extra = NULL) const;
1773 #endif 1974 #endif
1774 }; 1975 };
1775 1976
1776 // ParametersTypeData 1977 // ParametersTypeData
1777 // 1978 //
1828 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) { 2029 virtual void clean_weak_klass_links(BoolObjectClosure* is_alive_closure) {
1829 _parameters.clean_weak_klass_links(is_alive_closure); 2030 _parameters.clean_weak_klass_links(is_alive_closure);
1830 } 2031 }
1831 2032
1832 #ifndef PRODUCT 2033 #ifndef PRODUCT
1833 virtual void print_data_on(outputStream* st) const; 2034 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
1834 #endif 2035 #endif
1835 2036
1836 static ByteSize stack_slot_offset(int i) { 2037 static ByteSize stack_slot_offset(int i) {
1837 return cell_offset(stack_slot_local_offset(i)); 2038 return cell_offset(stack_slot_local_offset(i));
1838 } 2039 }
1839 2040
1840 static ByteSize type_offset(int i) { 2041 static ByteSize type_offset(int i) {
1841 return cell_offset(type_local_offset(i)); 2042 return cell_offset(type_local_offset(i));
1842 } 2043 }
2044 };
2045
2046 // SpeculativeTrapData
2047 //
2048 // A SpeculativeTrapData is used to record traps due to type
2049 // speculation. It records the root of the compilation: that type
2050 // speculation is wrong in the context of one compilation (for
2051 // method1) doesn't mean it's wrong in the context of another one (for
2052 // method2). Type speculation could have more/different data in the
2053 // context of the compilation of method2 and it's worthwhile to try an
2054 // optimization that failed for compilation of method1 in the context
2055 // of compilation of method2.
2056 // Space for SpeculativeTrapData entries is allocated from the extra
2057 // data space in the MDO. If we run out of space, the trap data for
2058 // the ProfileData at that bci is updated.
2059 class SpeculativeTrapData : public ProfileData {
2060 protected:
2061 enum {
2062 method_offset,
2063 speculative_trap_cell_count
2064 };
2065 public:
2066 SpeculativeTrapData(DataLayout* layout) : ProfileData(layout) {
2067 assert(layout->tag() == DataLayout::speculative_trap_data_tag, "wrong type");
2068 }
2069
2070 virtual bool is_SpeculativeTrapData() const { return true; }
2071
2072 static int static_cell_count() {
2073 return speculative_trap_cell_count;
2074 }
2075
2076 virtual int cell_count() const {
2077 return static_cell_count();
2078 }
2079
2080 // Direct accessor
2081 Method* method() const {
2082 return (Method*)intptr_at(method_offset);
2083 }
2084
2085 void set_method(Method* m) {
2086 set_intptr_at(method_offset, (intptr_t)m);
2087 }
2088
2089 #ifndef PRODUCT
2090 virtual void print_data_on(outputStream* st, const char* extra = NULL) const;
2091 #endif
1843 }; 2092 };
1844 2093
1845 // MethodData* 2094 // MethodData*
1846 // 2095 //
1847 // A MethodData* holds information which has been collected about 2096 // A MethodData* holds information which has been collected about
1883 // from the base of the data entry array. A "displacement" is the byte offset 2132 // from the base of the data entry array. A "displacement" is the byte offset
1884 // in certain ProfileData objects that indicate the amount the mdp must be 2133 // in certain ProfileData objects that indicate the amount the mdp must be
1885 // adjusted in the event of a change in control flow. 2134 // adjusted in the event of a change in control flow.
1886 // 2135 //
1887 2136
2137 CC_INTERP_ONLY(class BytecodeInterpreter;)
2138
1888 class MethodData : public Metadata { 2139 class MethodData : public Metadata {
1889 friend class VMStructs; 2140 friend class VMStructs;
2141 CC_INTERP_ONLY(friend class BytecodeInterpreter;)
1890 private: 2142 private:
1891 friend class ProfileData; 2143 friend class ProfileData;
1892 2144
1893 // Back pointer to the Method* 2145 // Back pointer to the Method*
1894 Method* _method; 2146 Method* _method;
1896 // Size of this oop in bytes 2148 // Size of this oop in bytes
1897 int _size; 2149 int _size;
1898 2150
1899 // Cached hint for bci_to_dp and bci_to_data 2151 // Cached hint for bci_to_dp and bci_to_data
1900 int _hint_di; 2152 int _hint_di;
2153
2154 Mutex _extra_data_lock;
1901 2155
1902 MethodData(methodHandle method, int size, TRAPS); 2156 MethodData(methodHandle method, int size, TRAPS);
1903 public: 2157 public:
1904 static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS); 2158 static MethodData* allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS);
1905 MethodData() {}; // For ciMethodData 2159 MethodData() : _extra_data_lock(Monitor::leaf, "MDO extra data lock") {}; // For ciMethodData
1906 2160
1907 bool is_methodData() const volatile { return true; } 2161 bool is_methodData() const volatile { return true; }
1908 void initialize(bool for_reprofile = false); 2162 void initialize(bool for_reprofile = false);
1909 2163
1910 // Whole-method sticky bits and flags 2164 // Whole-method sticky bits and flags
1911 enum { 2165 enum {
1912 #ifdef GRAAL 2166 _trap_hist_limit = 19 GRAAL_ONLY(+2), // decoupled from Deoptimization::Reason_LIMIT
1913 _trap_hist_limit = 19, // decoupled from Deoptimization::Reason_LIMIT
1914 #else
1915 _trap_hist_limit = 17, // decoupled from Deoptimization::Reason_LIMIT
1916 #endif
1917 _trap_hist_mask = max_jubyte, 2167 _trap_hist_mask = max_jubyte,
1918 _extra_data_count = 4 // extra DataLayout headers, for trap history 2168 _extra_data_count = 4 // extra DataLayout headers, for trap history
1919 }; // Public flag values 2169 }; // Public flag values
1920 private: 2170 private:
1921 uint _nof_decompiles; // count of all nmethod removals 2171 uint _nof_decompiles; // count of all nmethod removals
1946 // Same for backedges. 2196 // Same for backedges.
1947 InvocationCounter _backedge_counter; 2197 InvocationCounter _backedge_counter;
1948 // Counter values at the time profiling started. 2198 // Counter values at the time profiling started.
1949 int _invocation_counter_start; 2199 int _invocation_counter_start;
1950 int _backedge_counter_start; 2200 int _backedge_counter_start;
2201
2202 #if INCLUDE_RTM_OPT
2203 // State of RTM code generation during compilation of the method
2204 int _rtm_state;
2205 #endif
2206
1951 // Number of loops and blocks is computed when compiling the first 2207 // Number of loops and blocks is computed when compiling the first
1952 // time with C1. It is used to determine if method is trivial. 2208 // time with C1. It is used to determine if method is trivial.
1953 short _num_loops; 2209 short _num_loops;
1954 short _num_blocks; 2210 short _num_blocks;
1955 // Highest compile level this method has ever seen. 2211 // Highest compile level this method has ever seen.
1975 intptr_t _data[1]; 2231 intptr_t _data[1];
1976 2232
1977 // Helper for size computation 2233 // Helper for size computation
1978 static int compute_data_size(BytecodeStream* stream); 2234 static int compute_data_size(BytecodeStream* stream);
1979 static int bytecode_cell_count(Bytecodes::Code code); 2235 static int bytecode_cell_count(Bytecodes::Code code);
2236 static bool is_speculative_trap_bytecode(Bytecodes::Code code);
1980 enum { no_profile_data = -1, variable_cell_count = -2 }; 2237 enum { no_profile_data = -1, variable_cell_count = -2 };
1981 2238
1982 // Helper for initialization 2239 // Helper for initialization
1983 DataLayout* data_layout_at(int data_index) const { 2240 DataLayout* data_layout_at(int data_index) const {
1984 assert(data_index % sizeof(intptr_t) == 0, "unaligned"); 2241 assert(data_index % sizeof(intptr_t) == 0, "unaligned");
2018 } 2275 }
2019 2276
2020 // What is the index of the first data entry? 2277 // What is the index of the first data entry?
2021 int first_di() const { return 0; } 2278 int first_di() const { return 0; }
2022 2279
2280 ProfileData* bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent);
2023 // Find or create an extra ProfileData: 2281 // Find or create an extra ProfileData:
2024 ProfileData* bci_to_extra_data(int bci, bool create_if_missing); 2282 ProfileData* bci_to_extra_data(int bci, Method* m, bool create_if_missing);
2025 2283
2026 // return the argument info cell 2284 // return the argument info cell
2027 ArgInfoData *arg_info(); 2285 ArgInfoData *arg_info();
2028 2286
2029 enum { 2287 enum {
2032 type_profile_all = 2 2290 type_profile_all = 2
2033 }; 2291 };
2034 2292
2035 static bool profile_jsr292(methodHandle m, int bci); 2293 static bool profile_jsr292(methodHandle m, int bci);
2036 static int profile_arguments_flag(); 2294 static int profile_arguments_flag();
2037 static bool profile_arguments_jsr292_only();
2038 static bool profile_all_arguments(); 2295 static bool profile_all_arguments();
2039 static bool profile_arguments_for_invoke(methodHandle m, int bci); 2296 static bool profile_arguments_for_invoke(methodHandle m, int bci);
2040 static int profile_return_flag(); 2297 static int profile_return_flag();
2041 static bool profile_all_return(); 2298 static bool profile_all_return();
2042 static bool profile_return_for_invoke(methodHandle m, int bci); 2299 static bool profile_return_for_invoke(methodHandle m, int bci);
2043 static int profile_parameters_flag(); 2300 static int profile_parameters_flag();
2044 static bool profile_parameters_jsr292_only(); 2301 static bool profile_parameters_jsr292_only();
2045 static bool profile_all_parameters(); 2302 static bool profile_all_parameters();
2046 2303
2304 void clean_extra_data(BoolObjectClosure* is_alive);
2305 void clean_extra_data_helper(DataLayout* dp, int shift, bool reset = false);
2306 void verify_extra_data_clean(BoolObjectClosure* is_alive);
2307
2047 public: 2308 public:
2048 static int header_size() { 2309 static int header_size() {
2049 return sizeof(MethodData)/wordSize; 2310 return sizeof(MethodData)/wordSize;
2050 } 2311 }
2051 2312
2052 // Compute the size of a MethodData* before it is created. 2313 // Compute the size of a MethodData* before it is created.
2053 static int compute_allocation_size_in_bytes(methodHandle method); 2314 static int compute_allocation_size_in_bytes(methodHandle method);
2054 static int compute_allocation_size_in_words(methodHandle method); 2315 static int compute_allocation_size_in_words(methodHandle method);
2055 static int compute_extra_data_count(int data_size, int empty_bc_count); 2316 static int compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps);
2056 2317
2057 // Determine if a given bytecode can have profile information. 2318 // Determine if a given bytecode can have profile information.
2058 static bool bytecode_has_profile(Bytecodes::Code code) { 2319 static bool bytecode_has_profile(Bytecodes::Code code) {
2059 return bytecode_cell_count(code) != no_profile_data; 2320 return bytecode_cell_count(code) != no_profile_data;
2060 } 2321 }
2107 _backedge_counter_start = backedge_count(); 2368 _backedge_counter_start = backedge_count();
2108 } 2369 }
2109 2370
2110 InvocationCounter* invocation_counter() { return &_invocation_counter; } 2371 InvocationCounter* invocation_counter() { return &_invocation_counter; }
2111 InvocationCounter* backedge_counter() { return &_backedge_counter; } 2372 InvocationCounter* backedge_counter() { return &_backedge_counter; }
2373
2374 #if INCLUDE_RTM_OPT
2375 int rtm_state() const {
2376 return _rtm_state;
2377 }
2378 void set_rtm_state(RTMState rstate) {
2379 _rtm_state = (int)rstate;
2380 }
2381 void atomic_set_rtm_state(RTMState rstate) {
2382 Atomic::store((int)rstate, &_rtm_state);
2383 }
2384
2385 static int rtm_state_offset_in_bytes() {
2386 return offset_of(MethodData, _rtm_state);
2387 }
2388 #endif
2112 2389
2113 void set_would_profile(bool p) { _would_profile = p; } 2390 void set_would_profile(bool p) { _would_profile = p; }
2114 bool would_profile() const { return _would_profile; } 2391 bool would_profile() const { return _would_profile; }
2115 2392
2116 int highest_comp_level() const { return _highest_comp_level; } 2393 int highest_comp_level() const { return _highest_comp_level; }
2191 2468
2192 // Get the data at an arbitrary bci, or NULL if there is none. 2469 // Get the data at an arbitrary bci, or NULL if there is none.
2193 ProfileData* bci_to_data(int bci); 2470 ProfileData* bci_to_data(int bci);
2194 2471
2195 // Same, but try to create an extra_data record if one is needed: 2472 // Same, but try to create an extra_data record if one is needed:
2196 ProfileData* allocate_bci_to_data(int bci) { 2473 ProfileData* allocate_bci_to_data(int bci, Method* m) {
2197 ProfileData* data = bci_to_data(bci); 2474 ProfileData* data = NULL;
2198 return (data != NULL) ? data : bci_to_extra_data(bci, true); 2475 // If m not NULL, try to allocate a SpeculativeTrapData entry
2476 if (m == NULL) {
2477 data = bci_to_data(bci);
2478 }
2479 if (data != NULL) {
2480 return data;
2481 }
2482 data = bci_to_extra_data(bci, m, true);
2483 if (data != NULL) {
2484 return data;
2485 }
2486 // If SpeculativeTrapData allocation fails try to allocate a
2487 // regular entry
2488 data = bci_to_data(bci);
2489 if (data != NULL) {
2490 return data;
2491 }
2492 return bci_to_extra_data(bci, NULL, true);
2199 } 2493 }
2200 2494
2201 // Add a handful of extra data records, for trap tracking. 2495 // Add a handful of extra data records, for trap tracking.
2202 DataLayout* extra_data_base() const { return limit_data_position(); } 2496 DataLayout* extra_data_base() const { return limit_data_position(); }
2203 DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); } 2497 DataLayout* extra_data_limit() const { return (DataLayout*)((address)this + size_in_bytes()); }
2204 int extra_data_size() const { return (address)extra_data_limit() 2498 int extra_data_size() const { return (address)extra_data_limit()
2205 - (address)extra_data_base(); } 2499 - (address)extra_data_base(); }
2206 static DataLayout* next_extra(DataLayout* dp) { return (DataLayout*)((address)dp + in_bytes(DataLayout::cell_offset(0))); } 2500 static DataLayout* next_extra(DataLayout* dp);
2207 2501
2208 // Return (uint)-1 for overflow. 2502 // Return (uint)-1 for overflow.
2209 uint trap_count(int reason) const { 2503 uint trap_count(int reason) const {
2210 assert((uint)reason < GRAAL_ONLY(2*) _trap_hist_limit, "oob"); 2504 assert((uint)reason < GRAAL_ONLY(2*) _trap_hist_limit, "oob");
2211 return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1; 2505 return (int)((_trap_hist._array[reason]+1) & _trap_hist_mask) - 1;
2298 void verify_on(outputStream* st); 2592 void verify_on(outputStream* st);
2299 void verify_data_on(outputStream* st); 2593 void verify_data_on(outputStream* st);
2300 2594
2301 static bool profile_parameters_for_method(methodHandle m); 2595 static bool profile_parameters_for_method(methodHandle m);
2302 static bool profile_arguments(); 2596 static bool profile_arguments();
2597 static bool profile_arguments_jsr292_only();
2303 static bool profile_return(); 2598 static bool profile_return();
2304 static bool profile_parameters(); 2599 static bool profile_parameters();
2305 static bool profile_return_jsr292_only(); 2600 static bool profile_return_jsr292_only();
2306 2601
2602 void clean_method_data(BoolObjectClosure* is_alive);
2603
2307 void clean_weak_method_links(); 2604 void clean_weak_method_links();
2308 }; 2605 };
2309 2606
2310 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP 2607 #endif // SHARE_VM_OOPS_METHODDATAOOP_HPP