< prev index next >

src/hotspot/share/oops/methodData.cpp

Print this page

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

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

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

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




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

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





















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



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



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

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

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

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





 995   case Bytecodes::_invokespecial:
 996   case Bytecodes::_invokestatic: {
 997     int counter_data_cell_count = CounterData::static_cell_count();
 998     if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
 999         profile_return_for_invoke(stream->method(), stream->bci())) {
1000       cell_count = CallTypeData::compute_cell_count(stream);
1001     } else {
1002       cell_count = counter_data_cell_count;
1003     }
1004     if (cell_count > counter_data_cell_count) {
1005       tag = DataLayout::call_type_data_tag;
1006     } else {
1007       tag = DataLayout::counter_data_tag;
1008     }
1009     break;
1010   }
1011   case Bytecodes::_goto:
1012   case Bytecodes::_goto_w:
1013   case Bytecodes::_jsr:
1014   case Bytecodes::_jsr_w:

1046       tag = DataLayout::counter_data_tag;
1047     }
1048     break;
1049   }
1050   case Bytecodes::_ret:
1051     cell_count = RetData::static_cell_count();
1052     tag = DataLayout::ret_data_tag;
1053     break;
1054   case Bytecodes::_ifeq:
1055   case Bytecodes::_ifne:
1056   case Bytecodes::_iflt:
1057   case Bytecodes::_ifge:
1058   case Bytecodes::_ifgt:
1059   case Bytecodes::_ifle:
1060   case Bytecodes::_if_icmpeq:
1061   case Bytecodes::_if_icmpne:
1062   case Bytecodes::_if_icmplt:
1063   case Bytecodes::_if_icmpge:
1064   case Bytecodes::_if_icmpgt:
1065   case Bytecodes::_if_icmple:
1066   case Bytecodes::_if_acmpeq:
1067   case Bytecodes::_if_acmpne:
1068   case Bytecodes::_ifnull:
1069   case Bytecodes::_ifnonnull:
1070     cell_count = BranchData::static_cell_count();
1071     tag = DataLayout::branch_data_tag;
1072     break;





