< 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   int size = MethodData::compute_allocation_size_in_words(method);
 662 
 663   return new (loader_data, size, MetaspaceObj::MethodDataType, THREAD)
 664     MethodData(method);
 665 }
 666 
 667 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 668   if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
 669     return no_profile_data;
 670   }
 671   switch (code) {
 672   case Bytecodes::_checkcast:
 673   case Bytecodes::_instanceof:
 674   case Bytecodes::_aastore:
 675     if (TypeProfileCasts) {
 676       return ReceiverTypeData::static_cell_count();
 677     } else {
 678       return BitData::static_cell_count();
 679     }



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



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

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

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

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





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

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





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

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




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




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

 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   int size = MethodData::compute_allocation_size_in_words(method);
 687 
 688   return new (loader_data, size, MetaspaceObj::MethodDataType, THREAD)
 689     MethodData(method);
 690 }
 691 
 692 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 693   if (CompilerConfig::is_c1_simple_only() && !ProfileInterpreter) {
 694     return no_profile_data;
 695   }
 696   switch (code) {
 697   case Bytecodes::_checkcast:
 698   case Bytecodes::_instanceof:

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


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

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

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

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

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


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

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