src/share/vm/oops/methodData.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/oops

src/share/vm/oops/methodData.cpp

Print this page
rev 5349 : 8023657: New type profiling points: arguments to call
Summary: x86 interpreter and c1 type profiling for arguments at calls
Reviewed-by:
rev 5350 : 8026054: New type profiling points: type of return values at calls
Summary: x86 interpreter and c1 type profiling for return values at calls
Reviewed-by:


 139   int target;
 140   Bytecodes::Code c = stream->code();
 141   if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
 142     target = stream->dest_w();
 143   } else {
 144     target = stream->dest();
 145   }
 146   int my_di = mdo->dp_to_di(dp());
 147   int target_di = mdo->bci_to_di(target);
 148   int offset = target_di - my_di;
 149   set_displacement(offset);
 150 }
 151 
 152 #ifndef PRODUCT
 153 void JumpData::print_data_on(outputStream* st) const {
 154   print_shared(st, "JumpData");
 155   st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
 156 }
 157 #endif // !PRODUCT
 158 
 159 int TypeStackSlotEntries::compute_cell_count(BytecodeStream* stream) {
 160   int max = TypeProfileArgsLimit;
 161   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 162   Bytecode_invoke inv(stream->method(), stream->bci());
 163   
 164   ResourceMark rm;
 165   SignatureStream ss(inv.signature());
 166   int args_count = MIN2(ss.reference_parameter_count(), max);


 167 
 168   return args_count * per_arg_cell_count + (args_count > 0 ? header_cell_count() : 0);















 169 }
 170 
 171 class ArgumentOffsetComputer : public SignatureInfo {
 172 private:
 173   int _max;
 174   GrowableArray<int> _offsets;
 175 
 176   void set(int size, BasicType type) { _size += size; }
 177   void do_object(int begin, int end) {
 178     if (_offsets.length() < _max) {
 179       _offsets.push(_size);
 180     }
 181     SignatureInfo::do_object(begin, end);
 182   }
 183   void do_array (int begin, int end) {
 184     if (_offsets.length() < _max) {
 185       _offsets.push(_size);
 186     }
 187     SignatureInfo::do_array(begin, end);
 188   }
 189 
 190 public:
 191   ArgumentOffsetComputer(Symbol* signature, int max)
 192     : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) {
 193   }
 194 
 195   int total() { lazy_iterate_parameters(); return _size; }
 196 
 197   int off_at(int i) const { return _offsets.at(i); }
 198 };
 199 
 200 void TypeStackSlotEntries::post_initialize(BytecodeStream* stream) {
 201   ResourceMark rm;








 202 

 203   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 204   Bytecode_invoke inv(stream->method(), stream->bci());
 205 
 206 #ifdef ASSERT
 207   SignatureStream ss(inv.signature());



 208   int count = MIN2(ss.reference_parameter_count(), TypeProfileArgsLimit);
 209   assert(count > 0, "room for args type but none found?");
 210   check_number_of_arguments(count);
 211 #endif


 212   
 213   int start = 0;
 214   ArgumentOffsetComputer aos(inv.signature(), number_of_arguments()-start);
 215   aos.total();
 216   bool has_receiver = inv.has_receiver();
 217   for (int i = start; i < number_of_arguments(); i++) {
 218     set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0));
 219     set_type(i, type_none());
 220   }
 221 }
 222 
 223 bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {
 224   return !is_type_none(p) &&
 225     !((Klass*)klass_part(p))->is_loader_alive(is_alive_cl);
 226 }
 227 
 228 void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 229   for (int i = 0; i < number_of_arguments(); i++) {
 230     intptr_t p = type(i);
 231     if (is_loader_alive(is_alive_cl, p)) {
 232       set_type(i, type_none());
 233     }
 234   }
 235 }
 236 
 237 bool TypeStackSlotEntries::arguments_profiling_enabled() {




















 238   return MethodData::profile_arguments();
 239 }
 240 
 241 #ifndef PRODUCT
 242 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
 243   if (is_type_none(k)) {
 244     st->print("none");
 245   } else if (is_type_unknown(k)) {
 246     st->print("unknown");
 247   } else {
 248     valid_klass(k)->print_value_on(st);
 249   }
 250   if (was_null_seen(k)) {
 251     st->print(" (null seen)");
 252   }
 253 }
 254 
 255 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
 256   _pd->tab(st, true);
 257   st->print("argument types");
 258   for (int i = 0; i < number_of_arguments(); i++) {
 259     _pd->tab(st);
 260     st->print("%d: stack(%u) ", i, stack_slot(i));
 261     print_klass(st, type(i));
 262     st->cr();
 263   }
 264 }
 265 



















 266 void CallTypeData::print_data_on(outputStream* st) const {
 267   CounterData::print_data_on(st);
 268   _args.print_data_on(st);
 269 }
 270 
 271 void VirtualCallTypeData::print_data_on(outputStream* st) const {
 272   VirtualCallData::print_data_on(st);
 273   _args.print_data_on(st);
 274 }
 275 #endif
 276 
 277 // ==================================================================
 278 // ReceiverTypeData
 279 //
 280 // A ReceiverTypeData is used to access profiling information about a
 281 // dynamic type check.  It consists of a counter which counts the total times
 282 // that the check is reached, and a series of (Klass*, count) pairs
 283 // which are used to store a type profile for the receiver of the check.
 284 
 285 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 286     for (uint row = 0; row < row_limit(); row++) {
 287     Klass* p = receiver(row);
 288     if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
 289       clear_row(row);
 290     }
 291   }
 292 }
 293 


 513 
 514   return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
 515     MethodData(method(), size, CHECK_NULL);
 516 }
 517 
 518 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 519 #if defined(COMPILER1) && !defined(COMPILER2)
 520   return no_profile_data;
 521 #else
 522   switch (code) {
 523   case Bytecodes::_checkcast:
 524   case Bytecodes::_instanceof:
 525   case Bytecodes::_aastore:
 526     if (TypeProfileCasts) {
 527       return ReceiverTypeData::static_cell_count();
 528     } else {
 529       return BitData::static_cell_count();
 530     }
 531   case Bytecodes::_invokespecial:
 532   case Bytecodes::_invokestatic:
 533     if (MethodData::profile_arguments()) {
 534       return variable_cell_count;
 535     } else {
 536       return CounterData::static_cell_count();
 537     }
 538   case Bytecodes::_goto:
 539   case Bytecodes::_goto_w:
 540   case Bytecodes::_jsr:
 541   case Bytecodes::_jsr_w:
 542     return JumpData::static_cell_count();
 543   case Bytecodes::_invokevirtual:
 544   case Bytecodes::_invokeinterface:
 545     if (MethodData::profile_arguments()) {
 546       return variable_cell_count;
 547     } else {
 548       return VirtualCallData::static_cell_count();
 549     }
 550   case Bytecodes::_invokedynamic:
 551     if (MethodData::profile_arguments()) {
 552       return variable_cell_count;
 553     } else {
 554       return CounterData::static_cell_count();
 555     }
 556   case Bytecodes::_ret:
 557     return RetData::static_cell_count();
 558   case Bytecodes::_ifeq:
 559   case Bytecodes::_ifne:
 560   case Bytecodes::_iflt:
 561   case Bytecodes::_ifge:
 562   case Bytecodes::_ifgt:
 563   case Bytecodes::_ifle:
 564   case Bytecodes::_if_icmpeq:
 565   case Bytecodes::_if_icmpne:
 566   case Bytecodes::_if_icmplt:
 567   case Bytecodes::_if_icmpge:
 568   case Bytecodes::_if_icmpgt:
 569   case Bytecodes::_if_icmple:
 570   case Bytecodes::_if_acmpeq:
 571   case Bytecodes::_if_acmpne:


 579   return no_profile_data;
 580 #endif
 581 }
 582 
 583 // Compute the size of the profiling information corresponding to
 584 // the current bytecode.
 585 int MethodData::compute_data_size(BytecodeStream* stream) {
 586   int cell_count = bytecode_cell_count(stream->code());
 587   if (cell_count == no_profile_data) {
 588     return 0;
 589   }
 590   if (cell_count == variable_cell_count) {
 591     switch (stream->code()) {
 592     case Bytecodes::_lookupswitch:
 593     case Bytecodes::_tableswitch:
 594       cell_count = MultiBranchData::compute_cell_count(stream);
 595       break;
 596     case Bytecodes::_invokespecial:
 597     case Bytecodes::_invokestatic:
 598     case Bytecodes::_invokedynamic:
 599       assert(MethodData::profile_arguments(), "should be collecting args profile");
 600       if (profile_arguments_for_invoke(stream->method(), stream->bci())) {

 601         cell_count = CallTypeData::compute_cell_count(stream);
 602       } else {
 603         cell_count = CounterData::static_cell_count();
 604       }
 605       break;
 606     case Bytecodes::_invokevirtual:
 607     case Bytecodes::_invokeinterface: {
 608       assert(MethodData::profile_arguments(), "should be collecting args profile");
 609       if (profile_arguments_for_invoke(stream->method(), stream->bci())) {

 610         cell_count = VirtualCallTypeData::compute_cell_count(stream);
 611       } else {
 612         cell_count = VirtualCallData::static_cell_count();
 613       }
 614       break;
 615     }
 616     default:
 617       fatal("unexpected bytecode for var length profile data");
 618     }
 619   }
 620   // Note:  cell_count might be zero, meaning that there is just
 621   //        a DataLayout header, with no extra cells.
 622   assert(cell_count >= 0, "sanity");
 623   return DataLayout::compute_size_in_bytes(cell_count);
 624 }
 625 
 626 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) {
 627   if (ProfileTraps) {
 628     // Assume that up to 3% of BCIs with no MDP will need to allocate one.
 629     int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;


 682 #else
 683   int cell_count = -1;
 684   int tag = DataLayout::no_tag;
 685   DataLayout* data_layout = data_layout_at(data_index);
 686   Bytecodes::Code c = stream->code();
 687   switch (c) {
 688   case Bytecodes::_checkcast:
 689   case Bytecodes::_instanceof:
 690   case Bytecodes::_aastore:
 691     if (TypeProfileCasts) {
 692       cell_count = ReceiverTypeData::static_cell_count();
 693       tag = DataLayout::receiver_type_data_tag;
 694     } else {
 695       cell_count = BitData::static_cell_count();
 696       tag = DataLayout::bit_data_tag;
 697     }
 698     break;
 699   case Bytecodes::_invokespecial:
 700   case Bytecodes::_invokestatic: {
 701     int counter_data_cell_count = CounterData::static_cell_count();
 702     if (profile_arguments_for_invoke(stream->method(), stream->bci())) {

 703       cell_count = CallTypeData::compute_cell_count(stream);
 704     } else {
 705       cell_count = counter_data_cell_count;
 706     }
 707     if (cell_count > counter_data_cell_count) {
 708       tag = DataLayout::call_type_data_tag;
 709     } else {
 710       tag = DataLayout::counter_data_tag;
 711     }
 712     break;
 713   }
 714   case Bytecodes::_goto:
 715   case Bytecodes::_goto_w:
 716   case Bytecodes::_jsr:
 717   case Bytecodes::_jsr_w:
 718     cell_count = JumpData::static_cell_count();
 719     tag = DataLayout::jump_data_tag;
 720     break;
 721   case Bytecodes::_invokevirtual:
 722   case Bytecodes::_invokeinterface: {
 723     int virtual_call_data_cell_count = VirtualCallData::static_cell_count();
 724     if (profile_arguments_for_invoke(stream->method(), stream->bci())) {

 725       cell_count = VirtualCallTypeData::compute_cell_count(stream);
 726     } else {
 727       cell_count = virtual_call_data_cell_count;
 728     }
 729     if (cell_count > virtual_call_data_cell_count) {
 730       tag = DataLayout::virtual_call_type_data_tag;
 731     } else {
 732       tag = DataLayout::virtual_call_data_tag;
 733     }
 734     break;
 735   }
 736   case Bytecodes::_invokedynamic: {
 737     // %%% should make a type profile for any invokedynamic that takes a ref argument
 738     int counter_data_cell_count = CounterData::static_cell_count();
 739     if (profile_arguments_for_invoke(stream->method(), stream->bci())) {

 740       cell_count = CallTypeData::compute_cell_count(stream);
 741     } else {
 742       cell_count = counter_data_cell_count;
 743     }
 744     if (cell_count > counter_data_cell_count) {
 745       tag = DataLayout::call_type_data_tag;
 746     } else {
 747       tag = DataLayout::counter_data_tag;
 748     }
 749     break;
 750   }
 751   case Bytecodes::_ret:
 752     cell_count = RetData::static_cell_count();
 753     tag = DataLayout::ret_data_tag;
 754     break;
 755   case Bytecodes::_ifeq:
 756   case Bytecodes::_ifne:
 757   case Bytecodes::_iflt:
 758   case Bytecodes::_ifge:
 759   case Bytecodes::_ifgt:


 761   case Bytecodes::_if_icmpeq:
 762   case Bytecodes::_if_icmpne:
 763   case Bytecodes::_if_icmplt:
 764   case Bytecodes::_if_icmpge:
 765   case Bytecodes::_if_icmpgt:
 766   case Bytecodes::_if_icmple:
 767   case Bytecodes::_if_acmpeq:
 768   case Bytecodes::_if_acmpne:
 769   case Bytecodes::_ifnull:
 770   case Bytecodes::_ifnonnull:
 771     cell_count = BranchData::static_cell_count();
 772     tag = DataLayout::branch_data_tag;
 773     break;
 774   case Bytecodes::_lookupswitch:
 775   case Bytecodes::_tableswitch:
 776     cell_count = MultiBranchData::compute_cell_count(stream);
 777     tag = DataLayout::multi_branch_data_tag;
 778     break;
 779   }
 780   assert(tag == DataLayout::multi_branch_data_tag ||
 781          (MethodData::profile_arguments() &&
 782           (tag == DataLayout::call_type_data_tag ||
 783            tag == DataLayout::counter_data_tag ||
 784            tag == DataLayout::virtual_call_type_data_tag ||
 785            tag == DataLayout::virtual_call_data_tag)) ||
 786          cell_count == bytecode_cell_count(c), "cell counts must agree");
 787   if (cell_count >= 0) {
 788     assert(tag != DataLayout::no_tag, "bad tag");
 789     assert(bytecode_has_profile(c), "agree w/ BHP");
 790     data_layout->initialize(tag, stream->bci(), cell_count);
 791     return DataLayout::compute_size_in_bytes(cell_count);
 792   } else {
 793     assert(!bytecode_has_profile(c), "agree w/ !BHP");
 794     return 0;
 795   }
 796 #endif
 797 }
 798 
 799 // Get the data at an arbitrary (sort of) data index.
 800 ProfileData* MethodData::data_at(int data_index) const {
 801   if (out_of_bounds(data_index)) {


1094   guarantee(is_methodData(), "object must be method data");
1095   // guarantee(m->is_perm(), "should be in permspace");
1096   this->verify_data_on(st);
1097 }
1098 
1099 void MethodData::verify_data_on(outputStream* st) {
1100   NEEDS_CLEANUP;
1101   // not yet implemented.
1102 }
1103 
1104 bool MethodData::profile_jsr292(methodHandle m, int bci) {
1105   if (m->is_compiled_lambda_form()) {
1106     return true;
1107   }
1108 
1109   Bytecode_invoke inv(m , bci);
1110   return inv.is_invokedynamic() || inv.is_invokehandle();
1111 }
1112 
1113 int MethodData::profile_arguments_flag() {
1114   return TypeProfileLevel;
1115 }
1116 
1117 bool MethodData::profile_arguments() {
1118   return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all;
1119 }
1120 
1121 bool MethodData::profile_arguments_jsr292_only() {
1122   return profile_arguments_flag() == type_profile_jsr292;
1123 }
1124 
1125 bool MethodData::profile_all_arguments() {
1126   return profile_arguments_flag() == type_profile_all;
1127 }
1128 
1129 bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) {
1130   if (!profile_arguments()) {
1131     return false;
1132   }
1133   
1134   if (profile_all_arguments()) {
1135     return true;
1136   }
1137   
1138   assert(profile_arguments_jsr292_only(), "inconsistent");
1139   return profile_jsr292(m, bci);
1140 }
1141 






























 139   int target;
 140   Bytecodes::Code c = stream->code();
 141   if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
 142     target = stream->dest_w();
 143   } else {
 144     target = stream->dest();
 145   }
 146   int my_di = mdo->dp_to_di(dp());
 147   int target_di = mdo->bci_to_di(target);
 148   int offset = target_di - my_di;
 149   set_displacement(offset);
 150 }
 151 
 152 #ifndef PRODUCT
 153 void JumpData::print_data_on(outputStream* st) const {
 154   print_shared(st, "JumpData");
 155   st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
 156 }
 157 #endif // !PRODUCT
 158 
 159 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, int max) {
 160   int args_count = 0;



 161   ResourceMark rm;
 162   SignatureStream ss(signature);
 163   args_count += MIN2(ss.reference_parameter_count(), max);
 164   return args_count * per_arg_cell_count;
 165 }
 166 
 167 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {
 168   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 169   Bytecode_invoke inv(stream->method(), stream->bci());
 170   int args_cell = 0;
 171   if (arguments_profiling_enabled()) {
 172     args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), TypeProfileArgsLimit);
 173   }
 174   int ret_cell = 0;
 175   if (return_profiling_enabled() && (inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY)) {
 176     ret_cell = ReturnTypeEntry::static_cell_count();
 177   }
 178   int header_cell = 0;
 179   if (args_cell + ret_cell > 0) {
 180     header_cell = header_cell_count();
 181   }
 182   return header_cell + args_cell + ret_cell;
 183 }
 184 
 185 class ArgumentOffsetComputer : public SignatureInfo {
 186 private:
 187   int _max;
 188   GrowableArray<int> _offsets;
 189 
 190   void set(int size, BasicType type) { _size += size; }
 191   void do_object(int begin, int end) {
 192     if (_offsets.length() < _max) {
 193       _offsets.push(_size);
 194     }
 195     SignatureInfo::do_object(begin, end);
 196   }
 197   void do_array (int begin, int end) {
 198     if (_offsets.length() < _max) {
 199       _offsets.push(_size);
 200     }
 201     SignatureInfo::do_array(begin, end);
 202   }
 203 
 204 public:
 205   ArgumentOffsetComputer(Symbol* signature, int max)
 206     : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) {
 207   }
 208 
 209   int total() { lazy_iterate_parameters(); return _size; }
 210 
 211   int off_at(int i) const { return _offsets.at(i); }
 212 };
 213 
 214 void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver) {
 215   ResourceMark rm;
 216   int start = 0;
 217   ArgumentOffsetComputer aos(signature, _nb_entries-start);
 218   aos.total();
 219   for (int i = start; i < _nb_entries; i++) {
 220     set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0));
 221     set_type(i, type_none());
 222   }
 223 }
 224  
 225 void TypeEntriesAtCall::post_initialize(BytecodeStream* stream) {
 226   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 227   Bytecode_invoke inv(stream->method(), stream->bci());
 228 

 229   SignatureStream ss(inv.signature());
 230   if (arguments_profiling_enabled() && has_arguments()) {
 231 #ifdef ASSERT
 232     ResourceMark rm;
 233     int count = MIN2(ss.reference_parameter_count(), TypeProfileArgsLimit);
 234     assert(count > 0, "room for args type but none found?");
 235     check_number_of_arguments(count);
 236 #endif
 237     _args.post_initialize(inv.signature(), inv.has_receiver());
 238   }
 239   
 240   if (return_profiling_enabled() && has_return()) {
 241     assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");
 242     _ret.post_initialize();




 243   }
 244 }
 245 
 246 bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {
 247   return !is_type_none(p) &&
 248     !((Klass*)klass_part(p))->is_loader_alive(is_alive_cl);
 249 }
 250 
 251 void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 252   for (int i = 0; i < _nb_entries; i++) {
 253     intptr_t p = type(i);
 254     if (is_loader_alive(is_alive_cl, p)) {
 255       set_type(i, type_none());
 256     }
 257   }
 258 }
 259 
 260 void ReturnTypeEntry::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 261   intptr_t p = type();
 262   if (is_loader_alive(is_alive_cl, p)) {
 263     set_type(type_none());
 264   }
 265 }
 266 
 267 bool ReturnTypeEntry::profiling_enabled() {
 268   return MethodData::profile_return();
 269 }
 270 
 271 void TypeEntriesAtCall::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 272   if (arguments_profiling_enabled()) {
 273     _args.clean_weak_klass_links(is_alive_cl);
 274   }
 275   if (return_profiling_enabled()) {
 276     _ret.clean_weak_klass_links(is_alive_cl);
 277   }
 278 }
 279 
 280 bool TypeEntriesAtCall::arguments_profiling_enabled() {
 281   return MethodData::profile_arguments();
 282 }
 283 
 284 #ifndef PRODUCT
 285 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
 286   if (is_type_none(k)) {
 287     st->print("none");
 288   } else if (is_type_unknown(k)) {
 289     st->print("unknown");
 290   } else {
 291     valid_klass(k)->print_value_on(st);
 292   }
 293   if (was_null_seen(k)) {
 294     st->print(" (null seen)");
 295   }
 296 }
 297 
 298 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
 299   for (int i = 0; i < _nb_entries; i++) {


 300     _pd->tab(st);
 301     st->print("%d: stack(%u) ", i, stack_slot(i));
 302     print_klass(st, type(i));
 303     st->cr();
 304   }
 305 }
 306 
 307 void ReturnTypeEntry::print_data_on(outputStream* st) const {
 308   _pd->tab(st);
 309   print_klass(st, type());
 310   st->cr();
 311 }
 312 
 313 void TypeEntriesAtCall::print_data_on(outputStream* st) const {
 314   if (arguments_profiling_enabled() && has_arguments()) {
 315     _pd->tab(st, true);
 316     st->print("argument types");
 317     _args.print_data_on(st);
 318   }
 319   if (return_profiling_enabled() && has_return()) {
 320     _pd->tab(st, true);
 321     st->print("return type");
 322     _ret.print_data_on(st);
 323   }
 324 }
 325 
 326 void CallTypeData::print_data_on(outputStream* st) const {
 327   CounterData::print_data_on(st);
 328   _args_and_ret.print_data_on(st);
 329 }
 330 
 331 void VirtualCallTypeData::print_data_on(outputStream* st) const {
 332   VirtualCallData::print_data_on(st);
 333   _args_and_ret.print_data_on(st);
 334 }
 335 #endif
 336 
 337 // ==================================================================
 338 // ReceiverTypeData
 339 //
 340 // A ReceiverTypeData is used to access profiling information about a
 341 // dynamic type check.  It consists of a counter which counts the total times
 342 // that the check is reached, and a series of (Klass*, count) pairs
 343 // which are used to store a type profile for the receiver of the check.
 344 
 345 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 346     for (uint row = 0; row < row_limit(); row++) {
 347     Klass* p = receiver(row);
 348     if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
 349       clear_row(row);
 350     }
 351   }
 352 }
 353 


 573 
 574   return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
 575     MethodData(method(), size, CHECK_NULL);
 576 }
 577 
 578 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 579 #if defined(COMPILER1) && !defined(COMPILER2)
 580   return no_profile_data;
 581 #else
 582   switch (code) {
 583   case Bytecodes::_checkcast:
 584   case Bytecodes::_instanceof:
 585   case Bytecodes::_aastore:
 586     if (TypeProfileCasts) {
 587       return ReceiverTypeData::static_cell_count();
 588     } else {
 589       return BitData::static_cell_count();
 590     }
 591   case Bytecodes::_invokespecial:
 592   case Bytecodes::_invokestatic:
 593     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 594       return variable_cell_count;
 595     } else {
 596       return CounterData::static_cell_count();
 597     }
 598   case Bytecodes::_goto:
 599   case Bytecodes::_goto_w:
 600   case Bytecodes::_jsr:
 601   case Bytecodes::_jsr_w:
 602     return JumpData::static_cell_count();
 603   case Bytecodes::_invokevirtual:
 604   case Bytecodes::_invokeinterface:
 605     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 606       return variable_cell_count;
 607     } else {
 608       return VirtualCallData::static_cell_count();
 609     }
 610   case Bytecodes::_invokedynamic:
 611     if (MethodData::profile_arguments() || MethodData::profile_return()) {
 612       return variable_cell_count;
 613     } else {
 614       return CounterData::static_cell_count();
 615     }
 616   case Bytecodes::_ret:
 617     return RetData::static_cell_count();
 618   case Bytecodes::_ifeq:
 619   case Bytecodes::_ifne:
 620   case Bytecodes::_iflt:
 621   case Bytecodes::_ifge:
 622   case Bytecodes::_ifgt:
 623   case Bytecodes::_ifle:
 624   case Bytecodes::_if_icmpeq:
 625   case Bytecodes::_if_icmpne:
 626   case Bytecodes::_if_icmplt:
 627   case Bytecodes::_if_icmpge:
 628   case Bytecodes::_if_icmpgt:
 629   case Bytecodes::_if_icmple:
 630   case Bytecodes::_if_acmpeq:
 631   case Bytecodes::_if_acmpne:


 639   return no_profile_data;
 640 #endif
 641 }
 642 
 643 // Compute the size of the profiling information corresponding to
 644 // the current bytecode.
 645 int MethodData::compute_data_size(BytecodeStream* stream) {
 646   int cell_count = bytecode_cell_count(stream->code());
 647   if (cell_count == no_profile_data) {
 648     return 0;
 649   }
 650   if (cell_count == variable_cell_count) {
 651     switch (stream->code()) {
 652     case Bytecodes::_lookupswitch:
 653     case Bytecodes::_tableswitch:
 654       cell_count = MultiBranchData::compute_cell_count(stream);
 655       break;
 656     case Bytecodes::_invokespecial:
 657     case Bytecodes::_invokestatic:
 658     case Bytecodes::_invokedynamic:
 659       assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile");
 660       if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
 661           profile_return_for_invoke(stream->method(), stream->bci())) {
 662         cell_count = CallTypeData::compute_cell_count(stream);
 663       } else {
 664         cell_count = CounterData::static_cell_count();
 665       }
 666       break;
 667     case Bytecodes::_invokevirtual:
 668     case Bytecodes::_invokeinterface: {
 669       assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile");
 670       if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
 671           profile_return_for_invoke(stream->method(), stream->bci())) {
 672         cell_count = VirtualCallTypeData::compute_cell_count(stream);
 673       } else {
 674         cell_count = VirtualCallData::static_cell_count();
 675       }
 676       break;
 677     }
 678     default:
 679       fatal("unexpected bytecode for var length profile data");
 680     }
 681   }
 682   // Note:  cell_count might be zero, meaning that there is just
 683   //        a DataLayout header, with no extra cells.
 684   assert(cell_count >= 0, "sanity");
 685   return DataLayout::compute_size_in_bytes(cell_count);
 686 }
 687 
 688 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count) {
 689   if (ProfileTraps) {
 690     // Assume that up to 3% of BCIs with no MDP will need to allocate one.
 691     int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;


 744 #else
 745   int cell_count = -1;
 746   int tag = DataLayout::no_tag;
 747   DataLayout* data_layout = data_layout_at(data_index);
 748   Bytecodes::Code c = stream->code();
 749   switch (c) {
 750   case Bytecodes::_checkcast:
 751   case Bytecodes::_instanceof:
 752   case Bytecodes::_aastore:
 753     if (TypeProfileCasts) {
 754       cell_count = ReceiverTypeData::static_cell_count();
 755       tag = DataLayout::receiver_type_data_tag;
 756     } else {
 757       cell_count = BitData::static_cell_count();
 758       tag = DataLayout::bit_data_tag;
 759     }
 760     break;
 761   case Bytecodes::_invokespecial:
 762   case Bytecodes::_invokestatic: {
 763     int counter_data_cell_count = CounterData::static_cell_count();
 764     if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
 765         profile_return_for_invoke(stream->method(), stream->bci())) {
 766       cell_count = CallTypeData::compute_cell_count(stream);
 767     } else {
 768       cell_count = counter_data_cell_count;
 769     }
 770     if (cell_count > counter_data_cell_count) {
 771       tag = DataLayout::call_type_data_tag;
 772     } else {
 773       tag = DataLayout::counter_data_tag;
 774     }
 775     break;
 776   }
 777   case Bytecodes::_goto:
 778   case Bytecodes::_goto_w:
 779   case Bytecodes::_jsr:
 780   case Bytecodes::_jsr_w:
 781     cell_count = JumpData::static_cell_count();
 782     tag = DataLayout::jump_data_tag;
 783     break;
 784   case Bytecodes::_invokevirtual:
 785   case Bytecodes::_invokeinterface: {
 786     int virtual_call_data_cell_count = VirtualCallData::static_cell_count();
 787     if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
 788         profile_return_for_invoke(stream->method(), stream->bci())) {
 789       cell_count = VirtualCallTypeData::compute_cell_count(stream);
 790     } else {
 791       cell_count = virtual_call_data_cell_count;
 792     }
 793     if (cell_count > virtual_call_data_cell_count) {
 794       tag = DataLayout::virtual_call_type_data_tag;
 795     } else {
 796       tag = DataLayout::virtual_call_data_tag;
 797     }
 798     break;
 799   }
 800   case Bytecodes::_invokedynamic: {
 801     // %%% should make a type profile for any invokedynamic that takes a ref argument
 802     int counter_data_cell_count = CounterData::static_cell_count();
 803     if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
 804         profile_return_for_invoke(stream->method(), stream->bci())) {
 805       cell_count = CallTypeData::compute_cell_count(stream);
 806     } else {
 807       cell_count = counter_data_cell_count;
 808     }
 809     if (cell_count > counter_data_cell_count) {
 810       tag = DataLayout::call_type_data_tag;
 811     } else {
 812       tag = DataLayout::counter_data_tag;
 813     }
 814     break;
 815   }
 816   case Bytecodes::_ret:
 817     cell_count = RetData::static_cell_count();
 818     tag = DataLayout::ret_data_tag;
 819     break;
 820   case Bytecodes::_ifeq:
 821   case Bytecodes::_ifne:
 822   case Bytecodes::_iflt:
 823   case Bytecodes::_ifge:
 824   case Bytecodes::_ifgt:


 826   case Bytecodes::_if_icmpeq:
 827   case Bytecodes::_if_icmpne:
 828   case Bytecodes::_if_icmplt:
 829   case Bytecodes::_if_icmpge:
 830   case Bytecodes::_if_icmpgt:
 831   case Bytecodes::_if_icmple:
 832   case Bytecodes::_if_acmpeq:
 833   case Bytecodes::_if_acmpne:
 834   case Bytecodes::_ifnull:
 835   case Bytecodes::_ifnonnull:
 836     cell_count = BranchData::static_cell_count();
 837     tag = DataLayout::branch_data_tag;
 838     break;
 839   case Bytecodes::_lookupswitch:
 840   case Bytecodes::_tableswitch:
 841     cell_count = MultiBranchData::compute_cell_count(stream);
 842     tag = DataLayout::multi_branch_data_tag;
 843     break;
 844   }
 845   assert(tag == DataLayout::multi_branch_data_tag ||
 846          ((MethodData::profile_arguments() || MethodData::profile_return()) &&
 847           (tag == DataLayout::call_type_data_tag ||
 848            tag == DataLayout::counter_data_tag ||
 849            tag == DataLayout::virtual_call_type_data_tag ||
 850            tag == DataLayout::virtual_call_data_tag)) ||
 851          cell_count == bytecode_cell_count(c), "cell counts must agree");
 852   if (cell_count >= 0) {
 853     assert(tag != DataLayout::no_tag, "bad tag");
 854     assert(bytecode_has_profile(c), "agree w/ BHP");
 855     data_layout->initialize(tag, stream->bci(), cell_count);
 856     return DataLayout::compute_size_in_bytes(cell_count);
 857   } else {
 858     assert(!bytecode_has_profile(c), "agree w/ !BHP");
 859     return 0;
 860   }
 861 #endif
 862 }
 863 
 864 // Get the data at an arbitrary (sort of) data index.
 865 ProfileData* MethodData::data_at(int data_index) const {
 866   if (out_of_bounds(data_index)) {


1159   guarantee(is_methodData(), "object must be method data");
1160   // guarantee(m->is_perm(), "should be in permspace");
1161   this->verify_data_on(st);
1162 }
1163 
1164 void MethodData::verify_data_on(outputStream* st) {
1165   NEEDS_CLEANUP;
1166   // not yet implemented.
1167 }
1168 
1169 bool MethodData::profile_jsr292(methodHandle m, int bci) {
1170   if (m->is_compiled_lambda_form()) {
1171     return true;
1172   }
1173 
1174   Bytecode_invoke inv(m , bci);
1175   return inv.is_invokedynamic() || inv.is_invokehandle();
1176 }
1177 
1178 int MethodData::profile_arguments_flag() {
1179   return TypeProfileLevel % 10;
1180 }
1181 
1182 bool MethodData::profile_arguments() {
1183   return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all;
1184 }
1185 
1186 bool MethodData::profile_arguments_jsr292_only() {
1187   return profile_arguments_flag() == type_profile_jsr292;
1188 }
1189 
1190 bool MethodData::profile_all_arguments() {
1191   return profile_arguments_flag() == type_profile_all;
1192 }
1193 
1194 bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) {
1195   if (!profile_arguments()) {
1196     return false;
1197   }
1198   
1199   if (profile_all_arguments()) {
1200     return true;
1201   }
1202   
1203   assert(profile_arguments_jsr292_only(), "inconsistent");
1204   return profile_jsr292(m, bci);
1205 }
1206 
1207 int MethodData::profile_return_flag() {
1208   return TypeProfileLevel / 10;
1209 }
1210 
1211 bool MethodData::profile_return() {
1212   return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all;
1213 }
1214 
1215 bool MethodData::profile_return_jsr292_only() {
1216   return profile_return_flag() == type_profile_jsr292;
1217 }
1218 
1219 bool MethodData::profile_all_return() {
1220   return profile_return_flag() == type_profile_all;
1221 }
1222 
1223 bool MethodData::profile_return_for_invoke(methodHandle m, int bci) {
1224   if (!profile_return()) {
1225     return false;
1226   }
1227   
1228   if (profile_all_return()) {
1229     return true;
1230   }
1231   
1232   assert(profile_return_jsr292_only(), "inconsistent");
1233   return profile_jsr292(m, bci);
1234 }
src/share/vm/oops/methodData.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File