hotspot/src/share/vm/oops/methodData.cpp
changeset 33160 c59f1676d27e
parent 30183 a6588c0a3259
child 33198 b37ad9fbf681
equal deleted inserted replaced
33159:89b942323bd1 33160:c59f1676d27e
   411       clear_row(row);
   411       clear_row(row);
   412     }
   412     }
   413   }
   413   }
   414 }
   414 }
   415 
   415 
       
   416 #if INCLUDE_JVMCI
       
   417 void VirtualCallData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
       
   418   ReceiverTypeData::clean_weak_klass_links(is_alive_cl);
       
   419   for (uint row = 0; row < method_row_limit(); row++) {
       
   420     Method* p = method(row);
       
   421     if (p != NULL && !p->method_holder()->is_loader_alive(is_alive_cl)) {
       
   422       clear_method_row(row);
       
   423     }
       
   424   }
       
   425 }
       
   426 
       
   427 void VirtualCallData::clean_weak_method_links() {
       
   428   ReceiverTypeData::clean_weak_method_links();
       
   429   for (uint row = 0; row < method_row_limit(); row++) {
       
   430     Method* p = method(row);
       
   431     if (p != NULL && !p->on_stack()) {
       
   432       clear_method_row(row);
       
   433     }
       
   434   }
       
   435 }
       
   436 #endif // INCLUDE_JVMCI
       
   437 
   416 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const {
   438 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const {
   417   uint row;
   439   uint row;
   418   int entries = 0;
   440   int entries = 0;
   419   for (row = 0; row < row_limit(); row++) {
   441   for (row = 0; row < row_limit(); row++) {
   420     if (receiver(row) != NULL)  entries++;
   442     if (receiver(row) != NULL)  entries++;
   421   }
   443   }
       
   444 #if INCLUDE_JVMCI
       
   445   st->print_cr("count(%u) nonprofiled_count(%u) entries(%u)", count(), nonprofiled_count(), entries);
       
   446 #else
   422   st->print_cr("count(%u) entries(%u)", count(), entries);
   447   st->print_cr("count(%u) entries(%u)", count(), entries);
       
   448 #endif
   423   int total = count();
   449   int total = count();
   424   for (row = 0; row < row_limit(); row++) {
   450   for (row = 0; row < row_limit(); row++) {
   425     if (receiver(row) != NULL) {
   451     if (receiver(row) != NULL) {
   426       total += receiver_count(row);
   452       total += receiver_count(row);
   427     }
   453     }
   436 }
   462 }
   437 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {
   463 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {
   438   print_shared(st, "ReceiverTypeData", extra);
   464   print_shared(st, "ReceiverTypeData", extra);
   439   print_receiver_data_on(st);
   465   print_receiver_data_on(st);
   440 }
   466 }
       
   467 
       
   468 #if INCLUDE_JVMCI
       
   469 void VirtualCallData::print_method_data_on(outputStream* st) const {
       
   470   uint row;
       
   471   int entries = 0;
       
   472   for (row = 0; row < method_row_limit(); row++) {
       
   473     if (method(row) != NULL) entries++;
       
   474   }
       
   475   tab(st);
       
   476   st->print_cr("method_entries(%u)", entries);
       
   477   int total = count();
       
   478   for (row = 0; row < method_row_limit(); row++) {
       
   479     if (method(row) != NULL) {
       
   480       total += method_count(row);
       
   481     }
       
   482   }
       
   483   for (row = 0; row < method_row_limit(); row++) {
       
   484     if (method(row) != NULL) {
       
   485       tab(st);
       
   486       method(row)->print_value_on(st);
       
   487       st->print_cr("(%u %4.2f)", method_count(row), (float) method_count(row) / (float) total);
       
   488     }
       
   489   }
       
   490 }
       
   491 #endif // INCLUDE_JVMCI
       
   492 
   441 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const {
   493 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const {
   442   print_shared(st, "VirtualCallData", extra);
   494   print_shared(st, "VirtualCallData", extra);
   443   print_receiver_data_on(st);
   495   print_receiver_data_on(st);
       
   496   print_method_data_on(st);
   444 }
   497 }
   445 
   498 
   446 // ==================================================================
   499 // ==================================================================
   447 // RetData
   500 // RetData
   448 //
   501 //
   663   return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
   716   return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
   664     MethodData(method(), size, THREAD);
   717     MethodData(method(), size, THREAD);
   665 }
   718 }
   666 
   719 
   667 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
   720 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
   668 #if defined(COMPILER1) && !defined(COMPILER2)
   721 #if defined(COMPILER1) && !(defined(COMPILER2) || INCLUDE_JVMCI)
   669   return no_profile_data;
   722   return no_profile_data;
   670 #else
   723 #else
   671   switch (code) {
   724   switch (code) {
   672   case Bytecodes::_checkcast:
   725   case Bytecodes::_checkcast:
   673   case Bytecodes::_instanceof:
   726   case Bytecodes::_instanceof:
   795   }
   848   }
   796   return false;
   849   return false;
   797 }
   850 }
   798 
   851 
   799 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
   852 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
       
   853 #if INCLUDE_JVMCI
       
   854   if (ProfileTraps) {
       
   855     // Assume that up to 30% of the possibly trapping BCIs with no MDP will need to allocate one.
       
   856     int extra_data_count = MIN2(empty_bc_count, MAX2(4, (empty_bc_count * 30) / 100));
       
   857 
       
   858     // Make sure we have a minimum number of extra data slots to
       
   859     // allocate SpeculativeTrapData entries. We would want to have one
       
   860     // entry per compilation that inlines this method and for which
       
   861     // some type speculation assumption fails. So the room we need for
       
   862     // the SpeculativeTrapData entries doesn't directly depend on the
       
   863     // size of the method. Because it's hard to estimate, we reserve
       
   864     // space for an arbitrary number of entries.
       
   865     int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
       
   866       (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
       
   867 
       
   868     return MAX2(extra_data_count, spec_data_count);
       
   869   } else {
       
   870     return 0;
       
   871   }
       
   872 #else // INCLUDE_JVMCI
   800   if (ProfileTraps) {
   873   if (ProfileTraps) {
   801     // Assume that up to 3% of BCIs with no MDP will need to allocate one.
   874     // Assume that up to 3% of BCIs with no MDP will need to allocate one.
   802     int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
   875     int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
   803     // If the method is large, let the extra BCIs grow numerous (to ~1%).
   876     // If the method is large, let the extra BCIs grow numerous (to ~1%).
   804     int one_percent_of_data
   877     int one_percent_of_data
   820 
   893 
   821     return MAX2(extra_data_count, spec_data_count);
   894     return MAX2(extra_data_count, spec_data_count);
   822   } else {
   895   } else {
   823     return 0;
   896     return 0;
   824   }
   897   }
       
   898 #endif // INCLUDE_JVMCI
   825 }
   899 }
   826 
   900 
   827 // Compute the size of the MethodData* necessary to store
   901 // Compute the size of the MethodData* necessary to store
   828 // profiling information about a given method.  Size is in bytes.
   902 // profiling information about a given method.  Size is in bytes.
   829 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
   903 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
   833   int empty_bc_count = 0;  // number of bytecodes lacking data
   907   int empty_bc_count = 0;  // number of bytecodes lacking data
   834   bool needs_speculative_traps = false;
   908   bool needs_speculative_traps = false;
   835   while ((c = stream.next()) >= 0) {
   909   while ((c = stream.next()) >= 0) {
   836     int size_in_bytes = compute_data_size(&stream);
   910     int size_in_bytes = compute_data_size(&stream);
   837     data_size += size_in_bytes;
   911     data_size += size_in_bytes;
   838     if (size_in_bytes == 0)  empty_bc_count += 1;
   912     if (size_in_bytes == 0 JVMCI_ONLY(&& Bytecodes::can_trap(c)))  empty_bc_count += 1;
   839     needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
   913     needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
   840   }
   914   }
   841   int object_size = in_bytes(data_offset()) + data_size;
   915   int object_size = in_bytes(data_offset()) + data_size;
   842 
   916 
   843   // Add some extra DataLayout cells (at least one) to track stray traps.
   917   // Add some extra DataLayout cells (at least one) to track stray traps.
   867 
   941 
   868 // Initialize an individual data segment.  Returns the size of
   942 // Initialize an individual data segment.  Returns the size of
   869 // the segment in bytes.
   943 // the segment in bytes.
   870 int MethodData::initialize_data(BytecodeStream* stream,
   944 int MethodData::initialize_data(BytecodeStream* stream,
   871                                        int data_index) {
   945                                        int data_index) {
   872 #if defined(COMPILER1) && !defined(COMPILER2)
   946 #if defined(COMPILER1) && !(defined(COMPILER2) || INCLUDE_JVMCI)
   873   return 0;
   947   return 0;
   874 #else
   948 #else
   875   int cell_count = -1;
   949   int cell_count = -1;
   876   int tag = DataLayout::no_tag;
   950   int tag = DataLayout::no_tag;
   877   DataLayout* data_layout = data_layout_at(data_index);
   951   DataLayout* data_layout = data_layout_at(data_index);
  1058 
  1132 
  1059 // Initialize the MethodData* corresponding to a given method.
  1133 // Initialize the MethodData* corresponding to a given method.
  1060 MethodData::MethodData(methodHandle method, int size, TRAPS)
  1134 MethodData::MethodData(methodHandle method, int size, TRAPS)
  1061   : _extra_data_lock(Monitor::leaf, "MDO extra data lock"),
  1135   : _extra_data_lock(Monitor::leaf, "MDO extra data lock"),
  1062     _parameters_type_data_di(parameters_uninitialized) {
  1136     _parameters_type_data_di(parameters_uninitialized) {
       
  1137   // Set the method back-pointer.
       
  1138   _method = method();
       
  1139   initialize();
       
  1140 }
       
  1141 
       
  1142 void MethodData::initialize() {
  1063   No_Safepoint_Verifier no_safepoint;  // init function atomic wrt GC
  1143   No_Safepoint_Verifier no_safepoint;  // init function atomic wrt GC
  1064   ResourceMark rm;
  1144   ResourceMark rm;
  1065   // Set the method back-pointer.
       
  1066   _method = method();
       
  1067 
  1145 
  1068   init();
  1146   init();
  1069   set_creation_mileage(mileage_of(method()));
  1147   set_creation_mileage(mileage_of(method()));
  1070 
  1148 
  1071   // Go through the bytecodes and allocate and initialize the
  1149   // Go through the bytecodes and allocate and initialize the
  1072   // corresponding data cells.
  1150   // corresponding data cells.
  1073   int data_size = 0;
  1151   int data_size = 0;
  1074   int empty_bc_count = 0;  // number of bytecodes lacking data
  1152   int empty_bc_count = 0;  // number of bytecodes lacking data
  1075   _data[0] = 0;  // apparently not set below.
  1153   _data[0] = 0;  // apparently not set below.
  1076   BytecodeStream stream(method);
  1154   BytecodeStream stream(method());
  1077   Bytecodes::Code c;
  1155   Bytecodes::Code c;
  1078   bool needs_speculative_traps = false;
  1156   bool needs_speculative_traps = false;
  1079   while ((c = stream.next()) >= 0) {
  1157   while ((c = stream.next()) >= 0) {
  1080     int size_in_bytes = initialize_data(&stream, data_size);
  1158     int size_in_bytes = initialize_data(&stream, data_size);
  1081     data_size += size_in_bytes;
  1159     data_size += size_in_bytes;
  1082     if (size_in_bytes == 0)  empty_bc_count += 1;
  1160     if (size_in_bytes == 0 JVMCI_ONLY(&& Bytecodes::can_trap(c)))  empty_bc_count += 1;
  1083     needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
  1161     needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
  1084   }
  1162   }
  1085   _data_size = data_size;
  1163   _data_size = data_size;
  1086   int object_size = in_bytes(data_offset()) + data_size;
  1164   int object_size = in_bytes(data_offset()) + data_size;
  1087 
  1165 
  1095   // Add a cell to record information about modified arguments.
  1173   // Add a cell to record information about modified arguments.
  1096   // Set up _args_modified array after traps cells so that
  1174   // Set up _args_modified array after traps cells so that
  1097   // the code for traps cells works.
  1175   // the code for traps cells works.
  1098   DataLayout *dp = data_layout_at(data_size + extra_size);
  1176   DataLayout *dp = data_layout_at(data_size + extra_size);
  1099 
  1177 
  1100   int arg_size = method->size_of_parameters();
  1178   int arg_size = method()->size_of_parameters();
  1101   dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
  1179   dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
  1102 
  1180 
  1103   int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
  1181   int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
  1104   object_size += extra_size + arg_data_size;
  1182   object_size += extra_size + arg_data_size;
  1105 
  1183 
  1124   // least well-defined.
  1202   // least well-defined.
  1125   _hint_di = first_di();
  1203   _hint_di = first_di();
  1126 
  1204 
  1127   post_initialize(&stream);
  1205   post_initialize(&stream);
  1128 
  1206 
       
  1207   assert(object_size == compute_allocation_size_in_bytes(methodHandle(_method)), "MethodData: computed size != initialized size");
  1129   set_size(object_size);
  1208   set_size(object_size);
  1130 }
  1209 }
  1131 
  1210 
  1132 void MethodData::init() {
  1211 void MethodData::init() {
  1133   _invocation_counter.init();
  1212   _invocation_counter.init();
  1143 
  1222 
  1144   _tenure_traps = 0;
  1223   _tenure_traps = 0;
  1145   _num_loops = 0;
  1224   _num_loops = 0;
  1146   _num_blocks = 0;
  1225   _num_blocks = 0;
  1147   _would_profile = unknown;
  1226   _would_profile = unknown;
       
  1227 
       
  1228 #if INCLUDE_JVMCI
       
  1229   _jvmci_ir_size = 0;
       
  1230 #endif
  1148 
  1231 
  1149 #if INCLUDE_RTM_OPT
  1232 #if INCLUDE_RTM_OPT
  1150   _rtm_state = NoRTM; // No RTM lock eliding by default
  1233   _rtm_state = NoRTM; // No RTM lock eliding by default
  1151   if (UseRTMLocking &&
  1234   if (UseRTMLocking &&
  1152       !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) {
  1235       !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) {