5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "ci/ciCallProfile.hpp"
26 #include "ci/ciExceptionHandler.hpp"
27 #include "ci/ciInstanceKlass.hpp"
28 #include "ci/ciMethod.hpp"
29 #include "ci/ciMethodBlocks.hpp"
30 #include "ci/ciMethodData.hpp"
31 #include "ci/ciReplay.hpp"
32 #include "ci/ciStreams.hpp"
33 #include "ci/ciSymbol.hpp"
34 #include "ci/ciSymbols.hpp"
35 #include "ci/ciUtilities.inline.hpp"
36 #include "compiler/abstractCompiler.hpp"
37 #include "compiler/compilerDefinitions.inline.hpp"
38 #include "compiler/compilerOracle.hpp"
39 #include "compiler/compileTask.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 "oops/trainingData.hpp"
52 #include "prims/methodHandles.hpp"
53 #include "runtime/deoptimization.hpp"
54 #include "runtime/handles.inline.hpp"
55 #include "utilities/bitMap.inline.hpp"
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 // Take a snapshot of these values, so they will be commensurate with the MDO.
148 if (ProfileInterpreter || CompilerConfig::is_c1_profiling()) {
149 int invcnt = h_m->interpreter_invocation_count();
150 // if the value overflowed report it as max int
151 _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ;
152 _interpreter_throwout_count = h_m->interpreter_throwout_count();
153 } else {
154 _interpreter_invocation_count = 0;
155 _interpreter_throwout_count = 0;
156 }
157 if (_interpreter_invocation_count == 0)
158 _interpreter_invocation_count = 1;
159 _inline_instructions_size = -1;
160 if (ReplayCompiles) {
161 ciReplay::initialize(this);
162 }
163 }
164
165
166 // ------------------------------------------------------------------
167 // ciMethod::ciMethod
168 //
169 // Unloaded method.
170 ciMethod::ciMethod(ciInstanceKlass* holder,
171 ciSymbol* name,
172 ciSymbol* signature,
173 ciInstanceKlass* accessor) :
174 ciMetadata((Metadata*)nullptr),
175 _name( name),
176 _holder( holder),
177 _method_data( nullptr),
178 _method_blocks( nullptr),
179 _intrinsic_id( vmIntrinsics::_none),
180 _inline_instructions_size(-1),
181 _can_be_statically_bound(false),
182 _can_omit_stack_trace(true),
183 _liveness( nullptr)
184 #if defined(COMPILER2)
185 ,
186 _flow( nullptr),
187 _bcea( nullptr)
188 #endif // COMPILER2
189 {
190 // Usually holder and accessor are the same type but in some cases
191 // the holder has the wrong class loader (e.g. invokedynamic call
192 // sites) so we pass the accessor.
193 _signature = new (CURRENT_ENV->arena()) ciSignature(accessor, constantPoolHandle(), signature);
194 }
195
196
197 // ------------------------------------------------------------------
198 // ciMethod::load_code
199 //
200 // Load the bytecodes and exception handler table for this method.
201 void ciMethod::load_code() {
202 VM_ENTRY_MARK;
987 bool ciMethod::is_scoped() const {
988 return get_Method()->is_scoped();
989 }
990
991 // ------------------------------------------------------------------
992 // ciMethod::has_member_arg
993 //
994 // Return true if the method is a linker intrinsic like _linkToVirtual.
995 // These are built by the JVM.
996 bool ciMethod::has_member_arg() const {
997 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
998 return (MethodHandles::is_signature_polymorphic(iid) &&
999 MethodHandles::has_member_arg(iid));
1000 }
1001
1002 // ------------------------------------------------------------------
1003 // ciMethod::ensure_method_data
1004 //
1005 // Generate new MethodData* objects at compile time.
1006 // Return true if allocation was successful or no MDO is required.
1007 bool ciMethod::ensure_method_data(const methodHandle& h_m) {
1008 EXCEPTION_CONTEXT;
1009 if (is_native() || is_abstract() || h_m()->is_accessor()) {
1010 return true;
1011 }
1012 if (h_m()->method_data() == nullptr) {
1013 Method::build_profiling_method_data(h_m, THREAD);
1014 if (HAS_PENDING_EXCEPTION) {
1015 CLEAR_PENDING_EXCEPTION;
1016 }
1017 }
1018 if (h_m()->method_data() != nullptr) {
1019 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1020 return _method_data->load_data();
1021 } else {
1022 _method_data = CURRENT_ENV->get_empty_methodData();
1023 return false;
1024 }
1025 }
1026
1027 // public, retroactive version
1028 bool ciMethod::ensure_method_data() {
1029 bool result = true;
1030 if (_method_data == nullptr || _method_data->is_empty()) {
1031 GUARDED_VM_ENTRY({
1032 methodHandle mh(Thread::current(), get_Method());
1033 result = ensure_method_data(mh);
1034 });
1035 }
1036 return result;
1037 }
1038
1039
1040 // ------------------------------------------------------------------
1041 // ciMethod::method_data
1042 //
1043 ciMethodData* ciMethod::method_data() {
1044 if (_method_data != nullptr) {
1045 return _method_data;
1046 }
1047 VM_ENTRY_MARK;
1048 ciEnv* env = CURRENT_ENV;
1049 Thread* my_thread = JavaThread::current();
1050 methodHandle h_m(my_thread, get_Method());
1051
1052 if (h_m()->method_data() != nullptr) {
1053 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1054 _method_data->load_data();
1055 } else {
1056 _method_data = CURRENT_ENV->get_empty_methodData();
1057 }
1058 return _method_data;
1059
1060 }
1061
1062 // ------------------------------------------------------------------
1063 // ciMethod::method_data_or_null
1064 // Returns a pointer to ciMethodData if MDO exists on the VM side,
1065 // null otherwise.
1066 ciMethodData* ciMethod::method_data_or_null() {
1067 ciMethodData *md = method_data();
1068 if (md->is_empty()) {
1069 return nullptr;
1070 }
1071 return md;
1072 }
1073
1074 // ------------------------------------------------------------------
1075 // ciMethod::ensure_method_counters
1076 //
1077 MethodCounters* ciMethod::ensure_method_counters() {
1078 check_is_loaded();
1079 VM_ENTRY_MARK;
1080 methodHandle mh(THREAD, get_Method());
1081 MethodCounters* method_counters = mh->get_method_counters(CHECK_NULL);
1082 return method_counters;
1083 }
1084
1085 // ------------------------------------------------------------------
1086 // ciMethod::has_option
1087 //
1088 bool ciMethod::has_option(CompileCommandEnum option) {
1089 check_is_loaded();
1090 VM_ENTRY_MARK;
1091 methodHandle mh(THREAD, get_Method());
1092 return CompilerOracle::has_option(mh, option);
1093 }
1094
1095 // ------------------------------------------------------------------
1096 // ciMethod::has_option_value
1097 //
1098 bool ciMethod::has_option_value(CompileCommandEnum option, double& value) {
1099 check_is_loaded();
1100 VM_ENTRY_MARK;
1101 methodHandle mh(THREAD, get_Method());
1102 return CompilerOracle::has_option_value(mh, option, value);
1103 }
1104 // ------------------------------------------------------------------
1105 // ciMethod::can_be_compiled
1106 //
1107 // Have previous compilations of this method succeeded?
1108 bool ciMethod::can_be_compiled() {
1109 check_is_loaded();
1110 ciEnv* env = CURRENT_ENV;
1111 if (is_c1_compile(env->comp_level())) {
1112 return _is_c1_compilable;
1113 }
1114 return _is_c2_compilable;
1115 }
1116
1117 // ------------------------------------------------------------------
1118 // ciMethod::has_compiled_code
1119 bool ciMethod::has_compiled_code() {
1120 return inline_instructions_size() > 0;
1121 }
1122
1123 int ciMethod::highest_osr_comp_level() {
1124 check_is_loaded();
1125 VM_ENTRY_MARK;
1126 return get_Method()->highest_osr_comp_level();
1127 }
1128
1129 // ------------------------------------------------------------------
1130 // ciMethod::code_size_for_inlining
1131 //
1132 // Code size for inlining decisions. This method returns a code
1133 // size of 1 for methods which has the ForceInline annotation.
1136 if (get_Method()->force_inline()) {
1137 return 1;
1138 }
1139 return code_size();
1140 }
1141
1142 // ------------------------------------------------------------------
1143 // ciMethod::inline_instructions_size
1144 //
1145 // This is a rough metric for "fat" methods, compared before inlining
1146 // with InlineSmallCode. The CodeBlob::code_size accessor includes
1147 // junk like exception handler, stubs, and constant table, which are
1148 // not highly relevant to an inlined method. So we use the more
1149 // specific accessor nmethod::insts_size.
1150 // Also some instructions inside the code are excluded from inline
1151 // heuristic (e.g. post call nop instructions; see InlineSkippedInstructionsCounter)
1152 int ciMethod::inline_instructions_size() {
1153 if (_inline_instructions_size == -1) {
1154 if (TrainingData::have_data()) {
1155 GUARDED_VM_ENTRY(
1156 CompLevel level = static_cast<CompLevel>(CURRENT_ENV->comp_level());
1157 methodHandle top_level_mh(Thread::current(), CURRENT_ENV->task()->method());
1158 MethodTrainingData* mtd = MethodTrainingData::find(top_level_mh);
1159 if (mtd != nullptr) {
1160 CompileTrainingData* ctd = mtd->last_toplevel_compile(level);
1161 if (ctd != nullptr) {
1162 methodHandle mh(Thread::current(), get_Method());
1163 MethodTrainingData* this_mtd = MethodTrainingData::find(mh);
1164 if (this_mtd != nullptr) {
1165 auto r = ctd->ci_records().ciMethod__inline_instructions_size.find(this_mtd);
1166 if (r.is_valid()) {
1167 _inline_instructions_size = r.result();
1168 }
1169 }
1170 }
1171 }
1172 );
1173 }
1174 }
1175 if (_inline_instructions_size == -1) {
1176 GUARDED_VM_ENTRY(
1177 nmethod* code = get_Method()->code();
1178 if (code != nullptr && (code->comp_level() == CompLevel_full_optimization)) {
1179 int isize = code->insts_end() - code->verified_entry_point() - code->skipped_instructions_size();
1180 _inline_instructions_size = isize > 0 ? isize : 0;
1181 } else {
1182 _inline_instructions_size = 0;
1183 }
1184 if (TrainingData::need_data()) {
1185 CompileTrainingData* ctd = CURRENT_ENV->task()->training_data();
1186 if (ctd != nullptr) {
1187 methodHandle mh(Thread::current(), get_Method());
1188 MethodTrainingData* this_mtd = MethodTrainingData::make(mh);
1189 ctd->ci_records().ciMethod__inline_instructions_size.append_if_missing(_inline_instructions_size, this_mtd);
1190 }
1191 }
1192 );
1193 }
1194 return _inline_instructions_size;
1195 }
1196
1197 // ------------------------------------------------------------------
1198 // ciMethod::log_nmethod_identity
1199 void ciMethod::log_nmethod_identity(xmlStream* log) {
1200 GUARDED_VM_ENTRY(
1201 nmethod* code = get_Method()->code();
1202 if (code != nullptr) {
1203 code->log_identity(log);
1204 }
1205 )
1206 }
1207
1208 // ------------------------------------------------------------------
1209 // ciMethod::is_not_reached
1210 bool ciMethod::is_not_reached(int bci) {
1211 check_is_loaded();
1212 VM_ENTRY_MARK;
1213 return Interpreter::is_not_reached(
1214 methodHandle(THREAD, get_Method()), bci);
1215 }
1216
1217 // ------------------------------------------------------------------
1218 // ciMethod::was_never_executed
1219 bool ciMethod::was_executed_more_than(int times) {
1220 VM_ENTRY_MARK;
1221 return get_Method()->was_executed_more_than(times);
1222 }
1223
1224 // ------------------------------------------------------------------
1225 // ciMethod::has_unloaded_classes_in_signature
1226 bool ciMethod::has_unloaded_classes_in_signature() {
1227 // ciSignature is resolved against some accessing class and
1228 // signature classes aren't required to be local. As a benefit,
1229 // it makes signature classes visible through loader constraints.
1230 // So, encountering an unloaded class signals it is absent both in
1231 // the callee (local) and caller contexts.
1232 return signature()->has_unloaded_classes();
1233 }
1234
1235 // ------------------------------------------------------------------
1236 // ciMethod::is_klass_loaded
1237 bool ciMethod::is_klass_loaded(int refinfo_index, Bytecodes::Code bc, bool must_be_resolved) const {
1238 VM_ENTRY_MARK;
1239 return get_Method()->is_klass_loaded(refinfo_index, bc, must_be_resolved);
|
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "cds/aotLinkedClassBulkLoader.hpp"
26 #include "ci/ciCallProfile.hpp"
27 #include "ci/ciExceptionHandler.hpp"
28 #include "ci/ciInstanceKlass.hpp"
29 #include "ci/ciMethod.hpp"
30 #include "ci/ciMethodBlocks.hpp"
31 #include "ci/ciMethodData.hpp"
32 #include "ci/ciReplay.hpp"
33 #include "ci/ciStreams.hpp"
34 #include "ci/ciSymbol.hpp"
35 #include "ci/ciSymbols.hpp"
36 #include "ci/ciUtilities.inline.hpp"
37 #include "code/aotCodeCache.hpp"
38 #include "compiler/abstractCompiler.hpp"
39 #include "compiler/compilerDefinitions.inline.hpp"
40 #include "compiler/compilerOracle.hpp"
41 #include "compiler/compileTask.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"
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;
1008 bool ciMethod::is_scoped() const {
1009 return get_Method()->is_scoped();
1010 }
1011
1012 // ------------------------------------------------------------------
1013 // ciMethod::has_member_arg
1014 //
1015 // Return true if the method is a linker intrinsic like _linkToVirtual.
1016 // These are built by the JVM.
1017 bool ciMethod::has_member_arg() const {
1018 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
1019 return (MethodHandles::is_signature_polymorphic(iid) &&
1020 MethodHandles::has_member_arg(iid));
1021 }
1022
1023 // ------------------------------------------------------------------
1024 // ciMethod::ensure_method_data
1025 //
1026 // Generate new MethodData* objects at compile time.
1027 // Return true if allocation was successful or no MDO is required.
1028 bool ciMethod::ensure_method_data(const methodHandle& h_m, bool training_data_only) {
1029 EXCEPTION_CONTEXT;
1030 if (is_native() || is_abstract() || h_m()->is_accessor()) {
1031 return true;
1032 }
1033 if (h_m()->method_data() == nullptr) {
1034 if (training_data_only) {
1035 Method::install_training_method_data(h_m);
1036 } else {
1037 Method::build_profiling_method_data(h_m, THREAD);
1038 if (HAS_PENDING_EXCEPTION) {
1039 CLEAR_PENDING_EXCEPTION;
1040 }
1041 }
1042 }
1043 if (h_m()->method_data() != nullptr) {
1044 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1045 return _method_data->load_data();
1046 } else {
1047 _method_data = CURRENT_ENV->get_empty_methodData();
1048 return false;
1049 }
1050 }
1051
1052 // public, retroactive version
1053 bool ciMethod::ensure_method_data(bool training_data_only) {
1054 bool result = true;
1055 if (_method_data == nullptr || _method_data->is_empty()) {
1056 GUARDED_VM_ENTRY({
1057 methodHandle mh(Thread::current(), get_Method());
1058 result = ensure_method_data(mh, training_data_only);
1059 });
1060 }
1061 return result;
1062 }
1063
1064
1065 // ------------------------------------------------------------------
1066 // ciMethod::method_data
1067 //
1068 ciMethodData* ciMethod::method_data() {
1069 if (CURRENT_ENV->task()->is_aot_compile() && CURRENT_ENV->task()->comp_level() == CompLevel_full_optimization) {
1070 if (_method_data_recorded == nullptr) {
1071 VM_ENTRY_MARK;
1072 methodHandle h_m(thread, get_Method());
1073 MethodTrainingData* mtd = MethodTrainingData::find(h_m);
1074 MethodData* mdo = (mtd != nullptr ? mtd->final_profile() : nullptr);
1075 DirectiveSet* directives = DirectivesStack::getMatchingDirective(h_m, CURRENT_ENV->task()->compiler());
1076 int comp_id = CURRENT_ENV->task()->compile_id();
1077 if (mdo == nullptr || directives->IgnoreRecordedProfileOption) {
1078 if (directives->IgnoreRecordedProfileOption) {
1079 ResourceMark rm;
1080 log_debug(aot, compilation)("%d: Ignore recorded profile for %s", comp_id, h_m->name_and_sig_as_C_string());
1081 } else {
1082 ResourceMark rm;
1083 log_debug(aot, compilation)("%d: No profile for %s", comp_id, h_m->name_and_sig_as_C_string());
1084 }
1085 _method_data_recorded = CURRENT_ENV->get_empty_methodData();
1086 } else {
1087 #if INCLUDE_CDS
1088 if (mdo->extra_data_lock() == nullptr) {
1089 assert(!HAS_PENDING_EXCEPTION, "");
1090 mdo->restore_unshareable_info(thread);
1091 assert(!HAS_PENDING_EXCEPTION, "");
1092 }
1093 #endif
1094 _method_data_recorded = CURRENT_ENV->get_method_data(mdo);
1095 _method_data_recorded->load_data();
1096 {
1097 ResourceMark rm;
1098 log_debug(aot, compilation)("%d: Recorded profile " PTR_FORMAT " for %s", comp_id, p2i(mdo), h_m->name_and_sig_as_C_string());
1099 }
1100 }
1101 }
1102 assert(_method_data_recorded != nullptr, "");
1103 return _method_data_recorded;
1104 } else {
1105 if (_method_data != nullptr) {
1106 return _method_data;
1107 }
1108 VM_ENTRY_MARK;
1109 methodHandle h_m(thread, get_Method());
1110 MethodData* mdo = h_m()->method_data();
1111 if (mdo != nullptr) {
1112 _method_data = CURRENT_ENV->get_method_data(mdo);
1113 _method_data->load_data();
1114 } else {
1115 _method_data = CURRENT_ENV->get_empty_methodData();
1116 }
1117 return _method_data;
1118 }
1119 }
1120
1121 // ------------------------------------------------------------------
1122 // ciMethod::method_data_or_null
1123 // Returns a pointer to ciMethodData if MDO exists on the VM side,
1124 // null otherwise.
1125 ciMethodData* ciMethod::method_data_or_null() {
1126 ciMethodData *md = method_data();
1127 if (md->is_empty()) {
1128 return nullptr;
1129 }
1130 return md;
1131 }
1132
1133 // ------------------------------------------------------------------
1134 // ciMethod::ensure_method_counters
1135 //
1136 ciMetadata* ciMethod::ensure_method_counters() {
1137 check_is_loaded();
1138 VM_ENTRY_MARK;
1139 methodHandle mh(THREAD, get_Method());
1140 MethodCounters* method_counters = mh->get_method_counters(THREAD);
1141 if (method_counters != nullptr) {
1142 return CURRENT_ENV->get_method_counters(method_counters);
1143 }
1144 return nullptr;
1145 }
1146
1147 // ------------------------------------------------------------------
1148 // ciMethod::has_option
1149 //
1150 bool ciMethod::has_option(CompileCommandEnum option) {
1151 check_is_loaded();
1152 VM_ENTRY_MARK;
1153 methodHandle mh(THREAD, get_Method());
1154 return CompilerOracle::has_option(mh, option);
1155 }
1156
1157 // ------------------------------------------------------------------
1158 // ciMethod::has_option_value
1159 //
1160 bool ciMethod::has_option_value(CompileCommandEnum option, double& value) {
1161 check_is_loaded();
1162 VM_ENTRY_MARK;
1163 methodHandle mh(THREAD, get_Method());
1164 return CompilerOracle::has_option_value(mh, option, value);
1165 }
1166 // ------------------------------------------------------------------
1167 // ciMethod::can_be_compiled
1168 //
1169 // Have previous compilations of this method succeeded?
1170 bool ciMethod::can_be_compiled() {
1171 check_is_loaded();
1172 ciEnv* env = CURRENT_ENV;
1173 if (is_c1_compile(env->comp_level())) {
1174 return _is_c1_compilable;
1175 }
1176
1177 return _is_c2_compilable;
1178 }
1179
1180 // ------------------------------------------------------------------
1181 // ciMethod::has_compiled_code
1182 bool ciMethod::has_compiled_code() {
1183 return inline_instructions_size() > 0;
1184 }
1185
1186 int ciMethod::highest_osr_comp_level() {
1187 check_is_loaded();
1188 VM_ENTRY_MARK;
1189 return get_Method()->highest_osr_comp_level();
1190 }
1191
1192 // ------------------------------------------------------------------
1193 // ciMethod::code_size_for_inlining
1194 //
1195 // Code size for inlining decisions. This method returns a code
1196 // size of 1 for methods which has the ForceInline annotation.
1199 if (get_Method()->force_inline()) {
1200 return 1;
1201 }
1202 return code_size();
1203 }
1204
1205 // ------------------------------------------------------------------
1206 // ciMethod::inline_instructions_size
1207 //
1208 // This is a rough metric for "fat" methods, compared before inlining
1209 // with InlineSmallCode. The CodeBlob::code_size accessor includes
1210 // junk like exception handler, stubs, and constant table, which are
1211 // not highly relevant to an inlined method. So we use the more
1212 // specific accessor nmethod::insts_size.
1213 // Also some instructions inside the code are excluded from inline
1214 // heuristic (e.g. post call nop instructions; see InlineSkippedInstructionsCounter)
1215 int ciMethod::inline_instructions_size() {
1216 if (_inline_instructions_size == -1) {
1217 if (TrainingData::have_data()) {
1218 GUARDED_VM_ENTRY(
1219 CompLevel level = static_cast<CompLevel>(CURRENT_ENV->task()->comp_level());
1220 methodHandle top_level_mh(Thread::current(), CURRENT_ENV->task()->method());
1221 MethodTrainingData* mtd = MethodTrainingData::find(top_level_mh);
1222 if (mtd != nullptr) {
1223 CompileTrainingData* ctd = mtd->compile_data_for_aot_code(level);
1224 if (ctd != nullptr) {
1225 methodHandle mh(Thread::current(), get_Method());
1226 MethodTrainingData* this_mtd = MethodTrainingData::find(mh);
1227 if (this_mtd != nullptr) {
1228 auto r = ctd->ci_records().ciMethod__inline_instructions_size.find(this_mtd);
1229 if (r.is_valid()) {
1230 _inline_instructions_size = r.result();
1231 }
1232 }
1233 }
1234 }
1235 );
1236 }
1237 }
1238 if (_inline_instructions_size == -1) {
1239 GUARDED_VM_ENTRY(
1240 nmethod* code = get_Method()->code();
1241 if (code != nullptr && (code->comp_level() == CompLevel_full_optimization)) {
1242 int isize = code->is_aot() ? code->aot_code_entry()->inline_instructions_size()
1243 : code->inline_instructions_size();
1244 _inline_instructions_size = isize > 0 ? isize : 0;
1245 } else {
1246 _inline_instructions_size = 0;
1247 }
1248 if (TrainingData::need_data()) {
1249 CompileTrainingData* ctd = CURRENT_ENV->task()->training_data();
1250 if (ctd != nullptr) {
1251 methodHandle mh(Thread::current(), get_Method());
1252 MethodTrainingData* this_mtd = MethodTrainingData::make(mh);
1253 ctd->ci_records().ciMethod__inline_instructions_size.append_if_missing(_inline_instructions_size, this_mtd);
1254 }
1255 }
1256 );
1257 }
1258 return _inline_instructions_size;
1259 }
1260
1261 // ------------------------------------------------------------------
1262 // ciMethod::log_nmethod_identity
1263 void ciMethod::log_nmethod_identity(xmlStream* log) {
1264 GUARDED_VM_ENTRY(
1265 nmethod* code = get_Method()->code();
1266 if (code != nullptr) {
1267 code->log_identity(log);
1268 }
1269 )
1270 }
1271
1272 // ------------------------------------------------------------------
1273 // ciMethod::is_not_reached
1274 bool ciMethod::is_not_reached(int bci) {
1275 check_is_loaded();
1276 VM_ENTRY_MARK;
1277 return Interpreter::is_not_reached(
1278 methodHandle(THREAD, get_Method()), bci);
1279 }
1280
1281 // ------------------------------------------------------------------
1282 // ciMethod::was_never_executed
1283 bool ciMethod::was_executed_more_than(int times) {
1284 // Invocation counter is reset when the Method* is compiled.
1285 // If the method has compiled code we therefore assume it has
1286 // be executed more than n times.
1287 if (is_accessor() || is_empty() || has_compiled_code()) {
1288 // interpreter doesn't bump invocation counter of trivial methods
1289 // compiler does not bump invocation counter of compiled methods
1290 return true;
1291 }
1292 if (!method_data()->is_empty()) {
1293 return (method_data()->invocation_count() > times);
1294 }
1295 VM_ENTRY_MARK;
1296 return get_Method()->was_executed_more_than(times);
1297 }
1298
1299 // ------------------------------------------------------------------
1300 // ciMethod::has_unloaded_classes_in_signature
1301 bool ciMethod::has_unloaded_classes_in_signature() {
1302 // ciSignature is resolved against some accessing class and
1303 // signature classes aren't required to be local. As a benefit,
1304 // it makes signature classes visible through loader constraints.
1305 // So, encountering an unloaded class signals it is absent both in
1306 // the callee (local) and caller contexts.
1307 return signature()->has_unloaded_classes();
1308 }
1309
1310 // ------------------------------------------------------------------
1311 // ciMethod::is_klass_loaded
1312 bool ciMethod::is_klass_loaded(int refinfo_index, Bytecodes::Code bc, bool must_be_resolved) const {
1313 VM_ENTRY_MARK;
1314 return get_Method()->is_klass_loaded(refinfo_index, bc, must_be_resolved);
|