< 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 {

 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   print_shared(st, "ParametersTypeData", extra);
 641   tab(st);
 642   _parameters.print_data_on(st);
 643   st->cr();
 644 }
 645 
 646 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
 647   print_shared(st, "SpeculativeTrapData", extra);
 648   tab(st);
 649   method()->print_short_name(st);
 650   st->cr();
 651 }
 652 





















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



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



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

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

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

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





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

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





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

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




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




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

 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 {

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

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


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

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

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

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

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


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

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