< 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 //

 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;

 958 bool ciMethod::is_object_initializer() const {
 959    return name() == ciSymbols::object_initializer_name();
 960 }
 961 
 962 // ------------------------------------------------------------------
 963 // ciMethod::has_member_arg
 964 //
 965 // Return true if the method is a linker intrinsic like _linkToVirtual.
 966 // These are built by the JVM.
 967 bool ciMethod::has_member_arg() const {
 968   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 969   return (MethodHandles::is_signature_polymorphic(iid) &&
 970           MethodHandles::has_member_arg(iid));
 971 }
 972 
 973 // ------------------------------------------------------------------
 974 // ciMethod::ensure_method_data
 975 //
 976 // Generate new MethodData* objects at compile time.
 977 // Return true if allocation was successful or no MDO is required.
 978 bool ciMethod::ensure_method_data(const methodHandle& h_m) {
 979   EXCEPTION_CONTEXT;
 980   if (is_native() || is_abstract() || h_m()->is_accessor()) {
 981     return true;
 982   }
 983   if (h_m()->method_data() == nullptr) {
 984     Method::build_profiling_method_data(h_m, THREAD);
 985     if (HAS_PENDING_EXCEPTION) {
 986       CLEAR_PENDING_EXCEPTION;




 987     }
 988   }
 989   if (h_m()->method_data() != nullptr) {
 990     _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
 991     return _method_data->load_data();
 992   } else {
 993     _method_data = CURRENT_ENV->get_empty_methodData();
 994     return false;
 995   }
 996 }
 997 
 998 // public, retroactive version
 999 bool ciMethod::ensure_method_data() {
1000   bool result = true;
1001   if (_method_data == nullptr || _method_data->is_empty()) {
1002     GUARDED_VM_ENTRY({
1003       methodHandle mh(Thread::current(), get_Method());
1004       result = ensure_method_data(mh);
1005     });
1006   }
1007   return result;
1008 }
1009 
1010 
1011 // ------------------------------------------------------------------
1012 // ciMethod::method_data
1013 //
1014 ciMethodData* ciMethod::method_data() {
1015   if (_method_data != nullptr) {
1016     return _method_data;
1017   }
1018   VM_ENTRY_MARK;
1019   ciEnv* env = CURRENT_ENV;
1020   Thread* my_thread = JavaThread::current();
1021   methodHandle h_m(my_thread, get_Method());
1022 
1023   if (h_m()->method_data() != nullptr) {
1024     _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1025     _method_data->load_data();





















1026   } else {
1027     _method_data = CURRENT_ENV->get_empty_methodData();












1028   }
1029   return _method_data;
1030 
1031 }
1032 
1033 // ------------------------------------------------------------------
1034 // ciMethod::method_data_or_null
1035 // Returns a pointer to ciMethodData if MDO exists on the VM side,
1036 // null otherwise.
1037 ciMethodData* ciMethod::method_data_or_null() {
1038   ciMethodData *md = method_data();
1039   if (md->is_empty()) {
1040     return nullptr;
1041   }
1042   return md;
1043 }
1044 
1045 // ------------------------------------------------------------------
1046 // ciMethod::ensure_method_counters
1047 //
1048 MethodCounters* ciMethod::ensure_method_counters() {
1049   check_is_loaded();
1050   VM_ENTRY_MARK;

1065 
1066 // ------------------------------------------------------------------
1067 // ciMethod::has_option_value
1068 //
1069 bool ciMethod::has_option_value(CompileCommandEnum option, double& value) {
1070   check_is_loaded();
1071   VM_ENTRY_MARK;
1072   methodHandle mh(THREAD, get_Method());
1073   return CompilerOracle::has_option_value(mh, option, value);
1074 }
1075 // ------------------------------------------------------------------
1076 // ciMethod::can_be_compiled
1077 //
1078 // Have previous compilations of this method succeeded?
1079 bool ciMethod::can_be_compiled() {
1080   check_is_loaded();
1081   ciEnv* env = CURRENT_ENV;
1082   if (is_c1_compile(env->comp_level())) {
1083     return _is_c1_compilable;
1084   }







1085   return _is_c2_compilable;
1086 }
1087 
1088 // ------------------------------------------------------------------
1089 // ciMethod::has_compiled_code
1090 bool ciMethod::has_compiled_code() {
1091   return inline_instructions_size() > 0;
1092 }
1093 
1094 int ciMethod::highest_osr_comp_level() {
1095   check_is_loaded();
1096   VM_ENTRY_MARK;
1097   return get_Method()->highest_osr_comp_level();
1098 }
1099 
1100 // ------------------------------------------------------------------
1101 // ciMethod::code_size_for_inlining
1102 //
1103 // Code size for inlining decisions.  This method returns a code
1104 // size of 1 for methods which has the ForceInline annotation.
1105 int ciMethod::code_size_for_inlining() {
1106   check_is_loaded();
1107   if (get_Method()->force_inline()) {
1108     return 1;
1109   }
1110   return code_size();
1111 }
1112 
1113 // ------------------------------------------------------------------
1114 // ciMethod::inline_instructions_size
1115 //
1116 // This is a rough metric for "fat" methods, compared before inlining
1117 // with InlineSmallCode.  The CodeBlob::code_size accessor includes
1118 // junk like exception handler, stubs, and constant table, which are
1119 // not highly relevant to an inlined method.  So we use the more
1120 // specific accessor nmethod::insts_size.
1121 // Also some instructions inside the code are excluded from inline
1122 // heuristic (e.g. post call nop instructions; see InlineSkippedInstructionsCounter)
1123 int ciMethod::inline_instructions_size() {






















1124   if (_inline_instructions_size == -1) {
1125     GUARDED_VM_ENTRY(
1126       nmethod* code = get_Method()->code();
1127       if (code != nullptr && (code->comp_level() == CompLevel_full_optimization)) {
1128         int isize = code->insts_end() - code->verified_entry_point() - code->skipped_instructions_size();
1129         _inline_instructions_size = isize > 0 ? isize : 0;
1130       } else {
1131         _inline_instructions_size = 0;
1132       }








1133     );
1134   }
1135   return _inline_instructions_size;
1136 }
1137 
1138 // ------------------------------------------------------------------
1139 // ciMethod::log_nmethod_identity
1140 void ciMethod::log_nmethod_identity(xmlStream* log) {
1141   GUARDED_VM_ENTRY(
1142     nmethod* code = get_Method()->code();
1143     if (code != nullptr) {
1144       code->log_identity(log);
1145     }
1146   )
1147 }
1148 
1149 // ------------------------------------------------------------------
1150 // ciMethod::is_not_reached
1151 bool ciMethod::is_not_reached(int bci) {
1152   check_is_loaded();
1153   VM_ENTRY_MARK;
1154   return Interpreter::is_not_reached(
1155                methodHandle(THREAD, get_Method()), bci);
1156 }
1157 
1158 // ------------------------------------------------------------------
1159 // ciMethod::was_never_executed
1160 bool ciMethod::was_executed_more_than(int times) {











1161   VM_ENTRY_MARK;
1162   return get_Method()->was_executed_more_than(times);
1163 }
1164 
1165 // ------------------------------------------------------------------
1166 // ciMethod::has_unloaded_classes_in_signature
1167 bool ciMethod::has_unloaded_classes_in_signature() {
1168   // ciSignature is resolved against some accessing class and
1169   // signature classes aren't required to be local. As a benefit,
1170   // it makes signature classes visible through loader constraints.
1171   // So, encountering an unloaded class signals it is absent both in
1172   // the callee (local) and caller contexts.
1173   return signature()->has_unloaded_classes();
1174 }
1175 
1176 // ------------------------------------------------------------------
1177 // ciMethod::is_klass_loaded
1178 bool ciMethod::is_klass_loaded(int refinfo_index, Bytecodes::Code bc, bool must_be_resolved) const {
1179   VM_ENTRY_MARK;
1180   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/classPreloader.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 //

 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;

 980 bool ciMethod::is_object_initializer() const {
 981    return name() == ciSymbols::object_initializer_name();
 982 }
 983 
 984 // ------------------------------------------------------------------
 985 // ciMethod::has_member_arg
 986 //
 987 // Return true if the method is a linker intrinsic like _linkToVirtual.
 988 // These are built by the JVM.
 989 bool ciMethod::has_member_arg() const {
 990   vmIntrinsics::ID iid = _intrinsic_id;  // do not check if loaded
 991   return (MethodHandles::is_signature_polymorphic(iid) &&
 992           MethodHandles::has_member_arg(iid));
 993 }
 994 
 995 // ------------------------------------------------------------------
 996 // ciMethod::ensure_method_data
 997 //
 998 // Generate new MethodData* objects at compile time.
 999 // Return true if allocation was successful or no MDO is required.
1000 bool ciMethod::ensure_method_data(const methodHandle& h_m, bool training_data_only) {
1001   EXCEPTION_CONTEXT;
1002   if (is_native() || is_abstract() || h_m()->is_accessor()) {
1003     return true;
1004   }
1005   if (h_m()->method_data() == nullptr) {
1006     if (training_data_only) {
1007       Method::install_training_method_data(h_m);
1008     } else {
1009       Method::build_profiling_method_data(h_m, THREAD);
1010       if (HAS_PENDING_EXCEPTION) {
1011         CLEAR_PENDING_EXCEPTION;
1012       }
1013     }
1014   }
1015   if (h_m()->method_data() != nullptr) {
1016     _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1017     return _method_data->load_data();
1018   } else {
1019     _method_data = CURRENT_ENV->get_empty_methodData();
1020     return false;
1021   }
1022 }
1023 
1024 // public, retroactive version
1025 bool ciMethod::ensure_method_data(bool training_data_only) {
1026   bool result = true;
1027   if (_method_data == nullptr || _method_data->is_empty()) {
1028     GUARDED_VM_ENTRY({
1029       methodHandle mh(Thread::current(), get_Method());
1030       result = ensure_method_data(mh, training_data_only);
1031     });
1032   }
1033   return result;
1034 }
1035 
1036 
1037 // ------------------------------------------------------------------
1038 // ciMethod::method_data
1039 //
1040 ciMethodData* ciMethod::method_data() {
1041   if (CURRENT_ENV->task()->is_precompiled() && CURRENT_ENV->task()->comp_level() == CompLevel_full_optimization) {
1042     if (_method_data_recorded == nullptr) {
1043       VM_ENTRY_MARK;
1044       methodHandle h_m(thread, get_Method());
1045       MethodTrainingData* mtd = TrainingData::lookup_for(h_m());
1046       MethodData* mdo = (mtd != nullptr ? mtd->final_profile() : nullptr);
1047       DirectiveSet* directives = DirectivesStack::getMatchingDirective(h_m, CURRENT_ENV->task()->compiler());
1048       if (mdo == nullptr || directives->IgnoreRecordedProfileOption) {
1049         if (directives->IgnoreRecordedProfileOption) {
1050           ResourceMark rm;
1051           log_debug(precompile)("Ignore recorded profile for %s", h_m->name_and_sig_as_C_string());
1052         } else {
1053           ResourceMark rm;
1054           log_debug(precompile)("No profile for %s", h_m->name_and_sig_as_C_string());
1055         }
1056         _method_data_recorded = CURRENT_ENV->get_empty_methodData();
1057       } else {
1058         if (mdo->extra_data_lock() == nullptr) {
1059           assert(!HAS_PENDING_EXCEPTION, "");
1060           mdo->restore_unshareable_info(thread);
1061           assert(!HAS_PENDING_EXCEPTION, "");
1062         }
1063         _method_data_recorded = CURRENT_ENV->get_method_data(mdo);
1064         _method_data_recorded->load_data();
1065         {
1066           ResourceMark rm;
1067           log_debug(precompile)("Recorded profile " PTR_FORMAT " for %s", p2i(mdo), h_m->name_and_sig_as_C_string());
1068         }
1069       }
1070     }
1071     assert(_method_data_recorded != nullptr, "");
1072     return _method_data_recorded;
1073   } else {
1074     if (_method_data != nullptr) {
1075       return _method_data;
1076     }
1077     VM_ENTRY_MARK;
1078     methodHandle h_m(thread, get_Method());
1079     MethodData* mdo = h_m()->method_data();
1080     if (mdo != nullptr) {
1081       _method_data = CURRENT_ENV->get_method_data(mdo);
1082       _method_data->load_data();
1083     } else {
1084       _method_data = CURRENT_ENV->get_empty_methodData();
1085     }
1086     return _method_data;
1087   }


1088 }
1089 
1090 // ------------------------------------------------------------------
1091 // ciMethod::method_data_or_null
1092 // Returns a pointer to ciMethodData if MDO exists on the VM side,
1093 // null otherwise.
1094 ciMethodData* ciMethod::method_data_or_null() {
1095   ciMethodData *md = method_data();
1096   if (md->is_empty()) {
1097     return nullptr;
1098   }
1099   return md;
1100 }
1101 
1102 // ------------------------------------------------------------------
1103 // ciMethod::ensure_method_counters
1104 //
1105 MethodCounters* ciMethod::ensure_method_counters() {
1106   check_is_loaded();
1107   VM_ENTRY_MARK;

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