< prev index next >

src/hotspot/share/ci/ciMethod.cpp

Print this page

   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 

  25 #include "ci/ciCallProfile.hpp"
  26 #include "ci/ciExceptionHandler.hpp"
  27 #include "ci/ciInstanceKlass.hpp"
  28 #include "ci/ciMethod.hpp"
  29 #include "ci/ciMethodBlocks.hpp"
  30 #include "ci/ciMethodData.hpp"
  31 #include "ci/ciReplay.hpp"
  32 #include "ci/ciStreams.hpp"
  33 #include "ci/ciSymbol.hpp"
  34 #include "ci/ciSymbols.hpp"
  35 #include "ci/ciUtilities.inline.hpp"
  36 #include "compiler/abstractCompiler.hpp"
  37 #include "compiler/compilerDefinitions.inline.hpp"
  38 #include "compiler/compilerOracle.hpp"

  39 #include "compiler/methodLiveness.hpp"
  40 #include "interpreter/interpreter.hpp"
  41 #include "interpreter/linkResolver.hpp"
  42 #include "interpreter/oopMapCache.hpp"
  43 #include "logging/log.hpp"
  44 #include "logging/logStream.hpp"
  45 #include "memory/allocation.inline.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "oops/generateOopMap.hpp"
  48 #include "oops/method.inline.hpp"
  49 #include "oops/oop.inline.hpp"

  50 #include "prims/methodHandles.hpp"
  51 #include "runtime/deoptimization.hpp"
  52 #include "runtime/handles.inline.hpp"
  53 #include "utilities/bitMap.inline.hpp"
  54 #include "utilities/xmlstream.hpp"
  55 #ifdef COMPILER2
  56 #include "ci/bcEscapeAnalyzer.hpp"
  57 #include "ci/ciTypeFlow.hpp"
  58 #include "oops/method.hpp"
  59 #endif
  60 
  61 // ciMethod
  62 //
  63 // This class represents a Method* in the HotSpot virtual
  64 // machine.
  65 
  66 
  67 // ------------------------------------------------------------------
  68 // ciMethod::ciMethod
  69 //

 125   } else {
 126     // Have to use a conservative value in this case.
 127     _can_be_statically_bound = false;
 128     _can_omit_stack_trace = true;
 129   }
 130 
 131   // Adjust the definition of this condition to be more useful:
 132   // %%% take these conditions into account in vtable generation
 133   if (!_can_be_statically_bound && h_m->is_private())
 134     _can_be_statically_bound = true;
 135   if (_can_be_statically_bound && h_m->is_abstract())
 136     _can_be_statically_bound = false;
 137 
 138   // generating _signature may allow GC and therefore move m.
 139   // These fields are always filled in.
 140   _name = env->get_symbol(h_m->name());
 141   ciSymbol* sig_symbol = env->get_symbol(h_m->signature());
 142   constantPoolHandle cpool(Thread::current(), h_m->constants());
 143   _signature = new (env->arena()) ciSignature(_holder, cpool, sig_symbol);
 144   _method_data = nullptr;

 145   // Take a snapshot of these values, so they will be commensurate with the MDO.
 146   if (ProfileInterpreter || CompilerConfig::is_c1_profiling()) {
 147     int invcnt = h_m->interpreter_invocation_count();
 148     // if the value overflowed report it as max int
 149     _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ;
 150     _interpreter_throwout_count   = h_m->interpreter_throwout_count();
 151   } else {
 152     _interpreter_invocation_count = 0;
 153     _interpreter_throwout_count = 0;
 154   }
 155   if (_interpreter_invocation_count == 0)
 156     _interpreter_invocation_count = 1;
 157   _inline_instructions_size = -1;
 158   if (ReplayCompiles) {
 159     ciReplay::initialize(this);
 160   }
















 161 }
 162 
 163 
 164 // ------------------------------------------------------------------
 165 // ciMethod::ciMethod
 166 //
 167 // Unloaded method.
 168 ciMethod::ciMethod(ciInstanceKlass* holder,
 169                    ciSymbol*        name,
 170                    ciSymbol*        signature,
 171                    ciInstanceKlass* accessor) :
 172   ciMetadata((Metadata*)nullptr),
 173   _name(                   name),
 174   _holder(                 holder),
 175   _method_data(            nullptr),

 176   _method_blocks(          nullptr),
 177   _intrinsic_id(           vmIntrinsics::_none),
 178   _inline_instructions_size(-1),
 179   _can_be_statically_bound(false),
 180   _can_omit_stack_trace(true),

 181   _liveness(               nullptr)
 182 #if defined(COMPILER2)
 183   ,
 184   _flow(                   nullptr),
 185   _bcea(                   nullptr)
 186 #endif // COMPILER2
 187 {
 188   // Usually holder and accessor are the same type but in some cases
 189   // the holder has the wrong class loader (e.g. invokedynamic call
 190   // sites) so we pass the accessor.
 191   _signature = new (CURRENT_ENV->arena()) ciSignature(accessor, constantPoolHandle(), signature);
 192 }
 193 
 194 
 195 // ------------------------------------------------------------------
 196 // ciMethod::load_code
 197 //
 198 // Load the bytecodes and exception handler table for this method.
 199 void ciMethod::load_code() {
 200   VM_ENTRY_MARK;

 985 bool ciMethod::is_scoped() const {
 986    return get_Method()->is_scoped();
 987 }
 988 
 989 // ------------------------------------------------------------------
 990 // ciMethod::has_member_arg
 991 //
 992 // Return true if the method is a linker intrinsic like _linkToVirtual.
 993 // These are built by the JVM.
 994 bool ciMethod::has_member_arg() const {
 995   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 996   return (MethodHandles::is_signature_polymorphic(iid) &&
 997           MethodHandles::has_member_arg(iid));
 998 }
 999 
1000 // ------------------------------------------------------------------
1001 // ciMethod::ensure_method_data
1002 //
1003 // Generate new MethodData* objects at compile time.
1004 // Return true if allocation was successful or no MDO is required.
1005 bool ciMethod::ensure_method_data(const methodHandle& h_m) {
1006   EXCEPTION_CONTEXT;
1007   if (is_native() || is_abstract() || h_m()->is_accessor()) {
1008     return true;
1009   }
1010   if (h_m()->method_data() == nullptr) {
1011     Method::build_profiling_method_data(h_m, THREAD);
1012     if (HAS_PENDING_EXCEPTION) {
1013       CLEAR_PENDING_EXCEPTION;




1014     }
1015   }
1016   if (h_m()->method_data() != nullptr) {
1017     _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1018     return _method_data->load_data();
1019   } else {
1020     _method_data = CURRENT_ENV->get_empty_methodData();
1021     return false;
1022   }
1023 }
1024 
1025 // public, retroactive version
1026 bool ciMethod::ensure_method_data() {
1027   bool result = true;
1028   if (_method_data == nullptr || _method_data->is_empty()) {
1029     GUARDED_VM_ENTRY({
1030       methodHandle mh(Thread::current(), get_Method());
1031       result = ensure_method_data(mh);
1032     });
1033   }
1034   return result;
1035 }
1036 
1037 
1038 // ------------------------------------------------------------------
1039 // ciMethod::method_data
1040 //
1041 ciMethodData* ciMethod::method_data() {
1042   if (_method_data != nullptr) {
1043     return _method_data;
1044   }
1045   VM_ENTRY_MARK;
1046   ciEnv* env = CURRENT_ENV;
1047   Thread* my_thread = JavaThread::current();
1048   methodHandle h_m(my_thread, get_Method());
1049 
1050   if (h_m()->method_data() != nullptr) {
1051     _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1052     _method_data->load_data();























1053   } else {
1054     _method_data = CURRENT_ENV->get_empty_methodData();












1055   }
1056   return _method_data;
1057 
1058 }
1059 
1060 // ------------------------------------------------------------------
1061 // ciMethod::method_data_or_null
1062 // Returns a pointer to ciMethodData if MDO exists on the VM side,
1063 // null otherwise.
1064 ciMethodData* ciMethod::method_data_or_null() {
1065   ciMethodData *md = method_data();
1066   if (md->is_empty()) {
1067     return nullptr;
1068   }
1069   return md;
1070 }
1071 
1072 // ------------------------------------------------------------------
1073 // ciMethod::ensure_method_counters
1074 //
1075 MethodCounters* ciMethod::ensure_method_counters() {
1076   check_is_loaded();
1077   VM_ENTRY_MARK;

1092 
1093 // ------------------------------------------------------------------
1094 // ciMethod::has_option_value
1095 //
1096 bool ciMethod::has_option_value(CompileCommandEnum option, double& value) {
1097   check_is_loaded();
1098   VM_ENTRY_MARK;
1099   methodHandle mh(THREAD, get_Method());
1100   return CompilerOracle::has_option_value(mh, option, value);
1101 }
1102 // ------------------------------------------------------------------
1103 // ciMethod::can_be_compiled
1104 //
1105 // Have previous compilations of this method succeeded?
1106 bool ciMethod::can_be_compiled() {
1107   check_is_loaded();
1108   ciEnv* env = CURRENT_ENV;
1109   if (is_c1_compile(env->comp_level())) {
1110     return _is_c1_compilable;
1111   }







1112   return _is_c2_compilable;
1113 }
1114 
1115 // ------------------------------------------------------------------
1116 // ciMethod::has_compiled_code
1117 bool ciMethod::has_compiled_code() {
1118   return inline_instructions_size() > 0;
1119 }
1120 
1121 int ciMethod::highest_osr_comp_level() {
1122   check_is_loaded();
1123   VM_ENTRY_MARK;
1124   return get_Method()->highest_osr_comp_level();
1125 }
1126 
1127 // ------------------------------------------------------------------
1128 // ciMethod::code_size_for_inlining
1129 //
1130 // Code size for inlining decisions.  This method returns a code
1131 // size of 1 for methods which has the ForceInline annotation.
1132 int ciMethod::code_size_for_inlining() {
1133   check_is_loaded();
1134   if (get_Method()->force_inline()) {
1135     return 1;
1136   }
1137   return code_size();
1138 }
1139 
1140 // ------------------------------------------------------------------
1141 // ciMethod::inline_instructions_size
1142 //
1143 // This is a rough metric for "fat" methods, compared before inlining
1144 // with InlineSmallCode.  The CodeBlob::code_size accessor includes
1145 // junk like exception handler, stubs, and constant table, which are
1146 // not highly relevant to an inlined method.  So we use the more
1147 // specific accessor nmethod::insts_size.
1148 // Also some instructions inside the code are excluded from inline
1149 // heuristic (e.g. post call nop instructions; see InlineSkippedInstructionsCounter)
1150 int ciMethod::inline_instructions_size() {






















1151   if (_inline_instructions_size == -1) {
1152     GUARDED_VM_ENTRY(
1153       nmethod* code = get_Method()->code();
1154       if (code != nullptr && (code->comp_level() == CompLevel_full_optimization)) {
1155         int isize = code->insts_end() - code->verified_entry_point() - code->skipped_instructions_size();
1156         _inline_instructions_size = isize > 0 ? isize : 0;
1157       } else {
1158         _inline_instructions_size = 0;
1159       }








1160     );
1161   }
1162   return _inline_instructions_size;
1163 }
1164 
1165 // ------------------------------------------------------------------
1166 // ciMethod::log_nmethod_identity
1167 void ciMethod::log_nmethod_identity(xmlStream* log) {
1168   GUARDED_VM_ENTRY(
1169     nmethod* code = get_Method()->code();
1170     if (code != nullptr) {
1171       code->log_identity(log);
1172     }
1173   )
1174 }
1175 
1176 // ------------------------------------------------------------------
1177 // ciMethod::is_not_reached
1178 bool ciMethod::is_not_reached(int bci) {
1179   check_is_loaded();
1180   VM_ENTRY_MARK;
1181   return Interpreter::is_not_reached(
1182                methodHandle(THREAD, get_Method()), bci);
1183 }
1184 
1185 // ------------------------------------------------------------------
1186 // ciMethod::was_never_executed
1187 bool ciMethod::was_executed_more_than(int times) {











1188   VM_ENTRY_MARK;
1189   return get_Method()->was_executed_more_than(times);
1190 }
1191 
1192 // ------------------------------------------------------------------
1193 // ciMethod::has_unloaded_classes_in_signature
1194 bool ciMethod::has_unloaded_classes_in_signature() {
1195   // ciSignature is resolved against some accessing class and
1196   // signature classes aren't required to be local. As a benefit,
1197   // it makes signature classes visible through loader constraints.
1198   // So, encountering an unloaded class signals it is absent both in
1199   // the callee (local) and caller contexts.
1200   return signature()->has_unloaded_classes();
1201 }
1202 
1203 // ------------------------------------------------------------------
1204 // ciMethod::is_klass_loaded
1205 bool ciMethod::is_klass_loaded(int refinfo_index, Bytecodes::Code bc, bool must_be_resolved) const {
1206   VM_ENTRY_MARK;
1207   return get_Method()->is_klass_loaded(refinfo_index, bc, must_be_resolved);

   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "cds/aotLinkedClassBulkLoader.hpp"
  26 #include "ci/ciCallProfile.hpp"
  27 #include "ci/ciExceptionHandler.hpp"
  28 #include "ci/ciInstanceKlass.hpp"
  29 #include "ci/ciMethod.hpp"
  30 #include "ci/ciMethodBlocks.hpp"
  31 #include "ci/ciMethodData.hpp"
  32 #include "ci/ciReplay.hpp"
  33 #include "ci/ciStreams.hpp"
  34 #include "ci/ciSymbol.hpp"
  35 #include "ci/ciSymbols.hpp"
  36 #include "ci/ciUtilities.inline.hpp"
  37 #include "compiler/abstractCompiler.hpp"
  38 #include "compiler/compilerDefinitions.inline.hpp"
  39 #include "compiler/compilerOracle.hpp"
  40 #include "compiler/compileTask.hpp"
  41 #include "compiler/methodLiveness.hpp"
  42 #include "interpreter/interpreter.hpp"
  43 #include "interpreter/linkResolver.hpp"
  44 #include "interpreter/oopMapCache.hpp"
  45 #include "logging/log.hpp"
  46 #include "logging/logStream.hpp"
  47 #include "memory/allocation.inline.hpp"
  48 #include "memory/resourceArea.hpp"
  49 #include "oops/generateOopMap.hpp"
  50 #include "oops/method.inline.hpp"
  51 #include "oops/oop.inline.hpp"
  52 #include "oops/trainingData.hpp"
  53 #include "prims/methodHandles.hpp"
  54 #include "runtime/deoptimization.hpp"
  55 #include "runtime/handles.inline.hpp"
  56 #include "utilities/bitMap.inline.hpp"
  57 #include "utilities/xmlstream.hpp"
  58 #ifdef COMPILER2
  59 #include "ci/bcEscapeAnalyzer.hpp"
  60 #include "ci/ciTypeFlow.hpp"
  61 #include "oops/method.hpp"
  62 #endif
  63 
  64 // ciMethod
  65 //
  66 // This class represents a Method* in the HotSpot virtual
  67 // machine.
  68 
  69 
  70 // ------------------------------------------------------------------
  71 // ciMethod::ciMethod
  72 //

 128   } else {
 129     // Have to use a conservative value in this case.
 130     _can_be_statically_bound = false;
 131     _can_omit_stack_trace = true;
 132   }
 133 
 134   // Adjust the definition of this condition to be more useful:
 135   // %%% take these conditions into account in vtable generation
 136   if (!_can_be_statically_bound && h_m->is_private())
 137     _can_be_statically_bound = true;
 138   if (_can_be_statically_bound && h_m->is_abstract())
 139     _can_be_statically_bound = false;
 140 
 141   // generating _signature may allow GC and therefore move m.
 142   // These fields are always filled in.
 143   _name = env->get_symbol(h_m->name());
 144   ciSymbol* sig_symbol = env->get_symbol(h_m->signature());
 145   constantPoolHandle cpool(Thread::current(), h_m->constants());
 146   _signature = new (env->arena()) ciSignature(_holder, cpool, sig_symbol);
 147   _method_data = nullptr;
 148   _method_data_recorded = nullptr;
 149   // Take a snapshot of these values, so they will be commensurate with the MDO.
 150   if (ProfileInterpreter || CompilerConfig::is_c1_profiling()) {
 151     int invcnt = h_m->interpreter_invocation_count();
 152     // if the value overflowed report it as max int
 153     _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ;
 154     _interpreter_throwout_count   = h_m->interpreter_throwout_count();
 155   } else {
 156     _interpreter_invocation_count = 0;
 157     _interpreter_throwout_count = 0;
 158   }
 159   if (_interpreter_invocation_count == 0)
 160     _interpreter_invocation_count = 1;
 161   _inline_instructions_size = -1;
 162   if (ReplayCompiles) {
 163     ciReplay::initialize(this);
 164   }
 165   DirectiveSet* directives = DirectivesStack::getMatchingDirective(h_m, CURRENT_ENV->task()->compiler());
 166   ccstrlist bci_list = directives->TooManyTrapsAtBCIOption;
 167   int len = (int)strlen(bci_list);
 168   Arena* arena = CURRENT_ENV->arena();
 169   _has_trap_at_bci = new (arena) GrowableArray<int>(arena, 2, 0, 0);
 170   for (int i = 0; i < len; i++) {
 171     int v = -1;
 172     int read;
 173     if (sscanf(bci_list + i, "%i%n", &v, &read) != 1) {
 174       warning("wrong format for TooManyTrapsAtBCI option: \"%s\"", bci_list);
 175       break;
 176     }
 177     assert(v >= 0 && v < (1<<16), "%i", v);
 178     _has_trap_at_bci->append_if_missing(v);
 179     i += read;
 180   }
 181 }
 182 
 183 
 184 // ------------------------------------------------------------------
 185 // ciMethod::ciMethod
 186 //
 187 // Unloaded method.
 188 ciMethod::ciMethod(ciInstanceKlass* holder,
 189                    ciSymbol*        name,
 190                    ciSymbol*        signature,
 191                    ciInstanceKlass* accessor) :
 192   ciMetadata((Metadata*)nullptr),
 193   _name(                   name),
 194   _holder(                 holder),
 195   _method_data(            nullptr),
 196   _method_data_recorded(   nullptr),
 197   _method_blocks(          nullptr),
 198   _intrinsic_id(           vmIntrinsics::_none),
 199   _inline_instructions_size(-1),
 200   _can_be_statically_bound(false),
 201   _can_omit_stack_trace(true),
 202   _has_trap_at_bci(        nullptr),
 203   _liveness(               nullptr)
 204 #if defined(COMPILER2)
 205   ,
 206   _flow(                   nullptr),
 207   _bcea(                   nullptr)
 208 #endif // COMPILER2
 209 {
 210   // Usually holder and accessor are the same type but in some cases
 211   // the holder has the wrong class loader (e.g. invokedynamic call
 212   // sites) so we pass the accessor.
 213   _signature = new (CURRENT_ENV->arena()) ciSignature(accessor, constantPoolHandle(), signature);
 214 }
 215 
 216 
 217 // ------------------------------------------------------------------
 218 // ciMethod::load_code
 219 //
 220 // Load the bytecodes and exception handler table for this method.
 221 void ciMethod::load_code() {
 222   VM_ENTRY_MARK;

1007 bool ciMethod::is_scoped() const {
1008    return get_Method()->is_scoped();
1009 }
1010 
1011 // ------------------------------------------------------------------
1012 // ciMethod::has_member_arg
1013 //
1014 // Return true if the method is a linker intrinsic like _linkToVirtual.
1015 // These are built by the JVM.
1016 bool ciMethod::has_member_arg() const {
1017   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
1018   return (MethodHandles::is_signature_polymorphic(iid) &&
1019           MethodHandles::has_member_arg(iid));
1020 }
1021 
1022 // ------------------------------------------------------------------
1023 // ciMethod::ensure_method_data
1024 //
1025 // Generate new MethodData* objects at compile time.
1026 // Return true if allocation was successful or no MDO is required.
1027 bool ciMethod::ensure_method_data(const methodHandle& h_m, bool training_data_only) {
1028   EXCEPTION_CONTEXT;
1029   if (is_native() || is_abstract() || h_m()->is_accessor()) {
1030     return true;
1031   }
1032   if (h_m()->method_data() == nullptr) {
1033     if (training_data_only) {
1034       Method::install_training_method_data(h_m);
1035     } else {
1036       Method::build_profiling_method_data(h_m, THREAD);
1037       if (HAS_PENDING_EXCEPTION) {
1038         CLEAR_PENDING_EXCEPTION;
1039       }
1040     }
1041   }
1042   if (h_m()->method_data() != nullptr) {
1043     _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1044     return _method_data->load_data();
1045   } else {
1046     _method_data = CURRENT_ENV->get_empty_methodData();
1047     return false;
1048   }
1049 }
1050 
1051 // public, retroactive version
1052 bool ciMethod::ensure_method_data(bool training_data_only) {
1053   bool result = true;
1054   if (_method_data == nullptr || _method_data->is_empty()) {
1055     GUARDED_VM_ENTRY({
1056       methodHandle mh(Thread::current(), get_Method());
1057       result = ensure_method_data(mh, training_data_only);
1058     });
1059   }
1060   return result;
1061 }
1062 
1063 
1064 // ------------------------------------------------------------------
1065 // ciMethod::method_data
1066 //
1067 ciMethodData* ciMethod::method_data() {
1068   if (CURRENT_ENV->task()->is_precompiled() && CURRENT_ENV->task()->comp_level() == CompLevel_full_optimization) {
1069     if (_method_data_recorded == nullptr) {
1070       VM_ENTRY_MARK;
1071       methodHandle h_m(thread, get_Method());
1072       MethodTrainingData* mtd = MethodTrainingData::find(h_m);
1073       MethodData* mdo = (mtd != nullptr ? mtd->final_profile() : nullptr);
1074       DirectiveSet* directives = DirectivesStack::getMatchingDirective(h_m, CURRENT_ENV->task()->compiler());
1075       if (mdo == nullptr || directives->IgnoreRecordedProfileOption) {
1076         if (directives->IgnoreRecordedProfileOption) {
1077           ResourceMark rm;
1078           log_debug(precompile)("Ignore recorded profile for %s", h_m->name_and_sig_as_C_string());
1079         } else {
1080           ResourceMark rm;
1081           log_debug(precompile)("No profile for %s", h_m->name_and_sig_as_C_string());
1082         }
1083         _method_data_recorded = CURRENT_ENV->get_empty_methodData();
1084       } else {
1085 #if INCLUDE_CDS
1086         if (mdo->extra_data_lock() == nullptr) {
1087           assert(!HAS_PENDING_EXCEPTION, "");
1088           mdo->restore_unshareable_info(thread);
1089           assert(!HAS_PENDING_EXCEPTION, "");
1090         }
1091 #endif
1092         _method_data_recorded = CURRENT_ENV->get_method_data(mdo);
1093         _method_data_recorded->load_data();
1094         {
1095           ResourceMark rm;
1096           log_debug(precompile)("Recorded profile " PTR_FORMAT " for %s", p2i(mdo), h_m->name_and_sig_as_C_string());
1097         }
1098       }
1099     }
1100     assert(_method_data_recorded != nullptr, "");
1101     return _method_data_recorded;
1102   } else {
1103     if (_method_data != nullptr) {
1104       return _method_data;
1105     }
1106     VM_ENTRY_MARK;
1107     methodHandle h_m(thread, get_Method());
1108     MethodData* mdo = h_m()->method_data();
1109     if (mdo != nullptr) {
1110       _method_data = CURRENT_ENV->get_method_data(mdo);
1111       _method_data->load_data();
1112     } else {
1113       _method_data = CURRENT_ENV->get_empty_methodData();
1114     }
1115     return _method_data;
1116   }


1117 }
1118 
1119 // ------------------------------------------------------------------
1120 // ciMethod::method_data_or_null
1121 // Returns a pointer to ciMethodData if MDO exists on the VM side,
1122 // null otherwise.
1123 ciMethodData* ciMethod::method_data_or_null() {
1124   ciMethodData *md = method_data();
1125   if (md->is_empty()) {
1126     return nullptr;
1127   }
1128   return md;
1129 }
1130 
1131 // ------------------------------------------------------------------
1132 // ciMethod::ensure_method_counters
1133 //
1134 MethodCounters* ciMethod::ensure_method_counters() {
1135   check_is_loaded();
1136   VM_ENTRY_MARK;

1151 
1152 // ------------------------------------------------------------------
1153 // ciMethod::has_option_value
1154 //
1155 bool ciMethod::has_option_value(CompileCommandEnum option, double& value) {
1156   check_is_loaded();
1157   VM_ENTRY_MARK;
1158   methodHandle mh(THREAD, get_Method());
1159   return CompilerOracle::has_option_value(mh, option, value);
1160 }
1161 // ------------------------------------------------------------------
1162 // ciMethod::can_be_compiled
1163 //
1164 // Have previous compilations of this method succeeded?
1165 bool ciMethod::can_be_compiled() {
1166   check_is_loaded();
1167   ciEnv* env = CURRENT_ENV;
1168   if (is_c1_compile(env->comp_level())) {
1169     return _is_c1_compilable;
1170   }
1171 
1172 #if INCLUDE_JVMCI
1173   if (EnableJVMCI && UseJVMCICompiler &&
1174       env->comp_level() == CompLevel_full_optimization && !AOTLinkedClassBulkLoader::class_preloading_finished()) {
1175     return false;
1176   }
1177 #endif
1178   return _is_c2_compilable;
1179 }
1180 
1181 // ------------------------------------------------------------------
1182 // ciMethod::has_compiled_code
1183 bool ciMethod::has_compiled_code() {
1184   return inline_instructions_size() > 0;
1185 }
1186 
1187 int ciMethod::highest_osr_comp_level() {
1188   check_is_loaded();
1189   VM_ENTRY_MARK;
1190   return get_Method()->highest_osr_comp_level();
1191 }
1192 
1193 // ------------------------------------------------------------------
1194 // ciMethod::code_size_for_inlining
1195 //
1196 // Code size for inlining decisions.  This method returns a code
1197 // size of 1 for methods which has the ForceInline annotation.
1198 int ciMethod::code_size_for_inlining() {
1199   check_is_loaded();
1200   if (get_Method()->force_inline()) {
1201     return 1;
1202   }
1203   return code_size();
1204 }
1205 
1206 // ------------------------------------------------------------------
1207 // ciMethod::inline_instructions_size
1208 //
1209 // This is a rough metric for "fat" methods, compared before inlining
1210 // with InlineSmallCode.  The CodeBlob::code_size accessor includes
1211 // junk like exception handler, stubs, and constant table, which are
1212 // not highly relevant to an inlined method.  So we use the more
1213 // specific accessor nmethod::insts_size.
1214 // Also some instructions inside the code are excluded from inline
1215 // heuristic (e.g. post call nop instructions; see InlineSkippedInstructionsCounter)
1216 int ciMethod::inline_instructions_size() {
1217   if (_inline_instructions_size == -1) {
1218     if (TrainingData::have_data()) {
1219       GUARDED_VM_ENTRY(
1220         CompLevel level = static_cast<CompLevel>(CURRENT_ENV->comp_level());
1221         methodHandle top_level_mh(Thread::current(), CURRENT_ENV->task()->method());
1222         MethodTrainingData* mtd = MethodTrainingData::find(top_level_mh);
1223         if (mtd != nullptr) {
1224           CompileTrainingData* ctd = mtd->last_toplevel_compile(level);
1225           if (ctd != nullptr) {
1226             methodHandle mh(Thread::current(), get_Method());
1227             MethodTrainingData* this_mtd = MethodTrainingData::find(mh);
1228             if (this_mtd != nullptr) {
1229               auto r = ctd->ci_records().ciMethod__inline_instructions_size.find(this_mtd);
1230               if (r.is_valid()) {
1231                 _inline_instructions_size = r.result();
1232               }
1233             }
1234           }
1235         }
1236       );
1237     }
1238   }
1239   if (_inline_instructions_size == -1) {
1240     GUARDED_VM_ENTRY(
1241       nmethod* code = get_Method()->code();
1242       if (code != nullptr && !code->is_aot() && (code->comp_level() == CompLevel_full_optimization)) {
1243         int isize = code->insts_end() - code->verified_entry_point() - code->skipped_instructions_size();
1244         _inline_instructions_size = isize > 0 ? isize : 0;
1245       } else {
1246         _inline_instructions_size = 0;
1247       }
1248       if (TrainingData::need_data()) {
1249         CompileTrainingData* ctd = CURRENT_ENV->task()->training_data();
1250         if (ctd != nullptr) {
1251           methodHandle mh(Thread::current(), get_Method());
1252           MethodTrainingData* this_mtd = MethodTrainingData::make(mh);
1253           ctd->ci_records().ciMethod__inline_instructions_size.append_if_missing(_inline_instructions_size, this_mtd);
1254         }
1255       }
1256     );
1257   }
1258   return _inline_instructions_size;
1259 }
1260 
1261 // ------------------------------------------------------------------
1262 // ciMethod::log_nmethod_identity
1263 void ciMethod::log_nmethod_identity(xmlStream* log) {
1264   GUARDED_VM_ENTRY(
1265     nmethod* code = get_Method()->code();
1266     if (code != nullptr) {
1267       code->log_identity(log);
1268     }
1269   )
1270 }
1271 
1272 // ------------------------------------------------------------------
1273 // ciMethod::is_not_reached
1274 bool ciMethod::is_not_reached(int bci) {
1275   check_is_loaded();
1276   VM_ENTRY_MARK;
1277   return Interpreter::is_not_reached(
1278                methodHandle(THREAD, get_Method()), bci);
1279 }
1280 
1281 // ------------------------------------------------------------------
1282 // ciMethod::was_never_executed
1283 bool ciMethod::was_executed_more_than(int times) {
1284   // Invocation counter is reset when the Method* is compiled.
1285   // If the method has compiled code we therefore assume it has
1286   // be executed more than n times.
1287   if (is_accessor() || is_empty() || has_compiled_code()) {
1288     // interpreter doesn't bump invocation counter of trivial methods
1289     // compiler does not bump invocation counter of compiled methods
1290     return true;
1291   }
1292   if (!method_data()->is_empty()) {
1293     return (method_data()->invocation_count() > times);
1294   }
1295   VM_ENTRY_MARK;
1296   return get_Method()->was_executed_more_than(times);
1297 }
1298 
1299 // ------------------------------------------------------------------
1300 // ciMethod::has_unloaded_classes_in_signature
1301 bool ciMethod::has_unloaded_classes_in_signature() {
1302   // ciSignature is resolved against some accessing class and
1303   // signature classes aren't required to be local. As a benefit,
1304   // it makes signature classes visible through loader constraints.
1305   // So, encountering an unloaded class signals it is absent both in
1306   // the callee (local) and caller contexts.
1307   return signature()->has_unloaded_classes();
1308 }
1309 
1310 // ------------------------------------------------------------------
1311 // ciMethod::is_klass_loaded
1312 bool ciMethod::is_klass_loaded(int refinfo_index, Bytecodes::Code bc, bool must_be_resolved) const {
1313   VM_ENTRY_MARK;
1314   return get_Method()->is_klass_loaded(refinfo_index, bc, must_be_resolved);
< prev index next >