< prev index next >

src/hotspot/share/oops/methodData.cpp

Print this page

 124 
 125 void ProfileData::print_data_on(outputStream* st, const MethodData* md) const {
 126   print_data_on(st, print_data_on_helper(md));
 127 }
 128 
 129 void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const {
 130   st->print("bci: %d ", bci());
 131   st->fill_to(tab_width_one + 1);
 132   st->print("%s", name);
 133   tab(st);
 134   int trap = trap_state();
 135   if (trap != 0) {
 136     char buf[100];
 137     st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
 138   }
 139   if (extra != nullptr) {
 140     st->print("%s", extra);
 141   }
 142   int flags = data()->flags();
 143   if (flags != 0) {
 144     st->print("flags(%d) ", flags);
 145   }
 146 }
 147 
 148 void ProfileData::tab(outputStream* st, bool first) const {
 149   st->fill_to(first ? tab_width_one : tab_width_two);
 150 }
 151 
 152 // ==================================================================
 153 // BitData
 154 //
 155 // A BitData corresponds to a one-bit flag.  This is used to indicate
 156 // whether a checkcast bytecode has seen a null value.
 157 
 158 
 159 void BitData::print_data_on(outputStream* st, const char* extra) const {
 160   print_shared(st, "BitData", extra);
 161   st->cr();
 162 }
 163 
 164 // ==================================================================

 194   set_displacement(offset);
 195 }
 196 
 197 void JumpData::print_data_on(outputStream* st, const char* extra) const {
 198   print_shared(st, "JumpData", extra);
 199   st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
 200 }
 201 
 202 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) {
 203   // Parameter profiling include the receiver
 204   int args_count = include_receiver ? 1 : 0;
 205   ResourceMark rm;
 206   ReferenceArgumentCount rac(signature);
 207   args_count += rac.count();
 208   args_count = MIN2(args_count, max);
 209   return args_count * per_arg_cell_count;
 210 }
 211 
 212 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {
 213   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 214   assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken");
 215   const methodHandle m = stream->method();
 216   int bci = stream->bci();
 217   Bytecode_invoke inv(m, bci);
 218   int args_cell = 0;
 219   if (MethodData::profile_arguments_for_invoke(m, bci)) {
 220     args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit);
 221   }
 222   int ret_cell = 0;
 223   if (MethodData::profile_return_for_invoke(m, bci) && is_reference_type(inv.result_type())) {
 224     ret_cell = ReturnTypeEntry::static_cell_count();
 225   }
 226   int header_cell = 0;
 227   if (args_cell + ret_cell > 0) {
 228     header_cell = header_cell_count();
 229   }
 230 
 231   return header_cell + args_cell + ret_cell;
 232 }
 233 
 234 class ArgumentOffsetComputer : public SignatureIterator {
 235 private:
 236   int _max;
 237   int _offset;
 238   GrowableArray<int> _offsets;
 239 
 240   friend class SignatureIterator;  // so do_parameters_on can call do_type
 241   void do_type(BasicType type) {
 242     if (is_reference_type(type) && _offsets.length() < _max) {
 243       _offsets.push(_offset);
 244     }

 307 #endif
 308     _args.post_initialize(inv.signature(), inv.has_receiver(), false);
 309   }
 310 
 311   if (has_return()) {
 312     assert(is_reference_type(inv.result_type()), "room for a ret type but doesn't return obj?");
 313     _ret.post_initialize();
 314   }
 315 }
 316 
 317 void TypeStackSlotEntries::clean_weak_klass_links(bool always_clean) {
 318   for (int i = 0; i < _number_of_entries; i++) {
 319     intptr_t p = type(i);
 320     Klass* k = (Klass*)klass_part(p);
 321     if (k != nullptr && (always_clean || !k->is_loader_alive())) {
 322       set_type(i, with_status((Klass*)nullptr, p));
 323     }
 324   }
 325 }
 326 
 327 void ReturnTypeEntry::clean_weak_klass_links(bool always_clean) {
 328   intptr_t p = type();
 329   Klass* k = (Klass*)klass_part(p);
 330   if (k != nullptr && (always_clean || !k->is_loader_alive())) {
 331     set_type(with_status((Klass*)nullptr, p));
 332   }
 333 }
 334 
 335 bool TypeEntriesAtCall::return_profiling_enabled() {
 336   return MethodData::profile_return();
 337 }
 338 
 339 bool TypeEntriesAtCall::arguments_profiling_enabled() {
 340   return MethodData::profile_arguments();
 341 }
 342 
 343 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
 344   if (is_type_none(k)) {
 345     st->print("none");
 346   } else if (is_type_unknown(k)) {
 347     st->print("unknown");
 348   } else {
 349     valid_klass(k)->print_value_on(st);
 350   }
 351   if (was_null_seen(k)) {
 352     st->print(" (null seen)");
 353   }
 354 }
 355 
 356 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
 357   for (int i = 0; i < _number_of_entries; i++) {
 358     _pd->tab(st);
 359     st->print("%d: stack(%u) ", i, stack_slot(i));
 360     print_klass(st, type(i));
 361     st->cr();
 362   }
 363 }
 364 
 365 void ReturnTypeEntry::print_data_on(outputStream* st) const {
 366   _pd->tab(st);
 367   print_klass(st, type());
 368   st->cr();
 369 }
 370 
 371 void CallTypeData::print_data_on(outputStream* st, const char* extra) const {
 372   CounterData::print_data_on(st, extra);
 373   if (has_arguments()) {
 374     tab(st, true);
 375     st->print("argument types");
 376     _args.print_data_on(st);
 377   }
 378   if (has_return()) {
 379     tab(st, true);
 380     st->print("return type");
 381     _ret.print_data_on(st);
 382   }
 383 }
 384 
 385 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {

 506 }
 507 
 508 // ==================================================================
 509 // BranchData
 510 //
 511 // A BranchData is used to access profiling data for a two-way branch.
 512 // It consists of taken and not_taken counts as well as a data displacement
 513 // for the taken case.
 514 
 515 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 516   assert(stream->bci() == bci(), "wrong pos");
 517   int target = stream->dest();
 518   int my_di = mdo->dp_to_di(dp());
 519   int target_di = mdo->bci_to_di(target);
 520   int offset = target_di - my_di;
 521   set_displacement(offset);
 522 }
 523 
 524 void BranchData::print_data_on(outputStream* st, const char* extra) const {
 525   print_shared(st, "BranchData", extra);




 526   st->print_cr("taken(%u) displacement(%d)",
 527                taken(), displacement());
 528   tab(st);
 529   st->print_cr("not taken(%u)", not_taken());
 530 }
 531 
 532 // ==================================================================
 533 // MultiBranchData
 534 //
 535 // A MultiBranchData is used to access profiling information for
 536 // a multi-way branch (*switch bytecodes).  It consists of a series
 537 // of (count, displacement) pairs, which count the number of times each
 538 // case was taken and specify the data displacement for each branch target.
 539 
 540 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
 541   int cell_count = 0;
 542   if (stream->code() == Bytecodes::_tableswitch) {
 543     Bytecode_tableswitch sw(stream->method()(), stream->bcp());
 544     cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default
 545   } else {

 631 }
 632 
 633 bool ParametersTypeData::profiling_enabled() {
 634   return MethodData::profile_parameters();
 635 }
 636 
 637 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
 638   print_shared(st, "ParametersTypeData", extra);
 639   tab(st);
 640   _parameters.print_data_on(st);
 641   st->cr();
 642 }
 643 
 644 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
 645   print_shared(st, "SpeculativeTrapData", extra);
 646   tab(st);
 647   method()->print_short_name(st);
 648   st->cr();
 649 }
 650 




































 651 // ==================================================================
 652 // MethodData*
 653 //
 654 // A MethodData* holds information which has been collected about
 655 // a method.
 656 
 657 MethodData* MethodData::allocate(ClassLoaderData* loader_data, const methodHandle& method, TRAPS) {
 658   assert(!THREAD->owns_locks(), "Should not own any locks");
 659   int size = MethodData::compute_allocation_size_in_words(method);
 660 
 661   return new (loader_data, size, MetaspaceObj::MethodDataType, THREAD)
 662     MethodData(method);
 663 }
 664 
 665 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 666   if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
 667     return no_profile_data;
 668   }
 669   switch (code) {
 670   case Bytecodes::_checkcast:
 671   case Bytecodes::_instanceof:
 672   case Bytecodes::_aastore:
 673     if (TypeProfileCasts) {
 674       return ReceiverTypeData::static_cell_count();
 675     } else {
 676       return BitData::static_cell_count();
 677     }




 678   case Bytecodes::_invokespecial:
 679   case Bytecodes::_invokestatic:
 680     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 681       return variable_cell_count;
 682     } else {
 683       return CounterData::static_cell_count();
 684     }
 685   case Bytecodes::_goto:
 686   case Bytecodes::_goto_w:
 687   case Bytecodes::_jsr:
 688   case Bytecodes::_jsr_w:
 689     return JumpData::static_cell_count();
 690   case Bytecodes::_invokevirtual:
 691   case Bytecodes::_invokeinterface:
 692     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 693       return variable_cell_count;
 694     } else {
 695       return VirtualCallData::static_cell_count();
 696     }
 697   case Bytecodes::_invokedynamic:
 698     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 699       return variable_cell_count;
 700     } else {
 701       return CounterData::static_cell_count();
 702     }
 703   case Bytecodes::_ret:
 704     return RetData::static_cell_count();
 705   case Bytecodes::_ifeq:
 706   case Bytecodes::_ifne:
 707   case Bytecodes::_iflt:
 708   case Bytecodes::_ifge:
 709   case Bytecodes::_ifgt:
 710   case Bytecodes::_ifle:
 711   case Bytecodes::_if_icmpeq:
 712   case Bytecodes::_if_icmpne:
 713   case Bytecodes::_if_icmplt:
 714   case Bytecodes::_if_icmpge:
 715   case Bytecodes::_if_icmpgt:
 716   case Bytecodes::_if_icmple:
 717   case Bytecodes::_if_acmpeq:
 718   case Bytecodes::_if_acmpne:
 719   case Bytecodes::_ifnull:
 720   case Bytecodes::_ifnonnull:
 721     return BranchData::static_cell_count();



 722   case Bytecodes::_lookupswitch:
 723   case Bytecodes::_tableswitch:
 724     return variable_cell_count;
 725   default:
 726     return no_profile_data;
 727   }
 728 }
 729 
 730 // Compute the size of the profiling information corresponding to
 731 // the current bytecode.
 732 int MethodData::compute_data_size(BytecodeStream* stream) {
 733   int cell_count = bytecode_cell_count(stream->code());
 734   if (cell_count == no_profile_data) {
 735     return 0;
 736   }
 737   if (cell_count == variable_cell_count) {
 738     switch (stream->code()) {
 739     case Bytecodes::_lookupswitch:
 740     case Bytecodes::_tableswitch:
 741       cell_count = MultiBranchData::compute_cell_count(stream);

 760       } else {
 761         cell_count = VirtualCallData::static_cell_count();
 762       }
 763       break;
 764     }
 765     default:
 766       fatal("unexpected bytecode for var length profile data");
 767     }
 768   }
 769   // Note:  cell_count might be zero, meaning that there is just
 770   //        a DataLayout header, with no extra cells.
 771   assert(cell_count >= 0, "sanity");
 772   return DataLayout::compute_size_in_bytes(cell_count);
 773 }
 774 
 775 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {
 776   // Bytecodes for which we may use speculation
 777   switch (code) {
 778   case Bytecodes::_checkcast:
 779   case Bytecodes::_instanceof:

 780   case Bytecodes::_aastore:
 781   case Bytecodes::_invokevirtual:
 782   case Bytecodes::_invokeinterface:
 783   case Bytecodes::_if_acmpeq:
 784   case Bytecodes::_if_acmpne:
 785   case Bytecodes::_ifnull:
 786   case Bytecodes::_ifnonnull:
 787   case Bytecodes::_invokestatic:
 788 #ifdef COMPILER2
 789     if (CompilerConfig::is_c2_enabled()) {
 790       return UseTypeSpeculation;
 791     }
 792 #endif
 793   default:
 794     return false;
 795   }
 796   return false;
 797 }
 798 
 799 #if INCLUDE_JVMCI

 973 int MethodData::compute_allocation_size_in_words(const methodHandle& method) {
 974   int byte_size = compute_allocation_size_in_bytes(method);
 975   int word_size = align_up(byte_size, BytesPerWord) / BytesPerWord;
 976   return align_metadata_size(word_size);
 977 }
 978 
 979 // Initialize an individual data segment.  Returns the size of
 980 // the segment in bytes.
 981 int MethodData::initialize_data(BytecodeStream* stream,
 982                                        int data_index) {
 983   if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
 984     return 0;
 985   }
 986   int cell_count = -1;
 987   u1 tag = DataLayout::no_tag;
 988   DataLayout* data_layout = data_layout_at(data_index);
 989   Bytecodes::Code c = stream->code();
 990   switch (c) {
 991   case Bytecodes::_checkcast:
 992   case Bytecodes::_instanceof:
 993   case Bytecodes::_aastore:
 994     if (TypeProfileCasts) {
 995       cell_count = ReceiverTypeData::static_cell_count();
 996       tag = DataLayout::receiver_type_data_tag;
 997     } else {
 998       cell_count = BitData::static_cell_count();
 999       tag = DataLayout::bit_data_tag;
1000     }
1001     break;








1002   case Bytecodes::_invokespecial:
1003   case Bytecodes::_invokestatic: {
1004     int counter_data_cell_count = CounterData::static_cell_count();
1005     if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
1006         profile_return_for_invoke(stream->method(), stream->bci())) {
1007       cell_count = CallTypeData::compute_cell_count(stream);
1008     } else {
1009       cell_count = counter_data_cell_count;
1010     }
1011     if (cell_count > counter_data_cell_count) {
1012       tag = DataLayout::call_type_data_tag;
1013     } else {
1014       tag = DataLayout::counter_data_tag;
1015     }
1016     break;
1017   }
1018   case Bytecodes::_goto:
1019   case Bytecodes::_goto_w:
1020   case Bytecodes::_jsr:
1021   case Bytecodes::_jsr_w:

