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 5462 : 8026251: New type profiling points: parameters to methods
Summary: x86 interpreter and c1 type profiling for parameters on method entries
Reviewed-by:


  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "interpreter/bytecode.hpp"
  28 #include "interpreter/bytecodeStream.hpp"
  29 #include "interpreter/linkResolver.hpp"
  30 #include "memory/heapInspection.hpp"
  31 #include "oops/methodData.hpp"
  32 #include "prims/jvmtiRedefineClasses.hpp"
  33 #include "runtime/compilationPolicy.hpp"
  34 #include "runtime/deoptimization.hpp"
  35 #include "runtime/handles.inline.hpp"
  36 
  37 // ==================================================================
  38 // DataLayout
  39 //
  40 // Overlay for generic profiling data.
  41 
  42 // Some types of data layouts need a length field.
  43 bool DataLayout::needs_array_len(u1 tag) {
  44   return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag);
  45 }
  46 
  47 // Perform generic initialization of the data.  More specific
  48 // initialization occurs in overrides of ProfileData::post_initialize.
  49 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
  50   _header._bits = (intptr_t)0;
  51   _header._struct._tag = tag;
  52   _header._struct._bci = bci;
  53   for (int i = 0; i < cell_count; i++) {
  54     set_cell_at(i, (intptr_t)0);
  55   }
  56   if (needs_array_len(tag)) {
  57     set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
  58   }
  59   if (tag == call_type_data_tag) {
  60     CallTypeData::initialize(this, cell_count);
  61   } else if (tag == virtual_call_type_data_tag) {
  62     VirtualCallTypeData::initialize(this, cell_count);
  63   }
  64 }


 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   ResourceMark rm;
 161   SignatureStream ss(signature);
 162   int args_count = MIN2(ss.reference_parameter_count(), max);

 163   return args_count * per_arg_cell_count;
 164 }
 165 
 166 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {
 167   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 168   assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken");
 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 
 183   return header_cell + args_cell + ret_cell;
 184 }
 185 
 186 class ArgumentOffsetComputer : public SignatureInfo {
 187 private:
 188   int _max;
 189   GrowableArray<int> _offsets;
 190 
 191   void set(int size, BasicType type) { _size += size; }
 192   void do_object(int begin, int end) {


 195     }
 196     SignatureInfo::do_object(begin, end);
 197   }
 198   void do_array (int begin, int end) {
 199     if (_offsets.length() < _max) {
 200       _offsets.push(_size);
 201     }
 202     SignatureInfo::do_array(begin, end);
 203   }
 204 
 205 public:
 206   ArgumentOffsetComputer(Symbol* signature, int max)
 207     : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) {
 208   }
 209 
 210   int total() { lazy_iterate_parameters(); return _size; }
 211 
 212   int off_at(int i) const { return _offsets.at(i); }
 213 };
 214 
 215 void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver) {
 216   ResourceMark rm;
 217   ArgumentOffsetComputer aos(signature, _number_of_entries);







 218   aos.total();
 219   for (int i = 0; i < _number_of_entries; i++) {
 220     set_stack_slot(i, aos.off_at(i) + (has_receiver ? 1 : 0));
 221     set_type(i, type_none());
 222   }
 223 }
 224 
 225 void CallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 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 (has_arguments()) {
 231 #ifdef ASSERT
 232     ResourceMark rm;
 233     int count = MIN2(ss.reference_parameter_count(), (int)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 (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 void VirtualCallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 247   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 248   Bytecode_invoke inv(stream->method(), stream->bci());
 249 
 250   if (has_arguments()) {
 251 #ifdef ASSERT
 252     ResourceMark rm;
 253     SignatureStream ss(inv.signature());
 254     int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);
 255     assert(count > 0, "room for args type but none found?");
 256     check_number_of_arguments(count);
 257 #endif
 258     _args.post_initialize(inv.signature(), inv.has_receiver());
 259   }
 260 
 261   if (has_return()) {
 262     assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");
 263     _ret.post_initialize();
 264   }
 265 }
 266 
 267 bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {
 268   return !is_type_none(p) &&
 269     !((Klass*)klass_part(p))->is_loader_alive(is_alive_cl);
 270 }
 271 
 272 void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 273   for (int i = 0; i < _number_of_entries; i++) {
 274     intptr_t p = type(i);
 275     if (is_loader_alive(is_alive_cl, p)) {
 276       set_type(i, type_none());
 277     }
 278   }


 562   int cases = number_of_cases();
 563   for (int i = 0; i < cases; i++) {
 564     tab(st);
 565     st->print_cr("count(%u) displacement(%d)",
 566                  count_at(i), displacement_at(i));
 567   }
 568 }
 569 #endif
 570 
 571 #ifndef PRODUCT
 572 void ArgInfoData::print_data_on(outputStream* st) const {
 573   print_shared(st, "ArgInfoData");
 574   int nargs = number_of_args();
 575   for (int i = 0; i < nargs; i++) {
 576     st->print("  0x%x", arg_modified(i));
 577   }
 578   st->cr();
 579 }
 580 
 581 #endif




























 582 // ==================================================================
 583 // MethodData*
 584 //
 585 // A MethodData* holds information which has been collected about
 586 // a method.
 587 
 588 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
 589   int size = MethodData::compute_allocation_size_in_words(method);
 590 
 591   return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
 592     MethodData(method(), size, CHECK_NULL);
 593 }
 594 
 595 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 596 #if defined(COMPILER1) && !defined(COMPILER2)
 597   return no_profile_data;
 598 #else
 599   switch (code) {
 600   case Bytecodes::_checkcast:
 601   case Bytecodes::_instanceof:


 724 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
 725   int data_size = 0;
 726   BytecodeStream stream(method);
 727   Bytecodes::Code c;
 728   int empty_bc_count = 0;  // number of bytecodes lacking data
 729   while ((c = stream.next()) >= 0) {
 730     int size_in_bytes = compute_data_size(&stream);
 731     data_size += size_in_bytes;
 732     if (size_in_bytes == 0)  empty_bc_count += 1;
 733   }
 734   int object_size = in_bytes(data_offset()) + data_size;
 735 
 736   // Add some extra DataLayout cells (at least one) to track stray traps.
 737   int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
 738   object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
 739 
 740   // Add a cell to record information about modified arguments.
 741   int arg_size = method->size_of_parameters();
 742   object_size += DataLayout::compute_size_in_bytes(arg_size+1);
 743 






 744   return object_size;
 745 }
 746 
 747 // Compute the size of the MethodData* necessary to store
 748 // profiling information about a given method.  Size is in words
 749 int MethodData::compute_allocation_size_in_words(methodHandle method) {
 750   int byte_size = compute_allocation_size_in_bytes(method);
 751   int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
 752   return align_object_size(word_size);
 753 }
 754 
 755 // Initialize an individual data segment.  Returns the size of
 756 // the segment in bytes.
 757 int MethodData::initialize_data(BytecodeStream* stream,
 758                                        int data_index) {
 759 #if defined(COMPILER1) && !defined(COMPILER2)
 760   return 0;
 761 #else
 762   int cell_count = -1;
 763   int tag = DataLayout::no_tag;


 898   case DataLayout::counter_data_tag:
 899     return new CounterData(this);
 900   case DataLayout::jump_data_tag:
 901     return new JumpData(this);
 902   case DataLayout::receiver_type_data_tag:
 903     return new ReceiverTypeData(this);
 904   case DataLayout::virtual_call_data_tag:
 905     return new VirtualCallData(this);
 906   case DataLayout::ret_data_tag:
 907     return new RetData(this);
 908   case DataLayout::branch_data_tag:
 909     return new BranchData(this);
 910   case DataLayout::multi_branch_data_tag:
 911     return new MultiBranchData(this);
 912   case DataLayout::arg_info_data_tag:
 913     return new ArgInfoData(this);
 914   case DataLayout::call_type_data_tag:
 915     return new CallTypeData(this);
 916   case DataLayout::virtual_call_type_data_tag:
 917     return new VirtualCallTypeData(this);


 918   };
 919 }
 920 
 921 // Iteration over data.
 922 ProfileData* MethodData::next_data(ProfileData* current) const {
 923   int current_index = dp_to_di(current->dp());
 924   int next_index = current_index + current->size_in_bytes();
 925   ProfileData* next = data_at(next_index);
 926   return next;
 927 }
 928 
 929 // Give each of the data entries a chance to perform specific
 930 // data initialization.
 931 void MethodData::post_initialize(BytecodeStream* stream) {
 932   ResourceMark rm;
 933   ProfileData* data;
 934   for (data = first_data(); is_valid(data); data = next_data(data)) {
 935     stream->set_start(data->bci());
 936     stream->next();
 937     data->post_initialize(stream, this);
 938   }



 939 }
 940 
 941 // Initialize the MethodData* corresponding to a given method.
 942 MethodData::MethodData(methodHandle method, int size, TRAPS) {
 943   No_Safepoint_Verifier no_safepoint;  // init function atomic wrt GC
 944   ResourceMark rm;
 945   // Set the method back-pointer.
 946   _method = method();
 947 
 948   init();
 949   set_creation_mileage(mileage_of(method()));
 950 
 951   // Go through the bytecodes and allocate and initialize the
 952   // corresponding data cells.
 953   int data_size = 0;
 954   int empty_bc_count = 0;  // number of bytecodes lacking data
 955   _data[0] = 0;  // apparently not set below.
 956   BytecodeStream stream(method);
 957   Bytecodes::Code c;
 958   while ((c = stream.next()) >= 0) {
 959     int size_in_bytes = initialize_data(&stream, data_size);
 960     data_size += size_in_bytes;
 961     if (size_in_bytes == 0)  empty_bc_count += 1;
 962   }
 963   _data_size = data_size;
 964   int object_size = in_bytes(data_offset()) + data_size;
 965 
 966   // Add some extra DataLayout cells (at least one) to track stray traps.
 967   int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
 968   int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
 969 
 970   // Add a cell to record information about modified arguments.
 971   // Set up _args_modified array after traps cells so that
 972   // the code for traps cells works.
 973   DataLayout *dp = data_layout_at(data_size + extra_size);
 974 
 975   int arg_size = method->size_of_parameters();
 976   dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
 977 
 978   object_size += extra_size + DataLayout::compute_size_in_bytes(arg_size+1);
















 979 
 980   // Set an initial hint. Don't use set_hint_di() because
 981   // first_di() may be out of bounds if data_size is 0.
 982   // In that situation, _hint_di is never used, but at
 983   // least well-defined.
 984   _hint_di = first_di();
 985 
 986   post_initialize(&stream);
 987 
 988   set_size(object_size);
 989 }
 990 
 991 void MethodData::init() {
 992   _invocation_counter.init();
 993   _backedge_counter.init();
 994   _invocation_counter_start = 0;
 995   _backedge_counter_start = 0;
 996   _num_loops = 0;
 997   _num_blocks = 0;
 998   _highest_comp_level = 0;


1117 void MethodData::print_on(outputStream* st) const {
1118   assert(is_methodData(), "should be method data");
1119   st->print("method data for ");
1120   method()->print_value_on(st);
1121   st->cr();
1122   print_data_on(st);
1123 }
1124 
1125 #endif //PRODUCT
1126 
1127 void MethodData::print_value_on(outputStream* st) const {
1128   assert(is_methodData(), "should be method data");
1129   st->print("method data for ");
1130   method()->print_value_on(st);
1131 }
1132 
1133 #ifndef PRODUCT
1134 void MethodData::print_data_on(outputStream* st) const {
1135   ResourceMark rm;
1136   ProfileData* data = first_data();



1137   for ( ; is_valid(data); data = next_data(data)) {
1138     st->print("%d", dp_to_di(data->dp()));
1139     st->fill_to(6);
1140     data->print_data_on(st);
1141   }
1142   st->print_cr("--- Extra data:");
1143   DataLayout* dp    = extra_data_base();
1144   DataLayout* end   = extra_data_limit();
1145   for (; dp < end; dp = next_extra(dp)) {
1146     // No need for "OrderAccess::load_acquire" ops,
1147     // since the data structure is monotonic.
1148     if (dp->tag() == DataLayout::no_tag)  continue;
1149     if (dp->tag() == DataLayout::bit_data_tag) {
1150       data = new BitData(dp);
1151     } else {
1152       assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo");
1153       data = new ArgInfoData(dp);
1154       dp = end; // ArgInfoData is at the end of extra data section.
1155     }
1156     st->print("%d", dp_to_di(data->dp()));


1205 }
1206 
1207 bool MethodData::profile_all_arguments() {
1208   return profile_arguments_flag() == type_profile_all;
1209 }
1210 
1211 bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) {
1212   if (!profile_arguments()) {
1213     return false;
1214   }
1215 
1216   if (profile_all_arguments()) {
1217     return true;
1218   }
1219 
1220   assert(profile_arguments_jsr292_only(), "inconsistent");
1221   return profile_jsr292(m, bci);
1222 }
1223 
1224 int MethodData::profile_return_flag() {
1225   return TypeProfileLevel / 10;
1226 }
1227 
1228 bool MethodData::profile_return() {
1229   return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all;
1230 }
1231 
1232 bool MethodData::profile_return_jsr292_only() {
1233   return profile_return_flag() == type_profile_jsr292;
1234 }
1235 
1236 bool MethodData::profile_all_return() {
1237   return profile_return_flag() == type_profile_all;
1238 }
1239 
1240 bool MethodData::profile_return_for_invoke(methodHandle m, int bci) {
1241   if (!profile_return()) {
1242     return false;
1243   }
1244 
1245   if (profile_all_return()) {
1246     return true;
1247   }
1248 
1249   assert(profile_return_jsr292_only(), "inconsistent");
1250   return profile_jsr292(m, bci);





























1251 }


  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "interpreter/bytecode.hpp"
  28 #include "interpreter/bytecodeStream.hpp"
  29 #include "interpreter/linkResolver.hpp"
  30 #include "memory/heapInspection.hpp"
  31 #include "oops/methodData.hpp"
  32 #include "prims/jvmtiRedefineClasses.hpp"
  33 #include "runtime/compilationPolicy.hpp"
  34 #include "runtime/deoptimization.hpp"
  35 #include "runtime/handles.inline.hpp"
  36 
  37 // ==================================================================
  38 // DataLayout
  39 //
  40 // Overlay for generic profiling data.
  41 
  42 // Some types of data layouts need a length field.
  43 bool DataLayout::needs_array_len(u1 tag) {
  44   return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag) || (tag == parameters_type_data_tag);
  45 }
  46 
  47 // Perform generic initialization of the data.  More specific
  48 // initialization occurs in overrides of ProfileData::post_initialize.
  49 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
  50   _header._bits = (intptr_t)0;
  51   _header._struct._tag = tag;
  52   _header._struct._bci = bci;
  53   for (int i = 0; i < cell_count; i++) {
  54     set_cell_at(i, (intptr_t)0);
  55   }
  56   if (needs_array_len(tag)) {
  57     set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
  58   }
  59   if (tag == call_type_data_tag) {
  60     CallTypeData::initialize(this, cell_count);
  61   } else if (tag == virtual_call_type_data_tag) {
  62     VirtualCallTypeData::initialize(this, cell_count);
  63   }
  64 }


 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, bool include_receiver, int max) {
 160   // Parameter profiling include the receiver
 161   int args_count = include_receiver ? 1 : 0;
 162   ResourceMark rm;
 163   SignatureStream ss(signature);
 164   args_count += ss.reference_parameter_count();
 165   args_count = MIN2(args_count, max);
 166   return args_count * per_arg_cell_count;
 167 }
 168 
 169 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {
 170   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 171   assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken");
 172   Bytecode_invoke inv(stream->method(), stream->bci());
 173   int args_cell = 0;
 174   if (arguments_profiling_enabled()) {
 175     args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit);
 176   }
 177   int ret_cell = 0;
 178   if (return_profiling_enabled() && (inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY)) {
 179     ret_cell = ReturnTypeEntry::static_cell_count();
 180   }
 181   int header_cell = 0;
 182   if (args_cell + ret_cell > 0) {
 183     header_cell = header_cell_count();
 184   }
 185 
 186   return header_cell + args_cell + ret_cell;
 187 }
 188 
 189 class ArgumentOffsetComputer : public SignatureInfo {
 190 private:
 191   int _max;
 192   GrowableArray<int> _offsets;
 193 
 194   void set(int size, BasicType type) { _size += size; }
 195   void do_object(int begin, int end) {


 198     }
 199     SignatureInfo::do_object(begin, end);
 200   }
 201   void do_array (int begin, int end) {
 202     if (_offsets.length() < _max) {
 203       _offsets.push(_size);
 204     }
 205     SignatureInfo::do_array(begin, end);
 206   }
 207 
 208 public:
 209   ArgumentOffsetComputer(Symbol* signature, int max)
 210     : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) {
 211   }
 212 
 213   int total() { lazy_iterate_parameters(); return _size; }
 214 
 215   int off_at(int i) const { return _offsets.at(i); }
 216 };
 217 
 218 void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver, bool include_receiver) {
 219   ResourceMark rm;
 220   int start = 0;
 221   // Parameter profiling include the receiver
 222   if (include_receiver && has_receiver) {
 223     set_stack_slot(0, 0);
 224     set_type(0, type_none());
 225     start += 1;
 226   }
 227   ArgumentOffsetComputer aos(signature, _number_of_entries-start);
 228   aos.total();
 229   for (int i = start; i < _number_of_entries; i++) {
 230     set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0));
 231     set_type(i, type_none());
 232   }
 233 }
 234 
 235 void CallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 236   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 237   Bytecode_invoke inv(stream->method(), stream->bci());
 238 
 239   SignatureStream ss(inv.signature());
 240   if (has_arguments()) {
 241 #ifdef ASSERT
 242     ResourceMark rm;
 243     int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);
 244     assert(count > 0, "room for args type but none found?");
 245     check_number_of_arguments(count);
 246 #endif
 247     _args.post_initialize(inv.signature(), inv.has_receiver(), false);
 248   }
 249 
 250   if (has_return()) {
 251     assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");
 252     _ret.post_initialize();
 253   }
 254 }
 255 
 256 void VirtualCallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 257   assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
 258   Bytecode_invoke inv(stream->method(), stream->bci());
 259 
 260   if (has_arguments()) {
 261 #ifdef ASSERT
 262     ResourceMark rm;
 263     SignatureStream ss(inv.signature());
 264     int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);
 265     assert(count > 0, "room for args type but none found?");
 266     check_number_of_arguments(count);
 267 #endif
 268     _args.post_initialize(inv.signature(), inv.has_receiver(), false);
 269   }
 270 
 271   if (has_return()) {
 272     assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");
 273     _ret.post_initialize();
 274   }
 275 }
 276 
 277 bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {
 278   return !is_type_none(p) &&
 279     !((Klass*)klass_part(p))->is_loader_alive(is_alive_cl);
 280 }
 281 
 282 void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
 283   for (int i = 0; i < _number_of_entries; i++) {
 284     intptr_t p = type(i);
 285     if (is_loader_alive(is_alive_cl, p)) {
 286       set_type(i, type_none());
 287     }
 288   }


 572   int cases = number_of_cases();
 573   for (int i = 0; i < cases; i++) {
 574     tab(st);
 575     st->print_cr("count(%u) displacement(%d)",
 576                  count_at(i), displacement_at(i));
 577   }
 578 }
 579 #endif
 580 
 581 #ifndef PRODUCT
 582 void ArgInfoData::print_data_on(outputStream* st) const {
 583   print_shared(st, "ArgInfoData");
 584   int nargs = number_of_args();
 585   for (int i = 0; i < nargs; i++) {
 586     st->print("  0x%x", arg_modified(i));
 587   }
 588   st->cr();
 589 }
 590 
 591 #endif
 592 
 593 int ParametersTypeData::compute_cell_count(Method* m) {
 594   if (!MethodData::profile_parameters_for_method(m)) {
 595     return 0;
 596   }
 597   int max = TypeProfileParmsLimit == -1 ? INT_MAX : TypeProfileParmsLimit;
 598   int obj_args = TypeStackSlotEntries::compute_cell_count(m->signature(), !m->is_static(), max);
 599   if (obj_args > 0) {
 600     return obj_args + 1; // 1 cell for array len
 601   }
 602   return 0;
 603 }
 604 
 605 void ParametersTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
 606   _parameters.post_initialize(mdo->method()->signature(), !mdo->method()->is_static(), true);
 607 }
 608 
 609 bool ParametersTypeData::profiling_enabled() {
 610   return MethodData::profile_parameters();
 611 }
 612 
 613 #ifndef PRODUCT
 614 void ParametersTypeData::print_data_on(outputStream* st) const {
 615   st->print("parameter types");
 616   _parameters.print_data_on(st);
 617 }
 618 #endif
 619 
 620 // ==================================================================
 621 // MethodData*
 622 //
 623 // A MethodData* holds information which has been collected about
 624 // a method.
 625 
 626 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
 627   int size = MethodData::compute_allocation_size_in_words(method);
 628 
 629   return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
 630     MethodData(method(), size, CHECK_NULL);
 631 }
 632 
 633 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
 634 #if defined(COMPILER1) && !defined(COMPILER2)
 635   return no_profile_data;
 636 #else
 637   switch (code) {
 638   case Bytecodes::_checkcast:
 639   case Bytecodes::_instanceof:


 762 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
 763   int data_size = 0;
 764   BytecodeStream stream(method);
 765   Bytecodes::Code c;
 766   int empty_bc_count = 0;  // number of bytecodes lacking data
 767   while ((c = stream.next()) >= 0) {
 768     int size_in_bytes = compute_data_size(&stream);
 769     data_size += size_in_bytes;
 770     if (size_in_bytes == 0)  empty_bc_count += 1;
 771   }
 772   int object_size = in_bytes(data_offset()) + data_size;
 773 
 774   // Add some extra DataLayout cells (at least one) to track stray traps.
 775   int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
 776   object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
 777 
 778   // Add a cell to record information about modified arguments.
 779   int arg_size = method->size_of_parameters();
 780   object_size += DataLayout::compute_size_in_bytes(arg_size+1);
 781 
 782   // Reserve room for an area of the MDO dedicated to profiling of
 783   // parameters
 784   int args_cell = ParametersTypeData::compute_cell_count(method());
 785   if (args_cell > 0) {
 786     object_size += DataLayout::compute_size_in_bytes(args_cell);
 787   }
 788   return object_size;
 789 }
 790 
 791 // Compute the size of the MethodData* necessary to store
 792 // profiling information about a given method.  Size is in words
 793 int MethodData::compute_allocation_size_in_words(methodHandle method) {
 794   int byte_size = compute_allocation_size_in_bytes(method);
 795   int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
 796   return align_object_size(word_size);
 797 }
 798 
 799 // Initialize an individual data segment.  Returns the size of
 800 // the segment in bytes.
 801 int MethodData::initialize_data(BytecodeStream* stream,
 802                                        int data_index) {
 803 #if defined(COMPILER1) && !defined(COMPILER2)
 804   return 0;
 805 #else
 806   int cell_count = -1;
 807   int tag = DataLayout::no_tag;


 942   case DataLayout::counter_data_tag:
 943     return new CounterData(this);
 944   case DataLayout::jump_data_tag:
 945     return new JumpData(this);
 946   case DataLayout::receiver_type_data_tag:
 947     return new ReceiverTypeData(this);
 948   case DataLayout::virtual_call_data_tag:
 949     return new VirtualCallData(this);
 950   case DataLayout::ret_data_tag:
 951     return new RetData(this);
 952   case DataLayout::branch_data_tag:
 953     return new BranchData(this);
 954   case DataLayout::multi_branch_data_tag:
 955     return new MultiBranchData(this);
 956   case DataLayout::arg_info_data_tag:
 957     return new ArgInfoData(this);
 958   case DataLayout::call_type_data_tag:
 959     return new CallTypeData(this);
 960   case DataLayout::virtual_call_type_data_tag:
 961     return new VirtualCallTypeData(this);
 962   case DataLayout::parameters_type_data_tag:
 963     return new ParametersTypeData(this);
 964   };
 965 }
 966 
 967 // Iteration over data.
 968 ProfileData* MethodData::next_data(ProfileData* current) const {
 969   int current_index = dp_to_di(current->dp());
 970   int next_index = current_index + current->size_in_bytes();
 971   ProfileData* next = data_at(next_index);
 972   return next;
 973 }
 974 
 975 // Give each of the data entries a chance to perform specific
 976 // data initialization.
 977 void MethodData::post_initialize(BytecodeStream* stream) {
 978   ResourceMark rm;
 979   ProfileData* data;
 980   for (data = first_data(); is_valid(data); data = next_data(data)) {
 981     stream->set_start(data->bci());
 982     stream->next();
 983     data->post_initialize(stream, this);
 984   }
 985   if (_parameters_type_data_di != -1) {
 986     parameters_type_data()->post_initialize(NULL, this);
 987   }
 988 }
 989 
 990 // Initialize the MethodData* corresponding to a given method.
 991 MethodData::MethodData(methodHandle method, int size, TRAPS) {
 992   No_Safepoint_Verifier no_safepoint;  // init function atomic wrt GC
 993   ResourceMark rm;
 994   // Set the method back-pointer.
 995   _method = method();
 996 
 997   init();
 998   set_creation_mileage(mileage_of(method()));
 999 
1000   // Go through the bytecodes and allocate and initialize the
1001   // corresponding data cells.
1002   int data_size = 0;
1003   int empty_bc_count = 0;  // number of bytecodes lacking data
1004   _data[0] = 0;  // apparently not set below.
1005   BytecodeStream stream(method);
1006   Bytecodes::Code c;
1007   while ((c = stream.next()) >= 0) {
1008     int size_in_bytes = initialize_data(&stream, data_size);
1009     data_size += size_in_bytes;
1010     if (size_in_bytes == 0)  empty_bc_count += 1;
1011   }
1012   _data_size = data_size;
1013   int object_size = in_bytes(data_offset()) + data_size;
1014 
1015   // Add some extra DataLayout cells (at least one) to track stray traps.
1016   int extra_data_count = compute_extra_data_count(data_size, empty_bc_count);
1017   int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
1018 
1019   // Add a cell to record information about modified arguments.
1020   // Set up _args_modified array after traps cells so that
1021   // the code for traps cells works.
1022   DataLayout *dp = data_layout_at(data_size + extra_size);
1023 
1024   int arg_size = method->size_of_parameters();
1025   dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
1026 
1027   int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
1028   object_size += extra_size + arg_data_size;
1029 
1030   int args_cell = ParametersTypeData::compute_cell_count(method());
1031   // If we are profiling parameters, we reserver an area near the end
1032   // of the MDO after the slots for bytecodes (because there's no bci
1033   // for method entry so they don't fit with the framework for the
1034   // profiling of bytecodes). We store the offset within the MDO of
1035   // this area (or -1 if no parameter is profiled)
1036   if (args_cell > 0) {
1037     object_size += DataLayout::compute_size_in_bytes(args_cell);
1038     _parameters_type_data_di = data_size + extra_size + arg_data_size;
1039     DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
1040     dp->initialize(DataLayout::parameters_type_data_tag, 0, args_cell);
1041   } else {
1042     _parameters_type_data_di = -1;
1043   }
1044 
1045   // Set an initial hint. Don't use set_hint_di() because
1046   // first_di() may be out of bounds if data_size is 0.
1047   // In that situation, _hint_di is never used, but at
1048   // least well-defined.
1049   _hint_di = first_di();
1050 
1051   post_initialize(&stream);
1052 
1053   set_size(object_size);
1054 }
1055 
1056 void MethodData::init() {
1057   _invocation_counter.init();
1058   _backedge_counter.init();
1059   _invocation_counter_start = 0;
1060   _backedge_counter_start = 0;
1061   _num_loops = 0;
1062   _num_blocks = 0;
1063   _highest_comp_level = 0;


1182 void MethodData::print_on(outputStream* st) const {
1183   assert(is_methodData(), "should be method data");
1184   st->print("method data for ");
1185   method()->print_value_on(st);
1186   st->cr();
1187   print_data_on(st);
1188 }
1189 
1190 #endif //PRODUCT
1191 
1192 void MethodData::print_value_on(outputStream* st) const {
1193   assert(is_methodData(), "should be method data");
1194   st->print("method data for ");
1195   method()->print_value_on(st);
1196 }
1197 
1198 #ifndef PRODUCT
1199 void MethodData::print_data_on(outputStream* st) const {
1200   ResourceMark rm;
1201   ProfileData* data = first_data();
1202   if (_parameters_type_data_di != -1) {
1203     parameters_type_data()->print_data_on(st);
1204   }
1205   for ( ; is_valid(data); data = next_data(data)) {
1206     st->print("%d", dp_to_di(data->dp()));
1207     st->fill_to(6);
1208     data->print_data_on(st);
1209   }
1210   st->print_cr("--- Extra data:");
1211   DataLayout* dp    = extra_data_base();
1212   DataLayout* end   = extra_data_limit();
1213   for (; dp < end; dp = next_extra(dp)) {
1214     // No need for "OrderAccess::load_acquire" ops,
1215     // since the data structure is monotonic.
1216     if (dp->tag() == DataLayout::no_tag)  continue;
1217     if (dp->tag() == DataLayout::bit_data_tag) {
1218       data = new BitData(dp);
1219     } else {
1220       assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo");
1221       data = new ArgInfoData(dp);
1222       dp = end; // ArgInfoData is at the end of extra data section.
1223     }
1224     st->print("%d", dp_to_di(data->dp()));


1273 }
1274 
1275 bool MethodData::profile_all_arguments() {
1276   return profile_arguments_flag() == type_profile_all;
1277 }
1278 
1279 bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) {
1280   if (!profile_arguments()) {
1281     return false;
1282   }
1283 
1284   if (profile_all_arguments()) {
1285     return true;
1286   }
1287 
1288   assert(profile_arguments_jsr292_only(), "inconsistent");
1289   return profile_jsr292(m, bci);
1290 }
1291 
1292 int MethodData::profile_return_flag() {
1293   return (TypeProfileLevel % 100) / 10;
1294 }
1295 
1296 bool MethodData::profile_return() {
1297   return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all;
1298 }
1299 
1300 bool MethodData::profile_return_jsr292_only() {
1301   return profile_return_flag() == type_profile_jsr292;
1302 }
1303 
1304 bool MethodData::profile_all_return() {
1305   return profile_return_flag() == type_profile_all;
1306 }
1307 
1308 bool MethodData::profile_return_for_invoke(methodHandle m, int bci) {
1309   if (!profile_return()) {
1310     return false;
1311   }
1312 
1313   if (profile_all_return()) {
1314     return true;
1315   }
1316 
1317   assert(profile_return_jsr292_only(), "inconsistent");
1318   return profile_jsr292(m, bci);
1319 }
1320 
1321 int MethodData::profile_parameters_flag() {
1322   return TypeProfileLevel / 100;
1323 }
1324 
1325 bool MethodData::profile_parameters() {
1326   return profile_parameters_flag() > no_type_profile && profile_parameters_flag() <= type_profile_all;
1327 }
1328 
1329 bool MethodData::profile_parameters_jsr292_only() {
1330   return profile_parameters_flag() == type_profile_jsr292;
1331 }
1332 
1333 bool MethodData::profile_all_parameters() {
1334   return profile_parameters_flag() == type_profile_all;
1335 }
1336 
1337 bool MethodData::profile_parameters_for_method(methodHandle m) {
1338   if (!profile_parameters()) {
1339     return false;
1340   }
1341 
1342   if (profile_all_parameters()) {
1343     return true;
1344   }
1345 
1346   assert(profile_parameters_jsr292_only(), "inconsistent");
1347   return m->is_compiled_lambda_form();
1348 }
src/share/vm/oops/methodData.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File