Mercurial > hg > graal-compiler
comparison src/share/vm/oops/methodData.cpp @ 17810:62c54fcc0a35
Merge
author | kvn |
---|---|
date | Tue, 25 Mar 2014 17:07:36 -0700 |
parents | da862781b584 606acabe7b5c |
children | 78bbf4d43a14 |
comparison
equal
deleted
inserted
replaced
17809:a433eb716ce1 | 17810:62c54fcc0a35 |
---|---|
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 #include "classfile/systemDictionary.hpp" | 26 #include "classfile/systemDictionary.hpp" |
27 #include "compiler/compilerOracle.hpp" | |
27 #include "interpreter/bytecode.hpp" | 28 #include "interpreter/bytecode.hpp" |
28 #include "interpreter/bytecodeStream.hpp" | 29 #include "interpreter/bytecodeStream.hpp" |
29 #include "interpreter/linkResolver.hpp" | 30 #include "interpreter/linkResolver.hpp" |
30 #include "memory/heapInspection.hpp" | 31 #include "memory/heapInspection.hpp" |
31 #include "oops/methodData.hpp" | 32 #include "oops/methodData.hpp" |
78 // Constructor for invalid ProfileData. | 79 // Constructor for invalid ProfileData. |
79 ProfileData::ProfileData() { | 80 ProfileData::ProfileData() { |
80 _data = NULL; | 81 _data = NULL; |
81 } | 82 } |
82 | 83 |
84 char* ProfileData::print_data_on_helper(const MethodData* md) const { | |
85 DataLayout* dp = md->extra_data_base(); | |
86 DataLayout* end = md->extra_data_limit(); | |
87 stringStream ss; | |
88 for (;; dp = MethodData::next_extra(dp)) { | |
89 assert(dp < end, "moved past end of extra data"); | |
90 switch(dp->tag()) { | |
91 case DataLayout::speculative_trap_data_tag: | |
92 if (dp->bci() == bci()) { | |
93 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
94 int trap = data->trap_state(); | |
95 char buf[100]; | |
96 ss.print("trap/"); | |
97 data->method()->print_short_name(&ss); | |
98 ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); | |
99 } | |
100 break; | |
101 case DataLayout::bit_data_tag: | |
102 break; | |
103 case DataLayout::no_tag: | |
104 case DataLayout::arg_info_data_tag: | |
105 return ss.as_string(); | |
106 break; | |
107 default: | |
108 fatal(err_msg("unexpected tag %d", dp->tag())); | |
109 } | |
110 } | |
111 return NULL; | |
112 } | |
113 | |
114 void ProfileData::print_data_on(outputStream* st, const MethodData* md) const { | |
115 print_data_on(st, print_data_on_helper(md)); | |
116 } | |
117 | |
83 #ifndef PRODUCT | 118 #ifndef PRODUCT |
84 void ProfileData::print_shared(outputStream* st, const char* name) const { | 119 void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const { |
85 st->print("bci: %d", bci()); | 120 st->print("bci: %d", bci()); |
86 st->fill_to(tab_width_one); | 121 st->fill_to(tab_width_one); |
87 st->print("%s", name); | 122 st->print("%s", name); |
88 tab(st); | 123 tab(st); |
89 int trap = trap_state(); | 124 int trap = trap_state(); |
90 if (trap != 0) { | 125 if (trap != 0) { |
91 char buf[100]; | 126 char buf[100]; |
92 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); | 127 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap)); |
93 } | 128 } |
129 if (extra != NULL) { | |
130 st->print(extra); | |
131 } | |
94 int flags = data()->flags(); | 132 int flags = data()->flags(); |
95 if (flags != 0) | 133 if (flags != 0) { |
96 st->print("flags(%d) ", flags); | 134 st->print("flags(%d) ", flags); |
135 } | |
97 } | 136 } |
98 | 137 |
99 void ProfileData::tab(outputStream* st, bool first) const { | 138 void ProfileData::tab(outputStream* st, bool first) const { |
100 st->fill_to(first ? tab_width_one : tab_width_two); | 139 st->fill_to(first ? tab_width_one : tab_width_two); |
101 } | 140 } |
107 // A BitData corresponds to a one-bit flag. This is used to indicate | 146 // A BitData corresponds to a one-bit flag. This is used to indicate |
108 // whether a checkcast bytecode has seen a null value. | 147 // whether a checkcast bytecode has seen a null value. |
109 | 148 |
110 | 149 |
111 #ifndef PRODUCT | 150 #ifndef PRODUCT |
112 void BitData::print_data_on(outputStream* st) const { | 151 void BitData::print_data_on(outputStream* st, const char* extra) const { |
113 print_shared(st, "BitData"); | 152 print_shared(st, "BitData", extra); |
114 } | 153 } |
115 #endif // !PRODUCT | 154 #endif // !PRODUCT |
116 | 155 |
117 // ================================================================== | 156 // ================================================================== |
118 // CounterData | 157 // CounterData |
119 // | 158 // |
120 // A CounterData corresponds to a simple counter. | 159 // A CounterData corresponds to a simple counter. |
121 | 160 |
122 #ifndef PRODUCT | 161 #ifndef PRODUCT |
123 void CounterData::print_data_on(outputStream* st) const { | 162 void CounterData::print_data_on(outputStream* st, const char* extra) const { |
124 print_shared(st, "CounterData"); | 163 print_shared(st, "CounterData", extra); |
125 st->print_cr("count(%u)", count()); | 164 st->print_cr("count(%u)", count()); |
126 } | 165 } |
127 #endif // !PRODUCT | 166 #endif // !PRODUCT |
128 | 167 |
129 // ================================================================== | 168 // ================================================================== |
148 int offset = target_di - my_di; | 187 int offset = target_di - my_di; |
149 set_displacement(offset); | 188 set_displacement(offset); |
150 } | 189 } |
151 | 190 |
152 #ifndef PRODUCT | 191 #ifndef PRODUCT |
153 void JumpData::print_data_on(outputStream* st) const { | 192 void JumpData::print_data_on(outputStream* st, const char* extra) const { |
154 print_shared(st, "JumpData"); | 193 print_shared(st, "JumpData", extra); |
155 st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); | 194 st->print_cr("taken(%u) displacement(%d)", taken(), displacement()); |
156 } | 195 } |
157 #endif // !PRODUCT | 196 #endif // !PRODUCT |
158 | 197 |
159 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) { | 198 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) { |
330 _pd->tab(st); | 369 _pd->tab(st); |
331 print_klass(st, type()); | 370 print_klass(st, type()); |
332 st->cr(); | 371 st->cr(); |
333 } | 372 } |
334 | 373 |
335 void CallTypeData::print_data_on(outputStream* st) const { | 374 void CallTypeData::print_data_on(outputStream* st, const char* extra) const { |
336 CounterData::print_data_on(st); | 375 CounterData::print_data_on(st, extra); |
337 if (has_arguments()) { | 376 if (has_arguments()) { |
338 tab(st, true); | 377 tab(st, true); |
339 st->print("argument types"); | 378 st->print("argument types"); |
340 _args.print_data_on(st); | 379 _args.print_data_on(st); |
341 } | 380 } |
344 st->print("return type"); | 383 st->print("return type"); |
345 _ret.print_data_on(st); | 384 _ret.print_data_on(st); |
346 } | 385 } |
347 } | 386 } |
348 | 387 |
349 void VirtualCallTypeData::print_data_on(outputStream* st) const { | 388 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const { |
350 VirtualCallData::print_data_on(st); | 389 VirtualCallData::print_data_on(st, extra); |
351 if (has_arguments()) { | 390 if (has_arguments()) { |
352 tab(st, true); | 391 tab(st, true); |
353 st->print("argument types"); | 392 st->print("argument types"); |
354 _args.print_data_on(st); | 393 _args.print_data_on(st); |
355 } | 394 } |
398 receiver(row)->print_value_on(st); | 437 receiver(row)->print_value_on(st); |
399 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); | 438 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); |
400 } | 439 } |
401 } | 440 } |
402 } | 441 } |
403 void ReceiverTypeData::print_data_on(outputStream* st) const { | 442 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const { |
404 print_shared(st, "ReceiverTypeData"); | 443 print_shared(st, "ReceiverTypeData", extra); |
405 print_receiver_data_on(st); | 444 print_receiver_data_on(st); |
406 } | 445 } |
407 void VirtualCallData::print_data_on(outputStream* st) const { | 446 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const { |
408 print_shared(st, "VirtualCallData"); | 447 print_shared(st, "VirtualCallData", extra); |
409 print_receiver_data_on(st); | 448 print_receiver_data_on(st); |
410 } | 449 } |
411 #endif // !PRODUCT | 450 #endif // !PRODUCT |
412 | 451 |
413 // ================================================================== | 452 // ================================================================== |
459 return (DataLayout*) md->bci_to_dp(bci); | 498 return (DataLayout*) md->bci_to_dp(bci); |
460 } | 499 } |
461 #endif // CC_INTERP | 500 #endif // CC_INTERP |
462 | 501 |
463 #ifndef PRODUCT | 502 #ifndef PRODUCT |
464 void RetData::print_data_on(outputStream* st) const { | 503 void RetData::print_data_on(outputStream* st, const char* extra) const { |
465 print_shared(st, "RetData"); | 504 print_shared(st, "RetData", extra); |
466 uint row; | 505 uint row; |
467 int entries = 0; | 506 int entries = 0; |
468 for (row = 0; row < row_limit(); row++) { | 507 for (row = 0; row < row_limit(); row++) { |
469 if (bci(row) != no_bci) entries++; | 508 if (bci(row) != no_bci) entries++; |
470 } | 509 } |
494 int offset = target_di - my_di; | 533 int offset = target_di - my_di; |
495 set_displacement(offset); | 534 set_displacement(offset); |
496 } | 535 } |
497 | 536 |
498 #ifndef PRODUCT | 537 #ifndef PRODUCT |
499 void BranchData::print_data_on(outputStream* st) const { | 538 void BranchData::print_data_on(outputStream* st, const char* extra) const { |
500 print_shared(st, "BranchData"); | 539 print_shared(st, "BranchData", extra); |
501 st->print_cr("taken(%u) displacement(%d)", | 540 st->print_cr("taken(%u) displacement(%d)", |
502 taken(), displacement()); | 541 taken(), displacement()); |
503 tab(st); | 542 tab(st); |
504 st->print_cr("not taken(%u)", not_taken()); | 543 st->print_cr("not taken(%u)", not_taken()); |
505 } | 544 } |
568 set_default_displacement(offset); | 607 set_default_displacement(offset); |
569 } | 608 } |
570 } | 609 } |
571 | 610 |
572 #ifndef PRODUCT | 611 #ifndef PRODUCT |
573 void MultiBranchData::print_data_on(outputStream* st) const { | 612 void MultiBranchData::print_data_on(outputStream* st, const char* extra) const { |
574 print_shared(st, "MultiBranchData"); | 613 print_shared(st, "MultiBranchData", extra); |
575 st->print_cr("default_count(%u) displacement(%d)", | 614 st->print_cr("default_count(%u) displacement(%d)", |
576 default_count(), default_displacement()); | 615 default_count(), default_displacement()); |
577 int cases = number_of_cases(); | 616 int cases = number_of_cases(); |
578 for (int i = 0; i < cases; i++) { | 617 for (int i = 0; i < cases; i++) { |
579 tab(st); | 618 tab(st); |
582 } | 621 } |
583 } | 622 } |
584 #endif | 623 #endif |
585 | 624 |
586 #ifndef PRODUCT | 625 #ifndef PRODUCT |
587 void ArgInfoData::print_data_on(outputStream* st) const { | 626 void ArgInfoData::print_data_on(outputStream* st, const char* extra) const { |
588 print_shared(st, "ArgInfoData"); | 627 print_shared(st, "ArgInfoData", extra); |
589 int nargs = number_of_args(); | 628 int nargs = number_of_args(); |
590 for (int i = 0; i < nargs; i++) { | 629 for (int i = 0; i < nargs; i++) { |
591 st->print(" 0x%x", arg_modified(i)); | 630 st->print(" 0x%x", arg_modified(i)); |
592 } | 631 } |
593 st->cr(); | 632 st->cr(); |
614 bool ParametersTypeData::profiling_enabled() { | 653 bool ParametersTypeData::profiling_enabled() { |
615 return MethodData::profile_parameters(); | 654 return MethodData::profile_parameters(); |
616 } | 655 } |
617 | 656 |
618 #ifndef PRODUCT | 657 #ifndef PRODUCT |
619 void ParametersTypeData::print_data_on(outputStream* st) const { | 658 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const { |
620 st->print("parameter types"); | 659 st->print("parameter types", extra); |
621 _parameters.print_data_on(st); | 660 _parameters.print_data_on(st); |
661 } | |
662 | |
663 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const { | |
664 print_shared(st, "SpeculativeTrapData", extra); | |
665 tab(st); | |
666 method()->print_short_name(st); | |
667 st->cr(); | |
622 } | 668 } |
623 #endif | 669 #endif |
624 | 670 |
625 // ================================================================== | 671 // ================================================================== |
626 // MethodData* | 672 // MethodData* |
743 // a DataLayout header, with no extra cells. | 789 // a DataLayout header, with no extra cells. |
744 assert(cell_count >= 0, "sanity"); | 790 assert(cell_count >= 0, "sanity"); |
745 return DataLayout::compute_size_in_bytes(cell_count); | 791 return DataLayout::compute_size_in_bytes(cell_count); |
746 } | 792 } |
747 | 793 |
748 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) { | 794 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) { |
795 // Bytecodes for which we may use speculation | |
796 switch (code) { | |
797 case Bytecodes::_checkcast: | |
798 case Bytecodes::_instanceof: | |
799 case Bytecodes::_aastore: | |
800 case Bytecodes::_invokevirtual: | |
801 case Bytecodes::_invokeinterface: | |
802 case Bytecodes::_if_acmpeq: | |
803 case Bytecodes::_if_acmpne: | |
804 case Bytecodes::_invokestatic: | |
805 #ifdef COMPILER2 | |
806 return UseTypeSpeculation; | |
807 #endif | |
808 default: | |
809 return false; | |
810 } | |
811 return false; | |
812 } | |
813 | |
814 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { | |
749 if (ProfileTraps) { | 815 if (ProfileTraps) { |
750 // Assume that up to 3% of BCIs with no MDP will need to allocate one. | 816 // 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; | 817 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%). | 818 // If the method is large, let the extra BCIs grow numerous (to ~1%). |
753 int one_percent_of_data | 819 int one_percent_of_data |
754 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); | 820 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); |
755 if (extra_data_count < one_percent_of_data) | 821 if (extra_data_count < one_percent_of_data) |
756 extra_data_count = one_percent_of_data; | 822 extra_data_count = one_percent_of_data; |
757 if (extra_data_count > empty_bc_count) | 823 if (extra_data_count > empty_bc_count) |
758 extra_data_count = empty_bc_count; // no need for more | 824 extra_data_count = empty_bc_count; // no need for more |
759 return extra_data_count; | 825 |
826 // Make sure we have a minimum number of extra data slots to | |
827 // allocate SpeculativeTrapData entries. We would want to have one | |
828 // entry per compilation that inlines this method and for which | |
829 // some type speculation assumption fails. So the room we need for | |
830 // the SpeculativeTrapData entries doesn't directly depend on the | |
831 // size of the method. Because it's hard to estimate, we reserve | |
832 // space for an arbitrary number of entries. | |
833 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) * | |
834 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells()); | |
835 | |
836 return MAX2(extra_data_count, spec_data_count); | |
760 } else { | 837 } else { |
761 return 0; | 838 return 0; |
762 } | 839 } |
763 } | 840 } |
764 | 841 |
767 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { | 844 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { |
768 int data_size = 0; | 845 int data_size = 0; |
769 BytecodeStream stream(method); | 846 BytecodeStream stream(method); |
770 Bytecodes::Code c; | 847 Bytecodes::Code c; |
771 int empty_bc_count = 0; // number of bytecodes lacking data | 848 int empty_bc_count = 0; // number of bytecodes lacking data |
849 bool needs_speculative_traps = false; | |
772 while ((c = stream.next()) >= 0) { | 850 while ((c = stream.next()) >= 0) { |
773 int size_in_bytes = compute_data_size(&stream); | 851 int size_in_bytes = compute_data_size(&stream); |
774 data_size += size_in_bytes; | 852 data_size += size_in_bytes; |
775 if (size_in_bytes == 0) empty_bc_count += 1; | 853 if (size_in_bytes == 0) empty_bc_count += 1; |
854 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); | |
776 } | 855 } |
777 int object_size = in_bytes(data_offset()) + data_size; | 856 int object_size = in_bytes(data_offset()) + data_size; |
778 | 857 |
779 // Add some extra DataLayout cells (at least one) to track stray traps. | 858 // 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); | 859 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); | 860 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); |
782 | 861 |
783 // Add a cell to record information about modified arguments. | 862 // Add a cell to record information about modified arguments. |
784 int arg_size = method->size_of_parameters(); | 863 int arg_size = method->size_of_parameters(); |
785 object_size += DataLayout::compute_size_in_bytes(arg_size+1); | 864 object_size += DataLayout::compute_size_in_bytes(arg_size+1); |
991 parameters_type_data()->post_initialize(NULL, this); | 1070 parameters_type_data()->post_initialize(NULL, this); |
992 } | 1071 } |
993 } | 1072 } |
994 | 1073 |
995 // Initialize the MethodData* corresponding to a given method. | 1074 // Initialize the MethodData* corresponding to a given method. |
996 MethodData::MethodData(methodHandle method, int size, TRAPS) { | 1075 MethodData::MethodData(methodHandle method, int size, TRAPS) |
1076 : _extra_data_lock(Monitor::leaf, "MDO extra data lock") { | |
997 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC | 1077 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC |
998 ResourceMark rm; | 1078 ResourceMark rm; |
999 // Set the method back-pointer. | 1079 // Set the method back-pointer. |
1000 _method = method(); | 1080 _method = method(); |
1001 | 1081 |
1007 int data_size = 0; | 1087 int data_size = 0; |
1008 int empty_bc_count = 0; // number of bytecodes lacking data | 1088 int empty_bc_count = 0; // number of bytecodes lacking data |
1009 _data[0] = 0; // apparently not set below. | 1089 _data[0] = 0; // apparently not set below. |
1010 BytecodeStream stream(method); | 1090 BytecodeStream stream(method); |
1011 Bytecodes::Code c; | 1091 Bytecodes::Code c; |
1092 bool needs_speculative_traps = false; | |
1012 while ((c = stream.next()) >= 0) { | 1093 while ((c = stream.next()) >= 0) { |
1013 int size_in_bytes = initialize_data(&stream, data_size); | 1094 int size_in_bytes = initialize_data(&stream, data_size); |
1014 data_size += size_in_bytes; | 1095 data_size += size_in_bytes; |
1015 if (size_in_bytes == 0) empty_bc_count += 1; | 1096 if (size_in_bytes == 0) empty_bc_count += 1; |
1097 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); | |
1016 } | 1098 } |
1017 _data_size = data_size; | 1099 _data_size = data_size; |
1018 int object_size = in_bytes(data_offset()) + data_size; | 1100 int object_size = in_bytes(data_offset()) + data_size; |
1019 | 1101 |
1020 // Add some extra DataLayout cells (at least one) to track stray traps. | 1102 // 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); | 1103 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); | 1104 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); |
1105 | |
1106 // Let's zero the space for the extra data | |
1107 Copy::zero_to_bytes(((address)_data) + data_size, extra_size); | |
1023 | 1108 |
1024 // Add a cell to record information about modified arguments. | 1109 // Add a cell to record information about modified arguments. |
1025 // Set up _args_modified array after traps cells so that | 1110 // Set up _args_modified array after traps cells so that |
1026 // the code for traps cells works. | 1111 // the code for traps cells works. |
1027 DataLayout *dp = data_layout_at(data_size + extra_size); | 1112 DataLayout *dp = data_layout_at(data_size + extra_size); |
1030 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); | 1115 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); |
1031 | 1116 |
1032 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); | 1117 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); |
1033 object_size += extra_size + arg_data_size; | 1118 object_size += extra_size + arg_data_size; |
1034 | 1119 |
1035 int args_cell = ParametersTypeData::compute_cell_count(method()); | 1120 int parms_cell = ParametersTypeData::compute_cell_count(method()); |
1036 // If we are profiling parameters, we reserver an area near the end | 1121 // 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 | 1122 // 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 | 1123 // 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 | 1124 // profiling of bytecodes). We store the offset within the MDO of |
1040 // this area (or -1 if no parameter is profiled) | 1125 // this area (or -1 if no parameter is profiled) |
1041 if (args_cell > 0) { | 1126 if (parms_cell > 0) { |
1042 object_size += DataLayout::compute_size_in_bytes(args_cell); | 1127 object_size += DataLayout::compute_size_in_bytes(parms_cell); |
1043 _parameters_type_data_di = data_size + extra_size + arg_data_size; | 1128 _parameters_type_data_di = data_size + extra_size + arg_data_size; |
1044 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); | 1129 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); |
1045 dp->initialize(DataLayout::parameters_type_data_tag, 0, args_cell); | 1130 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell); |
1046 } else { | 1131 } else { |
1047 _parameters_type_data_di = -1; | 1132 _parameters_type_data_di = -1; |
1048 } | 1133 } |
1049 | 1134 |
1050 // Set an initial hint. Don't use set_hint_di() because | 1135 // Set an initial hint. Don't use set_hint_di() because |
1066 _num_loops = 0; | 1151 _num_loops = 0; |
1067 _num_blocks = 0; | 1152 _num_blocks = 0; |
1068 _highest_comp_level = 0; | 1153 _highest_comp_level = 0; |
1069 _highest_osr_comp_level = 0; | 1154 _highest_osr_comp_level = 0; |
1070 _would_profile = true; | 1155 _would_profile = true; |
1156 | |
1157 #if INCLUDE_RTM_OPT | |
1158 _rtm_state = NoRTM; // No RTM lock eliding by default | |
1159 if (UseRTMLocking && | |
1160 !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) { | |
1161 if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) { | |
1162 // Generate RTM lock eliding code without abort ratio calculation code. | |
1163 _rtm_state = UseRTM; | |
1164 } else if (UseRTMDeopt) { | |
1165 // Generate RTM lock eliding code and include abort ratio calculation | |
1166 // code if UseRTMDeopt is on. | |
1167 _rtm_state = ProfileRTM; | |
1168 } | |
1169 } | |
1170 #endif | |
1071 | 1171 |
1072 // Initialize flags and trap history. | 1172 // Initialize flags and trap history. |
1073 _nof_decompiles = 0; | 1173 _nof_decompiles = 0; |
1074 _nof_overflow_recompiles = 0; | 1174 _nof_overflow_recompiles = 0; |
1075 _nof_overflow_traps = 0; | 1175 _nof_overflow_traps = 0; |
1131 return data; | 1231 return data; |
1132 } else if (data->bci() > bci) { | 1232 } else if (data->bci() > bci) { |
1133 break; | 1233 break; |
1134 } | 1234 } |
1135 } | 1235 } |
1136 return bci_to_extra_data(bci, false); | 1236 return bci_to_extra_data(bci, NULL, false); |
1137 } | 1237 } |
1138 | 1238 |
1139 // Translate a bci to its corresponding extra data, or NULL. | 1239 DataLayout* MethodData::next_extra(DataLayout* dp) { |
1140 ProfileData* MethodData::bci_to_extra_data(int bci, bool create_if_missing) { | 1240 int nb_cells = 0; |
1141 DataLayout* dp = extra_data_base(); | 1241 switch(dp->tag()) { |
1142 DataLayout* end = extra_data_limit(); | 1242 case DataLayout::bit_data_tag: |
1143 DataLayout* avail = NULL; | 1243 case DataLayout::no_tag: |
1144 for (; dp < end; dp = next_extra(dp)) { | 1244 nb_cells = BitData::static_cell_count(); |
1245 break; | |
1246 case DataLayout::speculative_trap_data_tag: | |
1247 nb_cells = SpeculativeTrapData::static_cell_count(); | |
1248 break; | |
1249 default: | |
1250 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1251 } | |
1252 return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells)); | |
1253 } | |
1254 | |
1255 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) { | |
1256 DataLayout* end = extra_data_limit(); | |
1257 | |
1258 for (;; dp = next_extra(dp)) { | |
1259 assert(dp < end, "moved past end of extra data"); | |
1145 // No need for "OrderAccess::load_acquire" ops, | 1260 // No need for "OrderAccess::load_acquire" ops, |
1146 // since the data structure is monotonic. | 1261 // since the data structure is monotonic. |
1147 if (dp->tag() == DataLayout::no_tag) break; | 1262 switch(dp->tag()) { |
1148 if (dp->tag() == DataLayout::arg_info_data_tag) { | 1263 case DataLayout::no_tag: |
1149 dp = end; // ArgInfoData is at the end of extra data section. | 1264 return NULL; |
1265 case DataLayout::arg_info_data_tag: | |
1266 dp = end; | |
1267 return NULL; // ArgInfoData is at the end of extra data section. | |
1268 case DataLayout::bit_data_tag: | |
1269 if (m == NULL && dp->bci() == bci) { | |
1270 return new BitData(dp); | |
1271 } | |
1150 break; | 1272 break; |
1151 } | 1273 case DataLayout::speculative_trap_data_tag: |
1152 if (dp->bci() == bci) { | 1274 if (m != NULL) { |
1153 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); | 1275 SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
1276 // data->method() may be null in case of a concurrent | |
1277 // allocation. Maybe it's for the same method. Try to use that | |
1278 // entry in that case. | |
1279 if (dp->bci() == bci) { | |
1280 if (data->method() == NULL) { | |
1281 assert(concurrent, "impossible because no concurrent allocation"); | |
1282 return NULL; | |
1283 } else if (data->method() == m) { | |
1284 return data; | |
1285 } | |
1286 } | |
1287 } | |
1288 break; | |
1289 default: | |
1290 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1291 } | |
1292 } | |
1293 return NULL; | |
1294 } | |
1295 | |
1296 | |
1297 // Translate a bci to its corresponding extra data, or NULL. | |
1298 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) { | |
1299 // This code assumes an entry for a SpeculativeTrapData is 2 cells | |
1300 assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) == | |
1301 DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()), | |
1302 "code needs to be adjusted"); | |
1303 | |
1304 DataLayout* dp = extra_data_base(); | |
1305 DataLayout* end = extra_data_limit(); | |
1306 | |
1307 // Allocation in the extra data space has to be atomic because not | |
1308 // all entries have the same size and non atomic concurrent | |
1309 // allocation would result in a corrupted extra data space. | |
1310 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true); | |
1311 if (result != NULL) { | |
1312 return result; | |
1313 } | |
1314 | |
1315 if (create_if_missing && dp < end) { | |
1316 MutexLocker ml(&_extra_data_lock); | |
1317 // Check again now that we have the lock. Another thread may | |
1318 // have added extra data entries. | |
1319 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false); | |
1320 if (result != NULL || dp >= end) { | |
1321 return result; | |
1322 } | |
1323 | |
1324 assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free"); | |
1325 assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info"); | |
1326 u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag; | |
1327 // SpeculativeTrapData is 2 slots. Make sure we have room. | |
1328 if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) { | |
1329 return NULL; | |
1330 } | |
1331 DataLayout temp; | |
1332 temp.initialize(tag, bci, 0); | |
1333 | |
1334 dp->set_header(temp.header()); | |
1335 assert(dp->tag() == tag, "sane"); | |
1336 assert(dp->bci() == bci, "no concurrent allocation"); | |
1337 if (tag == DataLayout::bit_data_tag) { | |
1154 return new BitData(dp); | 1338 return new BitData(dp); |
1155 } | 1339 } else { |
1156 } | 1340 SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
1157 if (create_if_missing && dp < end) { | 1341 data->set_method(m); |
1158 // Allocate this one. There is no mutual exclusion, | 1342 return data; |
1159 // so two threads could allocate different BCIs to the | 1343 } |
1160 // same data layout. This means these extra data | |
1161 // records, like most other MDO contents, must not be | |
1162 // trusted too much. | |
1163 DataLayout temp; | |
1164 temp.initialize(DataLayout::bit_data_tag, bci, 0); | |
1165 dp->release_set_header(temp.header()); | |
1166 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); | |
1167 //NO: assert(dp->bci() == bci, "no concurrent allocation"); | |
1168 return new BitData(dp); | |
1169 } | 1344 } |
1170 return NULL; | 1345 return NULL; |
1171 } | 1346 } |
1172 | 1347 |
1173 ArgInfoData *MethodData::arg_info() { | 1348 ArgInfoData *MethodData::arg_info() { |
1208 parameters_type_data()->print_data_on(st); | 1383 parameters_type_data()->print_data_on(st); |
1209 } | 1384 } |
1210 for ( ; is_valid(data); data = next_data(data)) { | 1385 for ( ; is_valid(data); data = next_data(data)) { |
1211 st->print("%d", dp_to_di(data->dp())); | 1386 st->print("%d", dp_to_di(data->dp())); |
1212 st->fill_to(6); | 1387 st->fill_to(6); |
1213 data->print_data_on(st); | 1388 data->print_data_on(st, this); |
1214 } | 1389 } |
1215 st->print_cr("--- Extra data:"); | 1390 st->print_cr("--- Extra data:"); |
1216 DataLayout* dp = extra_data_base(); | 1391 DataLayout* dp = extra_data_base(); |
1217 DataLayout* end = extra_data_limit(); | 1392 DataLayout* end = extra_data_limit(); |
1218 for (; dp < end; dp = next_extra(dp)) { | 1393 for (;; dp = next_extra(dp)) { |
1394 assert(dp < end, "moved past end of extra data"); | |
1219 // No need for "OrderAccess::load_acquire" ops, | 1395 // No need for "OrderAccess::load_acquire" ops, |
1220 // since the data structure is monotonic. | 1396 // since the data structure is monotonic. |
1221 if (dp->tag() == DataLayout::no_tag) continue; | 1397 switch(dp->tag()) { |
1222 if (dp->tag() == DataLayout::bit_data_tag) { | 1398 case DataLayout::no_tag: |
1399 continue; | |
1400 case DataLayout::bit_data_tag: | |
1223 data = new BitData(dp); | 1401 data = new BitData(dp); |
1224 } else { | 1402 break; |
1225 assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo"); | 1403 case DataLayout::speculative_trap_data_tag: |
1404 data = new SpeculativeTrapData(dp); | |
1405 break; | |
1406 case DataLayout::arg_info_data_tag: | |
1226 data = new ArgInfoData(dp); | 1407 data = new ArgInfoData(dp); |
1227 dp = end; // ArgInfoData is at the end of extra data section. | 1408 dp = end; // ArgInfoData is at the end of extra data section. |
1409 break; | |
1410 default: | |
1411 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1228 } | 1412 } |
1229 st->print("%d", dp_to_di(data->dp())); | 1413 st->print("%d", dp_to_di(data->dp())); |
1230 st->fill_to(6); | 1414 st->fill_to(6); |
1231 data->print_data_on(st); | 1415 data->print_data_on(st); |
1416 if (dp >= end) return; | |
1232 } | 1417 } |
1233 } | 1418 } |
1234 #endif | 1419 #endif |
1235 | 1420 |
1236 #if INCLUDE_SERVICES | 1421 #if INCLUDE_SERVICES |
1349 } | 1534 } |
1350 | 1535 |
1351 assert(profile_parameters_jsr292_only(), "inconsistent"); | 1536 assert(profile_parameters_jsr292_only(), "inconsistent"); |
1352 return m->is_compiled_lambda_form(); | 1537 return m->is_compiled_lambda_form(); |
1353 } | 1538 } |
1539 | |
1540 void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) { | |
1541 if (shift == 0) { | |
1542 return; | |
1543 } | |
1544 if (!reset) { | |
1545 // Move all cells of trap entry at dp left by "shift" cells | |
1546 intptr_t* start = (intptr_t*)dp; | |
1547 intptr_t* end = (intptr_t*)next_extra(dp); | |
1548 for (intptr_t* ptr = start; ptr < end; ptr++) { | |
1549 *(ptr-shift) = *ptr; | |
1550 } | |
1551 } else { | |
1552 // Reset "shift" cells stopping at dp | |
1553 intptr_t* start = ((intptr_t*)dp) - shift; | |
1554 intptr_t* end = (intptr_t*)dp; | |
1555 for (intptr_t* ptr = start; ptr < end; ptr++) { | |
1556 *ptr = 0; | |
1557 } | |
1558 } | |
1559 } | |
1560 | |
1561 // Remove SpeculativeTrapData entries that reference an unloaded | |
1562 // method | |
1563 void MethodData::clean_extra_data(BoolObjectClosure* is_alive) { | |
1564 DataLayout* dp = extra_data_base(); | |
1565 DataLayout* end = extra_data_limit(); | |
1566 | |
1567 int shift = 0; | |
1568 for (; dp < end; dp = next_extra(dp)) { | |
1569 switch(dp->tag()) { | |
1570 case DataLayout::speculative_trap_data_tag: { | |
1571 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
1572 Method* m = data->method(); | |
1573 assert(m != NULL, "should have a method"); | |
1574 if (!m->method_holder()->is_loader_alive(is_alive)) { | |
1575 // "shift" accumulates the number of cells for dead | |
1576 // SpeculativeTrapData entries that have been seen so | |
1577 // far. Following entries must be shifted left by that many | |
1578 // cells to remove the dead SpeculativeTrapData entries. | |
1579 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp); | |
1580 } else { | |
1581 // Shift this entry left if it follows dead | |
1582 // SpeculativeTrapData entries | |
1583 clean_extra_data_helper(dp, shift); | |
1584 } | |
1585 break; | |
1586 } | |
1587 case DataLayout::bit_data_tag: | |
1588 // Shift this entry left if it follows dead SpeculativeTrapData | |
1589 // entries | |
1590 clean_extra_data_helper(dp, shift); | |
1591 continue; | |
1592 case DataLayout::no_tag: | |
1593 case DataLayout::arg_info_data_tag: | |
1594 // We are at end of the live trap entries. The previous "shift" | |
1595 // cells contain entries that are either dead or were shifted | |
1596 // left. They need to be reset to no_tag | |
1597 clean_extra_data_helper(dp, shift, true); | |
1598 return; | |
1599 default: | |
1600 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1601 } | |
1602 } | |
1603 } | |
1604 | |
1605 // Verify there's no unloaded method referenced by a | |
1606 // SpeculativeTrapData entry | |
1607 void MethodData::verify_extra_data_clean(BoolObjectClosure* is_alive) { | |
1608 #ifdef ASSERT | |
1609 DataLayout* dp = extra_data_base(); | |
1610 DataLayout* end = extra_data_limit(); | |
1611 | |
1612 for (; dp < end; dp = next_extra(dp)) { | |
1613 switch(dp->tag()) { | |
1614 case DataLayout::speculative_trap_data_tag: { | |
1615 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
1616 Method* m = data->method(); | |
1617 assert(m != NULL && m->method_holder()->is_loader_alive(is_alive), "Method should exist"); | |
1618 break; | |
1619 } | |
1620 case DataLayout::bit_data_tag: | |
1621 continue; | |
1622 case DataLayout::no_tag: | |
1623 case DataLayout::arg_info_data_tag: | |
1624 return; | |
1625 default: | |
1626 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1627 } | |
1628 } | |
1629 #endif | |
1630 } | |
1631 | |
1632 void MethodData::clean_method_data(BoolObjectClosure* is_alive) { | |
1633 for (ProfileData* data = first_data(); | |
1634 is_valid(data); | |
1635 data = next_data(data)) { | |
1636 data->clean_weak_klass_links(is_alive); | |
1637 } | |
1638 ParametersTypeData* parameters = parameters_type_data(); | |
1639 if (parameters != NULL) { | |
1640 parameters->clean_weak_klass_links(is_alive); | |
1641 } | |
1642 | |
1643 clean_extra_data(is_alive); | |
1644 verify_extra_data_clean(is_alive); | |
1645 } |