< prev index next >

src/hotspot/share/oops/methodData.cpp

Print this page

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

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

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

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




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

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




































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




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



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

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

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

 978 
 979 // Compute the size of the MethodData* necessary to store
 980 // profiling information about a given method.  Size is in words
 981 int MethodData::compute_allocation_size_in_words(const methodHandle& method) {
 982   int byte_size = compute_allocation_size_in_bytes(method);
 983   int word_size = align_up(byte_size, BytesPerWord) / BytesPerWord;
 984   return align_metadata_size(word_size);
 985 }
 986 
 987 // Initialize an individual data segment.  Returns the size of
 988 // the segment in bytes.
 989 int MethodData::initialize_data(BytecodeStream* stream,
 990                                        int data_index) {
 991   int cell_count = -1;
 992   u1 tag = DataLayout::no_tag;
 993   DataLayout* data_layout = data_layout_at(data_index);
 994   Bytecodes::Code c = stream->code();
 995   switch (c) {
 996   case Bytecodes::_checkcast:
 997   case Bytecodes::_instanceof:
 998   case Bytecodes::_aastore:
 999     if (TypeProfileCasts) {
1000       cell_count = ReceiverTypeData::static_cell_count();
1001       tag = DataLayout::receiver_type_data_tag;
1002     } else {
1003       cell_count = BitData::static_cell_count();
1004       tag = DataLayout::bit_data_tag;
1005     }
1006     break;








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

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





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

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






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






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

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

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

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

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

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

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


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

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

1023 
1024 // Compute the size of the MethodData* necessary to store
1025 // profiling information about a given method.  Size is in words
1026 int MethodData::compute_allocation_size_in_words(const methodHandle& method) {
1027   int byte_size = compute_allocation_size_in_bytes(method);
1028   int word_size = align_up(byte_size, BytesPerWord) / BytesPerWord;
1029   return align_metadata_size(word_size);
1030 }
1031 
1032 // Initialize an individual data segment.  Returns the size of
1033 // the segment in bytes.
1034 int MethodData::initialize_data(BytecodeStream* stream,
1035                                        int data_index) {
1036   int cell_count = -1;
1037   u1 tag = DataLayout::no_tag;
1038   DataLayout* data_layout = data_layout_at(data_index);
1039   Bytecodes::Code c = stream->code();
1040   switch (c) {
1041   case Bytecodes::_checkcast:
1042   case Bytecodes::_instanceof:

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

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


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

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