< prev index next >

src/hotspot/share/oops/methodData.cpp

Print this page

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

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

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

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




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

 631 void ParametersTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 632   _parameters.post_initialize(mdo->method()->signature(), !mdo->method()->is_static(), true);
 633 }
 634 
 635 bool ParametersTypeData::profiling_enabled() {
 636   return MethodData::profile_parameters();
 637 }
 638 
 639 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
 640   st->print("parameter types"); // FIXME extra ignored?
 641   _parameters.print_data_on(st);
 642 }
 643 
 644 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
 645   print_shared(st, "SpeculativeTrapData", extra);
 646   tab(st);
 647   method()->print_short_name(st);
 648   st->cr();
 649 }
 650 





















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



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



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

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

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

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





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

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





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

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




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




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

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

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

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

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

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

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


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

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

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

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

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


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

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