1053       tag = DataLayout::counter_data_tag;
1054     }
1055     break;
1056   }
1057   case Bytecodes::_ret:
1058     cell_count = RetData::static_cell_count();
1059     tag = DataLayout::ret_data_tag;
1060     break;
1061   case Bytecodes::_ifeq:
1062   case Bytecodes::_ifne:
1063   case Bytecodes::_iflt:
1064   case Bytecodes::_ifge:
1065   case Bytecodes::_ifgt:
1066   case Bytecodes::_ifle:
1067   case Bytecodes::_if_icmpeq:
1068   case Bytecodes::_if_icmpne:
1069   case Bytecodes::_if_icmplt:
1070   case Bytecodes::_if_icmpge:
1071   case Bytecodes::_if_icmpgt:
1072   case Bytecodes::_if_icmple:
1073   case Bytecodes::_if_acmpeq:
1074   case Bytecodes::_if_acmpne:
1075   case Bytecodes::_ifnull:
1076   case Bytecodes::_ifnonnull:
1077     cell_count = BranchData::static_cell_count();
1078     tag = DataLayout::branch_data_tag;
1079     break;





1080   case Bytecodes::_lookupswitch:
1081   case Bytecodes::_tableswitch:
1082     cell_count = MultiBranchData::compute_cell_count(stream);
1083     tag = DataLayout::multi_branch_data_tag;
1084     break;
1085   default:
1086     break;
1087   }
1088   assert(tag == DataLayout::multi_branch_data_tag ||
1089          ((MethodData::profile_arguments() || MethodData::profile_return()) &&
1090           (tag == DataLayout::call_type_data_tag ||
1091            tag == DataLayout::counter_data_tag ||
1092            tag == DataLayout::virtual_call_type_data_tag ||
1093            tag == DataLayout::virtual_call_data_tag)) ||
1094          cell_count == bytecode_cell_count(c), "cell counts must agree");
1095   if (cell_count >= 0) {
1096     assert(tag != DataLayout::no_tag, "bad tag");
1097     assert(bytecode_has_profile(c), "agree w/ BHP");
1098     data_layout->initialize(tag, checked_cast<u2>(stream->bci()), cell_count);
1099     return DataLayout::compute_size_in_bytes(cell_count);

1127   case DataLayout::receiver_type_data_tag:
1128     return ReceiverTypeData::static_cell_count();
1129   case DataLayout::virtual_call_data_tag:
1130     return VirtualCallData::static_cell_count();
1131   case DataLayout::ret_data_tag:
1132     return RetData::static_cell_count();
1133   case DataLayout::branch_data_tag:
1134     return BranchData::static_cell_count();
1135   case DataLayout::multi_branch_data_tag:
1136     return ((new MultiBranchData(this))->cell_count());
1137   case DataLayout::arg_info_data_tag:
1138     return ((new ArgInfoData(this))->cell_count());
1139   case DataLayout::call_type_data_tag:
1140     return ((new CallTypeData(this))->cell_count());
1141   case DataLayout::virtual_call_type_data_tag:
1142     return ((new VirtualCallTypeData(this))->cell_count());
1143   case DataLayout::parameters_type_data_tag:
1144     return ((new ParametersTypeData(this))->cell_count());
1145   case DataLayout::speculative_trap_data_tag:
1146     return SpeculativeTrapData::static_cell_count();






1147   }
1148 }
1149 ProfileData* DataLayout::data_in() {
1150   switch (tag()) {
1151   case DataLayout::no_tag:
1152   default:
1153     ShouldNotReachHere();
1154     return nullptr;
1155   case DataLayout::bit_data_tag:
1156     return new BitData(this);
1157   case DataLayout::counter_data_tag:
1158     return new CounterData(this);
1159   case DataLayout::jump_data_tag:
1160     return new JumpData(this);
1161   case DataLayout::receiver_type_data_tag:
1162     return new ReceiverTypeData(this);
1163   case DataLayout::virtual_call_data_tag:
1164     return new VirtualCallData(this);
1165   case DataLayout::ret_data_tag:
1166     return new RetData(this);
1167   case DataLayout::branch_data_tag:
1168     return new BranchData(this);
1169   case DataLayout::multi_branch_data_tag:
1170     return new MultiBranchData(this);
1171   case DataLayout::arg_info_data_tag:
1172     return new ArgInfoData(this);
1173   case DataLayout::call_type_data_tag:
1174     return new CallTypeData(this);
1175   case DataLayout::virtual_call_type_data_tag:
1176     return new VirtualCallTypeData(this);
1177   case DataLayout::parameters_type_data_tag:
1178     return new ParametersTypeData(this);
1179   case DataLayout::speculative_trap_data_tag:
1180     return new SpeculativeTrapData(this);






1181   }
1182 }
1183 
1184 // Iteration over data.
1185 ProfileData* MethodData::next_data(ProfileData* current) const {
1186   int current_index = dp_to_di(current->dp());
1187   int next_index = current_index + current->size_in_bytes();
1188   ProfileData* next = data_at(next_index);
1189   return next;
1190 }
1191 
1192 DataLayout* MethodData::next_data_layout(DataLayout* current) const {
1193   int current_index = dp_to_di((address)current);
1194   int next_index = current_index + current->size_in_bytes();
1195   if (out_of_bounds(next_index)) {
1196     return nullptr;
1197   }
1198   DataLayout* next = data_layout_at(next_index);
1199   return next;
1200 }

 124 
 125 void ProfileData::print_data_on(outputStream* st, const MethodData* md) const {
 126   print_data_on(st, print_data_on_helper(md));
 127 }
 128 
 129 void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const {
 130   st->print("bci: %d ", bci());
 131   st->fill_to(tab_width_one + 1);
 132   st->print("%s", name);
 133   tab(st);
 134   int trap = trap_state();
 135   if (trap != 0) {
 136     char buf[100];
 137     st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
 138   }
 139   if (extra != nullptr) {
 140     st->print("%s", extra);
 141   }
 142   int flags = data()->flags();
 143   if (flags != 0) {
 144     st->print("flags(%d) %p/%d", flags, data(), in_bytes(DataLayout::flags_offset()));
 145   }
 146 }
 147 
 148 void ProfileData::tab(outputStream* st, bool first) const {
 149   st->fill_to(first ? tab_width_one : tab_width_two);
 150 }
 151 
 152 // ==================================================================
 153 // BitData
 154 //
 155 // A BitData corresponds to a one-bit flag.  This is used to indicate
 156 // whether a checkcast bytecode has seen a null value.
 157 
 158 
 159 void BitData::print_data_on(outputStream* st, const char* extra) const {
 160   print_shared(st, "BitData", extra);
 161   st->cr();
 162 }
 163 
 164 // ==================================================================

 194   set_displacement(offset);
 195 }
 196 
 197 void JumpData::print_data_on(outputStream* st, const char* extra) const {
 198   print_shared(st, "JumpData", extra);
 199   st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
 200 }
 201 
 202 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) {
 203   // Parameter profiling include the receiver
 204   int args_count = include_receiver ? 1 : 0;
 205   ResourceMark rm;
 206   ReferenceArgumentCount rac(signature);
 207   args_count += rac.count();
 208   args_count = MIN2(args_count, max);
 209   return args_count * per_arg_cell_count;
 210 }
 211 
 212 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {
 213   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 214   assert(TypeStackSlotEntries::per_arg_count() > SingleTypeEntry::static_cell_count(), "code to test for arguments/results broken");
 215   const methodHandle m = stream->method();
 216   int bci = stream->bci();
 217   Bytecode_invoke inv(m, bci);
 218   int args_cell = 0;
 219   if (MethodData::profile_arguments_for_invoke(m, bci)) {
 220     args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit);
 221   }
 222   int ret_cell = 0;
 223   if (MethodData::profile_return_for_invoke(m, bci) && is_reference_type(inv.result_type())) {
 224     ret_cell = SingleTypeEntry::static_cell_count();
 225   }
 226   int header_cell = 0;
 227   if (args_cell + ret_cell > 0) {
 228     header_cell = header_cell_count();
 229   }
 230 
 231   return header_cell + args_cell + ret_cell;
 232 }
 233 
 234 class ArgumentOffsetComputer : public SignatureIterator {
 235 private:
 236   int _max;
 237   int _offset;
 238   GrowableArray<int> _offsets;
 239 
 240   friend class SignatureIterator;  // so do_parameters_on can call do_type
 241   void do_type(BasicType type) {
 242     if (is_reference_type(type) && _offsets.length() < _max) {
 243       _offsets.push(_offset);
 244     }

 307 #endif
 308     _args.post_initialize(inv.signature(), inv.has_receiver(), false);
 309   }
 310 
 311   if (has_return()) {
 312     assert(is_reference_type(inv.result_type()), "room for a ret type but doesn't return obj?");
 313     _ret.post_initialize();
 314   }
 315 }
 316 
 317 void TypeStackSlotEntries::clean_weak_klass_links(bool always_clean) {
 318   for (int i = 0; i < _number_of_entries; i++) {
 319     intptr_t p = type(i);
 320     Klass* k = (Klass*)klass_part(p);
 321     if (k != nullptr && (always_clean || !k->is_loader_alive())) {
 322       set_type(i, with_status((Klass*)nullptr, p));
 323     }
 324   }
 325 }
 326 
 327 void SingleTypeEntry::clean_weak_klass_links(bool always_clean) {
 328   intptr_t p = type();
 329   Klass* k = (Klass*)klass_part(p);
 330   if (k != nullptr && (always_clean || !k->is_loader_alive())) {
 331     set_type(with_status((Klass*)nullptr, p));
 332   }
 333 }
 334 
 335 bool TypeEntriesAtCall::return_profiling_enabled() {
 336   return MethodData::profile_return();
 337 }
 338 
 339 bool TypeEntriesAtCall::arguments_profiling_enabled() {
 340   return MethodData::profile_arguments();
 341 }
 342 
 343 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
 344   if (is_type_none(k)) {
 345     st->print("none");
 346   } else if (is_type_unknown(k)) {
 347     st->print("unknown");
 348   } else {
 349     valid_klass(k)->print_value_on(st);
 350   }
 351   if (was_null_seen(k)) {
 352     st->print(" (null seen)");
 353   }
 354 }
 355 
 356 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
 357   for (int i = 0; i < _number_of_entries; i++) {
 358     _pd->tab(st);
 359     st->print("%d: stack(%u) ", i, stack_slot(i));
 360     print_klass(st, type(i));
 361     st->cr();
 362   }
 363 }
 364 
 365 void SingleTypeEntry::print_data_on(outputStream* st) const {
 366   _pd->tab(st);
 367   print_klass(st, type());
 368   st->cr();
 369 }
 370 
 371 void CallTypeData::print_data_on(outputStream* st, const char* extra) const {
 372   CounterData::print_data_on(st, extra);
 373   if (has_arguments()) {
 374     tab(st, true);
 375     st->print("argument types");
 376     _args.print_data_on(st);
 377   }
 378   if (has_return()) {
 379     tab(st, true);
 380     st->print("return type");
 381     _ret.print_data_on(st);
 382   }
 383 }
 384 
 385 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {

 506 }
 507 
 508 // ==================================================================
 509 // BranchData
 510 //
 511 // A BranchData is used to access profiling data for a two-way branch.
 512 // It consists of taken and not_taken counts as well as a data displacement
 513 // for the taken case.
 514 
 515 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 516   assert(stream->bci() == bci(), "wrong pos");
 517   int target = stream->dest();
 518   int my_di = mdo->dp_to_di(dp());
 519   int target_di = mdo->bci_to_di(target);
 520   int offset = target_di - my_di;
 521   set_displacement(offset);
 522 }
 523 
 524 void BranchData::print_data_on(outputStream* st, const char* extra) const {
 525   print_shared(st, "BranchData", extra);
 526   if (data()->flags()) {
 527     tty->cr();
 528     tab(st);
 529   }
 530   st->print_cr("taken(%u) displacement(%d)",
 531                taken(), displacement());
 532   tab(st);
 533   st->print_cr("not taken(%u)", not_taken());
 534 }
 535 
 536 // ==================================================================
 537 // MultiBranchData
 538 //
 539 // A MultiBranchData is used to access profiling information for
 540 // a multi-way branch (*switch bytecodes).  It consists of a series
 541 // of (count, displacement) pairs, which count the number of times each
 542 // case was taken and specify the data displacement for each branch target.
 543 
 544 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
 545   int cell_count = 0;
 546   if (stream->code() == Bytecodes::_tableswitch) {
 547     Bytecode_tableswitch sw(stream->method()(), stream->bcp());
 548     cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default
 549   } else {

 635 }
 636 
 637 bool ParametersTypeData::profiling_enabled() {
 638   return MethodData::profile_parameters();
 639 }
 640 
 641 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
 642   print_shared(st, "ParametersTypeData", extra);
 643   tab(st);
 644   _parameters.print_data_on(st);
 645   st->cr();
 646 }
 647 
 648 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
 649   print_shared(st, "SpeculativeTrapData", extra);
 650   tab(st);
 651   method()->print_short_name(st);
 652   st->cr();
 653 }
 654 
 655 void ArrayStoreData::print_data_on(outputStream* st, const char* extra) const {
 656   print_shared(st, "ArrayStore", extra);
 657   st->cr();
 658   tab(st, true);
 659   st->print("array");
 660   _array.print_data_on(st);
 661   tab(st, true);
 662   st->print("element");
 663   if (null_seen()) {
 664     st->print(" (null seen)");
 665   }
 666   tab(st);
 667   print_receiver_data_on(st);
 668 }
 669 
 670 void ArrayLoadData::print_data_on(outputStream* st, const char* extra) const {
 671   print_shared(st, "ArrayLoad", extra);
 672   st->cr();
 673   tab(st, true);
 674   st->print("array");
 675   _array.print_data_on(st);
 676   tab(st, true);
 677   st->print("element");
 678   _element.print_data_on(st);
 679 }
 680 
 681 void ACmpData::print_data_on(outputStream* st, const char* extra) const {
 682   BranchData::print_data_on(st, extra);
 683   tab(st, true);
 684   st->print("left");
 685   _left.print_data_on(st);
 686   tab(st, true);
 687   st->print("right");
 688   _right.print_data_on(st);
 689 }
 690 
 691 // ==================================================================
 692 // MethodData*
 693 //
 694 // A MethodData* holds information which has been collected about
 695 // a method.
 696 
 697 MethodData* MethodData::allocate(ClassLoaderData* loader_data, const methodHandle& method, TRAPS) {
 698   assert(!THREAD->owns_locks(), "Should not own any locks");
 699   int size = MethodData::compute_allocation_size_in_words(method);
 700 
 701   return new (loader_data, size, MetaspaceObj::MethodDataType, THREAD)
 702     MethodData(method);
 703 }
 704 
 705 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 706   if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
 707     return no_profile_data;
 708   }
 709   switch (code) {
 710   case Bytecodes::_checkcast:
 711   case Bytecodes::_instanceof:

 712     if (TypeProfileCasts) {
 713       return ReceiverTypeData::static_cell_count();
 714     } else {
 715       return BitData::static_cell_count();
 716     }
 717   case Bytecodes::_aaload:
 718     return ArrayLoadData::static_cell_count();
 719   case Bytecodes::_aastore:
 720     return ArrayStoreData::static_cell_count();
 721   case Bytecodes::_invokespecial:
 722   case Bytecodes::_invokestatic:
 723     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 724       return variable_cell_count;
 725     } else {
 726       return CounterData::static_cell_count();
 727     }
 728   case Bytecodes::_goto:
 729   case Bytecodes::_goto_w:
 730   case Bytecodes::_jsr:
 731   case Bytecodes::_jsr_w:
 732     return JumpData::static_cell_count();
 733   case Bytecodes::_invokevirtual:
 734   case Bytecodes::_invokeinterface:
 735     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 736       return variable_cell_count;
 737     } else {
 738       return VirtualCallData::static_cell_count();
 739     }
 740   case Bytecodes::_invokedynamic:
 741     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 742       return variable_cell_count;
 743     } else {
 744       return CounterData::static_cell_count();
 745     }
 746   case Bytecodes::_ret:
 747     return RetData::static_cell_count();
 748   case Bytecodes::_ifeq:
 749   case Bytecodes::_ifne:
 750   case Bytecodes::_iflt:
 751   case Bytecodes::_ifge:
 752   case Bytecodes::_ifgt:
 753   case Bytecodes::_ifle:
 754   case Bytecodes::_if_icmpeq:
 755   case Bytecodes::_if_icmpne:
 756   case Bytecodes::_if_icmplt:
 757   case Bytecodes::_if_icmpge:
 758   case Bytecodes::_if_icmpgt:
 759   case Bytecodes::_if_icmple:


 760   case Bytecodes::_ifnull:
 761   case Bytecodes::_ifnonnull:
 762     return BranchData::static_cell_count();
 763   case Bytecodes::_if_acmpne:
 764   case Bytecodes::_if_acmpeq:
 765     return ACmpData::static_cell_count();
 766   case Bytecodes::_lookupswitch:
 767   case Bytecodes::_tableswitch:
 768     return variable_cell_count;
 769   default:
 770     return no_profile_data;
 771   }
 772 }
 773 
 774 // Compute the size of the profiling information corresponding to
 775 // the current bytecode.
 776 int MethodData::compute_data_size(BytecodeStream* stream) {
 777   int cell_count = bytecode_cell_count(stream->code());
 778   if (cell_count == no_profile_data) {
 779     return 0;
 780   }
 781   if (cell_count == variable_cell_count) {
 782     switch (stream->code()) {
 783     case Bytecodes::_lookupswitch:
 784     case Bytecodes::_tableswitch:
 785       cell_count = MultiBranchData::compute_cell_count(stream);

 804       } else {
 805         cell_count = VirtualCallData::static_cell_count();
 806       }
 807       break;
 808     }
 809     default:
 810       fatal("unexpected bytecode for var length profile data");
 811     }
 812   }
 813   // Note:  cell_count might be zero, meaning that there is just
 814   //        a DataLayout header, with no extra cells.
 815   assert(cell_count >= 0, "sanity");
 816   return DataLayout::compute_size_in_bytes(cell_count);
 817 }
 818 
 819 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {
 820   // Bytecodes for which we may use speculation
 821   switch (code) {
 822   case Bytecodes::_checkcast:
 823   case Bytecodes::_instanceof:
 824   case Bytecodes::_aaload:
 825   case Bytecodes::_aastore:
 826   case Bytecodes::_invokevirtual:
 827   case Bytecodes::_invokeinterface:
 828   case Bytecodes::_if_acmpeq:
 829   case Bytecodes::_if_acmpne:
 830   case Bytecodes::_ifnull:
 831   case Bytecodes::_ifnonnull:
 832   case Bytecodes::_invokestatic:
 833 #ifdef COMPILER2
 834     if (CompilerConfig::is_c2_enabled()) {
 835       return UseTypeSpeculation;
 836     }
 837 #endif
 838   default:
 839     return false;
 840   }
 841   return false;
 842 }
 843 
 844 #if INCLUDE_JVMCI