1073   case Bytecodes::_lookupswitch:
1074   case Bytecodes::_tableswitch:
1075     cell_count = MultiBranchData::compute_cell_count(stream);
1076     tag = DataLayout::multi_branch_data_tag;
1077     break;
1078   default:
1079     break;
1080   }
1081   assert(tag == DataLayout::multi_branch_data_tag ||
1082          ((MethodData::profile_arguments() || MethodData::profile_return()) &&
1083           (tag == DataLayout::call_type_data_tag ||
1084            tag == DataLayout::counter_data_tag ||
1085            tag == DataLayout::virtual_call_type_data_tag ||
1086            tag == DataLayout::virtual_call_data_tag)) ||
1087          cell_count == bytecode_cell_count(c), "cell counts must agree");
1088   if (cell_count >= 0) {
1089     assert(tag != DataLayout::no_tag, "bad tag");
1090     assert(bytecode_has_profile(c), "agree w/ BHP");
1091     data_layout->initialize(tag, stream->bci(), cell_count);
1092     return DataLayout::compute_size_in_bytes(cell_count);

1120   case DataLayout::receiver_type_data_tag:
1121     return ReceiverTypeData::static_cell_count();
1122   case DataLayout::virtual_call_data_tag:
1123     return VirtualCallData::static_cell_count();
1124   case DataLayout::ret_data_tag:
1125     return RetData::static_cell_count();
1126   case DataLayout::branch_data_tag:
1127     return BranchData::static_cell_count();
1128   case DataLayout::multi_branch_data_tag:
1129     return ((new MultiBranchData(this))->cell_count());
1130   case DataLayout::arg_info_data_tag:
1131     return ((new ArgInfoData(this))->cell_count());
1132   case DataLayout::call_type_data_tag:
1133     return ((new CallTypeData(this))->cell_count());
1134   case DataLayout::virtual_call_type_data_tag:
1135     return ((new VirtualCallTypeData(this))->cell_count());
1136   case DataLayout::parameters_type_data_tag:
1137     return ((new ParametersTypeData(this))->cell_count());
1138   case DataLayout::speculative_trap_data_tag:
1139     return SpeculativeTrapData::static_cell_count();




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




1174   }
1175 }
1176 
1177 // Iteration over data.
1178 ProfileData* MethodData::next_data(ProfileData* current) const {
1179   int current_index = dp_to_di(current->dp());
1180   int next_index = current_index + current->size_in_bytes();
1181   ProfileData* next = data_at(next_index);
1182   return next;
1183 }
1184 
1185 DataLayout* MethodData::next_data_layout(DataLayout* current) const {
1186   int current_index = dp_to_di((address)current);
1187   int next_index = current_index + current->size_in_bytes();
1188   if (out_of_bounds(next_index)) {
1189     return NULL;
1190   }
1191   DataLayout* next = data_layout_at(next_index);
1192   return next;
1193 }

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

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

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

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

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

 700     if (TypeProfileCasts) {
 701       return ReceiverTypeData::static_cell_count();
 702     } else {
 703       return BitData::static_cell_count();
 704     }
 705   case Bytecodes::_aaload:
 706   case Bytecodes::_aastore:
 707     return ArrayLoadStoreData::static_cell_count();
 708   case Bytecodes::_invokespecial:
 709   case Bytecodes::_invokestatic:
 710     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 711       return variable_cell_count;
 712     } else {
 713       return CounterData::static_cell_count();
 714     }
 715   case Bytecodes::_goto:
 716   case Bytecodes::_goto_w:
 717   case Bytecodes::_jsr:
 718   case Bytecodes::_jsr_w:
 719     return JumpData::static_cell_count();
 720   case Bytecodes::_invokevirtual:
 721   case Bytecodes::_invokeinterface:
 722     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 723       return variable_cell_count;
 724     } else {
 725       return VirtualCallData::static_cell_count();
 726     }
 727   case Bytecodes::_invokedynamic:
 728     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 729       return variable_cell_count;
 730     } else {
 731       return CounterData::static_cell_count();
 732     }
 733   case Bytecodes::_ret:
 734     return RetData::static_cell_count();
 735   case Bytecodes::_ifeq:
 736   case Bytecodes::_ifne:
 737   case Bytecodes::_iflt:
 738   case Bytecodes::_ifge:
 739   case Bytecodes::_ifgt:
 740   case Bytecodes::_ifle:
 741   case Bytecodes::_if_icmpeq:
 742   case Bytecodes::_if_icmpne:
 743   case Bytecodes::_if_icmplt:
 744   case Bytecodes::_if_icmpge:
 745   case Bytecodes::_if_icmpgt:
 746   case Bytecodes::_if_icmple:


 747   case Bytecodes::_ifnull:
 748   case Bytecodes::_ifnonnull:
 749     return BranchData::static_cell_count();
 750   case Bytecodes::_if_acmpne:
 751   case Bytecodes::_if_acmpeq:
 752     return ACmpData::static_cell_count();
 753   case Bytecodes::_lookupswitch:
 754   case Bytecodes::_tableswitch:
 755     return variable_cell_count;
 756   default:
 757     return no_profile_data;
 758   }
 759 }
 760 
 761 // Compute the size of the profiling information corresponding to
 762 // the current bytecode.
 763 int MethodData::compute_data_size(BytecodeStream* stream) {
 764   int cell_count = bytecode_cell_count(stream->code());
 765   if (cell_count == no_profile_data) {
 766     return 0;
 767   }
 768   if (cell_count == variable_cell_count) {
 769     switch (stream->code()) {
 770     case Bytecodes::_lookupswitch:
 771     case Bytecodes::_tableswitch:
 772       cell_count = MultiBranchData::compute_cell_count(stream);

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

 995 int MethodData::compute_allocation_size_in_words(const methodHandle& method) {
 996   int byte_size = compute_allocation_size_in_bytes(method);
 997   int word_size = align_up(byte_size, BytesPerWord) / BytesPerWord;
 998   return align_metadata_size(word_size);
 999 }
1000 
1001 // Initialize an individual data segment.  Returns the size of
1002 // the segment in bytes.
1003 int MethodData::initialize_data(BytecodeStream* stream,
1004                                        int data_index) {
1005   if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
1006     return 0;
1007   }
1008   int cell_count = -1;
1009   int tag = DataLayout::no_tag;
1010   DataLayout* data_layout = data_layout_at(data_index);
1011   Bytecodes::Code c = stream->code();
1012   switch (c) {
1013   case Bytecodes::_checkcast:
1014   case Bytecodes::_instanceof:

1015     if (TypeProfileCasts) {
1016       cell_count = ReceiverTypeData::static_cell_count();
1017       tag = DataLayout::receiver_type_data_tag;
1018     } else {
1019       cell_count = BitData::static_cell_count();
1020       tag = DataLayout::bit_data_tag;
1021     }
1022     break;
1023   case Bytecodes::_aaload:
1024   case Bytecodes::_aastore:
1025     cell_count = ArrayLoadStoreData::static_cell_count();
1026     tag = DataLayout::array_load_store_data_tag;
1027     break;
1028   case Bytecodes::_invokespecial:
1029   case Bytecodes::_invokestatic: {
1030     int counter_data_cell_count = CounterData::static_cell_count();
1031     if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
1032         profile_return_for_invoke(stream->method(), stream->bci())) {
1033       cell_count = CallTypeData::compute_cell_count(stream);
1034     } else {
1035       cell_count = counter_data_cell_count;
1036     }
1037     if (cell_count > counter_data_cell_count) {
1038       tag = DataLayout::call_type_data_tag;
1039     } else {
1040       tag = DataLayout::counter_data_tag;
1041     }
1042     break;
1043   }
1044   case Bytecodes::_goto:
1045   case Bytecodes::_goto_w:
1046   case Bytecodes::_jsr:
1047   case Bytecodes::_jsr_w:

1079       tag = DataLayout::counter_data_tag;
1080     }
1081     break;
1082   }
1083   case Bytecodes::_ret:
1084     cell_count = RetData::static_cell_count();
1085     tag = DataLayout::ret_data_tag;
1086     break;
1087   case Bytecodes::_ifeq:
1088   case Bytecodes::_ifne:
1089   case Bytecodes::_iflt:
1090   case Bytecodes::_ifge:
1091   case Bytecodes::_ifgt:
1092   case Bytecodes::_ifle:
1093   case Bytecodes::_if_icmpeq:
1094   case Bytecodes::_if_icmpne:
1095   case Bytecodes::_if_icmplt:
1096   case Bytecodes::_if_icmpge:
1097   case Bytecodes::_if_icmpgt:
1098   case Bytecodes::_if_icmple:


1099   case Bytecodes::_ifnull:
1100   case Bytecodes::_ifnonnull:
1101     cell_count = BranchData::static_cell_count();
1102     tag = DataLayout::branch_data_tag;
1103     break;
1104   case Bytecodes::_if_acmpeq:
1105   case Bytecodes::_if_acmpne:
1106     cell_count = ACmpData::static_cell_count();
1107     tag = DataLayout::acmp_data_tag;
1108     break;
1109   case Bytecodes::_lookupswitch:
1110   case Bytecodes::_tableswitch:
1111     cell_count = MultiBranchData::compute_cell_count(stream);
1112     tag = DataLayout::multi_branch_data_tag;
1113     break;
1114   default:
1115     break;
1116   }
1117   assert(tag == DataLayout::multi_branch_data_tag ||
1118          ((MethodData::profile_arguments() || MethodData::profile_return()) &&
1119           (tag == DataLayout::call_type_data_tag ||
1120            tag == DataLayout::counter_data_tag ||
1121            tag == DataLayout::virtual_call_type_data_tag ||
1122            tag == DataLayout::virtual_call_data_tag)) ||
1123          cell_count == bytecode_cell_count(c), "cell counts must agree");
1124   if (cell_count >= 0) {
1125     assert(tag != DataLayout::no_tag, "bad tag");
1126     assert(bytecode_has_profile(c), "agree w/ BHP");
1127     data_layout->initialize(tag, stream->bci(), cell_count);
1128     return DataLayout::compute_size_in_bytes(cell_count);

1156   case DataLayout::receiver_type_data_tag:
1157     return ReceiverTypeData::static_cell_count();
1158   case DataLayout::virtual_call_data_tag:
1159     return VirtualCallData::static_cell_count();
1160   case DataLayout::ret_data_tag:
1161     return RetData::static_cell_count();
1162   case DataLayout::branch_data_tag:
1163     return BranchData::static_cell_count();
1164   case DataLayout::multi_branch_data_tag:
1165     return ((new MultiBranchData(this))->cell_count());
1166   case DataLayout::arg_info_data_tag:
1167     return ((new ArgInfoData(this))->cell_count());
1168   case DataLayout::call_type_data_tag:
1169     return ((new CallTypeData(this))->cell_count());
1170   case DataLayout::virtual_call_type_data_tag:
1171     return ((new VirtualCallTypeData(this))->cell_count());
1172   case DataLayout::parameters_type_data_tag:
1173     return ((new ParametersTypeData(this))->cell_count());
1174   case DataLayout::speculative_trap_data_tag:
1175     return SpeculativeTrapData::static_cell_count();
1176   case DataLayout::array_load_store_data_tag:
1177     return ((new ArrayLoadStoreData(this))->cell_count());
1178   case DataLayout::acmp_data_tag:
1179     return ((new ACmpData(this))->cell_count());
1180   }
1181 }
1182 ProfileData* DataLayout::data_in() {
1183   switch (tag()) {
1184   case DataLayout::no_tag:
1185   default:
1186     ShouldNotReachHere();
1187     return NULL;
1188   case DataLayout::bit_data_tag:
1189     return new BitData(this);
1190   case DataLayout::counter_data_tag:
1191     return new CounterData(this);
1192   case DataLayout::jump_data_tag:
1193     return new JumpData(this);
1194   case DataLayout::receiver_type_data_tag:
1195     return new ReceiverTypeData(this);
1196   case DataLayout::virtual_call_data_tag:
1197     return new VirtualCallData(this);
1198   case DataLayout::ret_data_tag:
1199     return new RetData(this);
1200   case DataLayout::branch_data_tag:
1201     return new BranchData(this);
1202   case DataLayout::multi_branch_data_tag:
1203     return new MultiBranchData(this);
1204   case DataLayout::arg_info_data_tag:
1205     return new ArgInfoData(this);
1206   case DataLayout::call_type_data_tag:
1207     return new CallTypeData(this);
1208   case DataLayout::virtual_call_type_data_tag:
1209     return new VirtualCallTypeData(this);
1210   case DataLayout::parameters_type_data_tag:
1211     return new ParametersTypeData(this);
1212   case DataLayout::speculative_trap_data_tag:
1213     return new SpeculativeTrapData(this);
1214   case DataLayout::array_load_store_data_tag:
1215     return new ArrayLoadStoreData(this);
1216   case DataLayout::acmp_data_tag:
1217     return new ACmpData(this);
1218   }
1219 }
1220 
1221 // Iteration over data.
1222 ProfileData* MethodData::next_data(ProfileData* current) const {
1223   int current_index = dp_to_di(current->dp());
1224   int next_index = current_index + current->size_in_bytes();
1225   ProfileData* next = data_at(next_index);
1226   return next;
1227 }
1228 
1229 DataLayout* MethodData::next_data_layout(DataLayout* current) const {
1230   int current_index = dp_to_di((address)current);
1231   int next_index = current_index + current->size_in_bytes();
1232   if (out_of_bounds(next_index)) {
1233     return NULL;
1234   }
1235   DataLayout* next = data_layout_at(next_index);
1236   return next;
1237 }
< prev index next >