123
124 void ProfileData::print_data_on(outputStream* st, const MethodData* md) const {
125 print_data_on(st, print_data_on_helper(md));
126 }
127
128 void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const {
129 st->print("bci: %d ", bci());
130 st->fill_to(tab_width_one + 1);
131 st->print("%s", name);
132 tab(st);
133 int trap = trap_state();
134 if (trap != 0) {
135 char buf[100];
136 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
137 }
138 if (extra != nullptr) {
139 st->print("%s", extra);
140 }
141 int flags = data()->flags();
142 if (flags != 0) {
143 st->print("flags(%d) ", flags);
144 }
145 }
146
147 void ProfileData::tab(outputStream* st, bool first) const {
148 st->fill_to(first ? tab_width_one : tab_width_two);
149 }
150
151 // ==================================================================
152 // BitData
153 //
154 // A BitData corresponds to a one-bit flag. This is used to indicate
155 // whether a checkcast bytecode has seen a null value.
156
157
158 void BitData::print_data_on(outputStream* st, const char* extra) const {
159 print_shared(st, "BitData", extra);
160 st->cr();
161 }
162
163 // ==================================================================
193 set_displacement(offset);
194 }
195
196 void JumpData::print_data_on(outputStream* st, const char* extra) const {
197 print_shared(st, "JumpData", extra);
198 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
199 }
200
201 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) {
202 // Parameter profiling include the receiver
203 int args_count = include_receiver ? 1 : 0;
204 ResourceMark rm;
205 ReferenceArgumentCount rac(signature);
206 args_count += rac.count();
207 args_count = MIN2(args_count, max);
208 return args_count * per_arg_cell_count;
209 }
210
211 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {
212 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
213 assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken");
214 const methodHandle m = stream->method();
215 int bci = stream->bci();
216 Bytecode_invoke inv(m, bci);
217 int args_cell = 0;
218 if (MethodData::profile_arguments_for_invoke(m, bci)) {
219 args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit);
220 }
221 int ret_cell = 0;
222 if (MethodData::profile_return_for_invoke(m, bci) && is_reference_type(inv.result_type())) {
223 ret_cell = ReturnTypeEntry::static_cell_count();
224 }
225 int header_cell = 0;
226 if (args_cell + ret_cell > 0) {
227 header_cell = header_cell_count();
228 }
229
230 return header_cell + args_cell + ret_cell;
231 }
232
233 class ArgumentOffsetComputer : public SignatureIterator {
234 private:
235 int _max;
236 int _offset;
237 GrowableArray<int> _offsets;
238
239 friend class SignatureIterator; // so do_parameters_on can call do_type
240 void do_type(BasicType type) {
241 if (is_reference_type(type) && _offsets.length() < _max) {
242 _offsets.push(_offset);
243 }
306 #endif
307 _args.post_initialize(inv.signature(), inv.has_receiver(), false);
308 }
309
310 if (has_return()) {
311 assert(is_reference_type(inv.result_type()), "room for a ret type but doesn't return obj?");
312 _ret.post_initialize();
313 }
314 }
315
316 void TypeStackSlotEntries::clean_weak_klass_links(bool always_clean) {
317 for (int i = 0; i < _number_of_entries; i++) {
318 intptr_t p = type(i);
319 Klass* k = (Klass*)klass_part(p);
320 if (k != nullptr && (always_clean || !k->is_loader_alive())) {
321 set_type(i, with_status((Klass*)nullptr, p));
322 }
323 }
324 }
325
326 void ReturnTypeEntry::clean_weak_klass_links(bool always_clean) {
327 intptr_t p = type();
328 Klass* k = (Klass*)klass_part(p);
329 if (k != nullptr && (always_clean || !k->is_loader_alive())) {
330 set_type(with_status((Klass*)nullptr, p));
331 }
332 }
333
334 bool TypeEntriesAtCall::return_profiling_enabled() {
335 return MethodData::profile_return();
336 }
337
338 bool TypeEntriesAtCall::arguments_profiling_enabled() {
339 return MethodData::profile_arguments();
340 }
341
342 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
343 if (is_type_none(k)) {
344 st->print("none");
345 } else if (is_type_unknown(k)) {
346 st->print("unknown");
347 } else {
348 valid_klass(k)->print_value_on(st);
349 }
350 if (was_null_seen(k)) {
351 st->print(" (null seen)");
352 }
353 }
354
355 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
356 for (int i = 0; i < _number_of_entries; i++) {
357 _pd->tab(st);
358 st->print("%d: stack(%u) ", i, stack_slot(i));
359 print_klass(st, type(i));
360 st->cr();
361 }
362 }
363
364 void ReturnTypeEntry::print_data_on(outputStream* st) const {
365 _pd->tab(st);
366 print_klass(st, type());
367 st->cr();
368 }
369
370 void CallTypeData::print_data_on(outputStream* st, const char* extra) const {
371 CounterData::print_data_on(st, extra);
372 if (has_arguments()) {
373 tab(st, true);
374 st->print("argument types");
375 _args.print_data_on(st);
376 }
377 if (has_return()) {
378 tab(st, true);
379 st->print("return type");
380 _ret.print_data_on(st);
381 }
382 }
383
384 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {
509 }
510
511 // ==================================================================
512 // BranchData
513 //
514 // A BranchData is used to access profiling data for a two-way branch.
515 // It consists of taken and not_taken counts as well as a data displacement
516 // for the taken case.
517
518 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
519 assert(stream->bci() == bci(), "wrong pos");
520 int target = stream->dest();
521 int my_di = mdo->dp_to_di(dp());
522 int target_di = mdo->bci_to_di(target);
523 int offset = target_di - my_di;
524 set_displacement(offset);
525 }
526
527 void BranchData::print_data_on(outputStream* st, const char* extra) const {
528 print_shared(st, "BranchData", extra);
529 st->print_cr("taken(%u) displacement(%d)",
530 taken(), displacement());
531 tab(st);
532 st->print_cr("not taken(%u)", not_taken());
533 }
534
535 // ==================================================================
536 // MultiBranchData
537 //
538 // A MultiBranchData is used to access profiling information for
539 // a multi-way branch (*switch bytecodes). It consists of a series
540 // of (count, displacement) pairs, which count the number of times each
541 // case was taken and specify the data displacement for each branch target.
542
543 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
544 int cell_count = 0;
545 if (stream->code() == Bytecodes::_tableswitch) {
546 Bytecode_tableswitch sw(stream->method()(), stream->bcp());
547 cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default
548 } else {
634 }
635
636 bool ParametersTypeData::profiling_enabled() {
637 return MethodData::profile_parameters();
638 }
639
640 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
641 print_shared(st, "ParametersTypeData", extra);
642 tab(st);
643 _parameters.print_data_on(st);
644 st->cr();
645 }
646
647 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
648 print_shared(st, "SpeculativeTrapData", extra);
649 tab(st);
650 method()->print_short_name(st);
651 st->cr();
652 }
653
654 // ==================================================================
655 // MethodData*
656 //
657 // A MethodData* holds information which has been collected about
658 // a method.
659
660 MethodData* MethodData::allocate(ClassLoaderData* loader_data, const methodHandle& method, TRAPS) {
661 assert(!THREAD->owns_locks(), "Should not own any locks");
662 int size = MethodData::compute_allocation_size_in_words(method);
663
664 return new (loader_data, size, MetaspaceObj::MethodDataType, THREAD)
665 MethodData(method);
666 }
667
668 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
669 if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
670 return no_profile_data;
671 }
672 switch (code) {
673 case Bytecodes::_checkcast:
674 case Bytecodes::_instanceof:
675 case Bytecodes::_aastore:
676 if (TypeProfileCasts) {
677 return ReceiverTypeData::static_cell_count();
678 } else {
679 return BitData::static_cell_count();
680 }
681 case Bytecodes::_invokespecial:
682 case Bytecodes::_invokestatic:
683 if (MethodData::profile_arguments() || MethodData::profile_return()) {
684 return variable_cell_count;
685 } else {
686 return CounterData::static_cell_count();
687 }
688 case Bytecodes::_goto:
689 case Bytecodes::_goto_w:
690 case Bytecodes::_jsr:
691 case Bytecodes::_jsr_w:
692 return JumpData::static_cell_count();
693 case Bytecodes::_invokevirtual:
694 case Bytecodes::_invokeinterface:
695 if (MethodData::profile_arguments() || MethodData::profile_return()) {
696 return variable_cell_count;
697 } else {
698 return VirtualCallData::static_cell_count();
699 }
700 case Bytecodes::_invokedynamic:
701 if (MethodData::profile_arguments() || MethodData::profile_return()) {
702 return variable_cell_count;
703 } else {
704 return CounterData::static_cell_count();
705 }
706 case Bytecodes::_ret:
707 return RetData::static_cell_count();
708 case Bytecodes::_ifeq:
709 case Bytecodes::_ifne:
710 case Bytecodes::_iflt:
711 case Bytecodes::_ifge:
712 case Bytecodes::_ifgt:
713 case Bytecodes::_ifle:
714 case Bytecodes::_if_icmpeq:
715 case Bytecodes::_if_icmpne:
716 case Bytecodes::_if_icmplt:
717 case Bytecodes::_if_icmpge:
718 case Bytecodes::_if_icmpgt:
719 case Bytecodes::_if_icmple:
720 case Bytecodes::_if_acmpeq:
721 case Bytecodes::_if_acmpne:
722 case Bytecodes::_ifnull:
723 case Bytecodes::_ifnonnull:
724 return BranchData::static_cell_count();
725 case Bytecodes::_lookupswitch:
726 case Bytecodes::_tableswitch:
727 return variable_cell_count;
728 default:
729 return no_profile_data;
730 }
731 }
732
733 // Compute the size of the profiling information corresponding to
734 // the current bytecode.
735 int MethodData::compute_data_size(BytecodeStream* stream) {
736 int cell_count = bytecode_cell_count(stream->code());
737 if (cell_count == no_profile_data) {
738 return 0;
739 }
740 if (cell_count == variable_cell_count) {
741 switch (stream->code()) {
742 case Bytecodes::_lookupswitch:
743 case Bytecodes::_tableswitch:
744 cell_count = MultiBranchData::compute_cell_count(stream);
763 } else {
764 cell_count = VirtualCallData::static_cell_count();
765 }
766 break;
767 }
768 default:
769 fatal("unexpected bytecode for var length profile data");
770 }
771 }
772 // Note: cell_count might be zero, meaning that there is just
773 // a DataLayout header, with no extra cells.
774 assert(cell_count >= 0, "sanity");
775 return DataLayout::compute_size_in_bytes(cell_count);
776 }
777
778 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {
779 // Bytecodes for which we may use speculation
780 switch (code) {
781 case Bytecodes::_checkcast:
782 case Bytecodes::_instanceof:
783 case Bytecodes::_aastore:
784 case Bytecodes::_invokevirtual:
785 case Bytecodes::_invokeinterface:
786 case Bytecodes::_if_acmpeq:
787 case Bytecodes::_if_acmpne:
788 case Bytecodes::_ifnull:
789 case Bytecodes::_ifnonnull:
790 case Bytecodes::_invokestatic:
791 #ifdef COMPILER2
792 if (CompilerConfig::is_c2_enabled()) {
793 return UseTypeSpeculation;
794 }
795 #endif
796 default:
797 return false;
798 }
799 return false;
800 }
801
802 #if INCLUDE_JVMCI
976 int MethodData::compute_allocation_size_in_words(const methodHandle& method) {
977 int byte_size = compute_allocation_size_in_bytes(method);
978 int word_size = align_up(byte_size, BytesPerWord) / BytesPerWord;
979 return align_metadata_size(word_size);
980 }
981
982 // Initialize an individual data segment. Returns the size of
983 // the segment in bytes.
984 int MethodData::initialize_data(BytecodeStream* stream,
985 int data_index) {
986 if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
987 return 0;
988 }
989 int cell_count = -1;
990 u1 tag = DataLayout::no_tag;
991 DataLayout* data_layout = data_layout_at(data_index);
992 Bytecodes::Code c = stream->code();
993 switch (c) {
994 case Bytecodes::_checkcast:
995 case Bytecodes::_instanceof:
996 case Bytecodes::_aastore:
997 if (TypeProfileCasts) {
998 cell_count = ReceiverTypeData::static_cell_count();
999 tag = DataLayout::receiver_type_data_tag;
1000 } else {
1001 cell_count = BitData::static_cell_count();
1002 tag = DataLayout::bit_data_tag;
1003 }
1004 break;
1005 case Bytecodes::_invokespecial:
1006 case Bytecodes::_invokestatic: {
1007 int counter_data_cell_count = CounterData::static_cell_count();
1008 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
1009 profile_return_for_invoke(stream->method(), stream->bci())) {
1010 cell_count = CallTypeData::compute_cell_count(stream);
1011 } else {
1012 cell_count = counter_data_cell_count;
1013 }
1014 if (cell_count > counter_data_cell_count) {
1015 tag = DataLayout::call_type_data_tag;
1016 } else {
1017 tag = DataLayout::counter_data_tag;
1018 }
1019 break;
1020 }
1021 case Bytecodes::_goto:
1022 case Bytecodes::_goto_w:
1023 case Bytecodes::_jsr:
1024 case Bytecodes::_jsr_w:
1056 tag = DataLayout::counter_data_tag;
1057 }
1058 break;
1059 }
1060 case Bytecodes::_ret:
1061 cell_count = RetData::static_cell_count();
1062 tag = DataLayout::ret_data_tag;
1063 break;
1064 case Bytecodes::_ifeq:
1065 case Bytecodes::_ifne:
1066 case Bytecodes::_iflt:
1067 case Bytecodes::_ifge:
1068 case Bytecodes::_ifgt:
1069 case Bytecodes::_ifle:
1070 case Bytecodes::_if_icmpeq:
1071 case Bytecodes::_if_icmpne:
1072 case Bytecodes::_if_icmplt:
1073 case Bytecodes::_if_icmpge:
1074 case Bytecodes::_if_icmpgt:
1075 case Bytecodes::_if_icmple:
1076 case Bytecodes::_if_acmpeq:
1077 case Bytecodes::_if_acmpne:
1078 case Bytecodes::_ifnull:
1079 case Bytecodes::_ifnonnull:
1080 cell_count = BranchData::static_cell_count();
1081 tag = DataLayout::branch_data_tag;
1082 break;
1083 case Bytecodes::_lookupswitch:
1084 case Bytecodes::_tableswitch:
1085 cell_count = MultiBranchData::compute_cell_count(stream);
1086 tag = DataLayout::multi_branch_data_tag;
1087 break;
1088 default:
1089 break;
1090 }
1091 assert(tag == DataLayout::multi_branch_data_tag ||
1092 ((MethodData::profile_arguments() || MethodData::profile_return()) &&
1093 (tag == DataLayout::call_type_data_tag ||
1094 tag == DataLayout::counter_data_tag ||
1095 tag == DataLayout::virtual_call_type_data_tag ||
1096 tag == DataLayout::virtual_call_data_tag)) ||
1097 cell_count == bytecode_cell_count(c), "cell counts must agree");
1098 if (cell_count >= 0) {
1099 assert(tag != DataLayout::no_tag, "bad tag");
1100 assert(bytecode_has_profile(c), "agree w/ BHP");
1101 data_layout->initialize(tag, checked_cast<u2>(stream->bci()), cell_count);
1102 return DataLayout::compute_size_in_bytes(cell_count);
1130 case DataLayout::receiver_type_data_tag:
1131 return ReceiverTypeData::static_cell_count();
1132 case DataLayout::virtual_call_data_tag:
1133 return VirtualCallData::static_cell_count();
1134 case DataLayout::ret_data_tag:
1135 return RetData::static_cell_count();
1136 case DataLayout::branch_data_tag:
1137 return BranchData::static_cell_count();
1138 case DataLayout::multi_branch_data_tag:
1139 return ((new MultiBranchData(this))->cell_count());
1140 case DataLayout::arg_info_data_tag:
1141 return ((new ArgInfoData(this))->cell_count());
1142 case DataLayout::call_type_data_tag:
1143 return ((new CallTypeData(this))->cell_count());
1144 case DataLayout::virtual_call_type_data_tag:
1145 return ((new VirtualCallTypeData(this))->cell_count());
1146 case DataLayout::parameters_type_data_tag:
1147 return ((new ParametersTypeData(this))->cell_count());
1148 case DataLayout::speculative_trap_data_tag:
1149 return SpeculativeTrapData::static_cell_count();
1150 }
1151 }
1152 ProfileData* DataLayout::data_in() {
1153 switch (tag()) {
1154 case DataLayout::no_tag:
1155 default:
1156 ShouldNotReachHere();
1157 return nullptr;
1158 case DataLayout::bit_data_tag:
1159 return new BitData(this);
1160 case DataLayout::counter_data_tag:
1161 return new CounterData(this);
1162 case DataLayout::jump_data_tag:
1163 return new JumpData(this);
1164 case DataLayout::receiver_type_data_tag:
1165 return new ReceiverTypeData(this);
1166 case DataLayout::virtual_call_data_tag:
1167 return new VirtualCallData(this);
1168 case DataLayout::ret_data_tag:
1169 return new RetData(this);
1170 case DataLayout::branch_data_tag:
1171 return new BranchData(this);
1172 case DataLayout::multi_branch_data_tag:
1173 return new MultiBranchData(this);
1174 case DataLayout::arg_info_data_tag:
1175 return new ArgInfoData(this);
1176 case DataLayout::call_type_data_tag:
1177 return new CallTypeData(this);
1178 case DataLayout::virtual_call_type_data_tag:
1179 return new VirtualCallTypeData(this);
1180 case DataLayout::parameters_type_data_tag:
1181 return new ParametersTypeData(this);
1182 case DataLayout::speculative_trap_data_tag:
1183 return new SpeculativeTrapData(this);
1184 }
1185 }
1186
1187 // Iteration over data.
1188 ProfileData* MethodData::next_data(ProfileData* current) const {
1189 int current_index = dp_to_di(current->dp());
1190 int next_index = current_index + current->size_in_bytes();
1191 ProfileData* next = data_at(next_index);
1192 return next;
1193 }
1194
1195 DataLayout* MethodData::next_data_layout(DataLayout* current) const {
1196 int current_index = dp_to_di((address)current);
1197 int next_index = current_index + current->size_in_bytes();
1198 if (out_of_bounds(next_index)) {
1199 return nullptr;
1200 }
1201 DataLayout* next = data_layout_at(next_index);
1202 return next;
1203 }
|
123
124 void ProfileData::print_data_on(outputStream* st, const MethodData* md) const {
125 print_data_on(st, print_data_on_helper(md));
126 }
127
128 void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const {
129 st->print("bci: %d ", bci());
130 st->fill_to(tab_width_one + 1);
131 st->print("%s", name);
132 tab(st);
133 int trap = trap_state();
134 if (trap != 0) {
135 char buf[100];
136 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
137 }
138 if (extra != nullptr) {
139 st->print("%s", extra);
140 }
141 int flags = data()->flags();
142 if (flags != 0) {
143 st->print("flags(%d) %p/%d", flags, data(), in_bytes(DataLayout::flags_offset()));
144 }
145 }
146
147 void ProfileData::tab(outputStream* st, bool first) const {
148 st->fill_to(first ? tab_width_one : tab_width_two);
149 }
150
151 // ==================================================================
152 // BitData
153 //
154 // A BitData corresponds to a one-bit flag. This is used to indicate
155 // whether a checkcast bytecode has seen a null value.
156
157
158 void BitData::print_data_on(outputStream* st, const char* extra) const {
159 print_shared(st, "BitData", extra);
160 st->cr();
161 }
162
163 // ==================================================================
193 set_displacement(offset);
194 }
195
196 void JumpData::print_data_on(outputStream* st, const char* extra) const {
197 print_shared(st, "JumpData", extra);
198 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
199 }
200
201 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) {
202 // Parameter profiling include the receiver
203 int args_count = include_receiver ? 1 : 0;
204 ResourceMark rm;
205 ReferenceArgumentCount rac(signature);
206 args_count += rac.count();
207 args_count = MIN2(args_count, max);
208 return args_count * per_arg_cell_count;
209 }
210
211 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {
212 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
213 assert(TypeStackSlotEntries::per_arg_count() > SingleTypeEntry::static_cell_count(), "code to test for arguments/results broken");
214 const methodHandle m = stream->method();
215 int bci = stream->bci();
216 Bytecode_invoke inv(m, bci);
217 int args_cell = 0;
218 if (MethodData::profile_arguments_for_invoke(m, bci)) {
219 args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit);
220 }
221 int ret_cell = 0;
222 if (MethodData::profile_return_for_invoke(m, bci) && is_reference_type(inv.result_type())) {
223 ret_cell = SingleTypeEntry::static_cell_count();
224 }
225 int header_cell = 0;
226 if (args_cell + ret_cell > 0) {
227 header_cell = header_cell_count();
228 }
229
230 return header_cell + args_cell + ret_cell;
231 }
232
233 class ArgumentOffsetComputer : public SignatureIterator {
234 private:
235 int _max;
236 int _offset;
237 GrowableArray<int> _offsets;
238
239 friend class SignatureIterator; // so do_parameters_on can call do_type
240 void do_type(BasicType type) {
241 if (is_reference_type(type) && _offsets.length() < _max) {
242 _offsets.push(_offset);
243 }
306 #endif
307 _args.post_initialize(inv.signature(), inv.has_receiver(), false);
308 }
309
310 if (has_return()) {
311 assert(is_reference_type(inv.result_type()), "room for a ret type but doesn't return obj?");
312 _ret.post_initialize();
313 }
314 }
315
316 void TypeStackSlotEntries::clean_weak_klass_links(bool always_clean) {
317 for (int i = 0; i < _number_of_entries; i++) {
318 intptr_t p = type(i);
319 Klass* k = (Klass*)klass_part(p);
320 if (k != nullptr && (always_clean || !k->is_loader_alive())) {
321 set_type(i, with_status((Klass*)nullptr, p));
322 }
323 }
324 }
325
326 void SingleTypeEntry::clean_weak_klass_links(bool always_clean) {
327 intptr_t p = type();
328 Klass* k = (Klass*)klass_part(p);
329 if (k != nullptr && (always_clean || !k->is_loader_alive())) {
330 set_type(with_status((Klass*)nullptr, p));
331 }
332 }
333
334 bool TypeEntriesAtCall::return_profiling_enabled() {
335 return MethodData::profile_return();
336 }
337
338 bool TypeEntriesAtCall::arguments_profiling_enabled() {
339 return MethodData::profile_arguments();
340 }
341
342 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
343 if (is_type_none(k)) {
344 st->print("none");
345 } else if (is_type_unknown(k)) {
346 st->print("unknown");
347 } else {
348 valid_klass(k)->print_value_on(st);
349 }
350 if (was_null_seen(k)) {
351 st->print(" (null seen)");
352 }
353 }
354
355 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
356 for (int i = 0; i < _number_of_entries; i++) {
357 _pd->tab(st);
358 st->print("%d: stack(%u) ", i, stack_slot(i));
359 print_klass(st, type(i));
360 st->cr();
361 }
362 }
363
364 void SingleTypeEntry::print_data_on(outputStream* st) const {
365 _pd->tab(st);
366 print_klass(st, type());
367 st->cr();
368 }
369
370 void CallTypeData::print_data_on(outputStream* st, const char* extra) const {
371 CounterData::print_data_on(st, extra);
372 if (has_arguments()) {
373 tab(st, true);
374 st->print("argument types");
375 _args.print_data_on(st);
376 }
377 if (has_return()) {
378 tab(st, true);
379 st->print("return type");
380 _ret.print_data_on(st);
381 }
382 }
383
384 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {
509 }
510
511 // ==================================================================
512 // BranchData
513 //
514 // A BranchData is used to access profiling data for a two-way branch.
515 // It consists of taken and not_taken counts as well as a data displacement
516 // for the taken case.
517
518 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
519 assert(stream->bci() == bci(), "wrong pos");
520 int target = stream->dest();
521 int my_di = mdo->dp_to_di(dp());
522 int target_di = mdo->bci_to_di(target);
523 int offset = target_di - my_di;
524 set_displacement(offset);
525 }
526
527 void BranchData::print_data_on(outputStream* st, const char* extra) const {
528 print_shared(st, "BranchData", extra);
529 if (data()->flags()) {
530 tty->cr();
531 tab(st);
532 }
533 st->print_cr("taken(%u) displacement(%d)",
534 taken(), displacement());
535 tab(st);
536 st->print_cr("not taken(%u)", not_taken());
537 }
538
539 // ==================================================================
540 // MultiBranchData
541 //
542 // A MultiBranchData is used to access profiling information for
543 // a multi-way branch (*switch bytecodes). It consists of a series
544 // of (count, displacement) pairs, which count the number of times each
545 // case was taken and specify the data displacement for each branch target.
546
547 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
548 int cell_count = 0;
549 if (stream->code() == Bytecodes::_tableswitch) {
550 Bytecode_tableswitch sw(stream->method()(), stream->bcp());
551 cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default
552 } else {
638 }
639
640 bool ParametersTypeData::profiling_enabled() {
641 return MethodData::profile_parameters();
642 }
643
644 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
645 print_shared(st, "ParametersTypeData", extra);
646 tab(st);
647 _parameters.print_data_on(st);
648 st->cr();
649 }
650
651 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
652 print_shared(st, "SpeculativeTrapData", extra);
653 tab(st);
654 method()->print_short_name(st);
655 st->cr();
656 }
657
658 void ArrayLoadStoreData::print_data_on(outputStream* st, const char* extra) const {
659 print_shared(st, "ArrayLoadStore", extra);
660 st->cr();
661 tab(st, true);
662 st->print("array");
663 _array.print_data_on(st);
664 tab(st, true);
665 st->print("element");
666 _element.print_data_on(st);
667 }
668
669 void ACmpData::print_data_on(outputStream* st, const char* extra) const {
670 BranchData::print_data_on(st, extra);
671 tab(st, true);
672 st->print("left");
673 _left.print_data_on(st);
674 tab(st, true);
675 st->print("right");
676 _right.print_data_on(st);
677 }
678
679 // ==================================================================
680 // MethodData*
681 //
682 // A MethodData* holds information which has been collected about
683 // a method.
684
685 MethodData* MethodData::allocate(ClassLoaderData* loader_data, const methodHandle& method, TRAPS) {
686 assert(!THREAD->owns_locks(), "Should not own any locks");
687 int size = MethodData::compute_allocation_size_in_words(method);
688
689 return new (loader_data, size, MetaspaceObj::MethodDataType, THREAD)
690 MethodData(method);
691 }
692
693 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
694 if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
695 return no_profile_data;
696 }
697 switch (code) {
698 case Bytecodes::_checkcast:
699 case Bytecodes::_instanceof:
700 if (TypeProfileCasts) {
701 return ReceiverTypeData::static_cell_count();
702 } else {
703 return BitData::static_cell_count();
704 }
705 case Bytecodes::_aaload:
706 case Bytecodes::_aastore:
707 return ArrayLoadStoreData::static_cell_count();
708 case Bytecodes::_invokespecial:
709 case Bytecodes::_invokestatic:
710 if (MethodData::profile_arguments() || MethodData::profile_return()) {
711 return variable_cell_count;
712 } else {
713 return CounterData::static_cell_count();
714 }
715 case Bytecodes::_goto:
716 case Bytecodes::_goto_w:
717 case Bytecodes::_jsr:
718 case Bytecodes::_jsr_w:
719 return JumpData::static_cell_count();
720 case Bytecodes::_invokevirtual:
721 case Bytecodes::_invokeinterface:
722 if (MethodData::profile_arguments() || MethodData::profile_return()) {
723 return variable_cell_count;
724 } else {
725 return VirtualCallData::static_cell_count();
726 }
727 case Bytecodes::_invokedynamic:
728 if (MethodData::profile_arguments() || MethodData::profile_return()) {
729 return variable_cell_count;
730 } else {
731 return CounterData::static_cell_count();
732 }
733 case Bytecodes::_ret:
734 return RetData::static_cell_count();
735 case Bytecodes::_ifeq:
736 case Bytecodes::_ifne:
737 case Bytecodes::_iflt:
738 case Bytecodes::_ifge:
739 case Bytecodes::_ifgt:
740 case Bytecodes::_ifle:
741 case Bytecodes::_if_icmpeq:
742 case Bytecodes::_if_icmpne:
743 case Bytecodes::_if_icmplt:
744 case Bytecodes::_if_icmpge:
745 case Bytecodes::_if_icmpgt:
746 case Bytecodes::_if_icmple:
747 case Bytecodes::_ifnull:
748 case Bytecodes::_ifnonnull:
749 return BranchData::static_cell_count();
750 case Bytecodes::_if_acmpne:
751 case Bytecodes::_if_acmpeq:
752 return ACmpData::static_cell_count();
753 case Bytecodes::_lookupswitch:
754 case Bytecodes::_tableswitch:
755 return variable_cell_count;
756 default:
757 return no_profile_data;
758 }
759 }
760
761 // Compute the size of the profiling information corresponding to
762 // the current bytecode.
763 int MethodData::compute_data_size(BytecodeStream* stream) {
764 int cell_count = bytecode_cell_count(stream->code());
765 if (cell_count == no_profile_data) {
766 return 0;
767 }
768 if (cell_count == variable_cell_count) {
769 switch (stream->code()) {
770 case Bytecodes::_lookupswitch:
771 case Bytecodes::_tableswitch:
772 cell_count = MultiBranchData::compute_cell_count(stream);
791 } else {
792 cell_count = VirtualCallData::static_cell_count();
793 }
794 break;
795 }
796 default:
797 fatal("unexpected bytecode for var length profile data");
798 }
799 }
800 // Note: cell_count might be zero, meaning that there is just
801 // a DataLayout header, with no extra cells.
802 assert(cell_count >= 0, "sanity");
803 return DataLayout::compute_size_in_bytes(cell_count);
804 }
805
806 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {
807 // Bytecodes for which we may use speculation
808 switch (code) {
809 case Bytecodes::_checkcast:
810 case Bytecodes::_instanceof:
811 case Bytecodes::_aaload:
812 case Bytecodes::_aastore:
813 case Bytecodes::_invokevirtual:
814 case Bytecodes::_invokeinterface:
815 case Bytecodes::_if_acmpeq:
816 case Bytecodes::_if_acmpne:
817 case Bytecodes::_ifnull:
818 case Bytecodes::_ifnonnull:
819 case Bytecodes::_invokestatic:
820 #ifdef COMPILER2
821 if (CompilerConfig::is_c2_enabled()) {
822 return UseTypeSpeculation;
823 }
824 #endif
825 default:
826 return false;
827 }
828 return false;
829 }
830
831 #if INCLUDE_JVMCI
1005 int MethodData::compute_allocation_size_in_words(const methodHandle& method) {
1006 int byte_size = compute_allocation_size_in_bytes(method);
1007 int word_size = align_up(byte_size, BytesPerWord) / BytesPerWord;
1008 return align_metadata_size(word_size);
1009 }
1010
1011 // Initialize an individual data segment. Returns the size of
1012 // the segment in bytes.
1013 int MethodData::initialize_data(BytecodeStream* stream,
1014 int data_index) {
1015 if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
1016 return 0;
1017 }
1018 int cell_count = -1;
1019 u1 tag = DataLayout::no_tag;
1020 DataLayout* data_layout = data_layout_at(data_index);
1021 Bytecodes::Code c = stream->code();
1022 switch (c) {
1023 case Bytecodes::_checkcast:
1024 case Bytecodes::_instanceof:
1025 if (TypeProfileCasts) {
1026 cell_count = ReceiverTypeData::static_cell_count();
1027 tag = DataLayout::receiver_type_data_tag;
1028 } else {
1029 cell_count = BitData::static_cell_count();
1030 tag = DataLayout::bit_data_tag;
1031 }
1032 break;
1033 case Bytecodes::_aaload:
1034 case Bytecodes::_aastore:
1035 cell_count = ArrayLoadStoreData::static_cell_count();
1036 tag = DataLayout::array_load_store_data_tag;
1037 break;
1038 case Bytecodes::_invokespecial:
1039 case Bytecodes::_invokestatic: {
1040 int counter_data_cell_count = CounterData::static_cell_count();
1041 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
1042 profile_return_for_invoke(stream->method(), stream->bci())) {
1043 cell_count = CallTypeData::compute_cell_count(stream);
1044 } else {
1045 cell_count = counter_data_cell_count;
1046 }
1047 if (cell_count > counter_data_cell_count) {
1048 tag = DataLayout::call_type_data_tag;
1049 } else {
1050 tag = DataLayout::counter_data_tag;
1051 }
1052 break;
1053 }
1054 case Bytecodes::_goto:
1055 case Bytecodes::_goto_w:
1056 case Bytecodes::_jsr:
1057 case Bytecodes::_jsr_w:
1089 tag = DataLayout::counter_data_tag;
1090 }
1091 break;
1092 }
1093 case Bytecodes::_ret:
1094 cell_count = RetData::static_cell_count();
1095 tag = DataLayout::ret_data_tag;
1096 break;
1097 case Bytecodes::_ifeq:
1098 case Bytecodes::_ifne:
1099 case Bytecodes::_iflt:
1100 case Bytecodes::_ifge:
1101 case Bytecodes::_ifgt:
1102 case Bytecodes::_ifle:
1103 case Bytecodes::_if_icmpeq:
1104 case Bytecodes::_if_icmpne:
1105 case Bytecodes::_if_icmplt:
1106 case Bytecodes::_if_icmpge:
1107 case Bytecodes::_if_icmpgt:
1108 case Bytecodes::_if_icmple:
1109 case Bytecodes::_ifnull:
1110 case Bytecodes::_ifnonnull:
1111 cell_count = BranchData::static_cell_count();
1112 tag = DataLayout::branch_data_tag;
1113 break;
1114 case Bytecodes::_if_acmpeq:
1115 case Bytecodes::_if_acmpne:
1116 cell_count = ACmpData::static_cell_count();
1117 tag = DataLayout::acmp_data_tag;
1118 break;
1119 case Bytecodes::_lookupswitch:
1120 case Bytecodes::_tableswitch:
1121 cell_count = MultiBranchData::compute_cell_count(stream);
1122 tag = DataLayout::multi_branch_data_tag;
1123 break;
1124 default:
1125 break;
1126 }
1127 assert(tag == DataLayout::multi_branch_data_tag ||
1128 ((MethodData::profile_arguments() || MethodData::profile_return()) &&
1129 (tag == DataLayout::call_type_data_tag ||
1130 tag == DataLayout::counter_data_tag ||
1131 tag == DataLayout::virtual_call_type_data_tag ||
1132 tag == DataLayout::virtual_call_data_tag)) ||
1133 cell_count == bytecode_cell_count(c), "cell counts must agree");
1134 if (cell_count >= 0) {
1135 assert(tag != DataLayout::no_tag, "bad tag");
1136 assert(bytecode_has_profile(c), "agree w/ BHP");
1137 data_layout->initialize(tag, checked_cast<u2>(stream->bci()), cell_count);
1138 return DataLayout::compute_size_in_bytes(cell_count);
1166 case DataLayout::receiver_type_data_tag:
1167 return ReceiverTypeData::static_cell_count();
1168 case DataLayout::virtual_call_data_tag:
1169 return VirtualCallData::static_cell_count();
1170 case DataLayout::ret_data_tag:
1171 return RetData::static_cell_count();
1172 case DataLayout::branch_data_tag:
1173 return BranchData::static_cell_count();
1174 case DataLayout::multi_branch_data_tag:
1175 return ((new MultiBranchData(this))->cell_count());
1176 case DataLayout::arg_info_data_tag:
1177 return ((new ArgInfoData(this))->cell_count());
1178 case DataLayout::call_type_data_tag:
1179 return ((new CallTypeData(this))->cell_count());
1180 case DataLayout::virtual_call_type_data_tag:
1181 return ((new VirtualCallTypeData(this))->cell_count());
1182 case DataLayout::parameters_type_data_tag:
1183 return ((new ParametersTypeData(this))->cell_count());
1184 case DataLayout::speculative_trap_data_tag:
1185 return SpeculativeTrapData::static_cell_count();
1186 case DataLayout::array_load_store_data_tag:
1187 return ((new ArrayLoadStoreData(this))->cell_count());
1188 case DataLayout::acmp_data_tag:
1189 return ((new ACmpData(this))->cell_count());
1190 }
1191 }
1192 ProfileData* DataLayout::data_in() {
1193 switch (tag()) {
1194 case DataLayout::no_tag:
1195 default:
1196 ShouldNotReachHere();
1197 return nullptr;
1198 case DataLayout::bit_data_tag:
1199 return new BitData(this);
1200 case DataLayout::counter_data_tag:
1201 return new CounterData(this);
1202 case DataLayout::jump_data_tag:
1203 return new JumpData(this);
1204 case DataLayout::receiver_type_data_tag:
1205 return new ReceiverTypeData(this);
1206 case DataLayout::virtual_call_data_tag:
1207 return new VirtualCallData(this);
1208 case DataLayout::ret_data_tag:
1209 return new RetData(this);
1210 case DataLayout::branch_data_tag:
1211 return new BranchData(this);
1212 case DataLayout::multi_branch_data_tag:
1213 return new MultiBranchData(this);
1214 case DataLayout::arg_info_data_tag:
1215 return new ArgInfoData(this);
1216 case DataLayout::call_type_data_tag:
1217 return new CallTypeData(this);
1218 case DataLayout::virtual_call_type_data_tag:
1219 return new VirtualCallTypeData(this);
1220 case DataLayout::parameters_type_data_tag:
1221 return new ParametersTypeData(this);
1222 case DataLayout::speculative_trap_data_tag:
1223 return new SpeculativeTrapData(this);
1224 case DataLayout::array_load_store_data_tag:
1225 return new ArrayLoadStoreData(this);
1226 case DataLayout::acmp_data_tag:
1227 return new ACmpData(this);
1228 }
1229 }
1230
1231 // Iteration over data.
1232 ProfileData* MethodData::next_data(ProfileData* current) const {
1233 int current_index = dp_to_di(current->dp());
1234 int next_index = current_index + current->size_in_bytes();
1235 ProfileData* next = data_at(next_index);
1236 return next;
1237 }
1238
1239 DataLayout* MethodData::next_data_layout(DataLayout* current) const {
1240 int current_index = dp_to_di((address)current);
1241 int next_index = current_index + current->size_in_bytes();
1242 if (out_of_bounds(next_index)) {
1243 return nullptr;
1244 }
1245 DataLayout* next = data_layout_at(next_index);
1246 return next;
1247 }
|