1 /*
2 * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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 "precompiled.hpp"
26 #include "ci/ciCallProfile.hpp"
27 #include "ci/ciExceptionHandler.hpp"
28 #include "ci/ciInstanceKlass.hpp"
29 #include "ci/ciMethod.hpp"
30 #include "ci/ciMethodBlocks.hpp"
31 #include "ci/ciMethodData.hpp"
32 #include "ci/ciStreams.hpp"
33 #include "ci/ciSymbol.hpp"
34 #include "ci/ciReplay.hpp"
35 #include "ci/ciSymbols.hpp"
36 #include "ci/ciUtilities.inline.hpp"
37 #include "compiler/abstractCompiler.hpp"
38 #include "compiler/compilerDefinitions.inline.hpp"
39 #include "compiler/compilerOracle.hpp"
40 #include "compiler/methodLiveness.hpp"
41 #include "interpreter/interpreter.hpp"
42 #include "interpreter/linkResolver.hpp"
43 #include "interpreter/oopMapCache.hpp"
44 #include "logging/log.hpp"
45 #include "logging/logStream.hpp"
46 #include "memory/allocation.inline.hpp"
47 #include "memory/resourceArea.hpp"
48 #include "oops/generateOopMap.hpp"
49 #include "oops/method.inline.hpp"
50 #include "oops/oop.inline.hpp"
51 #include "prims/methodHandles.hpp"
52 #include "runtime/deoptimization.hpp"
53 #include "runtime/handles.inline.hpp"
54 #include "utilities/bitMap.inline.hpp"
55 #include "utilities/xmlstream.hpp"
56 #ifdef COMPILER2
57 #include "ci/bcEscapeAnalyzer.hpp"
58 #include "ci/ciTypeFlow.hpp"
59 #include "oops/method.hpp"
60 #endif
61
62 // ciMethod
63 //
64 // This class represents a Method* in the HotSpot virtual
65 // machine.
66
67
68 // ------------------------------------------------------------------
69 // ciMethod::ciMethod
70 //
126 } else {
127 // Have to use a conservative value in this case.
128 _can_be_statically_bound = false;
129 _can_omit_stack_trace = true;
130 }
131
132 // Adjust the definition of this condition to be more useful:
133 // %%% take these conditions into account in vtable generation
134 if (!_can_be_statically_bound && h_m->is_private())
135 _can_be_statically_bound = true;
136 if (_can_be_statically_bound && h_m->is_abstract())
137 _can_be_statically_bound = false;
138
139 // generating _signature may allow GC and therefore move m.
140 // These fields are always filled in.
141 _name = env->get_symbol(h_m->name());
142 ciSymbol* sig_symbol = env->get_symbol(h_m->signature());
143 constantPoolHandle cpool(Thread::current(), h_m->constants());
144 _signature = new (env->arena()) ciSignature(_holder, cpool, sig_symbol);
145 _method_data = nullptr;
146 // Take a snapshot of these values, so they will be commensurate with the MDO.
147 if (ProfileInterpreter || CompilerConfig::is_c1_profiling()) {
148 int invcnt = h_m->interpreter_invocation_count();
149 // if the value overflowed report it as max int
150 _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ;
151 _interpreter_throwout_count = h_m->interpreter_throwout_count();
152 } else {
153 _interpreter_invocation_count = 0;
154 _interpreter_throwout_count = 0;
155 }
156 if (_interpreter_invocation_count == 0)
157 _interpreter_invocation_count = 1;
158 _inline_instructions_size = -1;
159 if (ReplayCompiles) {
160 ciReplay::initialize(this);
161 }
162 }
163
164
165 // ------------------------------------------------------------------
166 // ciMethod::ciMethod
167 //
168 // Unloaded method.
169 ciMethod::ciMethod(ciInstanceKlass* holder,
170 ciSymbol* name,
171 ciSymbol* signature,
172 ciInstanceKlass* accessor) :
173 ciMetadata((Metadata*)nullptr),
174 _name( name),
175 _holder( holder),
176 _method_data( nullptr),
177 _method_blocks( nullptr),
178 _intrinsic_id( vmIntrinsics::_none),
179 _inline_instructions_size(-1),
180 _can_be_statically_bound(false),
181 _can_omit_stack_trace(true),
182 _liveness( nullptr)
183 #if defined(COMPILER2)
184 ,
185 _flow( nullptr),
186 _bcea( nullptr)
187 #endif // COMPILER2
188 {
189 // Usually holder and accessor are the same type but in some cases
190 // the holder has the wrong class loader (e.g. invokedynamic call
191 // sites) so we pass the accessor.
192 _signature = new (CURRENT_ENV->arena()) ciSignature(accessor, constantPoolHandle(), signature);
193 }
194
195
196 // ------------------------------------------------------------------
197 // ciMethod::load_code
198 //
199 // Load the bytecodes and exception handler table for this method.
200 void ciMethod::load_code() {
201 VM_ENTRY_MARK;
980 bool ciMethod::is_scoped() const {
981 return get_Method()->is_scoped();
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) {
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 Method::build_profiling_method_data(h_m, THREAD);
1007 if (HAS_PENDING_EXCEPTION) {
1008 CLEAR_PENDING_EXCEPTION;
1009 }
1010 }
1011 if (h_m()->method_data() != nullptr) {
1012 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1013 return _method_data->load_data();
1014 } else {
1015 _method_data = CURRENT_ENV->get_empty_methodData();
1016 return false;
1017 }
1018 }
1019
1020 // public, retroactive version
1021 bool ciMethod::ensure_method_data() {
1022 bool result = true;
1023 if (_method_data == nullptr || _method_data->is_empty()) {
1024 GUARDED_VM_ENTRY({
1025 methodHandle mh(Thread::current(), get_Method());
1026 result = ensure_method_data(mh);
1027 });
1028 }
1029 return result;
1030 }
1031
1032
1033 // ------------------------------------------------------------------
1034 // ciMethod::method_data
1035 //
1036 ciMethodData* ciMethod::method_data() {
1037 if (_method_data != nullptr) {
1038 return _method_data;
1039 }
1040 VM_ENTRY_MARK;
1041 ciEnv* env = CURRENT_ENV;
1042 Thread* my_thread = JavaThread::current();
1043 methodHandle h_m(my_thread, get_Method());
1044
1045 if (h_m()->method_data() != nullptr) {
1046 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1047 _method_data->load_data();
1048 } else {
1049 _method_data = CURRENT_ENV->get_empty_methodData();
1050 }
1051 return _method_data;
1052
1053 }
1054
1055 // ------------------------------------------------------------------
1056 // ciMethod::method_data_or_null
1057 // Returns a pointer to ciMethodData if MDO exists on the VM side,
1058 // null otherwise.
1059 ciMethodData* ciMethod::method_data_or_null() {
1060 ciMethodData *md = method_data();
1061 if (md->is_empty()) {
1062 return nullptr;
1063 }
1064 return md;
1065 }
1066
1067 // ------------------------------------------------------------------
1068 // ciMethod::ensure_method_counters
1069 //
1070 MethodCounters* ciMethod::ensure_method_counters() {
1071 check_is_loaded();
1072 VM_ENTRY_MARK;
1087
1088 // ------------------------------------------------------------------
1089 // ciMethod::has_option_value
1090 //
1091 bool ciMethod::has_option_value(CompileCommandEnum option, double& value) {
1092 check_is_loaded();
1093 VM_ENTRY_MARK;
1094 methodHandle mh(THREAD, get_Method());
1095 return CompilerOracle::has_option_value(mh, option, value);
1096 }
1097 // ------------------------------------------------------------------
1098 // ciMethod::can_be_compiled
1099 //
1100 // Have previous compilations of this method succeeded?
1101 bool ciMethod::can_be_compiled() {
1102 check_is_loaded();
1103 ciEnv* env = CURRENT_ENV;
1104 if (is_c1_compile(env->comp_level())) {
1105 return _is_c1_compilable;
1106 }
1107 return _is_c2_compilable;
1108 }
1109
1110 // ------------------------------------------------------------------
1111 // ciMethod::has_compiled_code
1112 bool ciMethod::has_compiled_code() {
1113 return inline_instructions_size() > 0;
1114 }
1115
1116 int ciMethod::highest_osr_comp_level() {
1117 check_is_loaded();
1118 VM_ENTRY_MARK;
1119 return get_Method()->highest_osr_comp_level();
1120 }
1121
1122 // ------------------------------------------------------------------
1123 // ciMethod::code_size_for_inlining
1124 //
1125 // Code size for inlining decisions. This method returns a code
1126 // size of 1 for methods which has the ForceInline annotation.
1127 int ciMethod::code_size_for_inlining() {
1128 check_is_loaded();
1129 if (get_Method()->force_inline()) {
1130 return 1;
1131 }
1132 return code_size();
1133 }
1134
1135 // ------------------------------------------------------------------
1136 // ciMethod::inline_instructions_size
1137 //
1138 // This is a rough metric for "fat" methods, compared before inlining
1139 // with InlineSmallCode. The CodeBlob::code_size accessor includes
1140 // junk like exception handler, stubs, and constant table, which are
1141 // not highly relevant to an inlined method. So we use the more
1142 // specific accessor nmethod::insts_size.
1143 // Also some instructions inside the code are excluded from inline
1144 // heuristic (e.g. post call nop instructions; see InlineSkippedInstructionsCounter)
1145 int ciMethod::inline_instructions_size() {
1146 if (_inline_instructions_size == -1) {
1147 GUARDED_VM_ENTRY(
1148 nmethod* code = get_Method()->code();
1149 if (code != nullptr && (code->comp_level() == CompLevel_full_optimization)) {
1150 int isize = code->insts_end() - code->verified_entry_point() - code->skipped_instructions_size();
1151 _inline_instructions_size = isize > 0 ? isize : 0;
1152 } else {
1153 _inline_instructions_size = 0;
1154 }
1155 );
1156 }
1157 return _inline_instructions_size;
1158 }
1159
1160 // ------------------------------------------------------------------
1161 // ciMethod::log_nmethod_identity
1162 void ciMethod::log_nmethod_identity(xmlStream* log) {
1163 GUARDED_VM_ENTRY(
1164 nmethod* code = get_Method()->code();
1165 if (code != nullptr) {
1166 code->log_identity(log);
1167 }
1168 )
1169 }
1170
1171 // ------------------------------------------------------------------
1172 // ciMethod::is_not_reached
1173 bool ciMethod::is_not_reached(int bci) {
1174 check_is_loaded();
1175 VM_ENTRY_MARK;
1176 return Interpreter::is_not_reached(
1177 methodHandle(THREAD, get_Method()), bci);
1178 }
1179
1180 // ------------------------------------------------------------------
1181 // ciMethod::was_never_executed
1182 bool ciMethod::was_executed_more_than(int times) {
1183 VM_ENTRY_MARK;
1184 return get_Method()->was_executed_more_than(times);
1185 }
1186
1187 // ------------------------------------------------------------------
1188 // ciMethod::has_unloaded_classes_in_signature
1189 bool ciMethod::has_unloaded_classes_in_signature() {
1190 // ciSignature is resolved against some accessing class and
1191 // signature classes aren't required to be local. As a benefit,
1192 // it makes signature classes visible through loader constraints.
1193 // So, encountering an unloaded class signals it is absent both in
1194 // the callee (local) and caller contexts.
1195 return signature()->has_unloaded_classes();
1196 }
1197
1198 // ------------------------------------------------------------------
1199 // ciMethod::is_klass_loaded
1200 bool ciMethod::is_klass_loaded(int refinfo_index, Bytecodes::Code bc, bool must_be_resolved) const {
1201 VM_ENTRY_MARK;
1202 return get_Method()->is_klass_loaded(refinfo_index, bc, must_be_resolved);
|
1 /*
2 * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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 "precompiled.hpp"
26 #include "cds/aotLinkedClassBulkLoader.hpp"
27 #include "ci/ciCallProfile.hpp"
28 #include "ci/ciExceptionHandler.hpp"
29 #include "ci/ciInstanceKlass.hpp"
30 #include "ci/ciMethod.hpp"
31 #include "ci/ciMethodBlocks.hpp"
32 #include "ci/ciMethodData.hpp"
33 #include "ci/ciStreams.hpp"
34 #include "ci/ciSymbol.hpp"
35 #include "ci/ciReplay.hpp"
36 #include "ci/ciSymbols.hpp"
37 #include "ci/ciUtilities.inline.hpp"
38 #include "compiler/compileTask.hpp"
39 #include "compiler/abstractCompiler.hpp"
40 #include "compiler/compilerDefinitions.inline.hpp"
41 #include "compiler/compilerOracle.hpp"
42 #include "compiler/methodLiveness.hpp"
43 #include "interpreter/interpreter.hpp"
44 #include "interpreter/linkResolver.hpp"
45 #include "interpreter/oopMapCache.hpp"
46 #include "logging/log.hpp"
47 #include "logging/logStream.hpp"
48 #include "memory/allocation.inline.hpp"
49 #include "memory/resourceArea.hpp"
50 #include "oops/generateOopMap.hpp"
51 #include "oops/method.inline.hpp"
52 #include "oops/oop.inline.hpp"
53 #include "oops/trainingData.hpp"
54 #include "prims/methodHandles.hpp"
55 #include "runtime/deoptimization.hpp"
56 #include "runtime/handles.inline.hpp"
57 #include "utilities/bitMap.inline.hpp"
58 #include "utilities/xmlstream.hpp"
59 #ifdef COMPILER2
60 #include "ci/bcEscapeAnalyzer.hpp"
61 #include "ci/ciTypeFlow.hpp"
62 #include "oops/method.hpp"
63 #endif
64
65 // ciMethod
66 //
67 // This class represents a Method* in the HotSpot virtual
68 // machine.
69
70
71 // ------------------------------------------------------------------
72 // ciMethod::ciMethod
73 //
129 } else {
130 // Have to use a conservative value in this case.
131 _can_be_statically_bound = false;
132 _can_omit_stack_trace = true;
133 }
134
135 // Adjust the definition of this condition to be more useful:
136 // %%% take these conditions into account in vtable generation
137 if (!_can_be_statically_bound && h_m->is_private())
138 _can_be_statically_bound = true;
139 if (_can_be_statically_bound && h_m->is_abstract())
140 _can_be_statically_bound = false;
141
142 // generating _signature may allow GC and therefore move m.
143 // These fields are always filled in.
144 _name = env->get_symbol(h_m->name());
145 ciSymbol* sig_symbol = env->get_symbol(h_m->signature());
146 constantPoolHandle cpool(Thread::current(), h_m->constants());
147 _signature = new (env->arena()) ciSignature(_holder, cpool, sig_symbol);
148 _method_data = nullptr;
149 _method_data_recorded = nullptr;
150 // Take a snapshot of these values, so they will be commensurate with the MDO.
151 if (ProfileInterpreter || CompilerConfig::is_c1_profiling()) {
152 int invcnt = h_m->interpreter_invocation_count();
153 // if the value overflowed report it as max int
154 _interpreter_invocation_count = invcnt < 0 ? max_jint : invcnt ;
155 _interpreter_throwout_count = h_m->interpreter_throwout_count();
156 } else {
157 _interpreter_invocation_count = 0;
158 _interpreter_throwout_count = 0;
159 }
160 if (_interpreter_invocation_count == 0)
161 _interpreter_invocation_count = 1;
162 _inline_instructions_size = -1;
163 if (ReplayCompiles) {
164 ciReplay::initialize(this);
165 }
166 DirectiveSet* directives = DirectivesStack::getMatchingDirective(h_m, CURRENT_ENV->task()->compiler());
167 ccstrlist bci_list = directives->TooManyTrapsAtBCIOption;
168 int len = (int)strlen(bci_list);
169 Arena* arena = CURRENT_ENV->arena();
170 _has_trap_at_bci = new (arena) GrowableArray<int>(arena, 2, 0, 0);
171 for (int i = 0; i < len; i++) {
172 int v = -1;
173 int read;
174 if (sscanf(bci_list + i, "%i%n", &v, &read) != 1) {
175 warning("wrong format for TooManyTrapsAtBCI option: \"%s\"", bci_list);
176 break;
177 }
178 assert(v >= 0 && v < (1<<16), "%i", v);
179 _has_trap_at_bci->append_if_missing(v);
180 i += read;
181 }
182 }
183
184
185 // ------------------------------------------------------------------
186 // ciMethod::ciMethod
187 //
188 // Unloaded method.
189 ciMethod::ciMethod(ciInstanceKlass* holder,
190 ciSymbol* name,
191 ciSymbol* signature,
192 ciInstanceKlass* accessor) :
193 ciMetadata((Metadata*)nullptr),
194 _name( name),
195 _holder( holder),
196 _method_data( nullptr),
197 _method_data_recorded( nullptr),
198 _method_blocks( nullptr),
199 _intrinsic_id( vmIntrinsics::_none),
200 _inline_instructions_size(-1),
201 _can_be_statically_bound(false),
202 _can_omit_stack_trace(true),
203 _has_trap_at_bci( nullptr),
204 _liveness( nullptr)
205 #if defined(COMPILER2)
206 ,
207 _flow( nullptr),
208 _bcea( nullptr)
209 #endif // COMPILER2
210 {
211 // Usually holder and accessor are the same type but in some cases
212 // the holder has the wrong class loader (e.g. invokedynamic call
213 // sites) so we pass the accessor.
214 _signature = new (CURRENT_ENV->arena()) ciSignature(accessor, constantPoolHandle(), signature);
215 }
216
217
218 // ------------------------------------------------------------------
219 // ciMethod::load_code
220 //
221 // Load the bytecodes and exception handler table for this method.
222 void ciMethod::load_code() {
223 VM_ENTRY_MARK;
1002 bool ciMethod::is_scoped() const {
1003 return get_Method()->is_scoped();
1004 }
1005
1006 // ------------------------------------------------------------------
1007 // ciMethod::has_member_arg
1008 //
1009 // Return true if the method is a linker intrinsic like _linkToVirtual.
1010 // These are built by the JVM.
1011 bool ciMethod::has_member_arg() const {
1012 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
1013 return (MethodHandles::is_signature_polymorphic(iid) &&
1014 MethodHandles::has_member_arg(iid));
1015 }
1016
1017 // ------------------------------------------------------------------
1018 // ciMethod::ensure_method_data
1019 //
1020 // Generate new MethodData* objects at compile time.
1021 // Return true if allocation was successful or no MDO is required.
1022 bool ciMethod::ensure_method_data(const methodHandle& h_m, bool training_data_only) {
1023 EXCEPTION_CONTEXT;
1024 if (is_native() || is_abstract() || h_m()->is_accessor()) {
1025 return true;
1026 }
1027 if (h_m()->method_data() == nullptr) {
1028 if (training_data_only) {
1029 Method::install_training_method_data(h_m);
1030 } else {
1031 Method::build_profiling_method_data(h_m, THREAD);
1032 if (HAS_PENDING_EXCEPTION) {
1033 CLEAR_PENDING_EXCEPTION;
1034 }
1035 }
1036 }
1037 if (h_m()->method_data() != nullptr) {
1038 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1039 return _method_data->load_data();
1040 } else {
1041 _method_data = CURRENT_ENV->get_empty_methodData();
1042 return false;
1043 }
1044 }
1045
1046 // public, retroactive version
1047 bool ciMethod::ensure_method_data(bool training_data_only) {
1048 bool result = true;
1049 if (_method_data == nullptr || _method_data->is_empty()) {
1050 GUARDED_VM_ENTRY({
1051 methodHandle mh(Thread::current(), get_Method());
1052 result = ensure_method_data(mh, training_data_only);
1053 });
1054 }
1055 return result;
1056 }
1057
1058
1059 // ------------------------------------------------------------------
1060 // ciMethod::method_data
1061 //
1062 ciMethodData* ciMethod::method_data() {
1063 if (CURRENT_ENV->task()->is_precompiled() && CURRENT_ENV->task()->comp_level() == CompLevel_full_optimization) {
1064 if (_method_data_recorded == nullptr) {
1065 VM_ENTRY_MARK;
1066 methodHandle h_m(thread, get_Method());
1067 MethodTrainingData* mtd = MethodTrainingData::find(h_m);
1068 MethodData* mdo = (mtd != nullptr ? mtd->final_profile() : nullptr);
1069 DirectiveSet* directives = DirectivesStack::getMatchingDirective(h_m, CURRENT_ENV->task()->compiler());
1070 if (mdo == nullptr || directives->IgnoreRecordedProfileOption) {
1071 if (directives->IgnoreRecordedProfileOption) {
1072 ResourceMark rm;
1073 log_debug(precompile)("Ignore recorded profile for %s", h_m->name_and_sig_as_C_string());
1074 } else {
1075 ResourceMark rm;
1076 log_debug(precompile)("No profile for %s", h_m->name_and_sig_as_C_string());
1077 }
1078 _method_data_recorded = CURRENT_ENV->get_empty_methodData();
1079 } else {
1080 #if INCLUDE_CDS
1081 if (mdo->extra_data_lock() == nullptr) {
1082 assert(!HAS_PENDING_EXCEPTION, "");
1083 mdo->restore_unshareable_info(thread);
1084 assert(!HAS_PENDING_EXCEPTION, "");
1085 }
1086 #endif
1087 _method_data_recorded = CURRENT_ENV->get_method_data(mdo);
1088 _method_data_recorded->load_data();
1089 {
1090 ResourceMark rm;
1091 log_debug(precompile)("Recorded profile " PTR_FORMAT " for %s", p2i(mdo), h_m->name_and_sig_as_C_string());
1092 }
1093 }
1094 }
1095 assert(_method_data_recorded != nullptr, "");
1096 return _method_data_recorded;
1097 } else {
1098 if (_method_data != nullptr) {
1099 return _method_data;
1100 }
1101 VM_ENTRY_MARK;
1102 methodHandle h_m(thread, get_Method());
1103 MethodData* mdo = h_m()->method_data();
1104 if (mdo != nullptr) {
1105 _method_data = CURRENT_ENV->get_method_data(mdo);
1106 _method_data->load_data();
1107 } else {
1108 _method_data = CURRENT_ENV->get_empty_methodData();
1109 }
1110 return _method_data;
1111 }
1112 }
1113
1114 // ------------------------------------------------------------------
1115 // ciMethod::method_data_or_null
1116 // Returns a pointer to ciMethodData if MDO exists on the VM side,
1117 // null otherwise.
1118 ciMethodData* ciMethod::method_data_or_null() {
1119 ciMethodData *md = method_data();
1120 if (md->is_empty()) {
1121 return nullptr;
1122 }
1123 return md;
1124 }
1125
1126 // ------------------------------------------------------------------
1127 // ciMethod::ensure_method_counters
1128 //
1129 MethodCounters* ciMethod::ensure_method_counters() {
1130 check_is_loaded();
1131 VM_ENTRY_MARK;
1146
1147 // ------------------------------------------------------------------
1148 // ciMethod::has_option_value
1149 //
1150 bool ciMethod::has_option_value(CompileCommandEnum option, double& value) {
1151 check_is_loaded();
1152 VM_ENTRY_MARK;
1153 methodHandle mh(THREAD, get_Method());
1154 return CompilerOracle::has_option_value(mh, option, value);
1155 }
1156 // ------------------------------------------------------------------
1157 // ciMethod::can_be_compiled
1158 //
1159 // Have previous compilations of this method succeeded?
1160 bool ciMethod::can_be_compiled() {
1161 check_is_loaded();
1162 ciEnv* env = CURRENT_ENV;
1163 if (is_c1_compile(env->comp_level())) {
1164 return _is_c1_compilable;
1165 }
1166
1167 #if INCLUDE_JVMCI
1168 if (EnableJVMCI && UseJVMCICompiler &&
1169 env->comp_level() == CompLevel_full_optimization && !AOTLinkedClassBulkLoader::class_preloading_finished()) {
1170 return false;
1171 }
1172 #endif
1173 return _is_c2_compilable;
1174 }
1175
1176 // ------------------------------------------------------------------
1177 // ciMethod::has_compiled_code
1178 bool ciMethod::has_compiled_code() {
1179 return inline_instructions_size() > 0;
1180 }
1181
1182 int ciMethod::highest_osr_comp_level() {
1183 check_is_loaded();
1184 VM_ENTRY_MARK;
1185 return get_Method()->highest_osr_comp_level();
1186 }
1187
1188 // ------------------------------------------------------------------
1189 // ciMethod::code_size_for_inlining
1190 //
1191 // Code size for inlining decisions. This method returns a code
1192 // size of 1 for methods which has the ForceInline annotation.
1193 int ciMethod::code_size_for_inlining() {
1194 check_is_loaded();
1195 if (get_Method()->force_inline()) {
1196 return 1;
1197 }
1198 return code_size();
1199 }
1200
1201 // ------------------------------------------------------------------
1202 // ciMethod::inline_instructions_size
1203 //
1204 // This is a rough metric for "fat" methods, compared before inlining
1205 // with InlineSmallCode. The CodeBlob::code_size accessor includes
1206 // junk like exception handler, stubs, and constant table, which are
1207 // not highly relevant to an inlined method. So we use the more
1208 // specific accessor nmethod::insts_size.
1209 // Also some instructions inside the code are excluded from inline
1210 // heuristic (e.g. post call nop instructions; see InlineSkippedInstructionsCounter)
1211 int ciMethod::inline_instructions_size() {
1212 if (_inline_instructions_size == -1) {
1213 if (TrainingData::have_data()) {
1214 GUARDED_VM_ENTRY(
1215 CompLevel level = static_cast<CompLevel>(CURRENT_ENV->comp_level());
1216 methodHandle top_level_mh(Thread::current(), CURRENT_ENV->task()->method());
1217 MethodTrainingData* mtd = MethodTrainingData::find(top_level_mh);
1218 if (mtd != nullptr) {
1219 CompileTrainingData* ctd = mtd->last_toplevel_compile(level);
1220 if (ctd != nullptr) {
1221 methodHandle mh(Thread::current(), get_Method());
1222 MethodTrainingData* this_mtd = MethodTrainingData::find(mh);
1223 if (this_mtd != nullptr) {
1224 auto r = ctd->ci_records().ciMethod__inline_instructions_size.find(this_mtd);
1225 if (r.is_valid()) {
1226 _inline_instructions_size = r.result();
1227 }
1228 }
1229 }
1230 }
1231 );
1232 }
1233 }
1234 if (_inline_instructions_size == -1) {
1235 GUARDED_VM_ENTRY(
1236 nmethod* code = get_Method()->code();
1237 if (code != nullptr && !code->is_scc() && (code->comp_level() == CompLevel_full_optimization)) {
1238 int isize = code->insts_end() - code->verified_entry_point() - code->skipped_instructions_size();
1239 _inline_instructions_size = isize > 0 ? isize : 0;
1240 } else {
1241 _inline_instructions_size = 0;
1242 }
1243 if (TrainingData::need_data()) {
1244 CompileTrainingData* ctd = CURRENT_ENV->task()->training_data();
1245 if (ctd != nullptr) {
1246 methodHandle mh(Thread::current(), get_Method());
1247 MethodTrainingData* this_mtd = MethodTrainingData::make(mh);
1248 ctd->ci_records().ciMethod__inline_instructions_size.append_if_missing(_inline_instructions_size, this_mtd);
1249 }
1250 }
1251 );
1252 }
1253 return _inline_instructions_size;
1254 }
1255
1256 // ------------------------------------------------------------------
1257 // ciMethod::log_nmethod_identity
1258 void ciMethod::log_nmethod_identity(xmlStream* log) {
1259 GUARDED_VM_ENTRY(
1260 nmethod* code = get_Method()->code();
1261 if (code != nullptr) {
1262 code->log_identity(log);
1263 }
1264 )
1265 }
1266
1267 // ------------------------------------------------------------------
1268 // ciMethod::is_not_reached
1269 bool ciMethod::is_not_reached(int bci) {
1270 check_is_loaded();
1271 VM_ENTRY_MARK;
1272 return Interpreter::is_not_reached(
1273 methodHandle(THREAD, get_Method()), bci);
1274 }
1275
1276 // ------------------------------------------------------------------
1277 // ciMethod::was_never_executed
1278 bool ciMethod::was_executed_more_than(int times) {
1279 // Invocation counter is reset when the Method* is compiled.
1280 // If the method has compiled code we therefore assume it has
1281 // be executed more than n times.
1282 if (is_accessor() || is_empty() || has_compiled_code()) {
1283 // interpreter doesn't bump invocation counter of trivial methods
1284 // compiler does not bump invocation counter of compiled methods
1285 return true;
1286 }
1287 if (!method_data()->is_empty()) {
1288 return (method_data()->invocation_count() > times);
1289 }
1290 VM_ENTRY_MARK;
1291 return get_Method()->was_executed_more_than(times);
1292 }
1293
1294 // ------------------------------------------------------------------
1295 // ciMethod::has_unloaded_classes_in_signature
1296 bool ciMethod::has_unloaded_classes_in_signature() {
1297 // ciSignature is resolved against some accessing class and
1298 // signature classes aren't required to be local. As a benefit,
1299 // it makes signature classes visible through loader constraints.
1300 // So, encountering an unloaded class signals it is absent both in
1301 // the callee (local) and caller contexts.
1302 return signature()->has_unloaded_classes();
1303 }
1304
1305 // ------------------------------------------------------------------
1306 // ciMethod::is_klass_loaded
1307 bool ciMethod::is_klass_loaded(int refinfo_index, Bytecodes::Code bc, bool must_be_resolved) const {
1308 VM_ENTRY_MARK;
1309 return get_Method()->is_klass_loaded(refinfo_index, bc, must_be_resolved);
|