comparison src/share/vm/oops/methodData.cpp @ 14909:4ca6dc0799b6

Backout jdk9 merge
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 01 Apr 2014 13:57:07 +0200
parents 8762b6b8fbb6
children 52b4284cb496
comparison
equal deleted inserted replaced
14908:8db6e76cb658 14909:4ca6dc0799b6
78 // Constructor for invalid ProfileData. 78 // Constructor for invalid ProfileData.
79 ProfileData::ProfileData() { 79 ProfileData::ProfileData() {
80 _data = NULL; 80 _data = NULL;
81 } 81 }
82 82
83 char* ProfileData::print_data_on_helper(const MethodData* md) const {
84 DataLayout* dp = md->extra_data_base();
85 DataLayout* end = md->extra_data_limit();
86 stringStream ss;
87 for (;; dp = MethodData::next_extra(dp)) {
88 assert(dp < end, "moved past end of extra data");
89 switch(dp->tag()) {
90 case DataLayout::speculative_trap_data_tag:
91 if (dp->bci() == bci()) {
92 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
93 int trap = data->trap_state();
94 char buf[100];
95 ss.print("trap/");
96 data->method()->print_short_name(&ss);
97 ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
98 }
99 break;
100 case DataLayout::bit_data_tag:
101 break;
102 case DataLayout::no_tag:
103 case DataLayout::arg_info_data_tag:
104 return ss.as_string();
105 break;
106 default:
107 fatal(err_msg("unexpected tag %d", dp->tag()));
108 }
109 }
110 return NULL;
111 }
112
113 void ProfileData::print_data_on(outputStream* st, const MethodData* md) const {
114 print_data_on(st, print_data_on_helper(md));
115 }
116
117 #ifndef PRODUCT 83 #ifndef PRODUCT
118 void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const { 84 void ProfileData::print_shared(outputStream* st, const char* name) const {
119 st->print("bci: %d", bci()); 85 st->print("bci: %d", bci());
120 st->fill_to(tab_width_one); 86 st->fill_to(tab_width_one);
121 st->print("%s", name); 87 st->print("%s", name);
122 tab(st); 88 tab(st);
123 int trap = trap_state(); 89 int trap = trap_state();
124 if (trap != 0) { 90 if (trap != 0) {
125 char buf[100]; 91 char buf[100];
126 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); 92 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
127 } 93 }
128 if (extra != NULL) {
129 st->print(extra);
130 }
131 int flags = data()->flags(); 94 int flags = data()->flags();
132 if (flags != 0) { 95 if (flags != 0)
133 st->print("flags(%d) ", flags); 96 st->print("flags(%d) ", flags);
134 }
135 } 97 }
136 98
137 void ProfileData::tab(outputStream* st, bool first) const { 99 void ProfileData::tab(outputStream* st, bool first) const {
138 st->fill_to(first ? tab_width_one : tab_width_two); 100 st->fill_to(first ? tab_width_one : tab_width_two);
139 } 101 }
145 // A BitData corresponds to a one-bit flag. This is used to indicate 107 // A BitData corresponds to a one-bit flag. This is used to indicate
146 // whether a checkcast bytecode has seen a null value. 108 // whether a checkcast bytecode has seen a null value.
147 109
148 110
149 #ifndef PRODUCT 111 #ifndef PRODUCT
150 void BitData::print_data_on(outputStream* st, const char* extra) const { 112 void BitData::print_data_on(outputStream* st) const {
151 print_shared(st, "BitData", extra); 113 print_shared(st, "BitData");
152 } 114 }
153 #endif // !PRODUCT 115 #endif // !PRODUCT
154 116
155 // ================================================================== 117 // ==================================================================
156 // CounterData 118 // CounterData
157 // 119 //
158 // A CounterData corresponds to a simple counter. 120 // A CounterData corresponds to a simple counter.
159 121
160 #ifndef PRODUCT 122 #ifndef PRODUCT
161 void CounterData::print_data_on(outputStream* st, const char* extra) const { 123 void CounterData::print_data_on(outputStream* st) const {
162 print_shared(st, "CounterData", extra); 124 print_shared(st, "CounterData");
163 st->print_cr("count(%u)", count()); 125 st->print_cr("count(%u)", count());
164 } 126 }
165 #endif // !PRODUCT 127 #endif // !PRODUCT
166 128
167 // ================================================================== 129 // ==================================================================
186 int offset = target_di - my_di; 148 int offset = target_di - my_di;
187 set_displacement(offset); 149 set_displacement(offset);
188 } 150 }
189 151
190 #ifndef PRODUCT 152 #ifndef PRODUCT
191 void JumpData::print_data_on(outputStream* st, const char* extra) const { 153 void JumpData::print_data_on(outputStream* st) const {
192 print_shared(st, "JumpData", extra); 154 print_shared(st, "JumpData");
193 st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); 155 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
194 } 156 }
195 #endif // !PRODUCT 157 #endif // !PRODUCT
196 158
197 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) { 159 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) {
368 _pd->tab(st); 330 _pd->tab(st);
369 print_klass(st, type()); 331 print_klass(st, type());
370 st->cr(); 332 st->cr();
371 } 333 }
372 334
373 void CallTypeData::print_data_on(outputStream* st, const char* extra) const { 335 void CallTypeData::print_data_on(outputStream* st) const {
374 CounterData::print_data_on(st, extra); 336 CounterData::print_data_on(st);
375 if (has_arguments()) { 337 if (has_arguments()) {
376 tab(st, true); 338 tab(st, true);
377 st->print("argument types"); 339 st->print("argument types");
378 _args.print_data_on(st); 340 _args.print_data_on(st);
379 } 341 }
382 st->print("return type"); 344 st->print("return type");
383 _ret.print_data_on(st); 345 _ret.print_data_on(st);
384 } 346 }
385 } 347 }
386 348
387 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const { 349 void VirtualCallTypeData::print_data_on(outputStream* st) const {
388 VirtualCallData::print_data_on(st, extra); 350 VirtualCallData::print_data_on(st);
389 if (has_arguments()) { 351 if (has_arguments()) {
390 tab(st, true); 352 tab(st, true);
391 st->print("argument types"); 353 st->print("argument types");
392 _args.print_data_on(st); 354 _args.print_data_on(st);
393 } 355 }
462 receiver(row)->print_value_on(st); 424 receiver(row)->print_value_on(st);
463 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); 425 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
464 } 426 }
465 } 427 }
466 } 428 }
467 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const { 429 void ReceiverTypeData::print_data_on(outputStream* st) const {
468 print_shared(st, "ReceiverTypeData", extra); 430 print_shared(st, "ReceiverTypeData");
469 print_receiver_data_on(st); 431 print_receiver_data_on(st);
470 } 432 }
471 433
472 #ifdef GRAAL 434 #ifdef GRAAL
473 void VirtualCallData::print_method_data_on(outputStream* st) const { 435 void VirtualCallData::print_method_data_on(outputStream* st) const {
492 } 454 }
493 } 455 }
494 } 456 }
495 #endif 457 #endif
496 458
497 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const { 459 void VirtualCallData::print_data_on(outputStream* st) const {
498 print_shared(st, "VirtualCallData", extra); 460 print_shared(st, "VirtualCallData");
499 print_receiver_data_on(st); 461 print_receiver_data_on(st);
500 #ifdef GRAAL 462 #ifdef GRAAL
501 print_method_data_on(st); 463 print_method_data_on(st);
502 #endif 464 #endif
503 } 465 }
545 } 507 }
546 } 508 }
547 return mdp; 509 return mdp;
548 } 510 }
549 511
550 #ifdef CC_INTERP
551 DataLayout* RetData::advance(MethodData *md, int bci) {
552 return (DataLayout*) md->bci_to_dp(bci);
553 }
554 #endif // CC_INTERP
555 512
556 #ifndef PRODUCT 513 #ifndef PRODUCT
557 void RetData::print_data_on(outputStream* st, const char* extra) const { 514 void RetData::print_data_on(outputStream* st) const {
558 print_shared(st, "RetData", extra); 515 print_shared(st, "RetData");
559 uint row; 516 uint row;
560 int entries = 0; 517 int entries = 0;
561 for (row = 0; row < row_limit(); row++) { 518 for (row = 0; row < row_limit(); row++) {
562 if (bci(row) != no_bci) entries++; 519 if (bci(row) != no_bci) entries++;
563 } 520 }
587 int offset = target_di - my_di; 544 int offset = target_di - my_di;
588 set_displacement(offset); 545 set_displacement(offset);
589 } 546 }
590 547
591 #ifndef PRODUCT 548 #ifndef PRODUCT
592 void BranchData::print_data_on(outputStream* st, const char* extra) const { 549 void BranchData::print_data_on(outputStream* st) const {
593 print_shared(st, "BranchData", extra); 550 print_shared(st, "BranchData");
594 st->print_cr("taken(%u) displacement(%d)", 551 st->print_cr("taken(%u) displacement(%d)",
595 taken(), displacement()); 552 taken(), displacement());
596 tab(st); 553 tab(st);
597 st->print_cr("not taken(%u)", not_taken()); 554 st->print_cr("not taken(%u)", not_taken());
598 } 555 }
661 set_default_displacement(offset); 618 set_default_displacement(offset);
662 } 619 }
663 } 620 }
664 621
665 #ifndef PRODUCT 622 #ifndef PRODUCT
666 void MultiBranchData::print_data_on(outputStream* st, const char* extra) const { 623 void MultiBranchData::print_data_on(outputStream* st) const {
667 print_shared(st, "MultiBranchData", extra); 624 print_shared(st, "MultiBranchData");
668 st->print_cr("default_count(%u) displacement(%d)", 625 st->print_cr("default_count(%u) displacement(%d)",
669 default_count(), default_displacement()); 626 default_count(), default_displacement());
670 int cases = number_of_cases(); 627 int cases = number_of_cases();
671 for (int i = 0; i < cases; i++) { 628 for (int i = 0; i < cases; i++) {
672 tab(st); 629 tab(st);
675 } 632 }
676 } 633 }
677 #endif 634 #endif
678 635
679 #ifndef PRODUCT 636 #ifndef PRODUCT
680 void ArgInfoData::print_data_on(outputStream* st, const char* extra) const { 637 void ArgInfoData::print_data_on(outputStream* st) const {
681 print_shared(st, "ArgInfoData", extra); 638 print_shared(st, "ArgInfoData");
682 int nargs = number_of_args(); 639 int nargs = number_of_args();
683 for (int i = 0; i < nargs; i++) { 640 for (int i = 0; i < nargs; i++) {
684 st->print(" 0x%x", arg_modified(i)); 641 st->print(" 0x%x", arg_modified(i));
685 } 642 }
686 st->cr(); 643 st->cr();
707 bool ParametersTypeData::profiling_enabled() { 664 bool ParametersTypeData::profiling_enabled() {
708 return MethodData::profile_parameters(); 665 return MethodData::profile_parameters();
709 } 666 }
710 667
711 #ifndef PRODUCT 668 #ifndef PRODUCT
712 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const { 669 void ParametersTypeData::print_data_on(outputStream* st) const {
713 st->print("parameter types", extra); 670 st->print("parameter types");
714 _parameters.print_data_on(st); 671 _parameters.print_data_on(st);
715 }
716
717 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
718 print_shared(st, "SpeculativeTrapData", extra);
719 tab(st);
720 method()->print_short_name(st);
721 st->cr();
722 } 672 }
723 #endif 673 #endif
724 674
725 // ================================================================== 675 // ==================================================================
726 // MethodData* 676 // MethodData*
843 // a DataLayout header, with no extra cells. 793 // a DataLayout header, with no extra cells.
844 assert(cell_count >= 0, "sanity"); 794 assert(cell_count >= 0, "sanity");
845 return DataLayout::compute_size_in_bytes(cell_count); 795 return DataLayout::compute_size_in_bytes(cell_count);
846 } 796 }
847 797
848 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {
849 // Bytecodes for which we may use speculation
850 switch (code) {
851 case Bytecodes::_checkcast:
852 case Bytecodes::_instanceof:
853 case Bytecodes::_aastore:
854 case Bytecodes::_invokevirtual:
855 case Bytecodes::_invokeinterface:
856 case Bytecodes::_if_acmpeq:
857 case Bytecodes::_if_acmpne:
858 case Bytecodes::_invokestatic:
859 #ifdef COMPILER2
860 return UseTypeSpeculation;
861 #endif
862 default:
863 return false;
864 }
865 return false;
866 }
867
868 #ifdef GRAAL 798 #ifdef GRAAL
869 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { 799 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) {
870 if (!ProfileTraps) return 0; 800 if (!ProfileTraps) return 0;
871 801
872 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one. 802 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one.
873 return MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100)); 803 return MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100));
874 } 804 }
875 #else 805 #else
876 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { 806 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) {
877 if (ProfileTraps) { 807 if (ProfileTraps) {
878 // Assume that up to 3% of BCIs with no MDP will need to allocate one. 808 // Assume that up to 3% of BCIs with no MDP will need to allocate one.
879 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; 809 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
880 // If the method is large, let the extra BCIs grow numerous (to ~1%). 810 // If the method is large, let the extra BCIs grow numerous (to ~1%).
881 int one_percent_of_data 811 int one_percent_of_data
882 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); 812 = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
883 if (extra_data_count < one_percent_of_data) 813 if (extra_data_count < one_percent_of_data)
884 extra_data_count = one_percent_of_data; 814 extra_data_count = one_percent_of_data;
885 if (extra_data_count > empty_bc_count) 815 if (extra_data_count > empty_bc_count)
886 extra_data_count = empty_bc_count; // no need for more 816 extra_data_count = empty_bc_count; // no need for more
887 817 return extra_data_count;
888 // Make sure we have a minimum number of extra data slots to
889 // allocate SpeculativeTrapData entries. We would want to have one
890 // entry per compilation that inlines this method and for which
891 // some type speculation assumption fails. So the room we need for
892 // the SpeculativeTrapData entries doesn't directly depend on the
893 // size of the method. Because it's hard to estimate, we reserve
894 // space for an arbitrary number of entries.
895 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
896 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
897
898 return MAX2(extra_data_count, spec_data_count);
899 } else { 818 } else {
900 return 0; 819 return 0;
901 } 820 }
902 } 821 }
903 #endif 822 #endif
907 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { 826 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
908 int data_size = 0; 827 int data_size = 0;
909 BytecodeStream stream(method); 828 BytecodeStream stream(method);
910 Bytecodes::Code c; 829 Bytecodes::Code c;
911 int empty_bc_count = 0; // number of bytecodes lacking data 830 int empty_bc_count = 0; // number of bytecodes lacking data
912 bool needs_speculative_traps = false;
913 while ((c = stream.next()) >= 0) { 831 while ((c = stream.next()) >= 0) {
914 int size_in_bytes = compute_data_size(&stream); 832 int size_in_bytes = compute_data_size(&stream);
915 data_size += size_in_bytes; 833 data_size += size_in_bytes;
916 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; 834 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1;
917 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
918 } 835 }
919 int object_size = in_bytes(data_offset()) + data_size; 836 int object_size = in_bytes(data_offset()) + data_size;
920 837
921 // Add some extra DataLayout cells (at least one) to track stray traps. 838 // Add some extra DataLayout cells (at least one) to track stray traps.
922 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); 839 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
923 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); 840 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
924 841
925 // Add a cell to record information about modified arguments. 842 // Add a cell to record information about modified arguments.
926 int arg_size = method->size_of_parameters(); 843 int arg_size = method->size_of_parameters();
927 object_size += DataLayout::compute_size_in_bytes(arg_size+1); 844 object_size += DataLayout::compute_size_in_bytes(arg_size+1);
1153 int data_size = 0; 1070 int data_size = 0;
1154 int empty_bc_count = 0; // number of bytecodes lacking data 1071 int empty_bc_count = 0; // number of bytecodes lacking data
1155 _data[0] = 0; // apparently not set below. 1072 _data[0] = 0; // apparently not set below.
1156 BytecodeStream stream(method()); 1073 BytecodeStream stream(method());
1157 Bytecodes::Code c; 1074 Bytecodes::Code c;
1158 bool needs_speculative_traps = false;
1159 while ((c = stream.next()) >= 0) { 1075 while ((c = stream.next()) >= 0) {
1160 int size_in_bytes = initialize_data(&stream, data_size); 1076 int size_in_bytes = initialize_data(&stream, data_size);
1161 data_size += size_in_bytes; 1077 data_size += size_in_bytes;
1162 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; 1078 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1;
1163 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
1164 } 1079 }
1165 _data_size = data_size; 1080 _data_size = data_size;
1166 int object_size = in_bytes(data_offset()) + data_size; 1081 int object_size = in_bytes(data_offset()) + data_size;
1167 1082
1168 // Add some extra DataLayout cells (at least one) to track stray traps. 1083 // Add some extra DataLayout cells (at least one) to track stray traps.
1169 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); 1084 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
1170 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); 1085 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
1171 1086
1172 //#ifdef GRAAL 1087 #ifdef GRAAL
1173 // if (for_reprofile) { 1088 if (for_reprofile) {
1174 // // Clear out extra data 1089 // Clear out extra data
1175 // Copy::zero_to_bytes((HeapWord*) extra_data_base(), extra_size); 1090 Copy::zero_to_bytes((HeapWord*) extra_data_base(), extra_size);
1176 // } 1091 }
1177 //#endif 1092 #endif
1178 // Let's zero the space for the extra data
1179 Copy::zero_to_bytes(((address)_data) + data_size, extra_size);
1180 1093
1181 // Add a cell to record information about modified arguments. 1094 // Add a cell to record information about modified arguments.
1182 // Set up _args_modified array after traps cells so that 1095 // Set up _args_modified array after traps cells so that
1183 // the code for traps cells works. 1096 // the code for traps cells works.
1184 DataLayout *dp = data_layout_at(data_size + extra_size); 1097 DataLayout *dp = data_layout_at(data_size + extra_size);
1187 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); 1100 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1188 1101
1189 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); 1102 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1190 object_size += extra_size + arg_data_size; 1103 object_size += extra_size + arg_data_size;
1191 1104
1192 int parms_cell = ParametersTypeData::compute_cell_count(method()); 1105 int args_cell = ParametersTypeData::compute_cell_count(method());
1193 // If we are profiling parameters, we reserver an area near the end 1106 // If we are profiling parameters, we reserver an area near the end
1194 // of the MDO after the slots for bytecodes (because there's no bci 1107 // of the MDO after the slots for bytecodes (because there's no bci
1195 // for method entry so they don't fit with the framework for the 1108 // for method entry so they don't fit with the framework for the
1196 // profiling of bytecodes). We store the offset within the MDO of 1109 // profiling of bytecodes). We store the offset within the MDO of
1197 // this area (or -1 if no parameter is profiled) 1110 // this area (or -1 if no parameter is profiled)
1198 if (parms_cell > 0) { 1111 if (args_cell > 0) {
1199 object_size += DataLayout::compute_size_in_bytes(parms_cell); 1112 object_size += DataLayout::compute_size_in_bytes(args_cell);
1200 _parameters_type_data_di = data_size + extra_size + arg_data_size; 1113 _parameters_type_data_di = data_size + extra_size + arg_data_size;
1201 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); 1114 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1202 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell); 1115 dp->initialize(DataLayout::parameters_type_data_tag, 0, args_cell);
1203 } else { 1116 } else {
1204 _parameters_type_data_di = -1; 1117 _parameters_type_data_di = -1;
1205 } 1118 }
1206 1119
1207 // Set an initial hint. Don't use set_hint_di() because 1120 // Set an initial hint. Don't use set_hint_di() because
1292 return data; 1205 return data;
1293 } else if (data->bci() > bci) { 1206 } else if (data->bci() > bci) {
1294 break; 1207 break;
1295 } 1208 }
1296 } 1209 }
1297 return bci_to_extra_data(bci, NULL, false); 1210 return bci_to_extra_data(bci, false);
1298 } 1211 }
1299 1212
1300 DataLayout* MethodData::next_extra(DataLayout* dp) { 1213 // Translate a bci to its corresponding extra data, or NULL.
1301 int nb_cells = 0; 1214 ProfileData* MethodData::bci_to_extra_data(int bci, bool create_if_missing) {
1302 switch(dp->tag()) { 1215 DataLayout* dp = extra_data_base();
1303 case DataLayout::bit_data_tag: 1216 DataLayout* end = extra_data_limit();
1304 case DataLayout::no_tag: 1217 DataLayout* avail = NULL;
1305 nb_cells = BitData::static_cell_count(); 1218 for (; dp < end; dp = next_extra(dp)) {
1306 break;
1307 case DataLayout::speculative_trap_data_tag:
1308 nb_cells = SpeculativeTrapData::static_cell_count();
1309 break;
1310 default:
1311 fatal(err_msg("unexpected tag %d", dp->tag()));
1312 }
1313 return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells));
1314 }
1315
1316 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp) {
1317 DataLayout* end = extra_data_limit();
1318
1319 for (;; dp = next_extra(dp)) {
1320 assert(dp < end, "moved past end of extra data");
1321 // No need for "OrderAccess::load_acquire" ops, 1219 // No need for "OrderAccess::load_acquire" ops,
1322 // since the data structure is monotonic. 1220 // since the data structure is monotonic.
1323 switch(dp->tag()) { 1221 if (dp->tag() == DataLayout::no_tag) break;
1324 case DataLayout::no_tag: 1222 if (dp->tag() == DataLayout::arg_info_data_tag) {
1325 return NULL; 1223 dp = end; // ArgInfoData is at the end of extra data section.
1326 case DataLayout::arg_info_data_tag:
1327 dp = end;
1328 return NULL; // ArgInfoData is at the end of extra data section.
1329 case DataLayout::bit_data_tag:
1330 if (m == NULL && dp->bci() == bci) {
1331 return new BitData(dp);
1332 }
1333 break; 1224 break;
1334 case DataLayout::speculative_trap_data_tag: 1225 }
1335 if (m != NULL) { 1226 if (dp->bci() == bci) {
1336 SpeculativeTrapData* data = new SpeculativeTrapData(dp); 1227 assert(dp->tag() == DataLayout::bit_data_tag, "sane");
1337 // data->method() may be null in case of a concurrent 1228 return new BitData(dp);
1338 // allocation. Assume it's for the same method and use that 1229 }
1339 // entry in that case. 1230 }
1340 if (dp->bci() == bci) { 1231 if (create_if_missing && dp < end) {
1341 if (data->method() == NULL) { 1232 // Allocate this one. There is no mutual exclusion,
1342 return NULL; 1233 // so two threads could allocate different BCIs to the
1343 } else if (data->method() == m) { 1234 // same data layout. This means these extra data
1344 return data; 1235 // records, like most other MDO contents, must not be
1345 } 1236 // trusted too much.
1346 } 1237 DataLayout temp;
1347 } 1238 temp.initialize(DataLayout::bit_data_tag, bci, 0);
1348 break; 1239 dp->release_set_header(temp.header());
1349 default: 1240 assert(dp->tag() == DataLayout::bit_data_tag, "sane");
1350 fatal(err_msg("unexpected tag %d", dp->tag())); 1241 //NO: assert(dp->bci() == bci, "no concurrent allocation");
1351 } 1242 return new BitData(dp);
1352 }
1353 return NULL;
1354 }
1355
1356
1357 // Translate a bci to its corresponding extra data, or NULL.
1358 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) {
1359 // This code assumes an entry for a SpeculativeTrapData is 2 cells
1360 assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) ==
1361 DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()),
1362 "code needs to be adjusted");
1363
1364 DataLayout* dp = extra_data_base();
1365 DataLayout* end = extra_data_limit();
1366
1367 // Allocation in the extra data space has to be atomic because not
1368 // all entries have the same size and non atomic concurrent
1369 // allocation would result in a corrupted extra data space.
1370 while (true) {
1371 ProfileData* result = bci_to_extra_data_helper(bci, m, dp);
1372 if (result != NULL) {
1373 return result;
1374 }
1375
1376 if (create_if_missing && dp < end) {
1377 assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free");
1378 assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info");
1379 u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag;
1380 // SpeculativeTrapData is 2 slots. Make sure we have room.
1381 if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) {
1382 return NULL;
1383 }
1384 DataLayout temp;
1385 temp.initialize(tag, bci, 0);
1386 // May have been set concurrently
1387 if (dp->header() != temp.header() && !dp->atomic_set_header(temp.header())) {
1388 // Allocation failure because of concurrent allocation. Try
1389 // again.
1390 continue;
1391 }
1392 assert(dp->tag() == tag, "sane");
1393 assert(dp->bci() == bci, "no concurrent allocation");
1394 if (tag == DataLayout::bit_data_tag) {
1395 return new BitData(dp);
1396 } else {
1397 // If being allocated concurrently, one trap may be lost
1398 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1399 data->set_method(m);
1400 return data;
1401 }
1402 }
1403 return NULL;
1404 } 1243 }
1405 return NULL; 1244 return NULL;
1406 } 1245 }
1407 1246
1408 ArgInfoData *MethodData::arg_info() { 1247 ArgInfoData *MethodData::arg_info() {
1443 parameters_type_data()->print_data_on(st); 1282 parameters_type_data()->print_data_on(st);
1444 } 1283 }
1445 for ( ; is_valid(data); data = next_data(data)) { 1284 for ( ; is_valid(data); data = next_data(data)) {
1446 st->print("%d", dp_to_di(data->dp())); 1285 st->print("%d", dp_to_di(data->dp()));
1447 st->fill_to(6); 1286 st->fill_to(6);
1448 data->print_data_on(st, this); 1287 data->print_data_on(st);
1449 } 1288 }
1450 st->print_cr("--- Extra data:"); 1289 st->print_cr("--- Extra data:");
1451 DataLayout* dp = extra_data_base(); 1290 DataLayout* dp = extra_data_base();
1452 DataLayout* end = extra_data_limit(); 1291 DataLayout* end = extra_data_limit();
1453 for (;; dp = next_extra(dp)) { 1292 for (; dp < end; dp = next_extra(dp)) {
1454 assert(dp < end, "moved past end of extra data");
1455 // No need for "OrderAccess::load_acquire" ops, 1293 // No need for "OrderAccess::load_acquire" ops,
1456 // since the data structure is monotonic. 1294 // since the data structure is monotonic.
1457 switch(dp->tag()) { 1295 if (dp->tag() == DataLayout::no_tag) continue;
1458 case DataLayout::no_tag: 1296 if (dp->tag() == DataLayout::bit_data_tag) {
1459 continue;
1460 case DataLayout::bit_data_tag:
1461 data = new BitData(dp); 1297 data = new BitData(dp);
1462 break; 1298 } else {
1463 case DataLayout::speculative_trap_data_tag: 1299 assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo");
1464 data = new SpeculativeTrapData(dp);
1465 break;
1466 case DataLayout::arg_info_data_tag:
1467 data = new ArgInfoData(dp); 1300 data = new ArgInfoData(dp);
1468 dp = end; // ArgInfoData is at the end of extra data section. 1301 dp = end; // ArgInfoData is at the end of extra data section.
1469 break;
1470 default:
1471 fatal(err_msg("unexpected tag %d", dp->tag()));
1472 } 1302 }
1473 st->print("%d", dp_to_di(data->dp())); 1303 st->print("%d", dp_to_di(data->dp()));
1474 st->fill_to(6); 1304 st->fill_to(6);
1475 data->print_data_on(st); 1305 data->print_data_on(st);
1476 if (dp >= end) return;
1477 } 1306 }
1478 } 1307 }
1479 #endif 1308 #endif
1480 1309
1481 #if INCLUDE_SERVICES 1310 #if INCLUDE_SERVICES
1595 1424
1596 assert(profile_parameters_jsr292_only(), "inconsistent"); 1425 assert(profile_parameters_jsr292_only(), "inconsistent");
1597 return m->is_compiled_lambda_form(); 1426 return m->is_compiled_lambda_form();
1598 } 1427 }
1599 1428
1600 void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) {
1601 if (shift == 0) {
1602 return;
1603 }
1604 if (!reset) {
1605 // Move all cells of trap entry at dp left by "shift" cells
1606 intptr_t* start = (intptr_t*)dp;
1607 intptr_t* end = (intptr_t*)next_extra(dp);
1608 for (intptr_t* ptr = start; ptr < end; ptr++) {
1609 *(ptr-shift) = *ptr;
1610 }
1611 } else {
1612 // Reset "shift" cells stopping at dp
1613 intptr_t* start = ((intptr_t*)dp) - shift;
1614 intptr_t* end = (intptr_t*)dp;
1615 for (intptr_t* ptr = start; ptr < end; ptr++) {
1616 *ptr = 0;
1617 }
1618 }
1619 }
1620
1621 // Remove SpeculativeTrapData entries that reference an unloaded
1622 // method
1623 void MethodData::clean_extra_data(BoolObjectClosure* is_alive) {
1624 DataLayout* dp = extra_data_base();
1625 DataLayout* end = extra_data_limit();
1626
1627 int shift = 0;
1628 for (; dp < end; dp = next_extra(dp)) {
1629 switch(dp->tag()) {
1630 case DataLayout::speculative_trap_data_tag: {
1631 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1632 Method* m = data->method();
1633 assert(m != NULL, "should have a method");
1634 if (!m->method_holder()->is_loader_alive(is_alive)) {
1635 // "shift" accumulates the number of cells for dead
1636 // SpeculativeTrapData entries that have been seen so
1637 // far. Following entries must be shifted left by that many
1638 // cells to remove the dead SpeculativeTrapData entries.
1639 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp);
1640 } else {
1641 // Shift this entry left if it follows dead
1642 // SpeculativeTrapData entries
1643 clean_extra_data_helper(dp, shift);
1644 }
1645 break;
1646 }
1647 case DataLayout::bit_data_tag:
1648 // Shift this entry left if it follows dead SpeculativeTrapData
1649 // entries
1650 clean_extra_data_helper(dp, shift);
1651 continue;
1652 case DataLayout::no_tag:
1653 case DataLayout::arg_info_data_tag:
1654 // We are at end of the live trap entries. The previous "shift"
1655 // cells contain entries that are either dead or were shifted
1656 // left. They need to be reset to no_tag
1657 clean_extra_data_helper(dp, shift, true);
1658 return;
1659 default:
1660 fatal(err_msg("unexpected tag %d", dp->tag()));
1661 }
1662 }
1663 }
1664
1665 // Verify there's no unloaded method referenced by a
1666 // SpeculativeTrapData entry
1667 void MethodData::verify_extra_data_clean(BoolObjectClosure* is_alive) {
1668 #ifdef ASSERT
1669 DataLayout* dp = extra_data_base();
1670 DataLayout* end = extra_data_limit();
1671
1672 for (; dp < end; dp = next_extra(dp)) {
1673 switch(dp->tag()) {
1674 case DataLayout::speculative_trap_data_tag: {
1675 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1676 Method* m = data->method();
1677 assert(m != NULL && m->method_holder()->is_loader_alive(is_alive), "Method should exist");
1678 break;
1679 }
1680 case DataLayout::bit_data_tag:
1681 continue;
1682 case DataLayout::no_tag:
1683 case DataLayout::arg_info_data_tag:
1684 return;
1685 default:
1686 fatal(err_msg("unexpected tag %d", dp->tag()));
1687 }
1688 }
1689 #endif
1690 }
1691
1692 void MethodData::clean_method_data(BoolObjectClosure* is_alive) {
1693 for (ProfileData* data = first_data();
1694 is_valid(data);
1695 data = next_data(data)) {
1696 data->clean_weak_klass_links(is_alive);
1697 }
1698 ParametersTypeData* parameters = parameters_type_data();
1699 if (parameters != NULL) {
1700 parameters->clean_weak_klass_links(is_alive);
1701 }
1702
1703 clean_extra_data(is_alive);
1704 verify_extra_data_clean(is_alive);
1705 }
1706
1707 // Remove SpeculativeTrapData entries that reference a redefined
1708 // method
1709 void MethodData::clean_weak_method_extra_data() {
1710 DataLayout* dp = extra_data_base();
1711 DataLayout* end = extra_data_limit();
1712
1713 int shift = 0;
1714 for (; dp < end; dp = next_extra(dp)) {
1715 switch(dp->tag()) {
1716 case DataLayout::speculative_trap_data_tag: {
1717 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1718 Method* m = data->method();
1719 assert(m != NULL, "should have a method");
1720 if (!m->on_stack()) {
1721 // "shift" accumulates the number of cells for dead
1722 // SpeculativeTrapData entries that have been seen so
1723 // far. Following entries must be shifted left by that many
1724 // cells to remove the dead SpeculativeTrapData entries.
1725 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp);
1726 } else {
1727 // Shift this entry left if it follows dead
1728 // SpeculativeTrapData entries
1729 clean_extra_data_helper(dp, shift);
1730 }
1731 break;
1732 }
1733 case DataLayout::bit_data_tag:
1734 // Shift this entry left if it follows dead SpeculativeTrapData
1735 // entries
1736 clean_extra_data_helper(dp, shift);
1737 continue;
1738 case DataLayout::no_tag:
1739 case DataLayout::arg_info_data_tag:
1740 // We are at end of the live trap entries. The previous "shift"
1741 // cells contain entries that are either dead or were shifted
1742 // left. They need to be reset to no_tag
1743 clean_extra_data_helper(dp, shift, true);
1744 return;
1745 default:
1746 fatal(err_msg("unexpected tag %d", dp->tag()));
1747 }
1748 }
1749 }
1750
1751 // Verify there's no redefined method referenced by a
1752 // SpeculativeTrapData entry
1753 void MethodData::verify_weak_method_extra_data_clean() {
1754 #ifdef ASSERT
1755 DataLayout* dp = extra_data_base();
1756 DataLayout* end = extra_data_limit();
1757
1758 for (; dp < end; dp = next_extra(dp)) {
1759 switch(dp->tag()) {
1760 case DataLayout::speculative_trap_data_tag: {
1761 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1762 Method* m = data->method();
1763 assert(m != NULL && m->on_stack(), "Method should exist");
1764 break;
1765 }
1766 case DataLayout::bit_data_tag:
1767 continue;
1768 case DataLayout::no_tag:
1769 case DataLayout::arg_info_data_tag:
1770 return;
1771 default:
1772 fatal(err_msg("unexpected tag %d", dp->tag()));
1773 }
1774 }
1775 #endif
1776 }
1777
1778 void MethodData::clean_weak_method_links() { 1429 void MethodData::clean_weak_method_links() {
1779 for (ProfileData* data = first_data(); 1430 for (ProfileData* data = first_data();
1780 is_valid(data); 1431 is_valid(data);
1781 data = next_data(data)) { 1432 data = next_data(data)) {
1782 data->clean_weak_method_links(); 1433 data->clean_weak_method_links();
1783 } 1434 }
1784 1435 }
1785 clean_weak_method_extra_data();
1786 verify_weak_method_extra_data_clean();
1787 }