< prev index next >

src/hotspot/share/oops/methodData.cpp

Print this page

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

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

 340     intptr_t p = type(i);
 341     Klass* k = (Klass*)klass_part(p);
 342     if (k != nullptr) {
 343       if (!always_clean && k->is_instance_klass() && InstanceKlass::cast(k)->is_not_initialized()) {
 344         continue; // skip not-yet-initialized classes // TODO: maybe clear the slot instead?
 345       }
 346       if (always_clean || !k->is_loader_present_and_alive() || is_excluded(k)) {
 347         set_type(i, with_status((Klass*)nullptr, p));
 348       }
 349     }
 350   }
 351 }
 352 
 353 void TypeStackSlotEntries::metaspace_pointers_do(MetaspaceClosure* it) {
 354   for (int i = 0; i < _number_of_entries; i++) {
 355     Klass** k = (Klass**)type_adr(i); // tagged
 356     it->push(k);
 357   }
 358 }
 359 
 360 void ReturnTypeEntry::clean_weak_klass_links(bool always_clean) {
 361   intptr_t p = type();
 362   Klass* k = (Klass*)klass_part(p);
 363   if (k != nullptr) {
 364     if (!always_clean && k->is_instance_klass() && InstanceKlass::cast(k)->is_not_initialized()) {
 365       return; // skip not-yet-initialized classes // TODO: maybe clear the slot instead?
 366     }
 367     if (always_clean || !k->is_loader_present_and_alive() || is_excluded(k)) {
 368       set_type(with_status((Klass*)nullptr, p));
 369     }
 370   }
 371 }
 372 
 373 void ReturnTypeEntry::metaspace_pointers_do(MetaspaceClosure* it) {
 374   Klass** k = (Klass**)type_adr(); // tagged
 375   it->push(k);
 376 }
 377 
 378 bool TypeEntriesAtCall::return_profiling_enabled() {
 379   return MethodData::profile_return();
 380 }
 381 
 382 bool TypeEntriesAtCall::arguments_profiling_enabled() {
 383   return MethodData::profile_arguments();
 384 }
 385 
 386 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
 387   if (is_type_none(k)) {
 388     st->print("none");
 389   } else if (is_type_unknown(k)) {
 390     st->print("unknown");
 391   } else {
 392     valid_klass(k)->print_value_on(st);
 393   }
 394   if (was_null_seen(k)) {
 395     st->print(" (null seen)");
 396   }
 397 }
 398 
 399 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
 400   for (int i = 0; i < _number_of_entries; i++) {
 401     _pd->tab(st);
 402     st->print("%d: stack(%u) ", i, stack_slot(i));
 403     print_klass(st, type(i));
 404     st->cr();
 405   }
 406 }
 407 
 408 void ReturnTypeEntry::print_data_on(outputStream* st) const {
 409   _pd->tab(st);
 410   print_klass(st, type());
 411   st->cr();
 412 }
 413 
 414 void CallTypeData::print_data_on(outputStream* st, const char* extra) const {
 415   CounterData::print_data_on(st, extra);
 416   if (has_arguments()) {
 417     tab(st, true);
 418     st->print("argument types");
 419     _args.print_data_on(st);
 420   }
 421   if (has_return()) {
 422     tab(st, true);
 423     st->print("return type");
 424     _ret.print_data_on(st);
 425   }
 426 }
 427 
 428 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {

 561 }
 562 
 563 // ==================================================================
 564 // BranchData
 565 //
 566 // A BranchData is used to access profiling data for a two-way branch.
 567 // It consists of taken and not_taken counts as well as a data displacement
 568 // for the taken case.
 569 
 570 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 571   assert(stream->bci() == bci(), "wrong pos");
 572   int target = stream->dest();
 573   int my_di = mdo->dp_to_di(dp());
 574   int target_di = mdo->bci_to_di(target);
 575   int offset = target_di - my_di;
 576   set_displacement(offset);
 577 }
 578 
 579 void BranchData::print_data_on(outputStream* st, const char* extra) const {
 580   print_shared(st, "BranchData", extra);




 581   st->print_cr("taken(%u) displacement(%d)",
 582                taken(), displacement());
 583   tab(st);
 584   st->print_cr("not taken(%u)", not_taken());
 585 }
 586 
 587 // ==================================================================
 588 // MultiBranchData
 589 //
 590 // A MultiBranchData is used to access profiling information for
 591 // a multi-way branch (*switch bytecodes).  It consists of a series
 592 // of (count, displacement) pairs, which count the number of times each
 593 // case was taken and specify the data displacement for each branch target.
 594 
 595 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
 596   int cell_count = 0;
 597   if (stream->code() == Bytecodes::_tableswitch) {
 598     Bytecode_tableswitch sw(stream->method()(), stream->bcp());
 599     cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default
 600   } else {

 691 
 692 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
 693   print_shared(st, "ParametersTypeData", extra);
 694   tab(st);
 695   _parameters.print_data_on(st);
 696   st->cr();
 697 }
 698 
 699 void SpeculativeTrapData::metaspace_pointers_do(MetaspaceClosure* it) {
 700   Method** m = (Method**)intptr_at_adr(speculative_trap_method);
 701   it->push(m);
 702 }
 703 
 704 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
 705   print_shared(st, "SpeculativeTrapData", extra);
 706   tab(st);
 707   method()->print_short_name(st);
 708   st->cr();
 709 }
 710 




































 711 // ==================================================================
 712 // MethodData*
 713 //
 714 // A MethodData* holds information which has been collected about
 715 // a method.
 716 
 717 MethodData* MethodData::allocate(ClassLoaderData* loader_data, const methodHandle& method, TRAPS) {
 718   assert(!THREAD->owns_locks(), "Should not own any locks");
 719   int size = MethodData::compute_allocation_size_in_words(method);
 720 
 721   return new (loader_data, size, MetaspaceObj::MethodDataType, THREAD)
 722     MethodData(method);
 723 }
 724 
 725 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 726   switch (code) {
 727   case Bytecodes::_checkcast:
 728   case Bytecodes::_instanceof:
 729   case Bytecodes::_aastore:
 730     if (TypeProfileCasts) {
 731       return ReceiverTypeData::static_cell_count();
 732     } else {
 733       return BitData::static_cell_count();
 734     }




 735   case Bytecodes::_invokespecial:
 736   case Bytecodes::_invokestatic:
 737     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 738       return variable_cell_count;
 739     } else {
 740       return CounterData::static_cell_count();
 741     }
 742   case Bytecodes::_goto:
 743   case Bytecodes::_goto_w:
 744   case Bytecodes::_jsr:
 745   case Bytecodes::_jsr_w:
 746     return JumpData::static_cell_count();
 747   case Bytecodes::_invokevirtual:
 748   case Bytecodes::_invokeinterface:
 749     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 750       return variable_cell_count;
 751     } else {
 752       return VirtualCallData::static_cell_count();
 753     }
 754   case Bytecodes::_invokedynamic:
 755     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 756       return variable_cell_count;
 757     } else {
 758       return CounterData::static_cell_count();
 759     }
 760   case Bytecodes::_ret:
 761     return RetData::static_cell_count();
 762   case Bytecodes::_ifeq:
 763   case Bytecodes::_ifne:
 764   case Bytecodes::_iflt:
 765   case Bytecodes::_ifge:
 766   case Bytecodes::_ifgt:
 767   case Bytecodes::_ifle:
 768   case Bytecodes::_if_icmpeq:
 769   case Bytecodes::_if_icmpne:
 770   case Bytecodes::_if_icmplt:
 771   case Bytecodes::_if_icmpge:
 772   case Bytecodes::_if_icmpgt:
 773   case Bytecodes::_if_icmple:
 774   case Bytecodes::_if_acmpeq:
 775   case Bytecodes::_if_acmpne:
 776   case Bytecodes::_ifnull:
 777   case Bytecodes::_ifnonnull:
 778     return BranchData::static_cell_count();



 779   case Bytecodes::_lookupswitch:
 780   case Bytecodes::_tableswitch:
 781     return variable_cell_count;
 782   default:
 783     return no_profile_data;
 784   }
 785 }
 786 
 787 // Compute the size of the profiling information corresponding to
 788 // the current bytecode.
 789 int MethodData::compute_data_size(BytecodeStream* stream) {
 790   int cell_count = bytecode_cell_count(stream->code());
 791   if (cell_count == no_profile_data) {
 792     return 0;
 793   }
 794   if (cell_count == variable_cell_count) {
 795     switch (stream->code()) {
 796     case Bytecodes::_lookupswitch:
 797     case Bytecodes::_tableswitch:
 798       cell_count = MultiBranchData::compute_cell_count(stream);

 817       } else {
 818         cell_count = VirtualCallData::static_cell_count();
 819       }
 820       break;
 821     }
 822     default:
 823       fatal("unexpected bytecode for var length profile data");
 824     }
 825   }
 826   // Note:  cell_count might be zero, meaning that there is just
 827   //        a DataLayout header, with no extra cells.
 828   assert(cell_count >= 0, "sanity");
 829   return DataLayout::compute_size_in_bytes(cell_count);
 830 }
 831 
 832 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {
 833   // Bytecodes for which we may use speculation
 834   switch (code) {
 835   case Bytecodes::_checkcast:
 836   case Bytecodes::_instanceof:

 837   case Bytecodes::_aastore:
 838   case Bytecodes::_invokevirtual:
 839   case Bytecodes::_invokeinterface:
 840   case Bytecodes::_if_acmpeq:
 841   case Bytecodes::_if_acmpne:
 842   case Bytecodes::_ifnull:
 843   case Bytecodes::_ifnonnull:
 844   case Bytecodes::_invokestatic:
 845 #ifdef COMPILER2
 846     if (CompilerConfig::is_c2_enabled()) {
 847       return UseTypeSpeculation;
 848     }
 849 #endif
 850   default:
 851     return false;
 852   }
 853   return false;
 854 }
 855 
 856 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {

 924 
 925 // Compute the size of the MethodData* necessary to store
 926 // profiling information about a given method.  Size is in words
 927 int MethodData::compute_allocation_size_in_words(const methodHandle& method) {
 928   int byte_size = compute_allocation_size_in_bytes(method);
 929   int word_size = align_up(byte_size, BytesPerWord) / BytesPerWord;
 930   return align_metadata_size(word_size);
 931 }
 932 
 933 // Initialize an individual data segment.  Returns the size of
 934 // the segment in bytes.
 935 int MethodData::initialize_data(BytecodeStream* stream,
 936                                        int data_index) {
 937   int cell_count = -1;
 938   u1 tag = DataLayout::no_tag;
 939   DataLayout* data_layout = data_layout_at(data_index);
 940   Bytecodes::Code c = stream->code();
 941   switch (c) {
 942   case Bytecodes::_checkcast:
 943   case Bytecodes::_instanceof:
 944   case Bytecodes::_aastore:
 945     if (TypeProfileCasts) {
 946       cell_count = ReceiverTypeData::static_cell_count();
 947       tag = DataLayout::receiver_type_data_tag;
 948     } else {
 949       cell_count = BitData::static_cell_count();
 950       tag = DataLayout::bit_data_tag;
 951     }
 952     break;








 953   case Bytecodes::_invokespecial:
 954   case Bytecodes::_invokestatic: {
 955     int counter_data_cell_count = CounterData::static_cell_count();
 956     if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
 957         profile_return_for_invoke(stream->method(), stream->bci())) {
 958       cell_count = CallTypeData::compute_cell_count(stream);
 959     } else {
 960       cell_count = counter_data_cell_count;
 961     }
 962     if (cell_count > counter_data_cell_count) {
 963       tag = DataLayout::call_type_data_tag;
 964     } else {
 965       tag = DataLayout::counter_data_tag;
 966     }
 967     break;
 968   }
 969   case Bytecodes::_goto:
 970   case Bytecodes::_goto_w:
 971   case Bytecodes::_jsr:
 972   case Bytecodes::_jsr_w:

1004       tag = DataLayout::counter_data_tag;
1005     }
1006     break;
1007   }
1008   case Bytecodes::_ret:
1009     cell_count = RetData::static_cell_count();
1010     tag = DataLayout::ret_data_tag;
1011     break;
1012   case Bytecodes::_ifeq:
1013   case Bytecodes::_ifne:
1014   case Bytecodes::_iflt:
1015   case Bytecodes::_ifge:
1016   case Bytecodes::_ifgt:
1017   case Bytecodes::_ifle:
1018   case Bytecodes::_if_icmpeq:
1019   case Bytecodes::_if_icmpne:
1020   case Bytecodes::_if_icmplt:
1021   case Bytecodes::_if_icmpge:
1022   case Bytecodes::_if_icmpgt:
1023   case Bytecodes::_if_icmple:
1024   case Bytecodes::_if_acmpeq:
1025   case Bytecodes::_if_acmpne:
1026   case Bytecodes::_ifnull:
1027   case Bytecodes::_ifnonnull:
1028     cell_count = BranchData::static_cell_count();
1029     tag = DataLayout::branch_data_tag;
1030     break;





