< prev index next >

src/hotspot/share/ci/ciMethod.cpp

Print this page

   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 "precompiled.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/ciStreams.hpp"
  33 #include "ci/ciSymbol.hpp"
  34 #include "ci/ciReplay.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/methodLiveness.hpp"
  41 #include "interpreter/interpreter.hpp"
  42 #include "interpreter/linkResolver.hpp"
  43 #include "interpreter/oopMapCache.hpp"
  44 #include "logging/log.hpp"
  45 #include "logging/logStream.hpp"
  46 #include "memory/allocation.inline.hpp"
  47 #include "memory/resourceArea.hpp"
  48 #include "oops/generateOopMap.hpp"
  49 #include "oops/method.inline.hpp"
  50 #include "oops/oop.inline.hpp"

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

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

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
















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

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

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

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




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























1051   } else {
1052     _method_data = CURRENT_ENV->get_empty_methodData();












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

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







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






















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








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











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

   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 "precompiled.hpp"
  26 #include "cds/aotLinkedClassBulkLoader.hpp"
  27 #include "ci/ciCallProfile.hpp"
  28 #include "ci/ciExceptionHandler.hpp"
  29 #include "ci/ciInstanceKlass.hpp"
  30 #include "ci/ciMethod.hpp"
  31 #include "ci/ciMethodBlocks.hpp"
  32 #include "ci/ciMethodData.hpp"
  33 #include "ci/ciStreams.hpp"
  34 #include "ci/ciSymbol.hpp"
  35 #include "ci/ciReplay.hpp"
  36 #include "ci/ciSymbols.hpp"
  37 #include "ci/ciUtilities.inline.hpp"
  38 #include "compiler/compileTask.hpp"
  39 #include "compiler/abstractCompiler.hpp"
  40 #include "compiler/compilerDefinitions.inline.hpp"
  41 #include "compiler/compilerOracle.hpp"
  42 #include "compiler/methodLiveness.hpp"
  43 #include "interpreter/interpreter.hpp"
  44 #include "interpreter/linkResolver.hpp"
  45 #include "interpreter/oopMapCache.hpp"
  46 #include "logging/log.hpp"
  47 #include "logging/logStream.hpp"
  48 #include "memory/allocation.inline.hpp"
  49 #include "memory/resourceArea.hpp"
  50 #include "oops/generateOopMap.hpp"
  51 #include "oops/method.inline.hpp"
  52 #include "oops/oop.inline.hpp"
  53 #include "oops/trainingData.hpp"
  54 #include "prims/methodHandles.hpp"
  55 #include "runtime/deoptimization.hpp"
  56 #include "runtime/handles.inline.hpp"
  57 #include "utilities/bitMap.inline.hpp"
  58 #include "utilities/xmlstream.hpp"
  59 #ifdef COMPILER2
  60 #include "ci/bcEscapeAnalyzer.hpp"
  61 #include "ci/ciTypeFlow.hpp"
  62 #include "oops/method.hpp"
  63 #endif
  64 
  65 // ciMethod
  66 //
  67 // This class represents a Method* in the HotSpot virtual
  68 // machine.
  69 
  70 
  71 // ------------------------------------------------------------------
  72 // ciMethod::ciMethod
  73 //

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

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


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

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