Mercurial > hg > graal-compiler
comparison src/share/vm/oops/methodData.cpp @ 17728:b8413a9cbb84
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 | 6e1826d5c23e |
children | 1a43981d86ea |
comparison
equal
deleted
inserted
replaced
17727:cfd4aac53239 | 17728:b8413a9cbb84 |
---|---|
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 // ================================================================== |
454 return mdp; | 492 return mdp; |
455 } | 493 } |
456 | 494 |
457 | 495 |
458 #ifndef PRODUCT | 496 #ifndef PRODUCT |
459 void RetData::print_data_on(outputStream* st) const { | 497 void RetData::print_data_on(outputStream* st, const char* extra) const { |
460 print_shared(st, "RetData"); | 498 print_shared(st, "RetData", extra); |
461 uint row; | 499 uint row; |
462 int entries = 0; | 500 int entries = 0; |
463 for (row = 0; row < row_limit(); row++) { | 501 for (row = 0; row < row_limit(); row++) { |
464 if (bci(row) != no_bci) entries++; | 502 if (bci(row) != no_bci) entries++; |
465 } | 503 } |
489 int offset = target_di - my_di; | 527 int offset = target_di - my_di; |
490 set_displacement(offset); | 528 set_displacement(offset); |
491 } | 529 } |
492 | 530 |
493 #ifndef PRODUCT | 531 #ifndef PRODUCT |
494 void BranchData::print_data_on(outputStream* st) const { | 532 void BranchData::print_data_on(outputStream* st, const char* extra) const { |
495 print_shared(st, "BranchData"); | 533 print_shared(st, "BranchData", extra); |
496 st->print_cr("taken(%u) displacement(%d)", | 534 st->print_cr("taken(%u) displacement(%d)", |
497 taken(), displacement()); | 535 taken(), displacement()); |
498 tab(st); | 536 tab(st); |
499 st->print_cr("not taken(%u)", not_taken()); | 537 st->print_cr("not taken(%u)", not_taken()); |
500 } | 538 } |
563 set_default_displacement(offset); | 601 set_default_displacement(offset); |
564 } | 602 } |
565 } | 603 } |
566 | 604 |
567 #ifndef PRODUCT | 605 #ifndef PRODUCT |
568 void MultiBranchData::print_data_on(outputStream* st) const { | 606 void MultiBranchData::print_data_on(outputStream* st, const char* extra) const { |
569 print_shared(st, "MultiBranchData"); | 607 print_shared(st, "MultiBranchData", extra); |
570 st->print_cr("default_count(%u) displacement(%d)", | 608 st->print_cr("default_count(%u) displacement(%d)", |
571 default_count(), default_displacement()); | 609 default_count(), default_displacement()); |
572 int cases = number_of_cases(); | 610 int cases = number_of_cases(); |
573 for (int i = 0; i < cases; i++) { | 611 for (int i = 0; i < cases; i++) { |
574 tab(st); | 612 tab(st); |
577 } | 615 } |
578 } | 616 } |
579 #endif | 617 #endif |
580 | 618 |
581 #ifndef PRODUCT | 619 #ifndef PRODUCT |
582 void ArgInfoData::print_data_on(outputStream* st) const { | 620 void ArgInfoData::print_data_on(outputStream* st, const char* extra) const { |
583 print_shared(st, "ArgInfoData"); | 621 print_shared(st, "ArgInfoData", extra); |
584 int nargs = number_of_args(); | 622 int nargs = number_of_args(); |
585 for (int i = 0; i < nargs; i++) { | 623 for (int i = 0; i < nargs; i++) { |
586 st->print(" 0x%x", arg_modified(i)); | 624 st->print(" 0x%x", arg_modified(i)); |
587 } | 625 } |
588 st->cr(); | 626 st->cr(); |
609 bool ParametersTypeData::profiling_enabled() { | 647 bool ParametersTypeData::profiling_enabled() { |
610 return MethodData::profile_parameters(); | 648 return MethodData::profile_parameters(); |
611 } | 649 } |
612 | 650 |
613 #ifndef PRODUCT | 651 #ifndef PRODUCT |
614 void ParametersTypeData::print_data_on(outputStream* st) const { | 652 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const { |
615 st->print("parameter types"); | 653 st->print("parameter types", extra); |
616 _parameters.print_data_on(st); | 654 _parameters.print_data_on(st); |
655 } | |
656 | |
657 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const { | |
658 print_shared(st, "SpeculativeTrapData", extra); | |
659 tab(st); | |
660 method()->print_short_name(st); | |
661 st->cr(); | |
617 } | 662 } |
618 #endif | 663 #endif |
619 | 664 |
620 // ================================================================== | 665 // ================================================================== |
621 // MethodData* | 666 // MethodData* |
738 // a DataLayout header, with no extra cells. | 783 // a DataLayout header, with no extra cells. |
739 assert(cell_count >= 0, "sanity"); | 784 assert(cell_count >= 0, "sanity"); |
740 return DataLayout::compute_size_in_bytes(cell_count); | 785 return DataLayout::compute_size_in_bytes(cell_count); |
741 } | 786 } |
742 | 787 |
743 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) { | 788 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) { |
789 // Bytecodes for which we may use speculation | |
790 switch (code) { | |
791 case Bytecodes::_checkcast: | |
792 case Bytecodes::_instanceof: | |
793 case Bytecodes::_aastore: | |
794 case Bytecodes::_invokevirtual: | |
795 case Bytecodes::_invokeinterface: | |
796 case Bytecodes::_if_acmpeq: | |
797 case Bytecodes::_if_acmpne: | |
798 case Bytecodes::_invokestatic: | |
799 #ifdef COMPILER2 | |
800 return UseTypeSpeculation; | |
801 #endif | |
802 default: | |
803 return false; | |
804 } | |
805 return false; | |
806 } | |
807 | |
808 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { | |
744 if (ProfileTraps) { | 809 if (ProfileTraps) { |
745 // Assume that up to 3% of BCIs with no MDP will need to allocate one. | 810 // Assume that up to 3% of BCIs with no MDP will need to allocate one. |
746 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; | 811 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; |
747 // If the method is large, let the extra BCIs grow numerous (to ~1%). | 812 // If the method is large, let the extra BCIs grow numerous (to ~1%). |
748 int one_percent_of_data | 813 int one_percent_of_data |
749 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); | 814 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); |
750 if (extra_data_count < one_percent_of_data) | 815 if (extra_data_count < one_percent_of_data) |
751 extra_data_count = one_percent_of_data; | 816 extra_data_count = one_percent_of_data; |
752 if (extra_data_count > empty_bc_count) | 817 if (extra_data_count > empty_bc_count) |
753 extra_data_count = empty_bc_count; // no need for more | 818 extra_data_count = empty_bc_count; // no need for more |
754 return extra_data_count; | 819 |
820 // Make sure we have a minimum number of extra data slots to | |
821 // allocate SpeculativeTrapData entries. We would want to have one | |
822 // entry per compilation that inlines this method and for which | |
823 // some type speculation assumption fails. So the room we need for | |
824 // the SpeculativeTrapData entries doesn't directly depend on the | |
825 // size of the method. Because it's hard to estimate, we reserve | |
826 // space for an arbitrary number of entries. | |
827 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) * | |
828 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells()); | |
829 | |
830 return MAX2(extra_data_count, spec_data_count); | |
755 } else { | 831 } else { |
756 return 0; | 832 return 0; |
757 } | 833 } |
758 } | 834 } |
759 | 835 |
762 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { | 838 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { |
763 int data_size = 0; | 839 int data_size = 0; |
764 BytecodeStream stream(method); | 840 BytecodeStream stream(method); |
765 Bytecodes::Code c; | 841 Bytecodes::Code c; |
766 int empty_bc_count = 0; // number of bytecodes lacking data | 842 int empty_bc_count = 0; // number of bytecodes lacking data |
843 bool needs_speculative_traps = false; | |
767 while ((c = stream.next()) >= 0) { | 844 while ((c = stream.next()) >= 0) { |
768 int size_in_bytes = compute_data_size(&stream); | 845 int size_in_bytes = compute_data_size(&stream); |
769 data_size += size_in_bytes; | 846 data_size += size_in_bytes; |
770 if (size_in_bytes == 0) empty_bc_count += 1; | 847 if (size_in_bytes == 0) empty_bc_count += 1; |
848 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); | |
771 } | 849 } |
772 int object_size = in_bytes(data_offset()) + data_size; | 850 int object_size = in_bytes(data_offset()) + data_size; |
773 | 851 |
774 // Add some extra DataLayout cells (at least one) to track stray traps. | 852 // Add some extra DataLayout cells (at least one) to track stray traps. |
775 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); | 853 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); |
776 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); | 854 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); |
777 | 855 |
778 // Add a cell to record information about modified arguments. | 856 // Add a cell to record information about modified arguments. |
779 int arg_size = method->size_of_parameters(); | 857 int arg_size = method->size_of_parameters(); |
780 object_size += DataLayout::compute_size_in_bytes(arg_size+1); | 858 object_size += DataLayout::compute_size_in_bytes(arg_size+1); |
1002 int data_size = 0; | 1080 int data_size = 0; |
1003 int empty_bc_count = 0; // number of bytecodes lacking data | 1081 int empty_bc_count = 0; // number of bytecodes lacking data |
1004 _data[0] = 0; // apparently not set below. | 1082 _data[0] = 0; // apparently not set below. |
1005 BytecodeStream stream(method); | 1083 BytecodeStream stream(method); |
1006 Bytecodes::Code c; | 1084 Bytecodes::Code c; |
1085 bool needs_speculative_traps = false; | |
1007 while ((c = stream.next()) >= 0) { | 1086 while ((c = stream.next()) >= 0) { |
1008 int size_in_bytes = initialize_data(&stream, data_size); | 1087 int size_in_bytes = initialize_data(&stream, data_size); |
1009 data_size += size_in_bytes; | 1088 data_size += size_in_bytes; |
1010 if (size_in_bytes == 0) empty_bc_count += 1; | 1089 if (size_in_bytes == 0) empty_bc_count += 1; |
1090 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); | |
1011 } | 1091 } |
1012 _data_size = data_size; | 1092 _data_size = data_size; |
1013 int object_size = in_bytes(data_offset()) + data_size; | 1093 int object_size = in_bytes(data_offset()) + data_size; |
1014 | 1094 |
1015 // Add some extra DataLayout cells (at least one) to track stray traps. | 1095 // Add some extra DataLayout cells (at least one) to track stray traps. |
1016 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); | 1096 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); |
1017 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); | 1097 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); |
1098 | |
1099 // Let's zero the space for the extra data | |
1100 Copy::zero_to_bytes(((address)_data) + data_size, extra_size); | |
1018 | 1101 |
1019 // Add a cell to record information about modified arguments. | 1102 // Add a cell to record information about modified arguments. |
1020 // Set up _args_modified array after traps cells so that | 1103 // Set up _args_modified array after traps cells so that |
1021 // the code for traps cells works. | 1104 // the code for traps cells works. |
1022 DataLayout *dp = data_layout_at(data_size + extra_size); | 1105 DataLayout *dp = data_layout_at(data_size + extra_size); |
1025 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); | 1108 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); |
1026 | 1109 |
1027 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); | 1110 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); |
1028 object_size += extra_size + arg_data_size; | 1111 object_size += extra_size + arg_data_size; |
1029 | 1112 |
1030 int args_cell = ParametersTypeData::compute_cell_count(method()); | 1113 int parms_cell = ParametersTypeData::compute_cell_count(method()); |
1031 // If we are profiling parameters, we reserver an area near the end | 1114 // If we are profiling parameters, we reserver an area near the end |
1032 // of the MDO after the slots for bytecodes (because there's no bci | 1115 // of the MDO after the slots for bytecodes (because there's no bci |
1033 // for method entry so they don't fit with the framework for the | 1116 // for method entry so they don't fit with the framework for the |
1034 // profiling of bytecodes). We store the offset within the MDO of | 1117 // profiling of bytecodes). We store the offset within the MDO of |
1035 // this area (or -1 if no parameter is profiled) | 1118 // this area (or -1 if no parameter is profiled) |
1036 if (args_cell > 0) { | 1119 if (parms_cell > 0) { |
1037 object_size += DataLayout::compute_size_in_bytes(args_cell); | 1120 object_size += DataLayout::compute_size_in_bytes(parms_cell); |
1038 _parameters_type_data_di = data_size + extra_size + arg_data_size; | 1121 _parameters_type_data_di = data_size + extra_size + arg_data_size; |
1039 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); | 1122 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); |
1040 dp->initialize(DataLayout::parameters_type_data_tag, 0, args_cell); | 1123 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell); |
1041 } else { | 1124 } else { |
1042 _parameters_type_data_di = -1; | 1125 _parameters_type_data_di = -1; |
1043 } | 1126 } |
1044 | 1127 |
1045 // Set an initial hint. Don't use set_hint_di() because | 1128 // Set an initial hint. Don't use set_hint_di() because |
1126 return data; | 1209 return data; |
1127 } else if (data->bci() > bci) { | 1210 } else if (data->bci() > bci) { |
1128 break; | 1211 break; |
1129 } | 1212 } |
1130 } | 1213 } |
1131 return bci_to_extra_data(bci, false); | 1214 return bci_to_extra_data(bci, NULL, false); |
1132 } | 1215 } |
1133 | 1216 |
1134 // Translate a bci to its corresponding extra data, or NULL. | 1217 DataLayout* MethodData::next_extra(DataLayout* dp) { |
1135 ProfileData* MethodData::bci_to_extra_data(int bci, bool create_if_missing) { | 1218 int nb_cells = 0; |
1136 DataLayout* dp = extra_data_base(); | 1219 switch(dp->tag()) { |
1137 DataLayout* end = extra_data_limit(); | 1220 case DataLayout::bit_data_tag: |
1138 DataLayout* avail = NULL; | 1221 case DataLayout::no_tag: |
1139 for (; dp < end; dp = next_extra(dp)) { | 1222 nb_cells = BitData::static_cell_count(); |
1223 break; | |
1224 case DataLayout::speculative_trap_data_tag: | |
1225 nb_cells = SpeculativeTrapData::static_cell_count(); | |
1226 break; | |
1227 default: | |
1228 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1229 } | |
1230 return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells)); | |
1231 } | |
1232 | |
1233 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp) { | |
1234 DataLayout* end = extra_data_limit(); | |
1235 | |
1236 for (;; dp = next_extra(dp)) { | |
1237 assert(dp < end, "moved past end of extra data"); | |
1140 // No need for "OrderAccess::load_acquire" ops, | 1238 // No need for "OrderAccess::load_acquire" ops, |
1141 // since the data structure is monotonic. | 1239 // since the data structure is monotonic. |
1142 if (dp->tag() == DataLayout::no_tag) break; | 1240 switch(dp->tag()) { |
1143 if (dp->tag() == DataLayout::arg_info_data_tag) { | 1241 case DataLayout::no_tag: |
1144 dp = end; // ArgInfoData is at the end of extra data section. | 1242 return NULL; |
1243 case DataLayout::arg_info_data_tag: | |
1244 dp = end; | |
1245 return NULL; // ArgInfoData is at the end of extra data section. | |
1246 case DataLayout::bit_data_tag: | |
1247 if (m == NULL && dp->bci() == bci) { | |
1248 return new BitData(dp); | |
1249 } | |
1145 break; | 1250 break; |
1146 } | 1251 case DataLayout::speculative_trap_data_tag: |
1147 if (dp->bci() == bci) { | 1252 if (m != NULL) { |
1148 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); | 1253 SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
1149 return new BitData(dp); | 1254 // data->method() may be null in case of a concurrent |
1150 } | 1255 // allocation. Assume it's for the same method and use that |
1151 } | 1256 // entry in that case. |
1152 if (create_if_missing && dp < end) { | 1257 if (dp->bci() == bci) { |
1153 // Allocate this one. There is no mutual exclusion, | 1258 if (data->method() == NULL) { |
1154 // so two threads could allocate different BCIs to the | 1259 return NULL; |
1155 // same data layout. This means these extra data | 1260 } else if (data->method() == m) { |
1156 // records, like most other MDO contents, must not be | 1261 return data; |
1157 // trusted too much. | 1262 } |
1158 DataLayout temp; | 1263 } |
1159 temp.initialize(DataLayout::bit_data_tag, bci, 0); | 1264 } |
1160 dp->release_set_header(temp.header()); | 1265 break; |
1161 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); | 1266 default: |
1162 //NO: assert(dp->bci() == bci, "no concurrent allocation"); | 1267 fatal(err_msg("unexpected tag %d", dp->tag())); |
1163 return new BitData(dp); | 1268 } |
1269 } | |
1270 return NULL; | |
1271 } | |
1272 | |
1273 | |
1274 // Translate a bci to its corresponding extra data, or NULL. | |
1275 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) { | |
1276 // This code assumes an entry for a SpeculativeTrapData is 2 cells | |
1277 assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) == | |
1278 DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()), | |
1279 "code needs to be adjusted"); | |
1280 | |
1281 DataLayout* dp = extra_data_base(); | |
1282 DataLayout* end = extra_data_limit(); | |
1283 | |
1284 // Allocation in the extra data space has to be atomic because not | |
1285 // all entries have the same size and non atomic concurrent | |
1286 // allocation would result in a corrupted extra data space. | |
1287 while (true) { | |
1288 ProfileData* result = bci_to_extra_data_helper(bci, m, dp); | |
1289 if (result != NULL) { | |
1290 return result; | |
1291 } | |
1292 | |
1293 if (create_if_missing && dp < end) { | |
1294 assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free"); | |
1295 assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info"); | |
1296 u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag; | |
1297 // SpeculativeTrapData is 2 slots. Make sure we have room. | |
1298 if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) { | |
1299 return NULL; | |
1300 } | |
1301 DataLayout temp; | |
1302 temp.initialize(tag, bci, 0); | |
1303 // May have been set concurrently | |
1304 if (dp->header() != temp.header() && !dp->atomic_set_header(temp.header())) { | |
1305 // Allocation failure because of concurrent allocation. Try | |
1306 // again. | |
1307 continue; | |
1308 } | |
1309 assert(dp->tag() == tag, "sane"); | |
1310 assert(dp->bci() == bci, "no concurrent allocation"); | |
1311 if (tag == DataLayout::bit_data_tag) { | |
1312 return new BitData(dp); | |
1313 } else { | |
1314 // If being allocated concurrently, one trap may be lost | |
1315 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
1316 data->set_method(m); | |
1317 return data; | |
1318 } | |
1319 } | |
1320 return NULL; | |
1164 } | 1321 } |
1165 return NULL; | 1322 return NULL; |
1166 } | 1323 } |
1167 | 1324 |
1168 ArgInfoData *MethodData::arg_info() { | 1325 ArgInfoData *MethodData::arg_info() { |
1203 parameters_type_data()->print_data_on(st); | 1360 parameters_type_data()->print_data_on(st); |
1204 } | 1361 } |
1205 for ( ; is_valid(data); data = next_data(data)) { | 1362 for ( ; is_valid(data); data = next_data(data)) { |
1206 st->print("%d", dp_to_di(data->dp())); | 1363 st->print("%d", dp_to_di(data->dp())); |
1207 st->fill_to(6); | 1364 st->fill_to(6); |
1208 data->print_data_on(st); | 1365 data->print_data_on(st, this); |
1209 } | 1366 } |
1210 st->print_cr("--- Extra data:"); | 1367 st->print_cr("--- Extra data:"); |
1211 DataLayout* dp = extra_data_base(); | 1368 DataLayout* dp = extra_data_base(); |
1212 DataLayout* end = extra_data_limit(); | 1369 DataLayout* end = extra_data_limit(); |
1213 for (; dp < end; dp = next_extra(dp)) { | 1370 for (;; dp = next_extra(dp)) { |
1371 assert(dp < end, "moved past end of extra data"); | |
1214 // No need for "OrderAccess::load_acquire" ops, | 1372 // No need for "OrderAccess::load_acquire" ops, |
1215 // since the data structure is monotonic. | 1373 // since the data structure is monotonic. |
1216 if (dp->tag() == DataLayout::no_tag) continue; | 1374 switch(dp->tag()) { |
1217 if (dp->tag() == DataLayout::bit_data_tag) { | 1375 case DataLayout::no_tag: |
1376 continue; | |
1377 case DataLayout::bit_data_tag: | |
1218 data = new BitData(dp); | 1378 data = new BitData(dp); |
1219 } else { | 1379 break; |
1220 assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo"); | 1380 case DataLayout::speculative_trap_data_tag: |
1381 data = new SpeculativeTrapData(dp); | |
1382 break; | |
1383 case DataLayout::arg_info_data_tag: | |
1221 data = new ArgInfoData(dp); | 1384 data = new ArgInfoData(dp); |
1222 dp = end; // ArgInfoData is at the end of extra data section. | 1385 dp = end; // ArgInfoData is at the end of extra data section. |
1386 break; | |
1387 default: | |
1388 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1223 } | 1389 } |
1224 st->print("%d", dp_to_di(data->dp())); | 1390 st->print("%d", dp_to_di(data->dp())); |
1225 st->fill_to(6); | 1391 st->fill_to(6); |
1226 data->print_data_on(st); | 1392 data->print_data_on(st); |
1393 if (dp >= end) return; | |
1227 } | 1394 } |
1228 } | 1395 } |
1229 #endif | 1396 #endif |
1230 | 1397 |
1231 #if INCLUDE_SERVICES | 1398 #if INCLUDE_SERVICES |
1344 } | 1511 } |
1345 | 1512 |
1346 assert(profile_parameters_jsr292_only(), "inconsistent"); | 1513 assert(profile_parameters_jsr292_only(), "inconsistent"); |
1347 return m->is_compiled_lambda_form(); | 1514 return m->is_compiled_lambda_form(); |
1348 } | 1515 } |
1516 | |
1517 void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) { | |
1518 if (shift == 0) { | |
1519 return; | |
1520 } | |
1521 if (!reset) { | |
1522 // Move all cells of trap entry at dp left by "shift" cells | |
1523 intptr_t* start = (intptr_t*)dp; | |
1524 intptr_t* end = (intptr_t*)next_extra(dp); | |
1525 for (intptr_t* ptr = start; ptr < end; ptr++) { | |
1526 *(ptr-shift) = *ptr; | |
1527 } | |
1528 } else { | |
1529 // Reset "shift" cells stopping at dp | |
1530 intptr_t* start = ((intptr_t*)dp) - shift; | |
1531 intptr_t* end = (intptr_t*)dp; | |
1532 for (intptr_t* ptr = start; ptr < end; ptr++) { | |
1533 *ptr = 0; | |
1534 } | |
1535 } | |
1536 } | |
1537 | |
1538 // Remove SpeculativeTrapData entries that reference an unloaded | |
1539 // method | |
1540 void MethodData::clean_extra_data(BoolObjectClosure* is_alive) { | |
1541 DataLayout* dp = extra_data_base(); | |
1542 DataLayout* end = extra_data_limit(); | |
1543 | |
1544 int shift = 0; | |
1545 for (; dp < end; dp = next_extra(dp)) { | |
1546 switch(dp->tag()) { | |
1547 case DataLayout::speculative_trap_data_tag: { | |
1548 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
1549 Method* m = data->method(); | |
1550 assert(m != NULL, "should have a method"); | |
1551 if (!m->method_holder()->is_loader_alive(is_alive)) { | |
1552 // "shift" accumulates the number of cells for dead | |
1553 // SpeculativeTrapData entries that have been seen so | |
1554 // far. Following entries must be shifted left by that many | |
1555 // cells to remove the dead SpeculativeTrapData entries. | |
1556 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp); | |
1557 } else { | |
1558 // Shift this entry left if it follows dead | |
1559 // SpeculativeTrapData entries | |
1560 clean_extra_data_helper(dp, shift); | |
1561 } | |
1562 break; | |
1563 } | |
1564 case DataLayout::bit_data_tag: | |
1565 // Shift this entry left if it follows dead SpeculativeTrapData | |
1566 // entries | |
1567 clean_extra_data_helper(dp, shift); | |
1568 continue; | |
1569 case DataLayout::no_tag: | |
1570 case DataLayout::arg_info_data_tag: | |
1571 // We are at end of the live trap entries. The previous "shift" | |
1572 // cells contain entries that are either dead or were shifted | |
1573 // left. They need to be reset to no_tag | |
1574 clean_extra_data_helper(dp, shift, true); | |
1575 return; | |
1576 default: | |
1577 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1578 } | |
1579 } | |
1580 } | |
1581 | |
1582 // Verify there's no unloaded method referenced by a | |
1583 // SpeculativeTrapData entry | |
1584 void MethodData::verify_extra_data_clean(BoolObjectClosure* is_alive) { | |
1585 #ifdef ASSERT | |
1586 DataLayout* dp = extra_data_base(); | |
1587 DataLayout* end = extra_data_limit(); | |
1588 | |
1589 for (; dp < end; dp = next_extra(dp)) { | |
1590 switch(dp->tag()) { | |
1591 case DataLayout::speculative_trap_data_tag: { | |
1592 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
1593 Method* m = data->method(); | |
1594 assert(m != NULL && m->method_holder()->is_loader_alive(is_alive), "Method should exist"); | |
1595 break; | |
1596 } | |
1597 case DataLayout::bit_data_tag: | |
1598 continue; | |
1599 case DataLayout::no_tag: | |
1600 case DataLayout::arg_info_data_tag: | |
1601 return; | |
1602 default: | |
1603 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1604 } | |
1605 } | |
1606 #endif | |
1607 } | |
1608 | |
1609 void MethodData::clean_method_data(BoolObjectClosure* is_alive) { | |
1610 for (ProfileData* data = first_data(); | |
1611 is_valid(data); | |
1612 data = next_data(data)) { | |
1613 data->clean_weak_klass_links(is_alive); | |
1614 } | |
1615 ParametersTypeData* parameters = parameters_type_data(); | |
1616 if (parameters != NULL) { | |
1617 parameters->clean_weak_klass_links(is_alive); | |
1618 } | |
1619 | |
1620 clean_extra_data(is_alive); | |
1621 verify_extra_data_clean(is_alive); | |
1622 } |