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/ciConstant.hpp"
27 #include "ci/ciEnv.hpp"
28 #include "ci/ciField.hpp"
29 #include "ci/ciInstance.hpp"
30 #include "ci/ciInstanceKlass.hpp"
31 #include "ci/ciMethod.hpp"
32 #include "ci/ciNullObject.hpp"
33 #include "ci/ciReplay.hpp"
34 #include "ci/ciSymbols.hpp"
35 #include "ci/ciUtilities.inline.hpp"
36 #include "classfile/javaClasses.hpp"
37 #include "classfile/javaClasses.inline.hpp"
38 #include "classfile/systemDictionary.hpp"
39 #include "classfile/vmClasses.hpp"
40 #include "classfile/vmSymbols.hpp"
41 #include "code/codeCache.hpp"
42 #include "code/scopeDesc.hpp"
43 #include "compiler/compilationLog.hpp"
44 #include "compiler/compilationPolicy.hpp"
45 #include "compiler/compileBroker.hpp"
46 #include "compiler/compilerEvent.hpp"
47 #include "compiler/compileLog.hpp"
48 #include "compiler/compileTask.hpp"
49 #include "compiler/disassembler.hpp"
50 #include "gc/shared/collectedHeap.inline.hpp"
51 #include "interpreter/bytecodeStream.hpp"
52 #include "interpreter/linkResolver.hpp"
53 #include "jfr/jfrEvents.hpp"
54 #include "jvm.h"
55 #include "logging/log.hpp"
56 #include "memory/allocation.inline.hpp"
57 #include "memory/oopFactory.hpp"
58 #include "memory/resourceArea.hpp"
59 #include "memory/universe.hpp"
60 #include "oops/constantPool.inline.hpp"
61 #include "oops/cpCache.inline.hpp"
62 #include "oops/method.inline.hpp"
63 #include "oops/methodData.hpp"
64 #include "oops/objArrayKlass.hpp"
65 #include "oops/objArrayOop.inline.hpp"
66 #include "oops/oop.inline.hpp"
67 #include "oops/resolvedIndyEntry.hpp"
68 #include "oops/symbolHandle.hpp"
69 #include "prims/jvmtiExport.hpp"
70 #include "prims/methodHandles.hpp"
71 #include "runtime/fieldDescriptor.inline.hpp"
72 #include "runtime/handles.inline.hpp"
73 #include "runtime/init.hpp"
74 #include "runtime/javaThread.hpp"
75 #include "runtime/jniHandles.inline.hpp"
76 #include "runtime/reflection.hpp"
77 #include "runtime/safepointVerifiers.hpp"
78 #include "runtime/sharedRuntime.hpp"
79 #include "utilities/dtrace.hpp"
80 #include "utilities/macros.hpp"
81 #ifdef COMPILER1
82 #include "c1/c1_Runtime1.hpp"
83 #endif
84 #ifdef COMPILER2
85 #include "opto/runtime.hpp"
86 #endif
87
88 // ciEnv
89 //
90 // This class is the top level broker for requests from the compiler
91 // to the VM.
154
155 oop o = Universe::null_ptr_exception_instance();
156 assert(o != nullptr, "should have been initialized");
157 _NullPointerException_instance = get_object(o)->as_instance();
158 o = Universe::arithmetic_exception_instance();
159 assert(o != nullptr, "should have been initialized");
160 _ArithmeticException_instance = get_object(o)->as_instance();
161
162 _ArrayIndexOutOfBoundsException_instance = nullptr;
163 _ArrayStoreException_instance = nullptr;
164 _ClassCastException_instance = nullptr;
165 _the_null_string = nullptr;
166 _the_min_jint_string = nullptr;
167
168 _jvmti_redefinition_count = 0;
169 _jvmti_can_hotswap_or_post_breakpoint = false;
170 _jvmti_can_access_local_variables = false;
171 _jvmti_can_post_on_exceptions = false;
172 _jvmti_can_pop_frame = false;
173
174 _dyno_klasses = nullptr;
175 _dyno_locs = nullptr;
176 _dyno_name[0] = '\0';
177 }
178
179 // Record components of a location descriptor string. Components are appended by the constructor and
180 // removed by the destructor, like a stack, so scope matters. These location descriptors are used to
181 // locate dynamic classes, and terminate at a Method* or oop field associated with dynamic/hidden class.
182 //
183 // Example use:
184 //
185 // {
186 // RecordLocation fp(this, "field1");
187 // // location: "field1"
188 // { RecordLocation fp(this, " field2"); // location: "field1 field2" }
189 // // location: "field1"
190 // { RecordLocation fp(this, " field3"); // location: "field1 field3" }
191 // // location: "field1"
192 // }
193 // // location: ""
274 // During VM initialization, these instances have not yet been created.
275 // Assertions ensure that these instances are not accessed before
276 // their initialization.
277
278 assert(Universe::is_fully_initialized(), "must be");
279
280 _NullPointerException_instance = nullptr;
281 _ArithmeticException_instance = nullptr;
282 _ArrayIndexOutOfBoundsException_instance = nullptr;
283 _ArrayStoreException_instance = nullptr;
284 _ClassCastException_instance = nullptr;
285 _the_null_string = nullptr;
286 _the_min_jint_string = nullptr;
287
288 _jvmti_redefinition_count = 0;
289 _jvmti_can_hotswap_or_post_breakpoint = false;
290 _jvmti_can_access_local_variables = false;
291 _jvmti_can_post_on_exceptions = false;
292 _jvmti_can_pop_frame = false;
293
294 _dyno_klasses = nullptr;
295 _dyno_locs = nullptr;
296 }
297
298 ciEnv::~ciEnv() {
299 GUARDED_VM_ENTRY(
300 CompilerThread* current_thread = CompilerThread::current();
301 _factory->remove_symbols();
302 // Need safepoint to clear the env on the thread. RedefineClasses might
303 // be reading it.
304 current_thread->set_env(nullptr);
305 )
306 }
307
308 // ------------------------------------------------------------------
309 // Cache Jvmti state
310 bool ciEnv::cache_jvmti_state() {
311 VM_ENTRY_MARK;
312 // Get Jvmti capabilities under lock to get consistent values.
313 MutexLocker mu(JvmtiThreadState_lock);
346 if (!_jvmti_can_get_owned_monitor_info &&
347 JvmtiExport::can_get_owned_monitor_info()) {
348 return true;
349 }
350 if (!_jvmti_can_walk_any_space &&
351 JvmtiExport::can_walk_any_space()) {
352 return true;
353 }
354
355 return false;
356 }
357
358 // ------------------------------------------------------------------
359 // Cache DTrace flags
360 void ciEnv::cache_dtrace_flags() {
361 // Need lock?
362 _dtrace_method_probes = DTraceMethodProbes;
363 _dtrace_alloc_probes = DTraceAllocProbes;
364 }
365
366 // ------------------------------------------------------------------
367 // helper for lazy exception creation
368 ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) {
369 VM_ENTRY_MARK;
370 if (handle == nullptr) {
371 // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance.
372 InstanceKlass* ik = SystemDictionary::find_instance_klass(THREAD, name, Handle(), Handle());
373 jobject objh = nullptr;
374 if (ik != nullptr) {
375 oop obj = ik->allocate_instance(THREAD);
376 if (!HAS_PENDING_EXCEPTION)
377 objh = JNIHandles::make_global(Handle(THREAD, obj));
378 }
379 if (HAS_PENDING_EXCEPTION) {
380 CLEAR_PENDING_EXCEPTION;
381 } else {
382 handle = objh;
383 }
384 }
385 oop obj = JNIHandles::resolve(handle);
386 return obj == nullptr? nullptr: get_object(obj)->as_instance();
387 }
388
389 ciInstanceKlass* ciEnv::get_box_klass_for_primitive_type(BasicType type) {
390 switch (type) {
391 case T_BOOLEAN: return Boolean_klass();
392 case T_BYTE : return Byte_klass();
393 case T_CHAR : return Character_klass();
394 case T_SHORT : return Short_klass();
395 case T_INT : return Integer_klass();
396 case T_LONG : return Long_klass();
397 case T_FLOAT : return Float_klass();
398 case T_DOUBLE : return Double_klass();
399
400 default:
401 assert(false, "not a primitive: %s", type2name(type));
402 return nullptr;
403 }
404 }
405
406 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() {
407 if (_ArrayIndexOutOfBoundsException_instance == nullptr) {
408 _ArrayIndexOutOfBoundsException_instance
409 = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle,
410 vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
411 }
412 return _ArrayIndexOutOfBoundsException_instance;
413 }
414 ciInstance* ciEnv::ArrayStoreException_instance() {
415 if (_ArrayStoreException_instance == nullptr) {
416 _ArrayStoreException_instance
417 = get_or_create_exception(_ArrayStoreException_handle,
418 vmSymbols::java_lang_ArrayStoreException());
419 }
420 return _ArrayStoreException_instance;
421 }
422 ciInstance* ciEnv::ClassCastException_instance() {
423 if (_ClassCastException_instance == nullptr) {
424 _ClassCastException_instance
425 = get_or_create_exception(_ClassCastException_handle,
426 vmSymbols::java_lang_ClassCastException());
427 }
428 return _ClassCastException_instance;
429 }
430
431 ciInstance* ciEnv::the_null_string() {
432 if (_the_null_string == nullptr) {
433 VM_ENTRY_MARK;
434 _the_null_string = get_object(Universe::the_null_string())->as_instance();
435 }
436 return _the_null_string;
437 }
438
439 ciInstance* ciEnv::the_min_jint_string() {
440 if (_the_min_jint_string == nullptr) {
441 VM_ENTRY_MARK;
442 _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance();
443 }
444 return _the_min_jint_string;
445 }
446
900 case Bytecodes::_invokevirtual:
901 case Bytecodes::_invokeinterface:
902 case Bytecodes::_invokespecial:
903 case Bytecodes::_invokestatic:
904 {
905 Method* m = ConstantPool::method_at_if_loaded(cpool, index);
906 if (m != nullptr) {
907 return get_method(m);
908 }
909 }
910 break;
911 default:
912 break;
913 }
914 }
915
916 if (holder_is_accessible) { // Our declared holder is loaded.
917 constantTag tag = cpool->tag_ref_at(index, bc);
918 assert(accessor->get_instanceKlass() == cpool->pool_holder(), "not the pool holder?");
919 Method* m = lookup_method(accessor, holder, name_sym, sig_sym, bc, tag);
920 if (m != nullptr &&
921 (bc == Bytecodes::_invokestatic
922 ? m->method_holder()->is_not_initialized()
923 : !m->method_holder()->is_loaded())) {
924 m = nullptr;
925 }
926 if (m != nullptr && ReplayCompiles && !ciReplay::is_loaded(m)) {
927 m = nullptr;
928 }
929 if (m != nullptr) {
930 // We found the method.
931 return get_method(m);
932 }
933 }
934
935 // Either the declared holder was not loaded, or the method could
936 // not be found. Create a dummy ciMethod to represent the failed
937 // lookup.
938 ciSymbol* name = get_symbol(name_sym);
939 ciSymbol* signature = get_symbol(sig_sym);
940 return get_unloaded_method(holder, name, signature, accessor);
941 }
942 }
943
944
985 _name_buffer =
986 (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len);
987 _name_buffer_len = req_len;
988 }
989 }
990 return _name_buffer;
991 }
992
993 // ------------------------------------------------------------------
994 // ciEnv::is_in_vm
995 bool ciEnv::is_in_vm() {
996 return JavaThread::current()->thread_state() == _thread_in_vm;
997 }
998
999 // ------------------------------------------------------------------
1000 // ciEnv::validate_compile_task_dependencies
1001 //
1002 // Check for changes during compilation (e.g. class loads, evolution,
1003 // breakpoints, call site invalidation).
1004 void ciEnv::validate_compile_task_dependencies(ciMethod* target) {
1005 if (failing()) return; // no need for further checks
1006
1007 Dependencies::DepType result = dependencies()->validate_dependencies(_task);
1008 if (result != Dependencies::end_marker) {
1009 if (result == Dependencies::call_site_target_value) {
1010 _inc_decompile_count_on_failure = false;
1011 record_failure("call site target change");
1012 } else if (Dependencies::is_klass_type(result)) {
1013 record_failure("concurrent class loading");
1014 } else {
1015 record_failure("invalid non-klass dependency");
1016 }
1017 }
1018 }
1019
1020 // ------------------------------------------------------------------
1021 // ciEnv::register_method
1022 void ciEnv::register_method(ciMethod* target,
1023 int entry_bci,
1024 CodeOffsets* offsets,
1025 int orig_pc_offset,
1026 CodeBuffer* code_buffer,
1027 int frame_words,
1028 OopMapSet* oop_map_set,
1029 ExceptionHandlerTable* handler_table,
1030 ImplicitExceptionTable* inc_table,
1031 AbstractCompiler* compiler,
1032 bool has_unsafe_access,
1033 bool has_wide_vectors,
1034 bool has_monitors,
1035 int immediate_oops_patched,
1036 RTMState rtm_state) {
1037 VM_ENTRY_MARK;
1038 nmethod* nm = nullptr;
1039 {
1040 methodHandle method(THREAD, target->get_Method());
1041
1042 // We require method counters to store some method state (max compilation levels) required by the compilation policy.
1043 if (method->get_method_counters(THREAD) == nullptr) {
1044 record_failure("can't create method counters");
1045 // All buffers in the CodeBuffer are allocated in the CodeCache.
1046 // If the code buffer is created on each compile attempt
1047 // as in C2, then it must be freed.
1048 code_buffer->free_blob();
1049 return;
1050 }
1051
1052 // Check if memory should be freed before allocation
1053 CodeCache::gc_on_allocation();
1054
1055 // To prevent compile queue updates.
1056 MutexLocker locker(THREAD, MethodCompileQueue_lock);
1057
1058 // Prevent InstanceKlass::add_to_hierarchy from running
1059 // and invalidating our dependencies until we install this method.
1060 // No safepoints are allowed. Otherwise, class redefinition can occur in between.
1061 MutexLocker ml(Compile_lock);
1062 NoSafepointVerifier nsv;
1063
1064 // Change in Jvmti state may invalidate compilation.
1065 if (!failing() && jvmti_state_changed()) {
1066 record_failure("Jvmti state change invalidated dependencies");
1067 }
1068
1069 // Change in DTrace flags may invalidate compilation.
1070 if (!failing() &&
1071 ( (!dtrace_method_probes() && DTraceMethodProbes) ||
1072 (!dtrace_alloc_probes() && DTraceAllocProbes) )) {
1073 record_failure("DTrace flags change invalidated dependencies");
1074 }
1075
1076 if (!failing() && target->needs_clinit_barrier() &&
1077 target->holder()->is_in_error_state()) {
1078 record_failure("method holder is in error state");
1079 }
1080
1081 if (!failing()) {
1082 if (log() != nullptr) {
1083 // Log the dependencies which this compilation declares.
1084 dependencies()->log_all_dependencies();
1085 }
1086
1087 // Encode the dependencies now, so we can check them right away.
1088 dependencies()->encode_content_bytes();
1089
1090 // Check for {class loads, evolution, breakpoints, ...} during compilation
1091 validate_compile_task_dependencies(target);
1092 }
1093 #if INCLUDE_RTM_OPT
1094 if (!failing() && (rtm_state != NoRTM) &&
1095 (method()->method_data() != nullptr) &&
1096 (method()->method_data()->rtm_state() != rtm_state)) {
1097 // Preemptive decompile if rtm state was changed.
1098 record_failure("RTM state change invalidated rtm code");
1099 }
1100 #endif
1101
1102 if (failing()) {
1103 // While not a true deoptimization, it is a preemptive decompile.
1104 MethodData* mdo = method()->method_data();
1105 if (mdo != nullptr && _inc_decompile_count_on_failure) {
1106 mdo->inc_decompile_count();
1107 }
1108
1109 // All buffers in the CodeBuffer are allocated in the CodeCache.
1110 // If the code buffer is created on each compile attempt
1111 // as in C2, then it must be freed.
1112 code_buffer->free_blob();
1113 return;
1114 }
1115
1116 assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry");
1117 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry");
1118
1119 nm = nmethod::new_nmethod(method,
1120 compile_id(),
1121 entry_bci,
1122 offsets,
1123 orig_pc_offset,
1124 debug_info(), dependencies(), code_buffer,
1125 frame_words, oop_map_set,
1126 handler_table, inc_table,
1127 compiler, CompLevel(task()->comp_level()));
1128
1129 // Free codeBlobs
1130 code_buffer->free_blob();
1131
1132 if (nm != nullptr) {
1133 nm->set_has_unsafe_access(has_unsafe_access);
1134 nm->set_has_wide_vectors(has_wide_vectors);
1135 nm->set_has_monitors(has_monitors);
1136 assert(!method->is_synchronized() || nm->has_monitors(), "");
1137 #if INCLUDE_RTM_OPT
1138 nm->set_rtm_state(rtm_state);
1139 #endif
1140
1141 if (entry_bci == InvocationEntryBci) {
1142 if (TieredCompilation) {
1143 // If there is an old version we're done with it
1144 nmethod* old = method->code();
1145 if (TraceMethodReplacement && old != nullptr) {
1146 ResourceMark rm;
1147 char *method_name = method->name_and_sig_as_C_string();
1148 tty->print_cr("Replacing method %s", method_name);
1149 }
1150 if (old != nullptr) {
1151 old->make_not_used();
1152 }
1153 }
1154
1155 LogTarget(Info, nmethod, install) lt;
1156 if (lt.is_enabled()) {
1157 ResourceMark rm;
1158 char *method_name = method->name_and_sig_as_C_string();
1159 lt.print("Installing method (%d) %s ",
1160 task()->comp_level(), method_name);
1161 }
1162 // Allow the code to be executed
1163 MutexLocker ml(NMethodState_lock, Mutex::_no_safepoint_check_flag);
1164 if (nm->make_in_use()) {
1165 method->set_code(method, nm);
1166 }
1167 } else {
1168 LogTarget(Info, nmethod, install) lt;
1169 if (lt.is_enabled()) {
1170 ResourceMark rm;
1171 char *method_name = method->name_and_sig_as_C_string();
1172 lt.print("Installing osr method (%d) %s @ %d",
1173 task()->comp_level(), method_name, entry_bci);
1174 }
1175 MutexLocker ml(NMethodState_lock, Mutex::_no_safepoint_check_flag);
1176 if (nm->make_in_use()) {
1177 method->method_holder()->add_osr_nmethod(nm);
1178 }
1179 }
1180 }
1181 }
1182
1183 NoSafepointVerifier nsv;
1184 if (nm != nullptr) {
1185 // Compilation succeeded, post what we know about it
1186 nm->post_compiled_method(task());
1187 task()->set_num_inlined_bytecodes(num_inlined_bytecodes());
1188 } else {
1189 // The CodeCache is full.
1190 record_failure("code cache is full");
1191 }
1192
1193 // safepoints are allowed again
1194 }
1195
1196 // ------------------------------------------------------------------
1197 // ciEnv::find_system_klass
1198 ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) {
1199 VM_ENTRY_MARK;
1200 return get_klass_by_name_impl(nullptr, constantPoolHandle(), klass_name, false);
1201 }
1202
1203 // ------------------------------------------------------------------
1204 // ciEnv::comp_level
1205 int ciEnv::comp_level() {
1206 if (task() == nullptr) return CompilationPolicy::highest_compile_level();
1207 return task()->comp_level();
1208 }
1209
1210 // ------------------------------------------------------------------
1211 // ciEnv::compile_id
1212 int ciEnv::compile_id() {
1213 if (task() == nullptr) return 0;
1214 return task()->compile_id();
1215 }
1216
1217 // ------------------------------------------------------------------
1218 // ciEnv::notice_inlined_method()
1219 void ciEnv::notice_inlined_method(ciMethod* method) {
1220 _num_inlined_bytecodes += method->code_size_for_inlining();
1221 }
1222
1223 // ------------------------------------------------------------------
1224 // ciEnv::num_inlined_bytecodes()
1225 int ciEnv::num_inlined_bytecodes() const {
1226 return _num_inlined_bytecodes;
1227 }
1228
1229 // ------------------------------------------------------------------
1230 // ciEnv::record_failure()
1231 void ciEnv::record_failure(const char* reason) {
1232 if (_failure_reason.get() == nullptr) {
1233 // Record the first failure reason.
1234 _failure_reason.set(reason);
1235 }
1236 }
1237
1238 void ciEnv::report_failure(const char* reason) {
1239 EventCompilationFailure event;
1240 if (event.should_commit()) {
1722 fileStream replay_data_stream(inline_data_file, /*need_close=*/true);
1723 GUARDED_VM_ENTRY(
1724 MutexLocker ml(Compile_lock);
1725 dump_replay_data_version(&replay_data_stream);
1726 dump_compile_data(&replay_data_stream);
1727 )
1728 replay_data_stream.flush();
1729 tty->print("# Compiler inline data is saved as: ");
1730 tty->print_cr("%s", buffer);
1731 } else {
1732 tty->print_cr("# Can't open file to dump inline data.");
1733 close(fd);
1734 }
1735 }
1736 }
1737 }
1738
1739 void ciEnv::dump_replay_data_version(outputStream* out) {
1740 out->print_cr("version %d", REPLAY_VERSION);
1741 }
|
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/archiveBuilder.hpp"
27 #include "cds/cdsConfig.hpp"
28 #include "ci/ciConstant.hpp"
29 #include "ci/ciEnv.hpp"
30 #include "ci/ciField.hpp"
31 #include "ci/ciInstance.hpp"
32 #include "ci/ciInstanceKlass.hpp"
33 #include "ci/ciMethod.hpp"
34 #include "ci/ciNullObject.hpp"
35 #include "ci/ciReplay.hpp"
36 #include "ci/ciSymbols.hpp"
37 #include "ci/ciUtilities.inline.hpp"
38 #include "classfile/javaClasses.hpp"
39 #include "classfile/javaClasses.inline.hpp"
40 #include "classfile/systemDictionary.hpp"
41 #include "classfile/vmClasses.hpp"
42 #include "classfile/vmSymbols.hpp"
43 #include "code/codeCache.hpp"
44 #include "code/scopeDesc.hpp"
45 #include "code/SCCache.hpp"
46 #include "compiler/compilationLog.hpp"
47 #include "compiler/compilationPolicy.hpp"
48 #include "compiler/compileBroker.hpp"
49 #include "compiler/compilerEvent.hpp"
50 #include "compiler/compileLog.hpp"
51 #include "compiler/compileTask.hpp"
52 #include "compiler/disassembler.hpp"
53 #include "gc/shared/collectedHeap.inline.hpp"
54 #include "gc/shared/barrierSetNMethod.hpp"
55 #include "interpreter/bytecodeStream.hpp"
56 #include "interpreter/linkResolver.hpp"
57 #include "jfr/jfrEvents.hpp"
58 #include "jvm.h"
59 #include "logging/log.hpp"
60 #include "memory/allocation.inline.hpp"
61 #include "memory/oopFactory.hpp"
62 #include "memory/resourceArea.hpp"
63 #include "memory/universe.hpp"
64 #include "oops/constantPool.inline.hpp"
65 #include "oops/cpCache.inline.hpp"
66 #include "oops/method.inline.hpp"
67 #include "oops/methodData.hpp"
68 #include "oops/objArrayKlass.hpp"
69 #include "oops/objArrayOop.inline.hpp"
70 #include "oops/oop.inline.hpp"
71 #include "oops/resolvedIndyEntry.hpp"
72 #include "oops/symbolHandle.hpp"
73 #include "oops/trainingData.hpp"
74 #include "prims/jvmtiExport.hpp"
75 #include "prims/methodHandles.hpp"
76 #include "runtime/fieldDescriptor.inline.hpp"
77 #include "runtime/flags/flagSetting.hpp"
78 #include "runtime/handles.inline.hpp"
79 #include "runtime/init.hpp"
80 #include "runtime/javaThread.hpp"
81 #include "runtime/jniHandles.inline.hpp"
82 #include "runtime/reflection.hpp"
83 #include "runtime/safepointVerifiers.hpp"
84 #include "runtime/sharedRuntime.hpp"
85 #include "utilities/dtrace.hpp"
86 #include "utilities/macros.hpp"
87 #ifdef COMPILER1
88 #include "c1/c1_Runtime1.hpp"
89 #endif
90 #ifdef COMPILER2
91 #include "opto/runtime.hpp"
92 #endif
93
94 // ciEnv
95 //
96 // This class is the top level broker for requests from the compiler
97 // to the VM.
160
161 oop o = Universe::null_ptr_exception_instance();
162 assert(o != nullptr, "should have been initialized");
163 _NullPointerException_instance = get_object(o)->as_instance();
164 o = Universe::arithmetic_exception_instance();
165 assert(o != nullptr, "should have been initialized");
166 _ArithmeticException_instance = get_object(o)->as_instance();
167
168 _ArrayIndexOutOfBoundsException_instance = nullptr;
169 _ArrayStoreException_instance = nullptr;
170 _ClassCastException_instance = nullptr;
171 _the_null_string = nullptr;
172 _the_min_jint_string = nullptr;
173
174 _jvmti_redefinition_count = 0;
175 _jvmti_can_hotswap_or_post_breakpoint = false;
176 _jvmti_can_access_local_variables = false;
177 _jvmti_can_post_on_exceptions = false;
178 _jvmti_can_pop_frame = false;
179
180 _scc_clinit_barriers_entry = nullptr;
181
182 _dyno_klasses = nullptr;
183 _dyno_locs = nullptr;
184 _dyno_name[0] = '\0';
185 }
186
187 // Record components of a location descriptor string. Components are appended by the constructor and
188 // removed by the destructor, like a stack, so scope matters. These location descriptors are used to
189 // locate dynamic classes, and terminate at a Method* or oop field associated with dynamic/hidden class.
190 //
191 // Example use:
192 //
193 // {
194 // RecordLocation fp(this, "field1");
195 // // location: "field1"
196 // { RecordLocation fp(this, " field2"); // location: "field1 field2" }
197 // // location: "field1"
198 // { RecordLocation fp(this, " field3"); // location: "field1 field3" }
199 // // location: "field1"
200 // }
201 // // location: ""
282 // During VM initialization, these instances have not yet been created.
283 // Assertions ensure that these instances are not accessed before
284 // their initialization.
285
286 assert(Universe::is_fully_initialized(), "must be");
287
288 _NullPointerException_instance = nullptr;
289 _ArithmeticException_instance = nullptr;
290 _ArrayIndexOutOfBoundsException_instance = nullptr;
291 _ArrayStoreException_instance = nullptr;
292 _ClassCastException_instance = nullptr;
293 _the_null_string = nullptr;
294 _the_min_jint_string = nullptr;
295
296 _jvmti_redefinition_count = 0;
297 _jvmti_can_hotswap_or_post_breakpoint = false;
298 _jvmti_can_access_local_variables = false;
299 _jvmti_can_post_on_exceptions = false;
300 _jvmti_can_pop_frame = false;
301
302 _scc_clinit_barriers_entry = nullptr;
303
304 _dyno_klasses = nullptr;
305 _dyno_locs = nullptr;
306 }
307
308 ciEnv::~ciEnv() {
309 GUARDED_VM_ENTRY(
310 CompilerThread* current_thread = CompilerThread::current();
311 _factory->remove_symbols();
312 // Need safepoint to clear the env on the thread. RedefineClasses might
313 // be reading it.
314 current_thread->set_env(nullptr);
315 )
316 }
317
318 // ------------------------------------------------------------------
319 // Cache Jvmti state
320 bool ciEnv::cache_jvmti_state() {
321 VM_ENTRY_MARK;
322 // Get Jvmti capabilities under lock to get consistent values.
323 MutexLocker mu(JvmtiThreadState_lock);
356 if (!_jvmti_can_get_owned_monitor_info &&
357 JvmtiExport::can_get_owned_monitor_info()) {
358 return true;
359 }
360 if (!_jvmti_can_walk_any_space &&
361 JvmtiExport::can_walk_any_space()) {
362 return true;
363 }
364
365 return false;
366 }
367
368 // ------------------------------------------------------------------
369 // Cache DTrace flags
370 void ciEnv::cache_dtrace_flags() {
371 // Need lock?
372 _dtrace_method_probes = DTraceMethodProbes;
373 _dtrace_alloc_probes = DTraceAllocProbes;
374 }
375
376 ciInstanceKlass* ciEnv::get_box_klass_for_primitive_type(BasicType type) {
377 switch (type) {
378 case T_BOOLEAN: return Boolean_klass();
379 case T_BYTE : return Byte_klass();
380 case T_CHAR : return Character_klass();
381 case T_SHORT : return Short_klass();
382 case T_INT : return Integer_klass();
383 case T_LONG : return Long_klass();
384 case T_FLOAT : return Float_klass();
385 case T_DOUBLE : return Double_klass();
386
387 default:
388 assert(false, "not a primitive: %s", type2name(type));
389 return nullptr;
390 }
391 }
392
393 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() {
394 if (_ArrayIndexOutOfBoundsException_instance == nullptr) {
395 VM_ENTRY_MARK;
396 _ArrayIndexOutOfBoundsException_instance = get_object(Universe::array_index_oob_exception_instance())->as_instance();
397 }
398 return _ArrayIndexOutOfBoundsException_instance;
399 }
400 ciInstance* ciEnv::ArrayStoreException_instance() {
401 if (_ArrayStoreException_instance == nullptr) {
402 VM_ENTRY_MARK;
403 _ArrayStoreException_instance = get_object(Universe::array_store_exception_instance())->as_instance();
404 }
405 return _ArrayStoreException_instance;
406 }
407 ciInstance* ciEnv::ClassCastException_instance() {
408 if (_ClassCastException_instance == nullptr) {
409 VM_ENTRY_MARK;
410 _ClassCastException_instance = get_object(Universe::class_cast_exception_instance())->as_instance();
411 }
412 return _ClassCastException_instance;
413 }
414
415 ciInstance* ciEnv::the_null_string() {
416 if (_the_null_string == nullptr) {
417 VM_ENTRY_MARK;
418 _the_null_string = get_object(Universe::the_null_string())->as_instance();
419 }
420 return _the_null_string;
421 }
422
423 ciInstance* ciEnv::the_min_jint_string() {
424 if (_the_min_jint_string == nullptr) {
425 VM_ENTRY_MARK;
426 _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance();
427 }
428 return _the_min_jint_string;
429 }
430
884 case Bytecodes::_invokevirtual:
885 case Bytecodes::_invokeinterface:
886 case Bytecodes::_invokespecial:
887 case Bytecodes::_invokestatic:
888 {
889 Method* m = ConstantPool::method_at_if_loaded(cpool, index);
890 if (m != nullptr) {
891 return get_method(m);
892 }
893 }
894 break;
895 default:
896 break;
897 }
898 }
899
900 if (holder_is_accessible) { // Our declared holder is loaded.
901 constantTag tag = cpool->tag_ref_at(index, bc);
902 assert(accessor->get_instanceKlass() == cpool->pool_holder(), "not the pool holder?");
903 Method* m = lookup_method(accessor, holder, name_sym, sig_sym, bc, tag);
904 if (m != nullptr) {
905 ciInstanceKlass* cik = get_instance_klass(m->method_holder());
906 if ((bc == Bytecodes::_invokestatic && cik->is_not_initialized()) || !cik->is_loaded()) {
907 m = nullptr;
908 }
909 }
910 if (m != nullptr && ReplayCompiles && !ciReplay::is_loaded(m)) {
911 m = nullptr;
912 }
913 if (m != nullptr) {
914 // We found the method.
915 return get_method(m);
916 }
917 }
918
919 // Either the declared holder was not loaded, or the method could
920 // not be found. Create a dummy ciMethod to represent the failed
921 // lookup.
922 ciSymbol* name = get_symbol(name_sym);
923 ciSymbol* signature = get_symbol(sig_sym);
924 return get_unloaded_method(holder, name, signature, accessor);
925 }
926 }
927
928
969 _name_buffer =
970 (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len);
971 _name_buffer_len = req_len;
972 }
973 }
974 return _name_buffer;
975 }
976
977 // ------------------------------------------------------------------
978 // ciEnv::is_in_vm
979 bool ciEnv::is_in_vm() {
980 return JavaThread::current()->thread_state() == _thread_in_vm;
981 }
982
983 // ------------------------------------------------------------------
984 // ciEnv::validate_compile_task_dependencies
985 //
986 // Check for changes during compilation (e.g. class loads, evolution,
987 // breakpoints, call site invalidation).
988 void ciEnv::validate_compile_task_dependencies(ciMethod* target) {
989 assert(!failing(), "should not call this when failing");
990
991 Dependencies::DepType result = dependencies()->validate_dependencies(_task);
992 if (result != Dependencies::end_marker) {
993 if (result == Dependencies::call_site_target_value) {
994 _inc_decompile_count_on_failure = false;
995 record_failure("call site target change");
996 } else if (Dependencies::is_klass_type(result)) {
997 record_failure("concurrent class loading");
998 } else {
999 record_failure("invalid non-klass dependency");
1000 }
1001 }
1002 }
1003
1004 // ------------------------------------------------------------------
1005 // ciEnv::register_method
1006 void ciEnv::register_method(ciMethod* target,
1007 int entry_bci,
1008 CodeOffsets* offsets,
1009 int orig_pc_offset,
1010 CodeBuffer* code_buffer,
1011 int frame_words,
1012 OopMapSet* oop_map_set,
1013 ExceptionHandlerTable* handler_table,
1014 ImplicitExceptionTable* inc_table,
1015 AbstractCompiler* compiler,
1016 bool has_clinit_barriers,
1017 bool for_preload,
1018 bool has_unsafe_access,
1019 bool has_wide_vectors,
1020 bool has_monitors,
1021 int immediate_oops_patched,
1022 bool install_code,
1023 RTMState rtm_state,
1024 SCCEntry* scc_entry) {
1025 VM_ENTRY_MARK;
1026 nmethod* nm = nullptr;
1027 {
1028 methodHandle method(THREAD, target->get_Method());
1029 bool preload = task()->preload(); // Code is preloaded before Java method execution
1030
1031 // We require method counters to store some method state (max compilation levels) required by the compilation policy.
1032 if (!preload && method->get_method_counters(THREAD) == nullptr) {
1033 record_failure("can't create method counters");
1034 // All buffers in the CodeBuffer are allocated in the CodeCache.
1035 // If the code buffer is created on each compile attempt
1036 // as in C2, then it must be freed.
1037 // But keep shared code.
1038 code_buffer->free_blob();
1039 return;
1040 }
1041
1042 // Check if memory should be freed before allocation
1043 CodeCache::gc_on_allocation();
1044
1045 // To prevent compile queue updates.
1046 MutexLocker locker(THREAD, MethodCompileQueue_lock);
1047
1048 // Prevent InstanceKlass::add_to_hierarchy from running
1049 // and invalidating our dependencies until we install this method.
1050 // No safepoints are allowed. Otherwise, class redefinition can occur in between.
1051 MutexLocker ml(Compile_lock);
1052 NoSafepointVerifier nsv;
1053
1054 if (scc_entry != nullptr && scc_entry->not_entrant()) {
1055 // This shared code was marked invalid while it was loaded
1056 code_buffer->free_blob();
1057 return;
1058 }
1059
1060 // Change in Jvmti state may invalidate compilation.
1061 if (!failing() && jvmti_state_changed()) {
1062 record_failure("Jvmti state change invalidated dependencies");
1063 }
1064
1065 // Change in DTrace flags may invalidate compilation.
1066 if (!failing() &&
1067 ( (!dtrace_method_probes() && DTraceMethodProbes) ||
1068 (!dtrace_alloc_probes() && DTraceAllocProbes) )) {
1069 record_failure("DTrace flags change invalidated dependencies");
1070 }
1071
1072 if (!preload && !failing() && target->needs_clinit_barrier() &&
1073 target->holder()->is_in_error_state()) {
1074 record_failure("method holder is in error state");
1075 }
1076
1077 if (!failing() && (scc_entry == nullptr)) {
1078 if (log() != nullptr) {
1079 // Log the dependencies which this compilation declares.
1080 dependencies()->log_all_dependencies();
1081 }
1082
1083 // Encode the dependencies now, so we can check them right away.
1084 dependencies()->encode_content_bytes();
1085 }
1086 // Check for {class loads, evolution, breakpoints, ...} during compilation
1087 if (!failing() && install_code) {
1088 // Check for {class loads, evolution, breakpoints, ...} during compilation
1089 validate_compile_task_dependencies(target);
1090 if (failing() && preload) {
1091 ResourceMark rm;
1092 char *method_name = method->name_and_sig_as_C_string();
1093 log_warning(scc)("preload code for '%s' failed dependency check", method_name);
1094 }
1095 }
1096 #if INCLUDE_RTM_OPT
1097 if (!failing() && (rtm_state != NoRTM) &&
1098 (method()->method_data() != nullptr) &&
1099 (method()->method_data()->rtm_state() != rtm_state)) {
1100 // Preemptive decompile if rtm state was changed.
1101 record_failure("RTM state change invalidated rtm code");
1102 }
1103 #endif
1104
1105 if (failing()) {
1106 // While not a true deoptimization, it is a preemptive decompile.
1107 MethodData* mdo = method()->method_data();
1108 if (mdo != nullptr && _inc_decompile_count_on_failure) {
1109 mdo->inc_decompile_count();
1110 }
1111
1112 // All buffers in the CodeBuffer are allocated in the CodeCache.
1113 // If the code buffer is created on each compile attempt
1114 // as in C2, then it must be freed.
1115 code_buffer->free_blob();
1116 return;
1117 }
1118
1119 assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry");
1120 assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry");
1121
1122 if (rtm_state == NoRTM && scc_entry == nullptr) {
1123 scc_entry = SCCache::store_nmethod(method,
1124 compile_id(),
1125 entry_bci,
1126 offsets,
1127 orig_pc_offset,
1128 debug_info(), dependencies(), code_buffer,
1129 frame_words, oop_map_set,
1130 handler_table, inc_table,
1131 compiler,
1132 CompLevel(task()->comp_level()),
1133 has_clinit_barriers,
1134 for_preload,
1135 has_unsafe_access,
1136 has_wide_vectors,
1137 has_monitors);
1138 if (scc_entry != nullptr) {
1139 scc_entry->set_inlined_bytecodes(num_inlined_bytecodes());
1140 if (has_clinit_barriers) {
1141 set_scc_clinit_barriers_entry(scc_entry); // Record it
1142 // Build second version of code without class initialization barriers
1143 code_buffer->free_blob();
1144 return;
1145 } else if (!for_preload) {
1146 SCCEntry* previous_entry = scc_clinit_barriers_entry();
1147 scc_entry->set_next(previous_entry); // Link it for case of deoptimization
1148 }
1149 }
1150 }
1151 if (install_code) {
1152 nm = nmethod::new_nmethod(method,
1153 compile_id(),
1154 entry_bci,
1155 offsets,
1156 orig_pc_offset,
1157 debug_info(), dependencies(), code_buffer,
1158 frame_words, oop_map_set,
1159 handler_table, inc_table,
1160 compiler, CompLevel(task()->comp_level()),
1161 scc_entry);
1162 }
1163 // Free codeBlobs
1164 code_buffer->free_blob();
1165
1166 if (nm != nullptr) {
1167 nm->set_has_unsafe_access(has_unsafe_access);
1168 nm->set_has_wide_vectors(has_wide_vectors);
1169 nm->set_has_monitors(has_monitors);
1170 nm->set_preloaded(preload);
1171 nm->set_has_clinit_barriers(has_clinit_barriers);
1172 assert(!method->is_synchronized() || nm->has_monitors(), "");
1173 #if INCLUDE_RTM_OPT
1174 nm->set_rtm_state(rtm_state);
1175 #endif
1176
1177 if (entry_bci == InvocationEntryBci) {
1178 if (TieredCompilation) {
1179 // If there is an old version we're done with it
1180 nmethod* old = method->code();
1181 if (TraceMethodReplacement && old != nullptr) {
1182 ResourceMark rm;
1183 char *method_name = method->name_and_sig_as_C_string();
1184 tty->print_cr("Replacing method %s", method_name);
1185 }
1186 if (old != nullptr) {
1187 old->make_not_used();
1188 }
1189 }
1190
1191 LogTarget(Info, nmethod, install) lt;
1192 if (lt.is_enabled()) {
1193 ResourceMark rm;
1194 char *method_name = method->name_and_sig_as_C_string();
1195 lt.print("Installing method (L%d) %s id=%d scc=%s%s%u",
1196 task()->comp_level(), method_name, compile_id(),
1197 task()->is_scc() ? "A" : "", preload ? "P" : "",
1198 (scc_entry != nullptr ? scc_entry->offset() : 0));
1199 }
1200 // Allow the code to be executed
1201 MutexLocker ml(NMethodState_lock, Mutex::_no_safepoint_check_flag);
1202 if (nm->make_in_use()) {
1203 #ifdef ASSERT
1204 BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1205 if (bs_nm != nullptr && bs_nm->supports_entry_barrier(nm)) {
1206 if (!bs_nm->is_armed(nm)) {
1207 log_info(init)("nmethod %d %d not armed", nm->compile_id(), nm->comp_level());
1208 }
1209 }
1210 #endif // ASSERT
1211 if (preload) {
1212 method->set_preload_code(nm);
1213 }
1214 if (!preload || target->holder()->is_linked()) {
1215 method->set_code(method, nm);
1216 }
1217 }
1218 } else {
1219 LogTarget(Info, nmethod, install) lt;
1220 if (lt.is_enabled()) {
1221 ResourceMark rm;
1222 char *method_name = method->name_and_sig_as_C_string();
1223 lt.print("Installing osr method (L%d) %s @ %d id=%u scc=%s%u",
1224 task()->comp_level(), method_name, entry_bci, compile_id(),
1225 task()->is_scc() ? "A" : "",
1226 (scc_entry != nullptr ? scc_entry->offset() : 0));
1227 }
1228 MutexLocker ml(NMethodState_lock, Mutex::_no_safepoint_check_flag);
1229 if (nm->make_in_use()) {
1230 method->method_holder()->add_osr_nmethod(nm);
1231 }
1232 }
1233 }
1234 }
1235
1236 NoSafepointVerifier nsv;
1237 if (nm != nullptr) {
1238 // Compilation succeeded, post what we know about it
1239 nm->post_compiled_method(task());
1240 task()->set_num_inlined_bytecodes(num_inlined_bytecodes());
1241 } else if (install_code) {
1242 // The CodeCache is full.
1243 record_failure("code cache is full");
1244 } else {
1245 task()->set_num_inlined_bytecodes(num_inlined_bytecodes());
1246 }
1247
1248 // safepoints are allowed again
1249 }
1250
1251 // ------------------------------------------------------------------
1252 // ciEnv::find_system_klass
1253 ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) {
1254 VM_ENTRY_MARK;
1255 return get_klass_by_name_impl(nullptr, constantPoolHandle(), klass_name, false);
1256 }
1257
1258 // ------------------------------------------------------------------
1259 // ciEnv::comp_level
1260 int ciEnv::comp_level() {
1261 if (task() == nullptr) return CompilationPolicy::highest_compile_level();
1262 return task()->comp_level();
1263 }
1264
1265 // ------------------------------------------------------------------
1266 // ciEnv::compile_id
1267 int ciEnv::compile_id() {
1268 if (task() == nullptr) return 0;
1269 return task()->compile_id();
1270 }
1271
1272 // ------------------------------------------------------------------
1273 // ciEnv::notice_inlined_method()
1274 void ciEnv::notice_inlined_method(ciMethod* method) {
1275 _num_inlined_bytecodes += method->code_size_for_inlining();
1276 CompileTrainingData* tdata = task()->training_data();
1277 if (tdata != nullptr) {
1278 GUARDED_VM_ENTRY({
1279 methodHandle mh(Thread::current(), method->get_Method());
1280 tdata->notice_inlined_method(task(), mh);
1281 });
1282 }
1283 }
1284
1285 // ------------------------------------------------------------------
1286 // ciEnv::num_inlined_bytecodes()
1287 int ciEnv::num_inlined_bytecodes() const {
1288 return _num_inlined_bytecodes;
1289 }
1290
1291 // ------------------------------------------------------------------
1292 // ciEnv::record_failure()
1293 void ciEnv::record_failure(const char* reason) {
1294 if (_failure_reason.get() == nullptr) {
1295 // Record the first failure reason.
1296 _failure_reason.set(reason);
1297 }
1298 }
1299
1300 void ciEnv::report_failure(const char* reason) {
1301 EventCompilationFailure event;
1302 if (event.should_commit()) {
1784 fileStream replay_data_stream(inline_data_file, /*need_close=*/true);
1785 GUARDED_VM_ENTRY(
1786 MutexLocker ml(Compile_lock);
1787 dump_replay_data_version(&replay_data_stream);
1788 dump_compile_data(&replay_data_stream);
1789 )
1790 replay_data_stream.flush();
1791 tty->print("# Compiler inline data is saved as: ");
1792 tty->print_cr("%s", buffer);
1793 } else {
1794 tty->print_cr("# Can't open file to dump inline data.");
1795 close(fd);
1796 }
1797 }
1798 }
1799 }
1800
1801 void ciEnv::dump_replay_data_version(outputStream* out) {
1802 out->print_cr("version %d", REPLAY_VERSION);
1803 }
1804
1805 bool ciEnv::is_precompiled() {
1806 return (task() != nullptr) && (task()->compile_reason() == CompileTask::Reason_Precompile ||
1807 task()->compile_reason() == CompileTask::Reason_PrecompileForPreload);
1808 }
1809
1810 bool ciEnv::is_fully_initialized(InstanceKlass* ik) {
1811 assert(is_precompiled(), "");
1812 if (task()->method()->method_holder() == ik) {
1813 return true; // FIXME: may be too strong; being_initialized, at least
1814 }
1815 switch (task()->compile_reason()) {
1816 case CompileTask::Reason_Precompile: {
1817 // check init dependencies
1818 MethodTrainingData* mtd = TrainingData::lookup_for(task()->method());
1819 if (mtd != nullptr) {
1820 CompileTrainingData* ctd = mtd->last_toplevel_compile(task()->comp_level());
1821 if (ctd != nullptr) {
1822 for (int i = 0; i < ctd->init_dep_count(); i++) {
1823 KlassTrainingData* ktd = ctd->init_dep(i);
1824 if (ktd->has_holder() && (ktd->holder() == ik)) {
1825 log_trace(precompile)("%d: init_dependency: %s: %s", task()->compile_id(), InstanceKlass::state2name(ik->init_state()), ik->external_name());
1826 return true; // init dependency present
1827 }
1828 }
1829 }
1830 }
1831 return false; // no init dependency
1832 }
1833 case CompileTask::Reason_PrecompileForPreload: {
1834 // FIXME: assumes that all shared classes are initialized
1835 if (ik->is_shared()) {
1836 return true; // class init barriers
1837 }
1838 if (CDSConfig::is_dumping_final_static_archive() && ArchiveBuilder::is_active() &&
1839 ArchiveBuilder::current()->has_been_archived((address)ik)) {
1840 return true; // class init barriers
1841 }
1842 return false;
1843 }
1844 default: fatal("%s", CompileTask::reason_name(task()->compile_reason()));
1845 }
1846 return false;
1847 }
1848
1849 InstanceKlass::ClassState ciEnv::compute_init_state_for_precompiled(InstanceKlass* ik) {
1850 ASSERT_IN_VM;
1851 assert(is_precompiled(), "");
1852 ResourceMark rm;
1853 if (is_fully_initialized(ik)) {
1854 log_trace(precompile)("%d: fully_initialized: %s", task()->compile_id(), ik->external_name());
1855 return InstanceKlass::ClassState::fully_initialized;
1856 } else if (MetaspaceObj::is_shared(ik)) {
1857 guarantee(ik->is_loaded(), ""); // FIXME: assumes pre-loading by CDS; ik->is_linked() requires pre-linking
1858 log_trace(precompile)("%d: %s: %s", task()->compile_id(), InstanceKlass::state2name(ik->init_state()), ik->external_name());
1859 return ik->init_state(); // not yet initialized
1860 } else if (CDSConfig::is_dumping_final_static_archive() && ArchiveBuilder::is_active()) {
1861 if (!ArchiveBuilder::current()->has_been_archived((address)ik)) {
1862 fatal("New workflow: should not compile code for unarchived class: %s", ik->external_name());
1863 }
1864 guarantee(ik->is_loaded(), "");
1865 log_trace(precompile)("%d: %s: %s", task()->compile_id(), InstanceKlass::state2name(ik->init_state()), ik->external_name());
1866 return ik->init_state(); // not yet initialized
1867 } else {
1868 // Not present in the archive.
1869 fatal("unloaded: %s", ik->external_name());
1870 // guarantee(SystemDictionaryShared::lookup_init_state(ik) == ik->init_state(), "");
1871 log_trace(precompile)("%d: allocated: %s", task()->compile_id(), ik->external_name());
1872 return InstanceKlass::ClassState::allocated; // not yet linked
1873 }
1874 }
|