1018 int MethodData::compute_allocation_size_in_words(const methodHandle& method) {
1019   int byte_size = compute_allocation_size_in_bytes(method);
1020   int word_size = align_up(byte_size, BytesPerWord) / BytesPerWord;
1021   return align_metadata_size(word_size);
1022 }
1023 
1024 // Initialize an individual data segment.  Returns the size of
1025 // the segment in bytes.
1026 int MethodData::initialize_data(BytecodeStream* stream,
1027                                        int data_index) {
1028   if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
1029     return 0;
1030   }
1031   int cell_count = -1;
1032   u1 tag = DataLayout::no_tag;
1033   DataLayout* data_layout = data_layout_at(data_index);
1034   Bytecodes::Code c = stream->code();
1035   switch (c) {
1036   case Bytecodes::_checkcast:
1037   case Bytecodes::_instanceof:

1038     if (TypeProfileCasts) {
1039       cell_count = ReceiverTypeData::static_cell_count();
1040       tag = DataLayout::receiver_type_data_tag;
1041     } else {
1042       cell_count = BitData::static_cell_count();
1043       tag = DataLayout::bit_data_tag;
1044     }
1045     break;
1046   case Bytecodes::_aaload:
1047     cell_count = ArrayLoadData::static_cell_count();
1048     tag = DataLayout::array_load_data_tag;
1049     break;
1050   case Bytecodes::_aastore:
1051     cell_count = ArrayStoreData::static_cell_count();
1052     tag = DataLayout::array_store_data_tag;
1053     break;
1054   case Bytecodes::_invokespecial:
1055   case Bytecodes::_invokestatic: {
1056     int counter_data_cell_count = CounterData::static_cell_count();
1057     if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
1058         profile_return_for_invoke(stream->method(), stream->bci())) {
1059       cell_count = CallTypeData::compute_cell_count(stream);
1060     } else {
1061       cell_count = counter_data_cell_count;
1062     }
1063     if (cell_count > counter_data_cell_count) {
1064       tag = DataLayout::call_type_data_tag;
1065     } else {
1066       tag = DataLayout::counter_data_tag;
1067     }
1068     break;
1069   }
1070   case Bytecodes::_goto:
1071   case Bytecodes::_goto_w:
1072   case Bytecodes::_jsr:
1073   case Bytecodes::_jsr_w:

