Mercurial > hg > truffle
comparison src/share/vm/oops/methodData.cpp @ 14521:29ccc4cbabca
Merge
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Wed, 12 Mar 2014 13:30:08 +0100 |
parents | d8041d695d19 |
children | 12eaf1a47a90 |
comparison
equal
deleted
inserted
replaced
14520:f84115370178 | 14521:29ccc4cbabca |
---|---|
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 } |
414 receiver(row)->print_value_on(st); | 452 receiver(row)->print_value_on(st); |
415 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); | 453 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total); |
416 } | 454 } |
417 } | 455 } |
418 } | 456 } |
419 void ReceiverTypeData::print_data_on(outputStream* st) const { | 457 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const { |
420 print_shared(st, "ReceiverTypeData"); | 458 print_shared(st, "ReceiverTypeData", extra); |
421 print_receiver_data_on(st); | 459 print_receiver_data_on(st); |
422 } | 460 } |
423 | 461 |
424 #ifdef GRAAL | 462 #ifdef GRAAL |
425 void VirtualCallData::print_method_data_on(outputStream* st) const { | 463 void VirtualCallData::print_method_data_on(outputStream* st) const { |
444 } | 482 } |
445 } | 483 } |
446 } | 484 } |
447 #endif | 485 #endif |
448 | 486 |
449 void VirtualCallData::print_data_on(outputStream* st) const { | 487 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const { |
450 print_shared(st, "VirtualCallData"); | 488 print_shared(st, "VirtualCallData", extra); |
451 print_receiver_data_on(st); | 489 print_receiver_data_on(st); |
452 #ifdef GRAAL | 490 #ifdef GRAAL |
453 print_method_data_on(st); | 491 print_method_data_on(st); |
454 #endif | 492 #endif |
455 } | 493 } |
497 } | 535 } |
498 } | 536 } |
499 return mdp; | 537 return mdp; |
500 } | 538 } |
501 | 539 |
540 #ifdef CC_INTERP | |
541 DataLayout* RetData::advance(MethodData *md, int bci) { | |
542 return (DataLayout*) md->bci_to_dp(bci); | |
543 } | |
544 #endif // CC_INTERP | |
502 | 545 |
503 #ifndef PRODUCT | 546 #ifndef PRODUCT |
504 void RetData::print_data_on(outputStream* st) const { | 547 void RetData::print_data_on(outputStream* st, const char* extra) const { |
505 print_shared(st, "RetData"); | 548 print_shared(st, "RetData", extra); |
506 uint row; | 549 uint row; |
507 int entries = 0; | 550 int entries = 0; |
508 for (row = 0; row < row_limit(); row++) { | 551 for (row = 0; row < row_limit(); row++) { |
509 if (bci(row) != no_bci) entries++; | 552 if (bci(row) != no_bci) entries++; |
510 } | 553 } |
534 int offset = target_di - my_di; | 577 int offset = target_di - my_di; |
535 set_displacement(offset); | 578 set_displacement(offset); |
536 } | 579 } |
537 | 580 |
538 #ifndef PRODUCT | 581 #ifndef PRODUCT |
539 void BranchData::print_data_on(outputStream* st) const { | 582 void BranchData::print_data_on(outputStream* st, const char* extra) const { |
540 print_shared(st, "BranchData"); | 583 print_shared(st, "BranchData", extra); |
541 st->print_cr("taken(%u) displacement(%d)", | 584 st->print_cr("taken(%u) displacement(%d)", |
542 taken(), displacement()); | 585 taken(), displacement()); |
543 tab(st); | 586 tab(st); |
544 st->print_cr("not taken(%u)", not_taken()); | 587 st->print_cr("not taken(%u)", not_taken()); |
545 } | 588 } |
608 set_default_displacement(offset); | 651 set_default_displacement(offset); |
609 } | 652 } |
610 } | 653 } |
611 | 654 |
612 #ifndef PRODUCT | 655 #ifndef PRODUCT |
613 void MultiBranchData::print_data_on(outputStream* st) const { | 656 void MultiBranchData::print_data_on(outputStream* st, const char* extra) const { |
614 print_shared(st, "MultiBranchData"); | 657 print_shared(st, "MultiBranchData", extra); |
615 st->print_cr("default_count(%u) displacement(%d)", | 658 st->print_cr("default_count(%u) displacement(%d)", |
616 default_count(), default_displacement()); | 659 default_count(), default_displacement()); |
617 int cases = number_of_cases(); | 660 int cases = number_of_cases(); |
618 for (int i = 0; i < cases; i++) { | 661 for (int i = 0; i < cases; i++) { |
619 tab(st); | 662 tab(st); |
622 } | 665 } |
623 } | 666 } |
624 #endif | 667 #endif |
625 | 668 |
626 #ifndef PRODUCT | 669 #ifndef PRODUCT |
627 void ArgInfoData::print_data_on(outputStream* st) const { | 670 void ArgInfoData::print_data_on(outputStream* st, const char* extra) const { |
628 print_shared(st, "ArgInfoData"); | 671 print_shared(st, "ArgInfoData", extra); |
629 int nargs = number_of_args(); | 672 int nargs = number_of_args(); |
630 for (int i = 0; i < nargs; i++) { | 673 for (int i = 0; i < nargs; i++) { |
631 st->print(" 0x%x", arg_modified(i)); | 674 st->print(" 0x%x", arg_modified(i)); |
632 } | 675 } |
633 st->cr(); | 676 st->cr(); |
654 bool ParametersTypeData::profiling_enabled() { | 697 bool ParametersTypeData::profiling_enabled() { |
655 return MethodData::profile_parameters(); | 698 return MethodData::profile_parameters(); |
656 } | 699 } |
657 | 700 |
658 #ifndef PRODUCT | 701 #ifndef PRODUCT |
659 void ParametersTypeData::print_data_on(outputStream* st) const { | 702 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const { |
660 st->print("parameter types"); | 703 st->print("parameter types", extra); |
661 _parameters.print_data_on(st); | 704 _parameters.print_data_on(st); |
705 } | |
706 | |
707 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const { | |
708 print_shared(st, "SpeculativeTrapData", extra); | |
709 tab(st); | |
710 method()->print_short_name(st); | |
711 st->cr(); | |
662 } | 712 } |
663 #endif | 713 #endif |
664 | 714 |
665 // ================================================================== | 715 // ================================================================== |
666 // MethodData* | 716 // MethodData* |
783 // a DataLayout header, with no extra cells. | 833 // a DataLayout header, with no extra cells. |
784 assert(cell_count >= 0, "sanity"); | 834 assert(cell_count >= 0, "sanity"); |
785 return DataLayout::compute_size_in_bytes(cell_count); | 835 return DataLayout::compute_size_in_bytes(cell_count); |
786 } | 836 } |
787 | 837 |
838 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) { | |
839 // Bytecodes for which we may use speculation | |
840 switch (code) { | |
841 case Bytecodes::_checkcast: | |
842 case Bytecodes::_instanceof: | |
843 case Bytecodes::_aastore: | |
844 case Bytecodes::_invokevirtual: | |
845 case Bytecodes::_invokeinterface: | |
846 case Bytecodes::_if_acmpeq: | |
847 case Bytecodes::_if_acmpne: | |
848 case Bytecodes::_invokestatic: | |
849 #ifdef COMPILER2 | |
850 return UseTypeSpeculation; | |
851 #endif | |
852 default: | |
853 return false; | |
854 } | |
855 return false; | |
856 } | |
857 | |
788 #ifdef GRAAL | 858 #ifdef GRAAL |
789 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) { | 859 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { |
790 if (!ProfileTraps) return 0; | 860 if (!ProfileTraps) return 0; |
791 | 861 |
792 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one. | 862 // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one. |
793 return MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100)); | 863 return MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100)); |
794 } | 864 } |
795 #else | 865 #else |
796 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) { | 866 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) { |
797 if (ProfileTraps) { | 867 if (ProfileTraps) { |
798 // Assume that up to 3% of BCIs with no MDP will need to allocate one. | 868 // Assume that up to 3% of BCIs with no MDP will need to allocate one. |
799 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; | 869 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1; |
800 // If the method is large, let the extra BCIs grow numerous (to ~1%). | 870 // If the method is large, let the extra BCIs grow numerous (to ~1%). |
801 int one_percent_of_data | 871 int one_percent_of_data |
802 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); | 872 = (uint)data_size / (DataLayout::header_size_in_bytes()*128); |
803 if (extra_data_count < one_percent_of_data) | 873 if (extra_data_count < one_percent_of_data) |
804 extra_data_count = one_percent_of_data; | 874 extra_data_count = one_percent_of_data; |
805 if (extra_data_count > empty_bc_count) | 875 if (extra_data_count > empty_bc_count) |
806 extra_data_count = empty_bc_count; // no need for more | 876 extra_data_count = empty_bc_count; // no need for more |
807 return extra_data_count; | 877 |
878 // Make sure we have a minimum number of extra data slots to | |
879 // allocate SpeculativeTrapData entries. We would want to have one | |
880 // entry per compilation that inlines this method and for which | |
881 // some type speculation assumption fails. So the room we need for | |
882 // the SpeculativeTrapData entries doesn't directly depend on the | |
883 // size of the method. Because it's hard to estimate, we reserve | |
884 // space for an arbitrary number of entries. | |
885 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) * | |
886 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells()); | |
887 | |
888 return MAX2(extra_data_count, spec_data_count); | |
808 } else { | 889 } else { |
809 return 0; | 890 return 0; |
810 } | 891 } |
811 } | 892 } |
812 #endif | 893 #endif |
816 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { | 897 int MethodData::compute_allocation_size_in_bytes(methodHandle method) { |
817 int data_size = 0; | 898 int data_size = 0; |
818 BytecodeStream stream(method); | 899 BytecodeStream stream(method); |
819 Bytecodes::Code c; | 900 Bytecodes::Code c; |
820 int empty_bc_count = 0; // number of bytecodes lacking data | 901 int empty_bc_count = 0; // number of bytecodes lacking data |
902 bool needs_speculative_traps = false; | |
821 while ((c = stream.next()) >= 0) { | 903 while ((c = stream.next()) >= 0) { |
822 int size_in_bytes = compute_data_size(&stream); | 904 int size_in_bytes = compute_data_size(&stream); |
823 data_size += size_in_bytes; | 905 data_size += size_in_bytes; |
824 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; | 906 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; |
907 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); | |
825 } | 908 } |
826 int object_size = in_bytes(data_offset()) + data_size; | 909 int object_size = in_bytes(data_offset()) + data_size; |
827 | 910 |
828 // Add some extra DataLayout cells (at least one) to track stray traps. | 911 // Add some extra DataLayout cells (at least one) to track stray traps. |
829 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); | 912 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); |
830 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); | 913 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0); |
831 | 914 |
832 // Add a cell to record information about modified arguments. | 915 // Add a cell to record information about modified arguments. |
833 int arg_size = method->size_of_parameters(); | 916 int arg_size = method->size_of_parameters(); |
834 object_size += DataLayout::compute_size_in_bytes(arg_size+1); | 917 object_size += DataLayout::compute_size_in_bytes(arg_size+1); |
1060 int data_size = 0; | 1143 int data_size = 0; |
1061 int empty_bc_count = 0; // number of bytecodes lacking data | 1144 int empty_bc_count = 0; // number of bytecodes lacking data |
1062 _data[0] = 0; // apparently not set below. | 1145 _data[0] = 0; // apparently not set below. |
1063 BytecodeStream stream(method()); | 1146 BytecodeStream stream(method()); |
1064 Bytecodes::Code c; | 1147 Bytecodes::Code c; |
1148 bool needs_speculative_traps = false; | |
1065 while ((c = stream.next()) >= 0) { | 1149 while ((c = stream.next()) >= 0) { |
1066 int size_in_bytes = initialize_data(&stream, data_size); | 1150 int size_in_bytes = initialize_data(&stream, data_size); |
1067 data_size += size_in_bytes; | 1151 data_size += size_in_bytes; |
1068 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; | 1152 if (size_in_bytes == 0 GRAAL_ONLY(&& Bytecodes::can_trap(c))) empty_bc_count += 1; |
1153 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c); | |
1069 } | 1154 } |
1070 _data_size = data_size; | 1155 _data_size = data_size; |
1071 int object_size = in_bytes(data_offset()) + data_size; | 1156 int object_size = in_bytes(data_offset()) + data_size; |
1072 | 1157 |
1073 // Add some extra DataLayout cells (at least one) to track stray traps. | 1158 // Add some extra DataLayout cells (at least one) to track stray traps. |
1074 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count); | 1159 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps); |
1075 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); | 1160 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0); |
1076 | 1161 |
1077 #ifdef GRAAL | 1162 //#ifdef GRAAL |
1078 if (for_reprofile) { | 1163 // if (for_reprofile) { |
1079 // Clear out extra data | 1164 // // Clear out extra data |
1080 Copy::zero_to_bytes((HeapWord*) extra_data_base(), extra_size); | 1165 // Copy::zero_to_bytes((HeapWord*) extra_data_base(), extra_size); |
1081 } | 1166 // } |
1082 #endif | 1167 //#endif |
1168 // Let's zero the space for the extra data | |
1169 Copy::zero_to_bytes(((address)_data) + data_size, extra_size); | |
1083 | 1170 |
1084 // Add a cell to record information about modified arguments. | 1171 // Add a cell to record information about modified arguments. |
1085 // Set up _args_modified array after traps cells so that | 1172 // Set up _args_modified array after traps cells so that |
1086 // the code for traps cells works. | 1173 // the code for traps cells works. |
1087 DataLayout *dp = data_layout_at(data_size + extra_size); | 1174 DataLayout *dp = data_layout_at(data_size + extra_size); |
1090 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); | 1177 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1); |
1091 | 1178 |
1092 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); | 1179 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1); |
1093 object_size += extra_size + arg_data_size; | 1180 object_size += extra_size + arg_data_size; |
1094 | 1181 |
1095 int args_cell = ParametersTypeData::compute_cell_count(method()); | 1182 int parms_cell = ParametersTypeData::compute_cell_count(method()); |
1096 // If we are profiling parameters, we reserver an area near the end | 1183 // If we are profiling parameters, we reserver an area near the end |
1097 // of the MDO after the slots for bytecodes (because there's no bci | 1184 // of the MDO after the slots for bytecodes (because there's no bci |
1098 // for method entry so they don't fit with the framework for the | 1185 // for method entry so they don't fit with the framework for the |
1099 // profiling of bytecodes). We store the offset within the MDO of | 1186 // profiling of bytecodes). We store the offset within the MDO of |
1100 // this area (or -1 if no parameter is profiled) | 1187 // this area (or -1 if no parameter is profiled) |
1101 if (args_cell > 0) { | 1188 if (parms_cell > 0) { |
1102 object_size += DataLayout::compute_size_in_bytes(args_cell); | 1189 object_size += DataLayout::compute_size_in_bytes(parms_cell); |
1103 _parameters_type_data_di = data_size + extra_size + arg_data_size; | 1190 _parameters_type_data_di = data_size + extra_size + arg_data_size; |
1104 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); | 1191 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size); |
1105 dp->initialize(DataLayout::parameters_type_data_tag, 0, args_cell); | 1192 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell); |
1106 } else { | 1193 } else { |
1107 _parameters_type_data_di = -1; | 1194 _parameters_type_data_di = -1; |
1108 } | 1195 } |
1109 | 1196 |
1110 // Set an initial hint. Don't use set_hint_di() because | 1197 // Set an initial hint. Don't use set_hint_di() because |
1192 return data; | 1279 return data; |
1193 } else if (data->bci() > bci) { | 1280 } else if (data->bci() > bci) { |
1194 break; | 1281 break; |
1195 } | 1282 } |
1196 } | 1283 } |
1197 return bci_to_extra_data(bci, false); | 1284 return bci_to_extra_data(bci, NULL, false); |
1198 } | 1285 } |
1199 | 1286 |
1200 // Translate a bci to its corresponding extra data, or NULL. | 1287 DataLayout* MethodData::next_extra(DataLayout* dp) { |
1201 ProfileData* MethodData::bci_to_extra_data(int bci, bool create_if_missing) { | 1288 int nb_cells = 0; |
1202 DataLayout* dp = extra_data_base(); | 1289 switch(dp->tag()) { |
1203 DataLayout* end = extra_data_limit(); | 1290 case DataLayout::bit_data_tag: |
1204 DataLayout* avail = NULL; | 1291 case DataLayout::no_tag: |
1205 for (; dp < end; dp = next_extra(dp)) { | 1292 nb_cells = BitData::static_cell_count(); |
1293 break; | |
1294 case DataLayout::speculative_trap_data_tag: | |
1295 nb_cells = SpeculativeTrapData::static_cell_count(); | |
1296 break; | |
1297 default: | |
1298 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1299 } | |
1300 return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells)); | |
1301 } | |
1302 | |
1303 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp) { | |
1304 DataLayout* end = extra_data_limit(); | |
1305 | |
1306 for (;; dp = next_extra(dp)) { | |
1307 assert(dp < end, "moved past end of extra data"); | |
1206 // No need for "OrderAccess::load_acquire" ops, | 1308 // No need for "OrderAccess::load_acquire" ops, |
1207 // since the data structure is monotonic. | 1309 // since the data structure is monotonic. |
1208 if (dp->tag() == DataLayout::no_tag) break; | 1310 switch(dp->tag()) { |
1209 if (dp->tag() == DataLayout::arg_info_data_tag) { | 1311 case DataLayout::no_tag: |
1210 dp = end; // ArgInfoData is at the end of extra data section. | 1312 return NULL; |
1313 case DataLayout::arg_info_data_tag: | |
1314 dp = end; | |
1315 return NULL; // ArgInfoData is at the end of extra data section. | |
1316 case DataLayout::bit_data_tag: | |
1317 if (m == NULL && dp->bci() == bci) { | |
1318 return new BitData(dp); | |
1319 } | |
1211 break; | 1320 break; |
1212 } | 1321 case DataLayout::speculative_trap_data_tag: |
1213 if (dp->bci() == bci) { | 1322 if (m != NULL) { |
1214 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); | 1323 SpeculativeTrapData* data = new SpeculativeTrapData(dp); |
1215 return new BitData(dp); | 1324 // data->method() may be null in case of a concurrent |
1216 } | 1325 // allocation. Assume it's for the same method and use that |
1217 } | 1326 // entry in that case. |
1218 if (create_if_missing && dp < end) { | 1327 if (dp->bci() == bci) { |
1219 // Allocate this one. There is no mutual exclusion, | 1328 if (data->method() == NULL) { |
1220 // so two threads could allocate different BCIs to the | 1329 return NULL; |
1221 // same data layout. This means these extra data | 1330 } else if (data->method() == m) { |
1222 // records, like most other MDO contents, must not be | 1331 return data; |
1223 // trusted too much. | 1332 } |
1224 DataLayout temp; | 1333 } |
1225 temp.initialize(DataLayout::bit_data_tag, bci, 0); | 1334 } |
1226 dp->release_set_header(temp.header()); | 1335 break; |
1227 assert(dp->tag() == DataLayout::bit_data_tag, "sane"); | 1336 default: |
1228 //NO: assert(dp->bci() == bci, "no concurrent allocation"); | 1337 fatal(err_msg("unexpected tag %d", dp->tag())); |
1229 return new BitData(dp); | 1338 } |
1339 } | |
1340 return NULL; | |
1341 } | |
1342 | |
1343 | |
1344 // Translate a bci to its corresponding extra data, or NULL. | |
1345 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) { | |
1346 // This code assumes an entry for a SpeculativeTrapData is 2 cells | |
1347 assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) == | |
1348 DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()), | |
1349 "code needs to be adjusted"); | |
1350 | |
1351 DataLayout* dp = extra_data_base(); | |
1352 DataLayout* end = extra_data_limit(); | |
1353 | |
1354 // Allocation in the extra data space has to be atomic because not | |
1355 // all entries have the same size and non atomic concurrent | |
1356 // allocation would result in a corrupted extra data space. | |
1357 while (true) { | |
1358 ProfileData* result = bci_to_extra_data_helper(bci, m, dp); | |
1359 if (result != NULL) { | |
1360 return result; | |
1361 } | |
1362 | |
1363 if (create_if_missing && dp < end) { | |
1364 assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free"); | |
1365 assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info"); | |
1366 u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag; | |
1367 // SpeculativeTrapData is 2 slots. Make sure we have room. | |
1368 if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) { | |
1369 return NULL; | |
1370 } | |
1371 DataLayout temp; | |
1372 temp.initialize(tag, bci, 0); | |
1373 // May have been set concurrently | |
1374 if (dp->header() != temp.header() && !dp->atomic_set_header(temp.header())) { | |
1375 // Allocation failure because of concurrent allocation. Try | |
1376 // again. | |
1377 continue; | |
1378 } | |
1379 assert(dp->tag() == tag, "sane"); | |
1380 assert(dp->bci() == bci, "no concurrent allocation"); | |
1381 if (tag == DataLayout::bit_data_tag) { | |
1382 return new BitData(dp); | |
1383 } else { | |
1384 // If being allocated concurrently, one trap may be lost | |
1385 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
1386 data->set_method(m); | |
1387 return data; | |
1388 } | |
1389 } | |
1390 return NULL; | |
1230 } | 1391 } |
1231 return NULL; | 1392 return NULL; |
1232 } | 1393 } |
1233 | 1394 |
1234 ArgInfoData *MethodData::arg_info() { | 1395 ArgInfoData *MethodData::arg_info() { |
1269 parameters_type_data()->print_data_on(st); | 1430 parameters_type_data()->print_data_on(st); |
1270 } | 1431 } |
1271 for ( ; is_valid(data); data = next_data(data)) { | 1432 for ( ; is_valid(data); data = next_data(data)) { |
1272 st->print("%d", dp_to_di(data->dp())); | 1433 st->print("%d", dp_to_di(data->dp())); |
1273 st->fill_to(6); | 1434 st->fill_to(6); |
1274 data->print_data_on(st); | 1435 data->print_data_on(st, this); |
1275 } | 1436 } |
1276 st->print_cr("--- Extra data:"); | 1437 st->print_cr("--- Extra data:"); |
1277 DataLayout* dp = extra_data_base(); | 1438 DataLayout* dp = extra_data_base(); |
1278 DataLayout* end = extra_data_limit(); | 1439 DataLayout* end = extra_data_limit(); |
1279 for (; dp < end; dp = next_extra(dp)) { | 1440 for (;; dp = next_extra(dp)) { |
1441 assert(dp < end, "moved past end of extra data"); | |
1280 // No need for "OrderAccess::load_acquire" ops, | 1442 // No need for "OrderAccess::load_acquire" ops, |
1281 // since the data structure is monotonic. | 1443 // since the data structure is monotonic. |
1282 if (dp->tag() == DataLayout::no_tag) continue; | 1444 switch(dp->tag()) { |
1283 if (dp->tag() == DataLayout::bit_data_tag) { | 1445 case DataLayout::no_tag: |
1446 continue; | |
1447 case DataLayout::bit_data_tag: | |
1284 data = new BitData(dp); | 1448 data = new BitData(dp); |
1285 } else { | 1449 break; |
1286 assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo"); | 1450 case DataLayout::speculative_trap_data_tag: |
1451 data = new SpeculativeTrapData(dp); | |
1452 break; | |
1453 case DataLayout::arg_info_data_tag: | |
1287 data = new ArgInfoData(dp); | 1454 data = new ArgInfoData(dp); |
1288 dp = end; // ArgInfoData is at the end of extra data section. | 1455 dp = end; // ArgInfoData is at the end of extra data section. |
1456 break; | |
1457 default: | |
1458 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1289 } | 1459 } |
1290 st->print("%d", dp_to_di(data->dp())); | 1460 st->print("%d", dp_to_di(data->dp())); |
1291 st->fill_to(6); | 1461 st->fill_to(6); |
1292 data->print_data_on(st); | 1462 data->print_data_on(st); |
1463 if (dp >= end) return; | |
1293 } | 1464 } |
1294 } | 1465 } |
1295 #endif | 1466 #endif |
1296 | 1467 |
1297 #if INCLUDE_SERVICES | 1468 #if INCLUDE_SERVICES |
1410 } | 1581 } |
1411 | 1582 |
1412 assert(profile_parameters_jsr292_only(), "inconsistent"); | 1583 assert(profile_parameters_jsr292_only(), "inconsistent"); |
1413 return m->is_compiled_lambda_form(); | 1584 return m->is_compiled_lambda_form(); |
1414 } | 1585 } |
1586 | |
1587 void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) { | |
1588 if (shift == 0) { | |
1589 return; | |
1590 } | |
1591 if (!reset) { | |
1592 // Move all cells of trap entry at dp left by "shift" cells | |
1593 intptr_t* start = (intptr_t*)dp; | |
1594 intptr_t* end = (intptr_t*)next_extra(dp); | |
1595 for (intptr_t* ptr = start; ptr < end; ptr++) { | |
1596 *(ptr-shift) = *ptr; | |
1597 } | |
1598 } else { | |
1599 // Reset "shift" cells stopping at dp | |
1600 intptr_t* start = ((intptr_t*)dp) - shift; | |
1601 intptr_t* end = (intptr_t*)dp; | |
1602 for (intptr_t* ptr = start; ptr < end; ptr++) { | |
1603 *ptr = 0; | |
1604 } | |
1605 } | |
1606 } | |
1607 | |
1608 // Remove SpeculativeTrapData entries that reference an unloaded | |
1609 // method | |
1610 void MethodData::clean_extra_data(BoolObjectClosure* is_alive) { | |
1611 DataLayout* dp = extra_data_base(); | |
1612 DataLayout* end = extra_data_limit(); | |
1613 | |
1614 int shift = 0; | |
1615 for (; dp < end; dp = next_extra(dp)) { | |
1616 switch(dp->tag()) { | |
1617 case DataLayout::speculative_trap_data_tag: { | |
1618 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
1619 Method* m = data->method(); | |
1620 assert(m != NULL, "should have a method"); | |
1621 if (!m->method_holder()->is_loader_alive(is_alive)) { | |
1622 // "shift" accumulates the number of cells for dead | |
1623 // SpeculativeTrapData entries that have been seen so | |
1624 // far. Following entries must be shifted left by that many | |
1625 // cells to remove the dead SpeculativeTrapData entries. | |
1626 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp); | |
1627 } else { | |
1628 // Shift this entry left if it follows dead | |
1629 // SpeculativeTrapData entries | |
1630 clean_extra_data_helper(dp, shift); | |
1631 } | |
1632 break; | |
1633 } | |
1634 case DataLayout::bit_data_tag: | |
1635 // Shift this entry left if it follows dead SpeculativeTrapData | |
1636 // entries | |
1637 clean_extra_data_helper(dp, shift); | |
1638 continue; | |
1639 case DataLayout::no_tag: | |
1640 case DataLayout::arg_info_data_tag: | |
1641 // We are at end of the live trap entries. The previous "shift" | |
1642 // cells contain entries that are either dead or were shifted | |
1643 // left. They need to be reset to no_tag | |
1644 clean_extra_data_helper(dp, shift, true); | |
1645 return; | |
1646 default: | |
1647 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1648 } | |
1649 } | |
1650 } | |
1651 | |
1652 // Verify there's no unloaded method referenced by a | |
1653 // SpeculativeTrapData entry | |
1654 void MethodData::verify_extra_data_clean(BoolObjectClosure* is_alive) { | |
1655 #ifdef ASSERT | |
1656 DataLayout* dp = extra_data_base(); | |
1657 DataLayout* end = extra_data_limit(); | |
1658 | |
1659 for (; dp < end; dp = next_extra(dp)) { | |
1660 switch(dp->tag()) { | |
1661 case DataLayout::speculative_trap_data_tag: { | |
1662 SpeculativeTrapData* data = new SpeculativeTrapData(dp); | |
1663 Method* m = data->method(); | |
1664 assert(m != NULL && m->method_holder()->is_loader_alive(is_alive), "Method should exist"); | |
1665 break; | |
1666 } | |
1667 case DataLayout::bit_data_tag: | |
1668 continue; | |
1669 case DataLayout::no_tag: | |
1670 case DataLayout::arg_info_data_tag: | |
1671 return; | |
1672 default: | |
1673 fatal(err_msg("unexpected tag %d", dp->tag())); | |
1674 } | |
1675 } | |
1676 #endif | |
1677 } | |
1678 | |
1679 void MethodData::clean_method_data(BoolObjectClosure* is_alive) { | |
1680 for (ProfileData* data = first_data(); | |
1681 is_valid(data); | |
1682 data = next_data(data)) { | |
1683 data->clean_weak_klass_links(is_alive); | |
1684 } | |
1685 ParametersTypeData* parameters = parameters_type_data(); | |
1686 if (parameters != NULL) { | |
1687 parameters->clean_weak_klass_links(is_alive); | |
1688 } | |
1689 | |
1690 clean_extra_data(is_alive); | |
1691 verify_extra_data_clean(is_alive); | |
1692 } |