1031   case Bytecodes::_lookupswitch:
1032   case Bytecodes::_tableswitch:
1033     cell_count = MultiBranchData::compute_cell_count(stream);
1034     tag = DataLayout::multi_branch_data_tag;
1035     break;
1036   default:
1037     break;
1038   }
1039   assert(tag == DataLayout::multi_branch_data_tag ||
1040          ((MethodData::profile_arguments() || MethodData::profile_return()) &&
1041           (tag == DataLayout::call_type_data_tag ||
1042            tag == DataLayout::counter_data_tag ||
1043            tag == DataLayout::virtual_call_type_data_tag ||
1044            tag == DataLayout::virtual_call_data_tag)) ||
1045          cell_count == bytecode_cell_count(c), "cell counts must agree");
1046   if (cell_count >= 0) {
1047     assert(tag != DataLayout::no_tag, "bad tag");
1048     assert(bytecode_has_profile(c), "agree w/ BHP");
1049     data_layout->initialize(tag, checked_cast<u2>(stream->bci()), cell_count);
1050     return DataLayout::compute_size_in_bytes(cell_count);

1078   case DataLayout::receiver_type_data_tag:
1079     return ReceiverTypeData::static_cell_count();
1080   case DataLayout::virtual_call_data_tag:
1081     return VirtualCallData::static_cell_count();
1082   case DataLayout::ret_data_tag:
1083     return RetData::static_cell_count();
1084   case DataLayout::branch_data_tag:
1085     return BranchData::static_cell_count();
1086   case DataLayout::multi_branch_data_tag:
1087     return ((new MultiBranchData(this))->cell_count());
1088   case DataLayout::arg_info_data_tag:
1089     return ((new ArgInfoData(this))->cell_count());
1090   case DataLayout::call_type_data_tag:
1091     return ((new CallTypeData(this))->cell_count());
1092   case DataLayout::virtual_call_type_data_tag:
1093     return ((new VirtualCallTypeData(this))->cell_count());
1094   case DataLayout::parameters_type_data_tag:
1095     return ((new ParametersTypeData(this))->cell_count());
1096   case DataLayout::speculative_trap_data_tag:
1097     return SpeculativeTrapData::static_cell_count();






1098   }
1099 }
1100 ProfileData* DataLayout::data_in() {
1101   switch (tag()) {
1102   case DataLayout::no_tag:
1103   default:
1104     ShouldNotReachHere();
1105     return nullptr;
1106   case DataLayout::bit_data_tag:
1107     return new BitData(this);
1108   case DataLayout::counter_data_tag:
1109     return new CounterData(this);
1110   case DataLayout::jump_data_tag:
1111     return new JumpData(this);
1112   case DataLayout::receiver_type_data_tag:
1113     return new ReceiverTypeData(this);
1114   case DataLayout::virtual_call_data_tag:
1115     return new VirtualCallData(this);
1116   case DataLayout::ret_data_tag:
1117     return new RetData(this);
1118   case DataLayout::branch_data_tag:
1119     return new BranchData(this);
1120   case DataLayout::multi_branch_data_tag:
1121     return new MultiBranchData(this);
1122   case DataLayout::arg_info_data_tag:
1123     return new ArgInfoData(this);
1124   case DataLayout::call_type_data_tag:
1125     return new CallTypeData(this);
1126   case DataLayout::virtual_call_type_data_tag:
1127     return new VirtualCallTypeData(this);
1128   case DataLayout::parameters_type_data_tag:
1129     return new ParametersTypeData(this);
1130   case DataLayout::speculative_trap_data_tag:
1131     return new SpeculativeTrapData(this);






1132   }
1133 }
1134 
1135 // Iteration over data.
1136 ProfileData* MethodData::next_data(ProfileData* current) const {
1137   int current_index = dp_to_di(current->dp());
1138   int next_index = current_index + current->size_in_bytes();
1139   ProfileData* next = data_at(next_index);
1140   return next;
1141 }
1142 
1143 DataLayout* MethodData::next_data_layout(DataLayout* current) const {
1144   int current_index = dp_to_di((address)current);
1145   int next_index = current_index + current->size_in_bytes();
1146   if (out_of_bounds(next_index)) {
1147     return nullptr;
1148   }
1149   DataLayout* next = data_layout_at(next_index);
1150   return next;
1151 }

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

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

 340     intptr_t p = type(i);
 341     Klass* k = (Klass*)klass_part(p);
 342     if (k != nullptr) {
 343       if (!always_clean && k->is_instance_klass() && InstanceKlass::cast(k)->is_not_initialized()) {
 344         continue; // skip not-yet-initialized classes // TODO: maybe clear the slot instead?
 345       }
 346       if (always_clean || !k->is_loader_present_and_alive() || is_excluded(k)) {
 347         set_type(i, with_status((Klass*)nullptr, p));
 348       }
 349     }
 350   }
 351 }
 352 
 353 void TypeStackSlotEntries::metaspace_pointers_do(MetaspaceClosure* it) {
 354   for (int i = 0; i < _number_of_entries; i++) {
 355     Klass** k = (Klass**)type_adr(i); // tagged
 356     it->push(k);
 357   }
 358 }
 359 
 360 void SingleTypeEntry::clean_weak_klass_links(bool always_clean) {
 361   intptr_t p = type();
 362   Klass* k = (Klass*)klass_part(p);
 363   if (k != nullptr) {
 364     if (!always_clean && k->is_instance_klass() && InstanceKlass::cast(k)->is_not_initialized()) {
 365       return; // skip not-yet-initialized classes // TODO: maybe clear the slot instead?
 366     }
 367     if (always_clean || !k->is_loader_present_and_alive() || is_excluded(k)) {
 368       set_type(with_status((Klass*)nullptr, p));
 369     }
 370   }
 371 }
 372 
 373 void SingleTypeEntry::metaspace_pointers_do(MetaspaceClosure* it) {
 374   Klass** k = (Klass**)type_adr(); // tagged
 375   it->push(k);
 376 }
 377 
 378 bool TypeEntriesAtCall::return_profiling_enabled() {
 379   return MethodData::profile_return();
 380 }
 381 
 382 bool TypeEntriesAtCall::arguments_profiling_enabled() {
 383   return MethodData::profile_arguments();
 384 }
 385 
 386 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
 387   if (is_type_none(k)) {
 388     st->print("none");
 389   } else if (is_type_unknown(k)) {
 390     st->print("unknown");
 391   } else {
 392     valid_klass(k)->print_value_on(st);
 393   }
 394   if (was_null_seen(k)) {
 395     st->print(" (null seen)");
 396   }
 397 }
 398 
 399 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
 400   for (int i = 0; i < _number_of_entries; i++) {
 401     _pd->tab(st);
 402     st->print("%d: stack(%u) ", i, stack_slot(i));
 403     print_klass(st, type(i));
 404     st->cr();
 405   }
 406 }
 407 
 408 void SingleTypeEntry::print_data_on(outputStream* st) const {
 409   _pd->tab(st);
 410   print_klass(st, type());
 411   st->cr();
 412 }
 413 
 414 void CallTypeData::print_data_on(outputStream* st, const char* extra) const {
 415   CounterData::print_data_on(st, extra);
 416   if (has_arguments()) {
 417     tab(st, true);
 418     st->print("argument types");
 419     _args.print_data_on(st);
 420   }
 421   if (has_return()) {
 422     tab(st, true);
 423     st->print("return type");
 424     _ret.print_data_on(st);
 425   }
 426 }
 427 
 428 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {

 561 }
 562 
 563 // ==================================================================
 564 // BranchData
 565 //
 566 // A BranchData is used to access profiling data for a two-way branch.
 567 // It consists of taken and not_taken counts as well as a data displacement
 568 // for the taken case.
 569 
 570 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 571   assert(stream->bci() == bci(), "wrong pos");
 572   int target = stream->dest();
 573   int my_di = mdo->dp_to_di(dp());
 574   int target_di = mdo->bci_to_di(target);
 575   int offset = target_di - my_di;
 576   set_displacement(offset);
 577 }
 578 
 579 void BranchData::print_data_on(outputStream* st, const char* extra) const {
 580   print_shared(st, "BranchData", extra);
 581   if (data()->flags()) {
 582     st->cr();
 583     tab(st);
 584   }
 585   st->print_cr("taken(%u) displacement(%d)",
 586                taken(), displacement());
 587   tab(st);
 588   st->print_cr("not taken(%u)", not_taken());
 589 }
 590 
 591 // ==================================================================
 592 // MultiBranchData
 593 //
 594 // A MultiBranchData is used to access profiling information for
 595 // a multi-way branch (*switch bytecodes).  It consists of a series
 596 // of (count, displacement) pairs, which count the number of times each
 597 // case was taken and specify the data displacement for each branch target.
 598 
 599 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
 600   int cell_count = 0;
 601   if (stream->code() == Bytecodes::_tableswitch) {
 602     Bytecode_tableswitch sw(stream->method()(), stream->bcp());
 603     cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default
 604   } else {

 695 
 696 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
 697   print_shared(st, "ParametersTypeData", extra);
 698   tab(st);
 699   _parameters.print_data_on(st);
 700   st->cr();
 701 }
 702 
 703 void SpeculativeTrapData::metaspace_pointers_do(MetaspaceClosure* it) {
 704   Method** m = (Method**)intptr_at_adr(speculative_trap_method);
 705   it->push(m);
 706 }
 707 
 708 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
 709   print_shared(st, "SpeculativeTrapData", extra);
 710   tab(st);
 711   method()->print_short_name(st);
 712   st->cr();
 713 }
 714 
 715 void ArrayStoreData::print_data_on(outputStream* st, const char* extra) const {
 716   print_shared(st, "ArrayStore", extra);
 717   st->cr();
 718   tab(st, true);
 719   st->print("array");
 720   _array.print_data_on(st);
 721   tab(st, true);
 722   st->print("element");
 723   if (null_seen()) {
 724     st->print(" (null seen)");
 725   }
 726   tab(st);
 727   print_receiver_data_on(st);
 728 }
 729 
 730 void ArrayLoadData::print_data_on(outputStream* st, const char* extra) const {
 731   print_shared(st, "ArrayLoad", extra);
 732   st->cr();
 733   tab(st, true);
 734   st->print("array");
 735   _array.print_data_on(st);
 736   tab(st, true);
 737   st->print("element");
 738   _element.print_data_on(st);
 739 }
 740 
 741 void ACmpData::print_data_on(outputStream* st, const char* extra) const {
 742   BranchData::print_data_on(st, extra);
 743   tab(st, true);
 744   st->print("left");
 745   _left.print_data_on(st);
 746   tab(st, true);
 747   st->print("right");
 748   _right.print_data_on(st);
 749 }
 750 
 751 // ==================================================================
 752 // MethodData*
 753 //
 754 // A MethodData* holds information which has been collected about
 755 // a method.
 756 
 757 MethodData* MethodData::allocate(ClassLoaderData* loader_data, const methodHandle& method, TRAPS) {
 758   assert(!THREAD->owns_locks(), "Should not own any locks");
 759   int size = MethodData::compute_allocation_size_in_words(method);
 760 
 761   return new (loader_data, size, MetaspaceObj::MethodDataType, THREAD)
 762     MethodData(method);
 763 }
 764 
 765 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 766   switch (code) {
 767   case Bytecodes::_checkcast:
 768   case Bytecodes::_instanceof:

 769     if (TypeProfileCasts) {
 770       return ReceiverTypeData::static_cell_count();
 771     } else {
 772       return BitData::static_cell_count();
 773     }
 774   case Bytecodes::_aaload:
 775     return ArrayLoadData::static_cell_count();
 776   case Bytecodes::_aastore:
 777     return ArrayStoreData::static_cell_count();
 778   case Bytecodes::_invokespecial:
 779   case Bytecodes::_invokestatic:
 780     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 781       return variable_cell_count;
 782     } else {
 783       return CounterData::static_cell_count();
 784     }
 785   case Bytecodes::_goto:
 786   case Bytecodes::_goto_w:
 787   case Bytecodes::_jsr:
 788   case Bytecodes::_jsr_w:
 789     return JumpData::static_cell_count();
 790   case Bytecodes::_invokevirtual:
 791   case Bytecodes::_invokeinterface:
 792     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 793       return variable_cell_count;
 794     } else {
 795       return VirtualCallData::static_cell_count();
 796     }
 797   case Bytecodes::_invokedynamic:
 798     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 799       return variable_cell_count;
 800     } else {
 801       return CounterData::static_cell_count();
 802     }
 803   case Bytecodes::_ret:
 804     return RetData::static_cell_count();
 805   case Bytecodes::_ifeq:
 806   case Bytecodes::_ifne:
 807   case Bytecodes::_iflt:
 808   case Bytecodes::_ifge:
 809   case Bytecodes::_ifgt:
 810   case Bytecodes::_ifle:
 811   case Bytecodes::_if_icmpeq:
 812   case Bytecodes::_if_icmpne:
 813   case Bytecodes::_if_icmplt:
 814   case Bytecodes::_if_icmpge:
 815   case Bytecodes::_if_icmpgt:
 816   case Bytecodes::_if_icmple:


 817   case Bytecodes::_ifnull:
 818   case Bytecodes::_ifnonnull:
 819     return BranchData::static_cell_count();
 820   case Bytecodes::_if_acmpne:
 821   case Bytecodes::_if_acmpeq:
 822     return ACmpData::static_cell_count();
 823   case Bytecodes::_lookupswitch:
 824   case Bytecodes::_tableswitch:
 825     return variable_cell_count;
 826   default:
 827     return no_profile_data;
 828   }
 829 }
 830 
 831 // Compute the size of the profiling information corresponding to
 832 // the current bytecode.
 833 int MethodData::compute_data_size(BytecodeStream* stream) {
 834   int cell_count = bytecode_cell_count(stream->code());
 835   if (cell_count == no_profile_data) {
 836     return 0;
 837   }
 838   if (cell_count == variable_cell_count) {
 839     switch (stream->code()) {
 840     case Bytecodes::_lookupswitch:
 841     case Bytecodes::_tableswitch:
 842       cell_count = MultiBranchData::compute_cell_count(stream);

 861       } else {
 862         cell_count = VirtualCallData::static_cell_count();
 863       }
 864       break;
 865     }
 866     default:
 867       fatal("unexpected bytecode for var length profile data");
 868     }
 869   }
 870   // Note:  cell_count might be zero, meaning that there is just
 871   //        a DataLayout header, with no extra cells.
 872   assert(cell_count >= 0, "sanity");
 873   return DataLayout::compute_size_in_bytes(cell_count);
 874 }
 875 
 876 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {
 877   // Bytecodes for which we may use speculation
 878   switch (code) {
 879   case Bytecodes::_checkcast:
 880   case Bytecodes::_instanceof:
 881   case Bytecodes::_aaload:
 882   case Bytecodes::_aastore:
 883   case Bytecodes::_invokevirtual:
 884   case Bytecodes::_invokeinterface:
 885   case Bytecodes::_if_acmpeq:
 886   case Bytecodes::_if_acmpne:
 887   case Bytecodes::_ifnull:
 888   case Bytecodes::_ifnonnull:
 889   case Bytecodes::_invokestatic:
 890 #ifdef COMPILER2
 891     if (CompilerConfig::is_c2_enabled()) {
 892       return UseTypeSpeculation;
 893     }
 894 #endif
 895   default:
 896     return false;
 897   }
 898   return false;
 899 }
 900 
 901 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {

 969 
 970 // Compute the size of the MethodData* necessary to store
 971 // profiling information about a given method.  Size is in words
 972 int MethodData::compute_allocation_size_in_words(const methodHandle& method) {
 973   int byte_size = compute_allocation_size_in_bytes(method);
 974   int word_size = align_up(byte_size, BytesPerWord) / BytesPerWord;
 975   return align_metadata_size(word_size);
 976 }
 977 
 978 // Initialize an individual data segment.  Returns the size of
 979 // the segment in bytes.
 980 int MethodData::initialize_data(BytecodeStream* stream,
 981                                        int data_index) {
 982   int cell_count = -1;
 983   u1 tag = DataLayout::no_tag;
 984   DataLayout* data_layout = data_layout_at(data_index);
 985   Bytecodes::Code c = stream->code();
 986   switch (c) {
 987   case Bytecodes::_checkcast:
 988   case Bytecodes::_instanceof:

 989     if (TypeProfileCasts) {
 990       cell_count = ReceiverTypeData::static_cell_count();
 991       tag = DataLayout::receiver_type_data_tag;
 992     } else {
 993       cell_count = BitData::static_cell_count();
 994       tag = DataLayout::bit_data_tag;
 995     }
 996     break;
 997   case Bytecodes::_aaload:
 998     cell_count = ArrayLoadData::static_cell_count();
 999     tag = DataLayout::array_load_data_tag;
1000     break;
1001   case Bytecodes::_aastore:
1002     cell_count = ArrayStoreData::static_cell_count();
1003     tag = DataLayout::array_store_data_tag;
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::_ifnull:
1077   case Bytecodes::_ifnonnull:
1078     cell_count = BranchData::static_cell_count();
1079     tag = DataLayout::branch_data_tag;
1080     break;
1081   case Bytecodes::_if_acmpeq:
1082   case Bytecodes::_if_acmpne:
1083     cell_count = ACmpData::static_cell_count();
1084     tag = DataLayout::acmp_data_tag;
1085     break;
1086   case Bytecodes::_lookupswitch:
1087   case Bytecodes::_tableswitch:
1088     cell_count = MultiBranchData::compute_cell_count(stream);
1089     tag = DataLayout::multi_branch_data_tag;
1090     break;
1091   default:
1092     break;
1093   }
1094   assert(tag == DataLayout::multi_branch_data_tag ||
1095          ((MethodData::profile_arguments() || MethodData::profile_return()) &&
1096           (tag == DataLayout::call_type_data_tag ||
1097            tag == DataLayout::counter_data_tag ||
1098            tag == DataLayout::virtual_call_type_data_tag ||
1099            tag == DataLayout::virtual_call_data_tag)) ||
1100          cell_count == bytecode_cell_count(c), "cell counts must agree");
1101   if (cell_count >= 0) {
1102     assert(tag != DataLayout::no_tag, "bad tag");
1103     assert(bytecode_has_profile(c), "agree w/ BHP");
1104     data_layout->initialize(tag, checked_cast<u2>(stream->bci()), cell_count);
1105     return DataLayout::compute_size_in_bytes(cell_count);

1133   case DataLayout::receiver_type_data_tag:
1134     return ReceiverTypeData::static_cell_count();
1135   case DataLayout::virtual_call_data_tag:
1136     return VirtualCallData::static_cell_count();
1137   case DataLayout::ret_data_tag:
1138     return RetData::static_cell_count();
1139   case DataLayout::branch_data_tag:
1140     return BranchData::static_cell_count();
1141   case DataLayout::multi_branch_data_tag:
1142     return ((new MultiBranchData(this))->cell_count());
1143   case DataLayout::arg_info_data_tag:
1144     return ((new ArgInfoData(this))->cell_count());
1145   case DataLayout::call_type_data_tag:
1146     return ((new CallTypeData(this))->cell_count());
1147   case DataLayout::virtual_call_type_data_tag:
1148     return ((new VirtualCallTypeData(this))->cell_count());
1149   case DataLayout::parameters_type_data_tag:
1150     return ((new ParametersTypeData(this))->cell_count());
1151   case DataLayout::speculative_trap_data_tag:
1152     return SpeculativeTrapData::static_cell_count();
1153   case DataLayout::array_store_data_tag:
1154     return ((new ArrayStoreData(this))->cell_count());
1155   case DataLayout::array_load_data_tag:
1156     return ((new ArrayLoadData(this))->cell_count());
1157   case DataLayout::acmp_data_tag:
1158     return ((new ACmpData(this))->cell_count());
1159   }
1160 }
1161 ProfileData* DataLayout::data_in() {
1162   switch (tag()) {
1163   case DataLayout::no_tag:
1164   default:
1165     ShouldNotReachHere();
1166     return nullptr;
1167   case DataLayout::bit_data_tag:
1168     return new BitData(this);
1169   case DataLayout::counter_data_tag:
1170     return new CounterData(this);
1171   case DataLayout::jump_data_tag:
1172     return new JumpData(this);
1173   case DataLayout::receiver_type_data_tag:
1174     return new ReceiverTypeData(this);
1175   case DataLayout::virtual_call_data_tag:
1176     return new VirtualCallData(this);
1177   case DataLayout::ret_data_tag:
1178     return new RetData(this);
1179   case DataLayout::branch_data_tag:
1180     return new BranchData(this);
1181   case DataLayout::multi_branch_data_tag:
1182     return new MultiBranchData(this);
1183   case DataLayout::arg_info_data_tag:
1184     return new ArgInfoData(this);
1185   case DataLayout::call_type_data_tag:
1186     return new CallTypeData(this);
1187   case DataLayout::virtual_call_type_data_tag:
1188     return new VirtualCallTypeData(this);
1189   case DataLayout::parameters_type_data_tag:
1190     return new ParametersTypeData(this);
1191   case DataLayout::speculative_trap_data_tag:
1192     return new SpeculativeTrapData(this);
1193   case DataLayout::array_store_data_tag:
1194     return new ArrayStoreData(this);
1195   case DataLayout::array_load_data_tag:
1196     return new ArrayLoadData(this);
1197   case DataLayout::acmp_data_tag:
1198     return new ACmpData(this);
1199   }
1200 }
1201 
1202 // Iteration over data.
1203 ProfileData* MethodData::next_data(ProfileData* current) const {
1204   int current_index = dp_to_di(current->dp());
1205   int next_index = current_index + current->size_in_bytes();
1206   ProfileData* next = data_at(next_index);
1207   return next;
1208 }
1209 
1210 DataLayout* MethodData::next_data_layout(DataLayout* current) const {
1211   int current_index = dp_to_di((address)current);
1212   int next_index = current_index + current->size_in_bytes();
1213   if (out_of_bounds(next_index)) {
1214     return nullptr;
1215   }
1216   DataLayout* next = data_layout_at(next_index);
1217   return next;
1218 }
< prev index next >