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;
967 bool ciMethod::is_scoped() const {
968 return get_Method()->is_scoped();
969 }
970
971 // ------------------------------------------------------------------
972 // ciMethod::has_member_arg
973 //
974 // Return true if the method is a linker intrinsic like _linkToVirtual.
975 // These are built by the JVM.
976 bool ciMethod::has_member_arg() const {
977 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
978 return (MethodHandles::is_signature_polymorphic(iid) &&
979 MethodHandles::has_member_arg(iid));
980 }
981
982 // ------------------------------------------------------------------
983 // ciMethod::ensure_method_data
984 //
985 // Generate new MethodData* objects at compile time.
986 // Return true if allocation was successful or no MDO is required.
987 bool ciMethod::ensure_method_data(const methodHandle& h_m) {
988 EXCEPTION_CONTEXT;
989 if (is_native() || is_abstract() || h_m()->is_accessor()) {
990 return true;
991 }
992 if (h_m()->method_data() == nullptr) {
993 Method::build_profiling_method_data(h_m, THREAD);
994 if (HAS_PENDING_EXCEPTION) {
995 CLEAR_PENDING_EXCEPTION;
996 }
997 }
998 if (h_m()->method_data() != nullptr) {
999 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1000 return _method_data->load_data();
1001 } else {
1002 _method_data = CURRENT_ENV->get_empty_methodData();
1003 return false;
1004 }
1005 }
1006
1007 // public, retroactive version
1008 bool ciMethod::ensure_method_data() {
1009 bool result = true;
1010 if (_method_data == nullptr || _method_data->is_empty()) {
1011 GUARDED_VM_ENTRY({
1012 methodHandle mh(Thread::current(), get_Method());
1013 result = ensure_method_data(mh);
1014 });
1015 }
1016 return result;
1017 }
1018
1019
1020 // ------------------------------------------------------------------
1021 // ciMethod::method_data
1022 //
1023 ciMethodData* ciMethod::method_data() {
1024 if (_method_data != nullptr) {
1025 return _method_data;
1026 }
1027 VM_ENTRY_MARK;
1028 ciEnv* env = CURRENT_ENV;
1029 Thread* my_thread = JavaThread::current();
1030 methodHandle h_m(my_thread, get_Method());
1031
1032 if (h_m()->method_data() != nullptr) {
1033 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1034 _method_data->load_data();
1035 } else {
1036 _method_data = CURRENT_ENV->get_empty_methodData();
1037 }
1038 return _method_data;
1039
1040 }
1041
1042 // ------------------------------------------------------------------
1043 // ciMethod::method_data_or_null
1044 // Returns a pointer to ciMethodData if MDO exists on the VM side,
1045 // null otherwise.
1046 ciMethodData* ciMethod::method_data_or_null() {
1047 ciMethodData *md = method_data();
1048 if (md->is_empty()) {
1049 return nullptr;
1050 }
1051 return md;
1052 }
1053
1054 // ------------------------------------------------------------------
1055 // ciMethod::ensure_method_counters
1056 //
1057 MethodCounters* ciMethod::ensure_method_counters() {
1058 check_is_loaded();
1059 VM_ENTRY_MARK;
1074
1075 // ------------------------------------------------------------------
1076 // ciMethod::has_option_value
1077 //
1078 bool ciMethod::has_option_value(CompileCommandEnum option, double& value) {
1079 check_is_loaded();
1080 VM_ENTRY_MARK;
1081 methodHandle mh(THREAD, get_Method());
1082 return CompilerOracle::has_option_value(mh, option, value);
1083 }
1084 // ------------------------------------------------------------------
1085 // ciMethod::can_be_compiled
1086 //
1087 // Have previous compilations of this method succeeded?
1088 bool ciMethod::can_be_compiled() {
1089 check_is_loaded();
1090 ciEnv* env = CURRENT_ENV;
1091 if (is_c1_compile(env->comp_level())) {
1092 return _is_c1_compilable;
1093 }
1094 return _is_c2_compilable;
1095 }
1096
1097 // ------------------------------------------------------------------
1098 // ciMethod::has_compiled_code
1099 bool ciMethod::has_compiled_code() {
1100 return inline_instructions_size() > 0;
1101 }
1102
1103 int ciMethod::highest_osr_comp_level() {
1104 check_is_loaded();
1105 VM_ENTRY_MARK;
1106 return get_Method()->highest_osr_comp_level();
1107 }
1108
1109 // ------------------------------------------------------------------
1110 // ciMethod::code_size_for_inlining
1111 //
1112 // Code size for inlining decisions. This method returns a code
1113 // size of 1 for methods which has the ForceInline annotation.
1114 int ciMethod::code_size_for_inlining() {
1115 check_is_loaded();
1116 if (get_Method()->force_inline()) {
1117 return 1;
1118 }
1119 return code_size();
1120 }
1121
1122 // ------------------------------------------------------------------
1123 // ciMethod::inline_instructions_size
1124 //
1125 // This is a rough metric for "fat" methods, compared before inlining
1126 // with InlineSmallCode. The CodeBlob::code_size accessor includes
1127 // junk like exception handler, stubs, and constant table, which are
1128 // not highly relevant to an inlined method. So we use the more
1129 // specific accessor nmethod::insts_size.
1130 // Also some instructions inside the code are excluded from inline
1131 // heuristic (e.g. post call nop instructions; see InlineSkippedInstructionsCounter)
1132 int ciMethod::inline_instructions_size() {
1133 if (_inline_instructions_size == -1) {
1134 GUARDED_VM_ENTRY(
1135 nmethod* code = get_Method()->code();
1136 if (code != nullptr && (code->comp_level() == CompLevel_full_optimization)) {
1137 int isize = code->insts_end() - code->verified_entry_point() - code->skipped_instructions_size();
1138 _inline_instructions_size = isize > 0 ? isize : 0;
1139 } else {
1140 _inline_instructions_size = 0;
1141 }
1142 );
1143 }
1144 return _inline_instructions_size;
1145 }
1146
1147 // ------------------------------------------------------------------
1148 // ciMethod::log_nmethod_identity
1149 void ciMethod::log_nmethod_identity(xmlStream* log) {
1150 GUARDED_VM_ENTRY(
1151 nmethod* code = get_Method()->code();
1152 if (code != nullptr) {
1153 code->log_identity(log);
1154 }
1155 )
1156 }
1157
1158 // ------------------------------------------------------------------
1159 // ciMethod::is_not_reached
1160 bool ciMethod::is_not_reached(int bci) {
1161 check_is_loaded();
1162 VM_ENTRY_MARK;
1163 return Interpreter::is_not_reached(
1164 methodHandle(THREAD, get_Method()), bci);
1165 }
1166
1167 // ------------------------------------------------------------------
1168 // ciMethod::was_never_executed
1169 bool ciMethod::was_executed_more_than(int times) {
1170 VM_ENTRY_MARK;
1171 return get_Method()->was_executed_more_than(times);
1172 }
1173
1174 // ------------------------------------------------------------------
1175 // ciMethod::has_unloaded_classes_in_signature
1176 bool ciMethod::has_unloaded_classes_in_signature() {
1177 // ciSignature is resolved against some accessing class and
1178 // signature classes aren't required to be local. As a benefit,
1179 // it makes signature classes visible through loader constraints.
1180 // So, encountering an unloaded class signals it is absent both in
1181 // the callee (local) and caller contexts.
1182 return signature()->has_unloaded_classes();
1183 }
1184
1185 // ------------------------------------------------------------------
1186 // ciMethod::is_klass_loaded
1187 bool ciMethod::is_klass_loaded(int refinfo_index, Bytecodes::Code bc, bool must_be_resolved) const {
1188 VM_ENTRY_MARK;
1189 return get_Method()->is_klass_loaded(refinfo_index, bc, must_be_resolved);
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "cds/classPreloader.hpp"
27 #include "ci/ciCallProfile.hpp"
28 #include "ci/ciExceptionHandler.hpp"
29 #include "ci/ciInstanceKlass.hpp"
30 #include "ci/ciMethod.hpp"
31 #include "ci/ciMethodBlocks.hpp"
32 #include "ci/ciMethodData.hpp"
33 #include "ci/ciStreams.hpp"
34 #include "ci/ciSymbol.hpp"
35 #include "ci/ciReplay.hpp"
36 #include "ci/ciSymbols.hpp"
37 #include "ci/ciUtilities.inline.hpp"
38 #include "compiler/compileTask.hpp"
39 #include "compiler/abstractCompiler.hpp"
40 #include "compiler/compilerDefinitions.inline.hpp"
41 #include "compiler/compilerOracle.hpp"
42 #include "compiler/methodLiveness.hpp"
43 #include "interpreter/interpreter.hpp"
44 #include "interpreter/linkResolver.hpp"
45 #include "interpreter/oopMapCache.hpp"
46 #include "logging/log.hpp"
47 #include "logging/logStream.hpp"
48 #include "memory/allocation.inline.hpp"
49 #include "memory/resourceArea.hpp"
50 #include "oops/generateOopMap.hpp"
51 #include "oops/method.inline.hpp"
52 #include "oops/oop.inline.hpp"
53 #include "oops/trainingData.hpp"
54 #include "prims/methodHandles.hpp"
55 #include "runtime/deoptimization.hpp"
56 #include "runtime/handles.inline.hpp"
57 #include "utilities/bitMap.inline.hpp"
58 #include "utilities/xmlstream.hpp"
59 #ifdef COMPILER2
60 #include "ci/bcEscapeAnalyzer.hpp"
61 #include "ci/ciTypeFlow.hpp"
62 #include "oops/method.hpp"
63 #endif
64
65 // ciMethod
66 //
67 // This class represents a Method* in the HotSpot virtual
68 // machine.
69
70
71 // ------------------------------------------------------------------
72 // ciMethod::ciMethod
73 //
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;
989 bool ciMethod::is_scoped() const {
990 return get_Method()->is_scoped();
991 }
992
993 // ------------------------------------------------------------------
994 // ciMethod::has_member_arg
995 //
996 // Return true if the method is a linker intrinsic like _linkToVirtual.
997 // These are built by the JVM.
998 bool ciMethod::has_member_arg() const {
999 vmIntrinsics::ID iid = _intrinsic_id; // do not check if loaded
1000 return (MethodHandles::is_signature_polymorphic(iid) &&
1001 MethodHandles::has_member_arg(iid));
1002 }
1003
1004 // ------------------------------------------------------------------
1005 // ciMethod::ensure_method_data
1006 //
1007 // Generate new MethodData* objects at compile time.
1008 // Return true if allocation was successful or no MDO is required.
1009 bool ciMethod::ensure_method_data(const methodHandle& h_m, bool training_data_only) {
1010 EXCEPTION_CONTEXT;
1011 if (is_native() || is_abstract() || h_m()->is_accessor()) {
1012 return true;
1013 }
1014 if (h_m()->method_data() == nullptr) {
1015 if (training_data_only) {
1016 Method::install_training_method_data(h_m);
1017 } else {
1018 Method::build_profiling_method_data(h_m, THREAD);
1019 if (HAS_PENDING_EXCEPTION) {
1020 CLEAR_PENDING_EXCEPTION;
1021 }
1022 }
1023 }
1024 if (h_m()->method_data() != nullptr) {
1025 _method_data = CURRENT_ENV->get_method_data(h_m()->method_data());
1026 return _method_data->load_data();
1027 } else {
1028 _method_data = CURRENT_ENV->get_empty_methodData();
1029 return false;
1030 }
1031 }
1032
1033 // public, retroactive version
1034 bool ciMethod::ensure_method_data(bool training_data_only) {
1035 bool result = true;
1036 if (_method_data == nullptr || _method_data->is_empty()) {
1037 GUARDED_VM_ENTRY({
1038 methodHandle mh(Thread::current(), get_Method());
1039 result = ensure_method_data(mh, training_data_only);
1040 });
1041 }
1042 return result;
1043 }
1044
1045
1046 // ------------------------------------------------------------------
1047 // ciMethod::method_data
1048 //
1049 ciMethodData* ciMethod::method_data() {
1050 if (CURRENT_ENV->task()->is_precompiled() && CURRENT_ENV->task()->comp_level() == CompLevel_full_optimization) {
1051 if (_method_data_recorded == nullptr) {
1052 VM_ENTRY_MARK;
1053 methodHandle h_m(thread, get_Method());
1054 MethodTrainingData* mtd = TrainingData::lookup_for(h_m());
1055 MethodData* mdo = (mtd != nullptr ? mtd->final_profile() : nullptr);
1056 DirectiveSet* directives = DirectivesStack::getMatchingDirective(h_m, CURRENT_ENV->task()->compiler());
1057 if (mdo == nullptr || directives->IgnoreRecordedProfileOption) {
1058 if (directives->IgnoreRecordedProfileOption) {
1059 ResourceMark rm;
1060 log_debug(precompile)("Ignore recorded profile for %s", h_m->name_and_sig_as_C_string());
1061 } else {
1062 ResourceMark rm;
1063 log_debug(precompile)("No profile for %s", h_m->name_and_sig_as_C_string());
1064 }
1065 _method_data_recorded = CURRENT_ENV->get_empty_methodData();
1066 } else {
1067 if (mdo->extra_data_lock() == nullptr) {
1068 assert(!HAS_PENDING_EXCEPTION, "");
1069 mdo->restore_unshareable_info(thread);
1070 assert(!HAS_PENDING_EXCEPTION, "");
1071 }
1072 _method_data_recorded = CURRENT_ENV->get_method_data(mdo);
1073 _method_data_recorded->load_data();
1074 {
1075 ResourceMark rm;
1076 log_debug(precompile)("Recorded profile " PTR_FORMAT " for %s", p2i(mdo), h_m->name_and_sig_as_C_string());
1077 }
1078 }
1079 }
1080 assert(_method_data_recorded != nullptr, "");
1081 return _method_data_recorded;
1082 } else {
1083 if (_method_data != nullptr) {
1084 return _method_data;
1085 }
1086 VM_ENTRY_MARK;
1087 methodHandle h_m(thread, get_Method());
1088 MethodData* mdo = h_m()->method_data();
1089 if (mdo != nullptr) {
1090 _method_data = CURRENT_ENV->get_method_data(mdo);
1091 _method_data->load_data();
1092 } else {
1093 _method_data = CURRENT_ENV->get_empty_methodData();
1094 }
1095 return _method_data;
1096 }
1097 }
1098
1099 // ------------------------------------------------------------------
1100 // ciMethod::method_data_or_null
1101 // Returns a pointer to ciMethodData if MDO exists on the VM side,
1102 // null otherwise.
1103 ciMethodData* ciMethod::method_data_or_null() {
1104 ciMethodData *md = method_data();
1105 if (md->is_empty()) {
1106 return nullptr;
1107 }
1108 return md;
1109 }
1110
1111 // ------------------------------------------------------------------
1112 // ciMethod::ensure_method_counters
1113 //
1114 MethodCounters* ciMethod::ensure_method_counters() {
1115 check_is_loaded();
1116 VM_ENTRY_MARK;
1131
1132 // ------------------------------------------------------------------
1133 // ciMethod::has_option_value
1134 //
1135 bool ciMethod::has_option_value(CompileCommandEnum option, double& value) {
1136 check_is_loaded();
1137 VM_ENTRY_MARK;
1138 methodHandle mh(THREAD, get_Method());
1139 return CompilerOracle::has_option_value(mh, option, value);
1140 }
1141 // ------------------------------------------------------------------
1142 // ciMethod::can_be_compiled
1143 //
1144 // Have previous compilations of this method succeeded?
1145 bool ciMethod::can_be_compiled() {
1146 check_is_loaded();
1147 ciEnv* env = CURRENT_ENV;
1148 if (is_c1_compile(env->comp_level())) {
1149 return _is_c1_compilable;
1150 }
1151
1152 #if INCLUDE_JVMCI
1153 if (EnableJVMCI && UseJVMCICompiler &&
1154 env->comp_level() == CompLevel_full_optimization && !ClassPreloader::class_preloading_finished()) {
1155 return false;
1156 }
1157 #endif
1158 return _is_c2_compilable;
1159 }
1160
1161 // ------------------------------------------------------------------
1162 // ciMethod::has_compiled_code
1163 bool ciMethod::has_compiled_code() {
1164 return inline_instructions_size() > 0;
1165 }
1166
1167 int ciMethod::highest_osr_comp_level() {
1168 check_is_loaded();
1169 VM_ENTRY_MARK;
1170 return get_Method()->highest_osr_comp_level();
1171 }
1172
1173 // ------------------------------------------------------------------
1174 // ciMethod::code_size_for_inlining
1175 //
1176 // Code size for inlining decisions. This method returns a code
1177 // size of 1 for methods which has the ForceInline annotation.
1178 int ciMethod::code_size_for_inlining() {
1179 check_is_loaded();
1180 if (get_Method()->force_inline()) {
1181 return 1;
1182 }
1183 return code_size();
1184 }
1185
1186 // ------------------------------------------------------------------
1187 // ciMethod::inline_instructions_size
1188 //
1189 // This is a rough metric for "fat" methods, compared before inlining
1190 // with InlineSmallCode. The CodeBlob::code_size accessor includes
1191 // junk like exception handler, stubs, and constant table, which are
1192 // not highly relevant to an inlined method. So we use the more
1193 // specific accessor nmethod::insts_size.
1194 // Also some instructions inside the code are excluded from inline
1195 // heuristic (e.g. post call nop instructions; see InlineSkippedInstructionsCounter)
1196 int ciMethod::inline_instructions_size() {
1197 if (_inline_instructions_size == -1) {
1198 if (TrainingData::have_data()) {
1199 GUARDED_VM_ENTRY(
1200 CompLevel level = static_cast<CompLevel>(CURRENT_ENV->comp_level());
1201 methodHandle top_level_mh(Thread::current(), CURRENT_ENV->task()->method());
1202 MethodTrainingData* mtd = MethodTrainingData::find(top_level_mh);
1203 if (mtd != nullptr) {
1204 CompileTrainingData* ctd = mtd->last_toplevel_compile(level);
1205 if (ctd != nullptr) {
1206 methodHandle mh(Thread::current(), get_Method());
1207 MethodTrainingData* this_mtd = MethodTrainingData::find(mh);
1208 if (this_mtd != nullptr) {
1209 auto r = ctd->ci_records().ciMethod__inline_instructions_size.find(this_mtd);
1210 if (r.is_valid()) {
1211 _inline_instructions_size = r.result();
1212 }
1213 }
1214 }
1215 }
1216 );
1217 }
1218 }
1219 if (_inline_instructions_size == -1) {
1220 GUARDED_VM_ENTRY(
1221 nmethod* code = get_Method()->code();
1222 if (code != nullptr && !code->is_scc() && (code->comp_level() == CompLevel_full_optimization)) {
1223 int isize = code->insts_end() - code->verified_entry_point() - code->skipped_instructions_size();
1224 _inline_instructions_size = isize > 0 ? isize : 0;
1225 } else {
1226 _inline_instructions_size = 0;
1227 }
1228 if (TrainingData::need_data()) {
1229 CompileTrainingData* ctd = CURRENT_ENV->task()->training_data();
1230 if (ctd != nullptr) {
1231 methodHandle mh(Thread::current(), get_Method());
1232 MethodTrainingData* this_mtd = MethodTrainingData::make(mh);
1233 ctd->ci_records().ciMethod__inline_instructions_size.append_if_missing(_inline_instructions_size, this_mtd);
1234 }
1235 }
1236 );
1237 }
1238 return _inline_instructions_size;
1239 }
1240
1241 // ------------------------------------------------------------------
1242 // ciMethod::log_nmethod_identity
1243 void ciMethod::log_nmethod_identity(xmlStream* log) {
1244 GUARDED_VM_ENTRY(
1245 nmethod* code = get_Method()->code();
1246 if (code != nullptr) {
1247 code->log_identity(log);
1248 }
1249 )
1250 }
1251
1252 // ------------------------------------------------------------------
1253 // ciMethod::is_not_reached
1254 bool ciMethod::is_not_reached(int bci) {
1255 check_is_loaded();
1256 VM_ENTRY_MARK;
1257 return Interpreter::is_not_reached(
1258 methodHandle(THREAD, get_Method()), bci);
1259 }
1260
1261 // ------------------------------------------------------------------
1262 // ciMethod::was_never_executed
1263 bool ciMethod::was_executed_more_than(int times) {
1264 // Invocation counter is reset when the Method* is compiled.
1265 // If the method has compiled code we therefore assume it has
1266 // be executed more than n times.
1267 if (is_accessor() || is_empty() || has_compiled_code()) {
1268 // interpreter doesn't bump invocation counter of trivial methods
1269 // compiler does not bump invocation counter of compiled methods
1270 return true;
1271 }
1272 if (!method_data()->is_empty()) {
1273 return (method_data()->invocation_count() > times);
1274 }
1275 VM_ENTRY_MARK;
1276 return get_Method()->was_executed_more_than(times);
1277 }
1278
1279 // ------------------------------------------------------------------
1280 // ciMethod::has_unloaded_classes_in_signature
1281 bool ciMethod::has_unloaded_classes_in_signature() {
1282 // ciSignature is resolved against some accessing class and
1283 // signature classes aren't required to be local. As a benefit,
1284 // it makes signature classes visible through loader constraints.
1285 // So, encountering an unloaded class signals it is absent both in
1286 // the callee (local) and caller contexts.
1287 return signature()->has_unloaded_classes();
1288 }
1289
1290 // ------------------------------------------------------------------
1291 // ciMethod::is_klass_loaded
1292 bool ciMethod::is_klass_loaded(int refinfo_index, Bytecodes::Code bc, bool must_be_resolved) const {
1293 VM_ENTRY_MARK;
1294 return get_Method()->is_klass_loaded(refinfo_index, bc, must_be_resolved);
|