1105       tag = DataLayout::counter_data_tag;
1106     }
1107     break;
1108   }
1109   case Bytecodes::_ret:
1110     cell_count = RetData::static_cell_count();
1111     tag = DataLayout::ret_data_tag;
1112     break;
1113   case Bytecodes::_ifeq:
1114   case Bytecodes::_ifne:
1115   case Bytecodes::_iflt:
1116   case Bytecodes::_ifge:
1117   case Bytecodes::_ifgt:
1118   case Bytecodes::_ifle:
1119   case Bytecodes::_if_icmpeq:
1120   case Bytecodes::_if_icmpne:
1121   case Bytecodes::_if_icmplt:
1122   case Bytecodes::_if_icmpge:
1123   case Bytecodes::_if_icmpgt:
1124   case Bytecodes::_if_icmple:


1125   case Bytecodes::_ifnull:
1126   case Bytecodes::_ifnonnull:
1127     cell_count = BranchData::static_cell_count();
1128     tag = DataLayout::branch_data_tag;
1129     break;
1130   case Bytecodes::_if_acmpeq:
1131   case Bytecodes::_if_acmpne:
1132     cell_count = ACmpData::static_cell_count();
1133     tag = DataLayout::acmp_data_tag;
1134     break;
1135   case Bytecodes::_lookupswitch:
1136   case Bytecodes::_tableswitch:
1137     cell_count = MultiBranchData::compute_cell_count(stream);
1138     tag = DataLayout::multi_branch_data_tag;
1139     break;
1140   default:
1141     break;
1142   }
1143   assert(tag == DataLayout::multi_branch_data_tag ||
1144          ((MethodData::profile_arguments() || MethodData::profile_return()) &&
1145           (tag == DataLayout::call_type_data_tag ||
1146            tag == DataLayout::counter_data_tag ||
1147            tag == DataLayout::virtual_call_type_data_tag ||
1148            tag == DataLayout::virtual_call_data_tag)) ||
1149          cell_count == bytecode_cell_count(c), "cell counts must agree");
1150   if (cell_count >= 0) {
1151     assert(tag != DataLayout::no_tag, "bad tag");
1152     assert(bytecode_has_profile(c), "agree w/ BHP");
1153     data_layout->initialize(tag, checked_cast<u2>(stream->bci()), cell_count);
1154     return DataLayout::compute_size_in_bytes(cell_count);

1182   case DataLayout::receiver_type_data_tag:
1183     return ReceiverTypeData::static_cell_count();
1184   case DataLayout::virtual_call_data_tag:
1185     return VirtualCallData::static_cell_count();
1186   case DataLayout::ret_data_tag:
1187     return RetData::static_cell_count();
1188   case DataLayout::branch_data_tag:
1189     return BranchData::static_cell_count();
1190   case DataLayout::multi_branch_data_tag:
1191     return ((new MultiBranchData(this))->cell_count());
1192   case DataLayout::arg_info_data_tag:
1193     return ((new ArgInfoData(this))->cell_count());
1194   case DataLayout::call_type_data_tag:
1195     return ((new CallTypeData(this))->cell_count());
1196   case DataLayout::virtual_call_type_data_tag:
1197     return ((new VirtualCallTypeData(this))->cell_count());
1198   case DataLayout::parameters_type_data_tag:
1199     return ((new ParametersTypeData(this))->cell_count());
1200   case DataLayout::speculative_trap_data_tag:
1201     return SpeculativeTrapData::static_cell_count();
1202   case DataLayout::array_store_data_tag:
1203     return ((new ArrayStoreData(this))->cell_count());
1204   case DataLayout::array_load_data_tag:
1205     return ((new ArrayLoadData(this))->cell_count());
1206   case DataLayout::acmp_data_tag:
1207     return ((new ACmpData(this))->cell_count());
1208   }
1209 }
1210 ProfileData* DataLayout::data_in() {
1211   switch (tag()) {
1212   case DataLayout::no_tag:
1213   default:
1214     ShouldNotReachHere();
1215     return nullptr;
1216   case DataLayout::bit_data_tag:
1217     return new BitData(this);
1218   case DataLayout::counter_data_tag:
1219     return new CounterData(this);
1220   case DataLayout::jump_data_tag:
1221     return new JumpData(this);
1222   case DataLayout::receiver_type_data_tag:
1223     return new ReceiverTypeData(this);
1224   case DataLayout::virtual_call_data_tag:
1225     return new VirtualCallData(this);
1226   case DataLayout::ret_data_tag:
1227     return new RetData(this);
1228   case DataLayout::branch_data_tag:
1229     return new BranchData(this);
1230   case DataLayout::multi_branch_data_tag:
1231     return new MultiBranchData(this);
1232   case DataLayout::arg_info_data_tag:
1233     return new ArgInfoData(this);
1234   case DataLayout::call_type_data_tag:
1235     return new CallTypeData(this);
1236   case DataLayout::virtual_call_type_data_tag:
1237     return new VirtualCallTypeData(this);
1238   case DataLayout::parameters_type_data_tag:
1239     return new ParametersTypeData(this);
1240   case DataLayout::speculative_trap_data_tag:
1241     return new SpeculativeTrapData(this);
1242   case DataLayout::array_store_data_tag:
1243     return new ArrayStoreData(this);
1244   case DataLayout::array_load_data_tag:
1245     return new ArrayLoadData(this);
1246   case DataLayout::acmp_data_tag:
1247     return new ACmpData(this);
1248   }
1249 }
1250 
1251 // Iteration over data.
1252 ProfileData* MethodData::next_data(ProfileData* current) const {
1253   int current_index = dp_to_di(current->dp());
1254   int next_index = current_index + current->size_in_bytes();
1255   ProfileData* next = data_at(next_index);
1256   return next;
1257 }
1258 
1259 DataLayout* MethodData::next_data_layout(DataLayout* current) const {
1260   int current_index = dp_to_di((address)current);
1261   int next_index = current_index + current->size_in_bytes();
1262   if (out_of_bounds(next_index)) {
1263     return nullptr;
1264   }
1265   DataLayout* next = data_layout_at(next_index);
1266   return next;
1267 }
< prev index next >