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

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

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
















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

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

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

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




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





















1032   } else {
1033     _method_data = CURRENT_ENV->get_empty_methodData();












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

1071 
1072 // ------------------------------------------------------------------
1073 // ciMethod::has_option_value
1074 //
1075 bool ciMethod::has_option_value(enum CompileCommand option, double& value) {
1076   check_is_loaded();
1077   VM_ENTRY_MARK;
1078   methodHandle mh(THREAD, get_Method());
1079   return CompilerOracle::has_option_value(mh, option, value);
1080 }
1081 // ------------------------------------------------------------------
1082 // ciMethod::can_be_compiled
1083 //
1084 // Have previous compilations of this method succeeded?
1085 bool ciMethod::can_be_compiled() {
1086   check_is_loaded();
1087   ciEnv* env = CURRENT_ENV;
1088   if (is_c1_compile(env->comp_level())) {
1089     return _is_c1_compilable;
1090   }







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






















1130   if (_inline_instructions_size == -1) {
1131     GUARDED_VM_ENTRY(
1132       CompiledMethod* code = get_Method()->code();
1133       if (code != nullptr && (code->comp_level() == CompLevel_full_optimization)) {
1134         int isize = code->insts_end() - code->verified_entry_point() - code->skipped_instructions_size();
1135         _inline_instructions_size = isize > 0 ? isize : 0;
1136       } else {
1137         _inline_instructions_size = 0;
1138       }








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











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

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

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


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

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