comparison src/share/vm/oops/methodData.cpp @ 14500:fdad2932c73f

8031752: Failed speculative optimizations should be reattempted when root of compilation is different Summary: support for speculative traps that keep track of the root of the compilation in which a trap occurs. Reviewed-by: kvn, twisti
author roland
date Tue, 25 Feb 2014 18:16:24 +0100
parents da862781b584
children d8041d695d19 53ed0f89f44e
comparison
equal deleted inserted replaced
14498:04e7587c97dc 14500:fdad2932c73f
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
83 #ifndef PRODUCT 117 #ifndef PRODUCT
84 void ProfileData::print_shared(outputStream* st, const char* name) const { 118 void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const {
85 st->print("bci: %d", bci()); 119 st->print("bci: %d", bci());
86 st->fill_to(tab_width_one); 120 st->fill_to(tab_width_one);
87 st->print("%s", name); 121 st->print("%s", name);
88 tab(st); 122 tab(st);
89 int trap = trap_state(); 123 int trap = trap_state();
90 if (trap != 0) { 124 if (trap != 0) {
91 char buf[100]; 125 char buf[100];
92 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); 126 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
93 } 127 }
128 if (extra != NULL) {
129 st->print(extra);
130 }
94 int flags = data()->flags(); 131 int flags = data()->flags();
95 if (flags != 0) 132 if (flags != 0) {
96 st->print("flags(%d) ", flags); 133 st->print("flags(%d) ", flags);
134 }
97 } 135 }
98 136
99 void ProfileData::tab(outputStream* st, bool first) const { 137 void ProfileData::tab(outputStream* st, bool first) const {
100 st->fill_to(first ? tab_width_one : tab_width_two); 138 st->fill_to(first ? tab_width_one : tab_width_two);
101 } 139 }
107 // A BitData corresponds to a one-bit flag. This is used to indicate 145 // A BitData corresponds to a one-bit flag. This is used to indicate
108 // whether a checkcast bytecode has seen a null value. 146 // whether a checkcast bytecode has seen a null value.
109 147
110 148
111 #ifndef PRODUCT 149 #ifndef PRODUCT
112 void BitData::print_data_on(outputStream* st) const { 150 void BitData::print_data_on(outputStream* st, const char* extra) const {
113 print_shared(st, "BitData"); 151 print_shared(st, "BitData", extra);
114 } 152 }
115 #endif // !PRODUCT 153 #endif // !PRODUCT
116 154
117 // ================================================================== 155 // ==================================================================
118 // CounterData 156 // CounterData
119 // 157 //
120 // A CounterData corresponds to a simple counter. 158 // A CounterData corresponds to a simple counter.
121 159
122 #ifndef PRODUCT 160 #ifndef PRODUCT
123 void CounterData::print_data_on(outputStream* st) const { 161 void CounterData::print_data_on(outputStream* st, const char* extra) const {
124 print_shared(st, "CounterData"); 162 print_shared(st, "CounterData", extra);
125 st->print_cr("count(%u)", count()); 163 st->print_cr("count(%u)", count());
126 } 164 }
127 #endif // !PRODUCT 165 #endif // !PRODUCT
128 166
129 // ================================================================== 167 // ==================================================================
148 int offset = target_di - my_di; 186 int offset = target_di - my_di;
149 set_displacement(offset); 187 set_displacement(offset);
150 } 188 }
151 189
152 #ifndef PRODUCT 190 #ifndef PRODUCT
153 void JumpData::print_data_on(outputStream* st) const { 191 void JumpData::print_data_on(outputStream* st, const char* extra) const {
154 print_shared(st, "JumpData"); 192 print_shared(st, "JumpData", extra);
155 st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); 193 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
156 } 194 }
157 #endif // !PRODUCT 195 #endif // !PRODUCT
158 196
159 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) { 197 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) {
330 _pd->tab(st); 368 _pd->tab(st);
331 print_klass(st, type()); 369 print_klass(st, type());
332 st->cr(); 370 st->cr();
333 } 371 }
334 372
335 void CallTypeData::print_data_on(outputStream* st) const { 373 void CallTypeData::print_data_on(outputStream* st, const char* extra) const {
336 CounterData::print_data_on(st); 374 CounterData::print_data_on(st, extra);
337 if (has_arguments()) { 375 if (has_arguments()) {
338 tab(st, true); 376 tab(st, true);
339 st->print("argument types"); 377 st->print("argument types");
340 _args.print_data_on(st); 378 _args.print_data_on(st);
341 } 379 }
344 st->print("return type"); 382 st->print("return type");
345 _ret.print_data_on(st); 383 _ret.print_data_on(st);
346 } 384 }
347 } 385 }
348 386
349 void VirtualCallTypeData::print_data_on(outputStream* st) const { 387 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {
350 VirtualCallData::print_data_on(st); 388 VirtualCallData::print_data_on(st, extra);
351 if (has_arguments()) { 389 if (has_arguments()) {
352 tab(st, true); 390 tab(st, true);
353 st->print("argument types"); 391 st->print("argument types");
354 _args.print_data_on(st); 392 _args.print_data_on(st);
355 } 393 }
398 receiver(row)->print_value_on(st); 436 receiver(row)->print_value_on(st);
399 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); 437 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
400 } 438 }
401 } 439 }
402 } 440 }
403 void ReceiverTypeData::print_data_on(outputStream* st) const { 441 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {
404 print_shared(st, "ReceiverTypeData"); 442 print_shared(st, "ReceiverTypeData", extra);
405 print_receiver_data_on(st); 443 print_receiver_data_on(st);
406 } 444 }
407 void VirtualCallData::print_data_on(outputStream* st) const { 445 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const {
408 print_shared(st, "VirtualCallData"); 446 print_shared(st, "VirtualCallData", extra);
409 print_receiver_data_on(st); 447 print_receiver_data_on(st);
410 } 448 }
411 #endif // !PRODUCT 449 #endif // !PRODUCT
412 450
413 // ================================================================== 451 // ==================================================================
459 return (DataLayout*) md->bci_to_dp(bci); 497 return (DataLayout*) md->bci_to_dp(bci);
460 } 498 }
461 #endif // CC_INTERP 499 #endif // CC_INTERP
462 500
463 #ifndef PRODUCT 501 #ifndef PRODUCT
464 void RetData::print_data_on(outputStream* st) const { 502 void RetData::print_data_on(outputStream* st, const char* extra) const {
465 print_shared(st, "RetData"); 503 print_shared(st, "RetData", extra);
466 uint row; 504 uint row;
467 int entries = 0; 505 int entries = 0;
468 for (row = 0; row < row_limit(); row++) { 506 for (row = 0; row < row_limit(); row++) {
469 if (bci(row) != no_bci) entries++; 507 if (bci(row) != no_bci) entries++;
470 } 508 }
494 int offset = target_di - my_di; 532 int offset = target_di - my_di;
495 set_displacement(offset); 533 set_displacement(offset);
496 } 534 }
497 535
498 #ifndef PRODUCT 536 #ifndef PRODUCT
499 void BranchData::print_data_on(outputStream* st) const { 537 void BranchData::print_data_on(outputStream* st, const char* extra) const {
500 print_shared(st, "BranchData"); 538 print_shared(st, "BranchData", extra);
501 st->print_cr("taken(%u) displacement(%d)", 539 st->print_cr("taken(%u) displacement(%d)",
502 taken(), displacement()); 540 taken(), displacement());
503 tab(st); 541 tab(st);
504 st->print_cr("not taken(%u)", not_taken()); 542 st->print_cr("not taken(%u)", not_taken());
505 } 543 }
568 set_default_displacement(offset); 606 set_default_displacement(offset);
569 } 607 }
570 } 608 }
571 609
572 #ifndef PRODUCT 610 #ifndef PRODUCT
573 void MultiBranchData::print_data_on(outputStream* st) const { 611 void MultiBranchData::print_data_on(outputStream* st, const char* extra) const {
574 print_shared(st, "MultiBranchData"); 612 print_shared(st, "MultiBranchData", extra);
575 st->print_cr("default_count(%u) displacement(%d)", 613 st->print_cr("default_count(%u) displacement(%d)",
576 default_count(), default_displacement()); 614 default_count(), default_displacement());
577 int cases = number_of_cases(); 615 int cases = number_of_cases();
578 for (int i = 0; i < cases; i++) { 616 for (int i = 0; i < cases; i++) {
579 tab(st); 617 tab(st);
582 } 620 }
583 } 621 }
584 #endif 622 #endif
585 623
586 #ifndef PRODUCT 624 #ifndef PRODUCT
587 void ArgInfoData::print_data_on(outputStream* st) const { 625 void ArgInfoData::print_data_on(outputStream* st, const char* extra) const {
588 print_shared(st, "ArgInfoData"); 626 print_shared(st, "ArgInfoData", extra);
589 int nargs = number_of_args(); 627 int nargs = number_of_args();
590 for (int i = 0; i < nargs; i++) { 628 for (int i = 0; i < nargs; i++) {
591 st->print(" 0x%x", arg_modified(i)); 629 st->print(" 0x%x", arg_modified(i));
592 } 630 }
593 st->cr(); 631 st->cr();
614 bool ParametersTypeData::profiling_enabled() { 652 bool ParametersTypeData::profiling_enabled() {
615 return MethodData::profile_parameters(); 653 return MethodData::profile_parameters();
616 } 654 }
617 655
618 #ifndef PRODUCT 656 #ifndef PRODUCT
619 void ParametersTypeData::print_data_on(outputStream* st) const { 657 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
620 st->print("parameter types"); 658 st->print("parameter types", extra);
621 _parameters.print_data_on(st); 659 _parameters.print_data_on(st);
660 }
661
662 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
663 print_shared(st, "SpeculativeTrapData", extra);
664 tab(st);
665 method()->print_short_name(st);
666 st->cr();
622 } 667 }
623 #endif 668 #endif
624 669
625 // ================================================================== 670 // ==================================================================
626 // MethodData* 671 // MethodData*
743 // a DataLayout header, with no extra cells. 788 // a DataLayout header, with no extra cells.
744 assert(cell_count >= 0, "sanity"); 789 assert(cell_count >= 0, "sanity");
745 return DataLayout::compute_size_in_bytes(cell_count); 790 return DataLayout::compute_size_in_bytes(cell_count);
746 } 791 }
747 792
748 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) { 793 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {
794 // Bytecodes for which we may use speculation
795 switch (code) {
796 case Bytecodes::_checkcast:
797 case Bytecodes::_instanceof:
798 case Bytecodes::_aastore:
799 case Bytecodes::_invokevirtual:
800 case Bytecodes::_invokeinterface:
801 case Bytecodes::_if_acmpeq:
802 case Bytecodes::_if_acmpne:
803 case Bytecodes::_invokestatic:
804 #ifdef COMPILER2
805 return UseTypeSpeculation;
806 #endif
807 default:
808 return false;
809 }
810 return false;
811 }
812
813 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
749 if (ProfileTraps) { 814 if (ProfileTraps) {
750 // Assume that up to 3% of BCIs with no MDP will need to allocate one. 815 // Assume that up to 3% of BCIs with no MDP will need to allocate one.
751 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; 816 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
752 // If the method is large, let the extra BCIs grow numerous (to ~1%). 817 // If the method is large, let the extra BCIs grow numerous (to ~1%).
753 int one_percent_of_data 818 int one_percent_of_data
754 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); 819 = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
755 if (extra_data_count < one_percent_of_data) 820 if (extra_data_count < one_percent_of_data)
756 extra_data_count = one_percent_of_data; 821 extra_data_count = one_percent_of_data;
757 if (extra_data_count > empty_bc_count) 822 if (extra_data_count > empty_bc_count)
758 extra_data_count = empty_bc_count; // no need for more 823 extra_data_count = empty_bc_count; // no need for more
759 return extra_data_count; 824
825 // Make sure we have a minimum number of extra data slots to
826 // allocate SpeculativeTrapData entries. We would want to have one
827 // entry per compilation that inlines this method and for which
828 // some type speculation assumption fails. So the room we need for
829 // the SpeculativeTrapData entries doesn't directly depend on the
830 // size of the method. Because it's hard to estimate, we reserve
831 // space for an arbitrary number of entries.
832 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
833 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
834
835 return MAX2(extra_data_count, spec_data_count);
760 } else { 836 } else {
761 return 0; 837 return 0;
762 } 838 }
763 } 839 }
764 840
767 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { 843 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
768 int data_size = 0; 844 int data_size = 0;
769 BytecodeStream stream(method); 845 BytecodeStream stream(method);
770 Bytecodes::Code c; 846 Bytecodes::Code c;
771 int empty_bc_count = 0; // number of bytecodes lacking data 847 int empty_bc_count = 0; // number of bytecodes lacking data
848 bool needs_speculative_traps = false;
772 while ((c = stream.next()) >= 0) { 849 while ((c = stream.next()) >= 0) {
773 int size_in_bytes = compute_data_size(&stream); 850 int size_in_bytes = compute_data_size(&stream);
774 data_size += size_in_bytes; 851 data_size += size_in_bytes;
775 if (size_in_bytes == 0) empty_bc_count += 1; 852 if (size_in_bytes == 0) empty_bc_count += 1;
853 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
776 } 854 }
777 int object_size = in_bytes(data_offset()) + data_size; 855 int object_size = in_bytes(data_offset()) + data_size;
778 856
779 // Add some extra DataLayout cells (at least one) to track stray traps. 857 // Add some extra DataLayout cells (at least one) to track stray traps.
780 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); 858 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
781 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); 859 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
782 860
783 // Add a cell to record information about modified arguments. 861 // Add a cell to record information about modified arguments.
784 int arg_size = method->size_of_parameters(); 862 int arg_size = method->size_of_parameters();
785 object_size += DataLayout::compute_size_in_bytes(arg_size+1); 863 object_size += DataLayout::compute_size_in_bytes(arg_size+1);
1007 int data_size = 0; 1085 int data_size = 0;
1008 int empty_bc_count = 0; // number of bytecodes lacking data 1086 int empty_bc_count = 0; // number of bytecodes lacking data
1009 _data[0] = 0; // apparently not set below. 1087 _data[0] = 0; // apparently not set below.
1010 BytecodeStream stream(method); 1088 BytecodeStream stream(method);
1011 Bytecodes::Code c; 1089 Bytecodes::Code c;
1090 bool needs_speculative_traps = false;
1012 while ((c = stream.next()) >= 0) { 1091 while ((c = stream.next()) >= 0) {
1013 int size_in_bytes = initialize_data(&stream, data_size); 1092 int size_in_bytes = initialize_data(&stream, data_size);
1014 data_size += size_in_bytes; 1093 data_size += size_in_bytes;
1015 if (size_in_bytes == 0) empty_bc_count += 1; 1094 if (size_in_bytes == 0) empty_bc_count += 1;
1095 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
1016 } 1096 }
1017 _data_size = data_size; 1097 _data_size = data_size;
1018 int object_size = in_bytes(data_offset()) + data_size; 1098 int object_size = in_bytes(data_offset()) + data_size;
1019 1099
1020 // Add some extra DataLayout cells (at least one) to track stray traps. 1100 // Add some extra DataLayout cells (at least one) to track stray traps.
1021 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); 1101 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
1022 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); 1102 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
1103
1104 // Let's zero the space for the extra data
1105 Copy::zero_to_bytes(((address)_data) + data_size, extra_size);
1023 1106
1024 // Add a cell to record information about modified arguments. 1107 // Add a cell to record information about modified arguments.
1025 // Set up _args_modified array after traps cells so that 1108 // Set up _args_modified array after traps cells so that
1026 // the code for traps cells works. 1109 // the code for traps cells works.
1027 DataLayout *dp = data_layout_at(data_size + extra_size); 1110 DataLayout *dp = data_layout_at(data_size + extra_size);
1030 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); 1113 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1031 1114
1032 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); 1115 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1033 object_size += extra_size + arg_data_size; 1116 object_size += extra_size + arg_data_size;
1034 1117
1035 int args_cell = ParametersTypeData::compute_cell_count(method()); 1118 int parms_cell = ParametersTypeData::compute_cell_count(method());
1036 // If we are profiling parameters, we reserver an area near the end 1119 // If we are profiling parameters, we reserver an area near the end
1037 // of the MDO after the slots for bytecodes (because there's no bci 1120 // of the MDO after the slots for bytecodes (because there's no bci
1038 // for method entry so they don't fit with the framework for the 1121 // for method entry so they don't fit with the framework for the
1039 // profiling of bytecodes). We store the offset within the MDO of 1122 // profiling of bytecodes). We store the offset within the MDO of
1040 // this area (or -1 if no parameter is profiled) 1123 // this area (or -1 if no parameter is profiled)
1041 if (args_cell > 0) { 1124 if (parms_cell > 0) {
1042 object_size += DataLayout::compute_size_in_bytes(args_cell); 1125 object_size += DataLayout::compute_size_in_bytes(parms_cell);
1043 _parameters_type_data_di = data_size + extra_size + arg_data_size; 1126 _parameters_type_data_di = data_size + extra_size + arg_data_size;
1044 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); 1127 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1045 dp->initialize(DataLayout::parameters_type_data_tag, 0, args_cell); 1128 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);
1046 } else { 1129 } else {
1047 _parameters_type_data_di = -1; 1130 _parameters_type_data_di = -1;
1048 } 1131 }
1049 1132
1050 // Set an initial hint. Don't use set_hint_di() because 1133 // Set an initial hint. Don't use set_hint_di() because
1131 return data; 1214 return data;
1132 } else if (data->bci() > bci) { 1215 } else if (data->bci() > bci) {
1133 break; 1216 break;
1134 } 1217 }
1135 } 1218 }
1136 return bci_to_extra_data(bci, false); 1219 return bci_to_extra_data(bci, NULL, false);
1137 } 1220 }
1138 1221
1139 // Translate a bci to its corresponding extra data, or NULL. 1222 DataLayout* MethodData::next_extra(DataLayout* dp) {
1140 ProfileData* MethodData::bci_to_extra_data(int bci, bool create_if_missing) { 1223 int nb_cells = 0;
1141 DataLayout* dp = extra_data_base(); 1224 switch(dp->tag()) {
1142 DataLayout* end = extra_data_limit(); 1225 case DataLayout::bit_data_tag:
1143 DataLayout* avail = NULL; 1226 case DataLayout::no_tag:
1144 for (; dp < end; dp = next_extra(dp)) { 1227 nb_cells = BitData::static_cell_count();
1228 break;
1229 case DataLayout::speculative_trap_data_tag:
1230 nb_cells = SpeculativeTrapData::static_cell_count();
1231 break;
1232 default:
1233 fatal(err_msg("unexpected tag %d", dp->tag()));
1234 }
1235 return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells));
1236 }
1237
1238 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp) {
1239 DataLayout* end = extra_data_limit();
1240
1241 for (;; dp = next_extra(dp)) {
1242 assert(dp < end, "moved past end of extra data");
1145 // No need for "OrderAccess::load_acquire" ops, 1243 // No need for "OrderAccess::load_acquire" ops,
1146 // since the data structure is monotonic. 1244 // since the data structure is monotonic.
1147 if (dp->tag() == DataLayout::no_tag) break; 1245 switch(dp->tag()) {
1148 if (dp->tag() == DataLayout::arg_info_data_tag) { 1246 case DataLayout::no_tag:
1149 dp = end; // ArgInfoData is at the end of extra data section. 1247 return NULL;
1248 case DataLayout::arg_info_data_tag:
1249 dp = end;
1250 return NULL; // ArgInfoData is at the end of extra data section.
1251 case DataLayout::bit_data_tag:
1252 if (m == NULL && dp->bci() == bci) {
1253 return new BitData(dp);
1254 }
1150 break; 1255 break;
1151 } 1256 case DataLayout::speculative_trap_data_tag:
1152 if (dp->bci() == bci) { 1257 if (m != NULL) {
1153 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); 1258 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1154 return new BitData(dp); 1259 // data->method() may be null in case of a concurrent
1155 } 1260 // allocation. Assume it's for the same method and use that
1156 } 1261 // entry in that case.
1157 if (create_if_missing && dp < end) { 1262 if (dp->bci() == bci) {
1158 // Allocate this one. There is no mutual exclusion, 1263 if (data->method() == NULL) {
1159 // so two threads could allocate different BCIs to the 1264 return NULL;
1160 // same data layout. This means these extra data 1265 } else if (data->method() == m) {
1161 // records, like most other MDO contents, must not be 1266 return data;
1162 // trusted too much. 1267 }
1163 DataLayout temp; 1268 }
1164 temp.initialize(DataLayout::bit_data_tag, bci, 0); 1269 }
1165 dp->release_set_header(temp.header()); 1270 break;
1166 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); 1271 default:
1167 //NO: assert(dp->bci() == bci, "no concurrent allocation"); 1272 fatal(err_msg("unexpected tag %d", dp->tag()));
1168 return new BitData(dp); 1273 }
1274 }
1275 return NULL;
1276 }
1277
1278
1279 // Translate a bci to its corresponding extra data, or NULL.
1280 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) {
1281 // This code assumes an entry for a SpeculativeTrapData is 2 cells
1282 assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) ==
1283 DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()),
1284 "code needs to be adjusted");
1285
1286 DataLayout* dp = extra_data_base();
1287 DataLayout* end = extra_data_limit();
1288
1289 // Allocation in the extra data space has to be atomic because not
1290 // all entries have the same size and non atomic concurrent
1291 // allocation would result in a corrupted extra data space.
1292 while (true) {
1293 ProfileData* result = bci_to_extra_data_helper(bci, m, dp);
1294 if (result != NULL) {
1295 return result;
1296 }
1297
1298 if (create_if_missing && dp < end) {
1299 assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free");
1300 assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info");
1301 u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag;
1302 // SpeculativeTrapData is 2 slots. Make sure we have room.
1303 if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) {
1304 return NULL;
1305 }
1306 DataLayout temp;
1307 temp.initialize(tag, bci, 0);
1308 // May have been set concurrently
1309 if (dp->header() != temp.header() && !dp->atomic_set_header(temp.header())) {
1310 // Allocation failure because of concurrent allocation. Try
1311 // again.
1312 continue;
1313 }
1314 assert(dp->tag() == tag, "sane");
1315 assert(dp->bci() == bci, "no concurrent allocation");
1316 if (tag == DataLayout::bit_data_tag) {
1317 return new BitData(dp);
1318 } else {
1319 // If being allocated concurrently, one trap may be lost
1320 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1321 data->set_method(m);
1322 return data;
1323 }
1324 }
1325 return NULL;
1169 } 1326 }
1170 return NULL; 1327 return NULL;
1171 } 1328 }
1172 1329
1173 ArgInfoData *MethodData::arg_info() { 1330 ArgInfoData *MethodData::arg_info() {
1208 parameters_type_data()->print_data_on(st); 1365 parameters_type_data()->print_data_on(st);
1209 } 1366 }
1210 for ( ; is_valid(data); data = next_data(data)) { 1367 for ( ; is_valid(data); data = next_data(data)) {
1211 st->print("%d", dp_to_di(data->dp())); 1368 st->print("%d", dp_to_di(data->dp()));
1212 st->fill_to(6); 1369 st->fill_to(6);
1213 data->print_data_on(st); 1370 data->print_data_on(st, this);
1214 } 1371 }
1215 st->print_cr("--- Extra data:"); 1372 st->print_cr("--- Extra data:");
1216 DataLayout* dp = extra_data_base(); 1373 DataLayout* dp = extra_data_base();
1217 DataLayout* end = extra_data_limit(); 1374 DataLayout* end = extra_data_limit();
1218 for (; dp < end; dp = next_extra(dp)) { 1375 for (;; dp = next_extra(dp)) {
1376 assert(dp < end, "moved past end of extra data");
1219 // No need for "OrderAccess::load_acquire" ops, 1377 // No need for "OrderAccess::load_acquire" ops,
1220 // since the data structure is monotonic. 1378 // since the data structure is monotonic.
1221 if (dp->tag() == DataLayout::no_tag) continue; 1379 switch(dp->tag()) {
1222 if (dp->tag() == DataLayout::bit_data_tag) { 1380 case DataLayout::no_tag:
1381 continue;
1382 case DataLayout::bit_data_tag:
1223 data = new BitData(dp); 1383 data = new BitData(dp);
1224 } else { 1384 break;
1225 assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo"); 1385 case DataLayout::speculative_trap_data_tag:
1386 data = new SpeculativeTrapData(dp);
1387 break;
1388 case DataLayout::arg_info_data_tag:
1226 data = new ArgInfoData(dp); 1389 data = new ArgInfoData(dp);
1227 dp = end; // ArgInfoData is at the end of extra data section. 1390 dp = end; // ArgInfoData is at the end of extra data section.
1391 break;
1392 default:
1393 fatal(err_msg("unexpected tag %d", dp->tag()));
1228 } 1394 }
1229 st->print("%d", dp_to_di(data->dp())); 1395 st->print("%d", dp_to_di(data->dp()));
1230 st->fill_to(6); 1396 st->fill_to(6);
1231 data->print_data_on(st); 1397 data->print_data_on(st);
1398 if (dp >= end) return;
1232 } 1399 }
1233 } 1400 }
1234 #endif 1401 #endif
1235 1402
1236 #if INCLUDE_SERVICES 1403 #if INCLUDE_SERVICES
1349 } 1516 }
1350 1517
1351 assert(profile_parameters_jsr292_only(), "inconsistent"); 1518 assert(profile_parameters_jsr292_only(), "inconsistent");
1352 return m->is_compiled_lambda_form(); 1519 return m->is_compiled_lambda_form();
1353 } 1520 }
1521
1522 void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) {
1523 if (shift == 0) {
1524 return;
1525 }
1526 if (!reset) {
1527 // Move all cells of trap entry at dp left by "shift" cells
1528 intptr_t* start = (intptr_t*)dp;
1529 intptr_t* end = (intptr_t*)next_extra(dp);
1530 for (intptr_t* ptr = start; ptr < end; ptr++) {
1531 *(ptr-shift) = *ptr;
1532 }
1533 } else {
1534 // Reset "shift" cells stopping at dp
1535 intptr_t* start = ((intptr_t*)dp) - shift;
1536 intptr_t* end = (intptr_t*)dp;
1537 for (intptr_t* ptr = start; ptr < end; ptr++) {
1538 *ptr = 0;
1539 }
1540 }
1541 }
1542
1543 // Remove SpeculativeTrapData entries that reference an unloaded
1544 // method
1545 void MethodData::clean_extra_data(BoolObjectClosure* is_alive) {
1546 DataLayout* dp = extra_data_base();
1547 DataLayout* end = extra_data_limit();
1548
1549 int shift = 0;
1550 for (; dp < end; dp = next_extra(dp)) {
1551 switch(dp->tag()) {
1552 case DataLayout::speculative_trap_data_tag: {
1553 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1554 Method* m = data->method();
1555 assert(m != NULL, "should have a method");
1556 if (!m->method_holder()->is_loader_alive(is_alive)) {
1557 // "shift" accumulates the number of cells for dead
1558 // SpeculativeTrapData entries that have been seen so
1559 // far. Following entries must be shifted left by that many
1560 // cells to remove the dead SpeculativeTrapData entries.
1561 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp);
1562 } else {
1563 // Shift this entry left if it follows dead
1564 // SpeculativeTrapData entries
1565 clean_extra_data_helper(dp, shift);
1566 }
1567 break;
1568 }
1569 case DataLayout::bit_data_tag:
1570 // Shift this entry left if it follows dead SpeculativeTrapData
1571 // entries
1572 clean_extra_data_helper(dp, shift);
1573 continue;
1574 case DataLayout::no_tag:
1575 case DataLayout::arg_info_data_tag:
1576 // We are at end of the live trap entries. The previous "shift"
1577 // cells contain entries that are either dead or were shifted
1578 // left. They need to be reset to no_tag
1579 clean_extra_data_helper(dp, shift, true);
1580 return;
1581 default:
1582 fatal(err_msg("unexpected tag %d", dp->tag()));
1583 }
1584 }
1585 }
1586
1587 // Verify there's no unloaded method referenced by a
1588 // SpeculativeTrapData entry
1589 void MethodData::verify_extra_data_clean(BoolObjectClosure* is_alive) {
1590 #ifdef ASSERT
1591 DataLayout* dp = extra_data_base();
1592 DataLayout* end = extra_data_limit();
1593
1594 for (; dp < end; dp = next_extra(dp)) {
1595 switch(dp->tag()) {
1596 case DataLayout::speculative_trap_data_tag: {
1597 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
1598 Method* m = data->method();
1599 assert(m != NULL && m->method_holder()->is_loader_alive(is_alive), "Method should exist");
1600 break;
1601 }
1602 case DataLayout::bit_data_tag:
1603 continue;
1604 case DataLayout::no_tag:
1605 case DataLayout::arg_info_data_tag:
1606 return;
1607 default:
1608 fatal(err_msg("unexpected tag %d", dp->tag()));
1609 }
1610 }
1611 #endif
1612 }
1613
1614 void MethodData::clean_method_data(BoolObjectClosure* is_alive) {
1615 for (ProfileData* data = first_data();
1616 is_valid(data);
1617 data = next_data(data)) {
1618 data->clean_weak_klass_links(is_alive);
1619 }
1620 ParametersTypeData* parameters = parameters_type_data();
1621 if (parameters != NULL) {
1622 parameters->clean_weak_klass_links(is_alive);
1623 }
1624
1625 clean_extra_data(is_alive);
1626 verify_extra_data_clean(is_alive);
1627 }