< prev index next >

src/hotspot/share/ci/ciEnv.cpp

Print this page

   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"


  26 #include "ci/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.

 155 
 156   oop o = Universe::null_ptr_exception_instance();
 157   assert(o != nullptr, "should have been initialized");
 158   _NullPointerException_instance = get_object(o)->as_instance();
 159   o = Universe::arithmetic_exception_instance();
 160   assert(o != nullptr, "should have been initialized");
 161   _ArithmeticException_instance = get_object(o)->as_instance();
 162 
 163   _ArrayIndexOutOfBoundsException_instance = nullptr;
 164   _ArrayStoreException_instance = nullptr;
 165   _ClassCastException_instance = nullptr;
 166   _the_null_string = nullptr;
 167   _the_min_jint_string = nullptr;
 168 
 169   _jvmti_redefinition_count = 0;
 170   _jvmti_can_hotswap_or_post_breakpoint = false;
 171   _jvmti_can_access_local_variables = false;
 172   _jvmti_can_post_on_exceptions = false;
 173   _jvmti_can_pop_frame = false;
 174 


 175   _dyno_klasses = nullptr;
 176   _dyno_locs = nullptr;
 177   _dyno_name[0] = '\0';
 178 }
 179 
 180 // Record components of a location descriptor string.  Components are appended by the constructor and
 181 // removed by the destructor, like a stack, so scope matters.  These location descriptors are used to
 182 // locate dynamic classes, and terminate at a Method* or oop field associated with dynamic/hidden class.
 183 //
 184 // Example use:
 185 //
 186 // {
 187 //   RecordLocation fp(this, "field1");
 188 //   // location: "field1"
 189 //   { RecordLocation fp(this, " field2"); // location: "field1 field2" }
 190 //   // location: "field1"
 191 //   { RecordLocation fp(this, " field3"); // location: "field1 field3" }
 192 //   // location: "field1"
 193 // }
 194 // // location: ""

 276   // During VM initialization, these instances have not yet been created.
 277   // Assertions ensure that these instances are not accessed before
 278   // their initialization.
 279 
 280   assert(Universe::is_fully_initialized(), "must be");
 281 
 282   _NullPointerException_instance = nullptr;
 283   _ArithmeticException_instance = nullptr;
 284   _ArrayIndexOutOfBoundsException_instance = nullptr;
 285   _ArrayStoreException_instance = nullptr;
 286   _ClassCastException_instance = nullptr;
 287   _the_null_string = nullptr;
 288   _the_min_jint_string = nullptr;
 289 
 290   _jvmti_redefinition_count = 0;
 291   _jvmti_can_hotswap_or_post_breakpoint = false;
 292   _jvmti_can_access_local_variables = false;
 293   _jvmti_can_post_on_exceptions = false;
 294   _jvmti_can_pop_frame = false;
 295 


 296   _dyno_klasses = nullptr;
 297   _dyno_locs = nullptr;
 298 }
 299 
 300 ciEnv::~ciEnv() {
 301   GUARDED_VM_ENTRY(
 302       CompilerThread* current_thread = CompilerThread::current();
 303       _factory->remove_symbols();
 304       // Need safepoint to clear the env on the thread.  RedefineClasses might
 305       // be reading it.
 306       current_thread->set_env(nullptr);
 307   )
 308 }
 309 
 310 // ------------------------------------------------------------------
 311 // Cache Jvmti state
 312 bool ciEnv::cache_jvmti_state() {
 313   VM_ENTRY_MARK;
 314   // Get Jvmti capabilities under lock to get consistent values.
 315   MutexLocker mu(JvmtiThreadState_lock);

 348   if (!_jvmti_can_get_owned_monitor_info &&
 349       JvmtiExport::can_get_owned_monitor_info()) {
 350     return true;
 351   }
 352   if (!_jvmti_can_walk_any_space &&
 353       JvmtiExport::can_walk_any_space()) {
 354     return true;
 355   }
 356 
 357   return false;
 358 }
 359 
 360 // ------------------------------------------------------------------
 361 // Cache DTrace flags
 362 void ciEnv::cache_dtrace_flags() {
 363   // Need lock?
 364   _dtrace_method_probes = DTraceMethodProbes;
 365   _dtrace_alloc_probes  = DTraceAllocProbes;
 366 }
 367 
 368 // ------------------------------------------------------------------
 369 // helper for lazy exception creation
 370 ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) {
 371   VM_ENTRY_MARK;
 372   if (handle == nullptr) {
 373     // Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance.
 374     InstanceKlass* ik = SystemDictionary::find_instance_klass(THREAD, name, Handle(), Handle());
 375     jobject objh = nullptr;
 376     if (ik != nullptr) {
 377       oop obj = ik->allocate_instance(THREAD);
 378       if (!HAS_PENDING_EXCEPTION)
 379         objh = JNIHandles::make_global(Handle(THREAD, obj));
 380     }
 381     if (HAS_PENDING_EXCEPTION) {
 382       CLEAR_PENDING_EXCEPTION;
 383     } else {
 384       handle = objh;
 385     }
 386   }
 387   oop obj = JNIHandles::resolve(handle);
 388   return obj == nullptr? nullptr: get_object(obj)->as_instance();
 389 }
 390 
 391 ciInstanceKlass* ciEnv::get_box_klass_for_primitive_type(BasicType type) {
 392   switch (type) {
 393     case T_BOOLEAN: return Boolean_klass();
 394     case T_BYTE   : return Byte_klass();
 395     case T_CHAR   : return Character_klass();
 396     case T_SHORT  : return Short_klass();
 397     case T_INT    : return Integer_klass();
 398     case T_LONG   : return Long_klass();
 399     case T_FLOAT  : return Float_klass();
 400     case T_DOUBLE : return Double_klass();
 401 
 402     default:
 403       assert(false, "not a primitive: %s", type2name(type));
 404       return nullptr;
 405   }
 406 }
 407 
 408 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() {
 409   if (_ArrayIndexOutOfBoundsException_instance == nullptr) {
 410     _ArrayIndexOutOfBoundsException_instance
 411           = get_or_create_exception(_ArrayIndexOutOfBoundsException_handle,
 412           vmSymbols::java_lang_ArrayIndexOutOfBoundsException());
 413   }
 414   return _ArrayIndexOutOfBoundsException_instance;
 415 }
 416 ciInstance* ciEnv::ArrayStoreException_instance() {
 417   if (_ArrayStoreException_instance == nullptr) {
 418     _ArrayStoreException_instance
 419           = get_or_create_exception(_ArrayStoreException_handle,
 420           vmSymbols::java_lang_ArrayStoreException());
 421   }
 422   return _ArrayStoreException_instance;
 423 }
 424 ciInstance* ciEnv::ClassCastException_instance() {
 425   if (_ClassCastException_instance == nullptr) {
 426     _ClassCastException_instance
 427           = get_or_create_exception(_ClassCastException_handle,
 428           vmSymbols::java_lang_ClassCastException());
 429   }
 430   return _ClassCastException_instance;
 431 }
 432 
 433 ciInstance* ciEnv::the_null_string() {
 434   if (_the_null_string == nullptr) {
 435     VM_ENTRY_MARK;
 436     _the_null_string = get_object(Universe::the_null_string())->as_instance();
 437   }
 438   return _the_null_string;
 439 }
 440 
 441 ciInstance* ciEnv::the_min_jint_string() {
 442   if (_the_min_jint_string == nullptr) {
 443     VM_ENTRY_MARK;
 444     _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance();
 445   }
 446   return _the_min_jint_string;
 447 }
 448 

 989       _name_buffer =
 990         (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len);
 991       _name_buffer_len = req_len;
 992     }
 993   }
 994   return _name_buffer;
 995 }
 996 
 997 // ------------------------------------------------------------------
 998 // ciEnv::is_in_vm
 999 bool ciEnv::is_in_vm() {
1000   return JavaThread::current()->thread_state() == _thread_in_vm;
1001 }
1002 
1003 // ------------------------------------------------------------------
1004 // ciEnv::validate_compile_task_dependencies
1005 //
1006 // Check for changes during compilation (e.g. class loads, evolution,
1007 // breakpoints, call site invalidation).
1008 void ciEnv::validate_compile_task_dependencies(ciMethod* target) {
1009   if (failing())  return;  // no need for further checks
1010 
1011   Dependencies::DepType result = dependencies()->validate_dependencies(_task);
1012   if (result != Dependencies::end_marker) {
1013     if (result == Dependencies::call_site_target_value) {
1014       _inc_decompile_count_on_failure = false;
1015       record_failure("call site target change");
1016     } else if (Dependencies::is_klass_type(result)) {
1017       record_failure("concurrent class loading");
1018     } else {
1019       record_failure("invalid non-klass dependency");
1020     }
1021   }
1022 }
1023 
1024 // ------------------------------------------------------------------
1025 // ciEnv::register_method
1026 void ciEnv::register_method(ciMethod* target,
1027                             int entry_bci,
1028                             CodeOffsets* offsets,
1029                             int orig_pc_offset,
1030                             CodeBuffer* code_buffer,
1031                             int frame_words,
1032                             OopMapSet* oop_map_set,
1033                             ExceptionHandlerTable* handler_table,
1034                             ImplicitExceptionTable* inc_table,
1035                             AbstractCompiler* compiler,


1036                             bool has_unsafe_access,
1037                             bool has_wide_vectors,
1038                             bool has_monitors,
1039                             int immediate_oops_patched,
1040                             RTMState  rtm_state) {


1041   VM_ENTRY_MARK;
1042   nmethod* nm = nullptr;
1043   {
1044     methodHandle method(THREAD, target->get_Method());

1045 
1046     // We require method counters to store some method state (max compilation levels) required by the compilation policy.
1047     if (method->get_method_counters(THREAD) == nullptr) {
1048       record_failure("can't create method counters");
1049       // All buffers in the CodeBuffer are allocated in the CodeCache.
1050       // If the code buffer is created on each compile attempt
1051       // as in C2, then it must be freed.

1052       code_buffer->free_blob();
1053       return;
1054     }
1055 
1056     // Check if memory should be freed before allocation
1057     CodeCache::gc_on_allocation();
1058 
1059     // To prevent compile queue updates.
1060     MutexLocker locker(THREAD, MethodCompileQueue_lock);
1061 
1062     // Prevent InstanceKlass::add_to_hierarchy from running
1063     // and invalidating our dependencies until we install this method.
1064     // No safepoints are allowed. Otherwise, class redefinition can occur in between.
1065     MutexLocker ml(Compile_lock);
1066     NoSafepointVerifier nsv;
1067 






1068     // Change in Jvmti state may invalidate compilation.
1069     if (!failing() && jvmti_state_changed()) {
1070       record_failure("Jvmti state change invalidated dependencies");
1071     }
1072 
1073     // Change in DTrace flags may invalidate compilation.
1074     if (!failing() &&
1075         ( (!dtrace_method_probes() && DTraceMethodProbes) ||
1076           (!dtrace_alloc_probes() && DTraceAllocProbes) )) {
1077       record_failure("DTrace flags change invalidated dependencies");
1078     }
1079 
1080     if (!failing() && target->needs_clinit_barrier() &&
1081         target->holder()->is_in_error_state()) {
1082       record_failure("method holder is in error state");
1083     }
1084 
1085     if (!failing()) {
1086       if (log() != nullptr) {
1087         // Log the dependencies which this compilation declares.
1088         dependencies()->log_all_dependencies();
1089       }
1090 
1091       // Encode the dependencies now, so we can check them right away.
1092       dependencies()->encode_content_bytes();
1093 


1094       // Check for {class loads, evolution, breakpoints, ...} during compilation
1095       validate_compile_task_dependencies(target);





1096     }
1097 #if INCLUDE_RTM_OPT
1098     if (!failing() && (rtm_state != NoRTM) &&
1099         (method()->method_data() != nullptr) &&
1100         (method()->method_data()->rtm_state() != rtm_state)) {
1101       // Preemptive decompile if rtm state was changed.
1102       record_failure("RTM state change invalidated rtm code");
1103     }
1104 #endif
1105 
1106     if (failing()) {
1107       // While not a true deoptimization, it is a preemptive decompile.
1108       MethodData* mdo = method()->method_data();
1109       if (mdo != nullptr && _inc_decompile_count_on_failure) {
1110         mdo->inc_decompile_count();
1111       }
1112 
1113       // All buffers in the CodeBuffer are allocated in the CodeCache.
1114       // If the code buffer is created on each compile attempt
1115       // as in C2, then it must be freed.
1116       code_buffer->free_blob();
1117       return;
1118     }
1119 
1120     assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry");
1121     assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry");
1122 
1123     nm =  nmethod::new_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, CompLevel(task()->comp_level()));
1132 































1133     // Free codeBlobs
1134     code_buffer->free_blob();
1135 
1136     if (nm != nullptr) {
1137       nm->set_has_unsafe_access(has_unsafe_access);
1138       nm->set_has_wide_vectors(has_wide_vectors);
1139       nm->set_has_monitors(has_monitors);


1140       assert(!method->is_synchronized() || nm->has_monitors(), "");
1141 #if INCLUDE_RTM_OPT
1142       nm->set_rtm_state(rtm_state);
1143 #endif
1144 
1145       if (entry_bci == InvocationEntryBci) {
1146         if (TieredCompilation) {
1147           // If there is an old version we're done with it
1148           CompiledMethod* old = method->code();
1149           if (TraceMethodReplacement && old != nullptr) {
1150             ResourceMark rm;
1151             char *method_name = method->name_and_sig_as_C_string();
1152             tty->print_cr("Replacing method %s", method_name);
1153           }
1154           if (old != nullptr) {
1155             old->make_not_used();
1156           }
1157         }
1158 
1159         LogTarget(Info, nmethod, install) lt;
1160         if (lt.is_enabled()) {
1161           ResourceMark rm;
1162           char *method_name = method->name_and_sig_as_C_string();
1163           lt.print("Installing method (%d) %s ",
1164                     task()->comp_level(), method_name);


1165         }
1166         // Allow the code to be executed
1167         MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1168         if (nm->make_in_use()) {
1169           method->set_code(method, nm);













1170         }
1171       } else {
1172         LogTarget(Info, nmethod, install) lt;
1173         if (lt.is_enabled()) {
1174           ResourceMark rm;
1175           char *method_name = method->name_and_sig_as_C_string();
1176           lt.print("Installing osr method (%d) %s @ %d",
1177                     task()->comp_level(), method_name, entry_bci);


1178         }
1179         MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1180         if (nm->make_in_use()) {
1181           method->method_holder()->add_osr_nmethod(nm);
1182         }
1183       }
1184     }
1185   }
1186 
1187   NoSafepointVerifier nsv;
1188   if (nm != nullptr) {
1189     // Compilation succeeded, post what we know about it
1190     nm->post_compiled_method(task());
1191     task()->set_num_inlined_bytecodes(num_inlined_bytecodes());
1192   } else {
1193     // The CodeCache is full.
1194     record_failure("code cache is full");


1195   }
1196 
1197   // safepoints are allowed again
1198 }
1199 
1200 // ------------------------------------------------------------------
1201 // ciEnv::find_system_klass
1202 ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) {
1203   VM_ENTRY_MARK;
1204   return get_klass_by_name_impl(nullptr, constantPoolHandle(), klass_name, false);
1205 }
1206 
1207 // ------------------------------------------------------------------
1208 // ciEnv::comp_level
1209 int ciEnv::comp_level() {
1210   if (task() == nullptr)  return CompilationPolicy::highest_compile_level();
1211   return task()->comp_level();
1212 }
1213 
1214 // ------------------------------------------------------------------
1215 // ciEnv::compile_id
1216 int ciEnv::compile_id() {
1217   if (task() == nullptr)  return 0;
1218   return task()->compile_id();
1219 }
1220 
1221 // ------------------------------------------------------------------
1222 // ciEnv::notice_inlined_method()
1223 void ciEnv::notice_inlined_method(ciMethod* method) {
1224   _num_inlined_bytecodes += method->code_size_for_inlining();







1225 }
1226 
1227 // ------------------------------------------------------------------
1228 // ciEnv::num_inlined_bytecodes()
1229 int ciEnv::num_inlined_bytecodes() const {
1230   return _num_inlined_bytecodes;
1231 }
1232 
1233 // ------------------------------------------------------------------
1234 // ciEnv::record_failure()
1235 void ciEnv::record_failure(const char* reason) {
1236   if (_failure_reason == nullptr) {
1237     // Record the first failure reason.
1238     _failure_reason = reason;
1239   }
1240 }
1241 
1242 void ciEnv::report_failure(const char* reason) {
1243   EventCompilationFailure event;
1244   if (event.should_commit()) {

1727         fileStream replay_data_stream(inline_data_file, /*need_close=*/true);
1728         GUARDED_VM_ENTRY(
1729           MutexLocker ml(Compile_lock);
1730           dump_replay_data_version(&replay_data_stream);
1731           dump_compile_data(&replay_data_stream);
1732         )
1733         replay_data_stream.flush();
1734         tty->print("# Compiler inline data is saved as: ");
1735         tty->print_cr("%s", buffer);
1736       } else {
1737         tty->print_cr("# Can't open file to dump inline data.");
1738         close(fd);
1739       }
1740     }
1741   }
1742 }
1743 
1744 void ciEnv::dump_replay_data_version(outputStream* out) {
1745   out->print_cr("version %d", REPLAY_VERSION);
1746 }








































































   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.

 161 
 162   oop o = Universe::null_ptr_exception_instance();
 163   assert(o != nullptr, "should have been initialized");
 164   _NullPointerException_instance = get_object(o)->as_instance();
 165   o = Universe::arithmetic_exception_instance();
 166   assert(o != nullptr, "should have been initialized");
 167   _ArithmeticException_instance = get_object(o)->as_instance();
 168 
 169   _ArrayIndexOutOfBoundsException_instance = nullptr;
 170   _ArrayStoreException_instance = nullptr;
 171   _ClassCastException_instance = nullptr;
 172   _the_null_string = nullptr;
 173   _the_min_jint_string = nullptr;
 174 
 175   _jvmti_redefinition_count = 0;
 176   _jvmti_can_hotswap_or_post_breakpoint = false;
 177   _jvmti_can_access_local_variables = false;
 178   _jvmti_can_post_on_exceptions = false;
 179   _jvmti_can_pop_frame = false;
 180 
 181   _scc_clinit_barriers_entry = nullptr;
 182 
 183   _dyno_klasses = nullptr;
 184   _dyno_locs = nullptr;
 185   _dyno_name[0] = '\0';
 186 }
 187 
 188 // Record components of a location descriptor string.  Components are appended by the constructor and
 189 // removed by the destructor, like a stack, so scope matters.  These location descriptors are used to
 190 // locate dynamic classes, and terminate at a Method* or oop field associated with dynamic/hidden class.
 191 //
 192 // Example use:
 193 //
 194 // {
 195 //   RecordLocation fp(this, "field1");
 196 //   // location: "field1"
 197 //   { RecordLocation fp(this, " field2"); // location: "field1 field2" }
 198 //   // location: "field1"
 199 //   { RecordLocation fp(this, " field3"); // location: "field1 field3" }
 200 //   // location: "field1"
 201 // }
 202 // // location: ""

 284   // During VM initialization, these instances have not yet been created.
 285   // Assertions ensure that these instances are not accessed before
 286   // their initialization.
 287 
 288   assert(Universe::is_fully_initialized(), "must be");
 289 
 290   _NullPointerException_instance = nullptr;
 291   _ArithmeticException_instance = nullptr;
 292   _ArrayIndexOutOfBoundsException_instance = nullptr;
 293   _ArrayStoreException_instance = nullptr;
 294   _ClassCastException_instance = nullptr;
 295   _the_null_string = nullptr;
 296   _the_min_jint_string = nullptr;
 297 
 298   _jvmti_redefinition_count = 0;
 299   _jvmti_can_hotswap_or_post_breakpoint = false;
 300   _jvmti_can_access_local_variables = false;
 301   _jvmti_can_post_on_exceptions = false;
 302   _jvmti_can_pop_frame = false;
 303 
 304   _scc_clinit_barriers_entry = nullptr;
 305 
 306   _dyno_klasses = nullptr;
 307   _dyno_locs = nullptr;
 308 }
 309 
 310 ciEnv::~ciEnv() {
 311   GUARDED_VM_ENTRY(
 312       CompilerThread* current_thread = CompilerThread::current();
 313       _factory->remove_symbols();
 314       // Need safepoint to clear the env on the thread.  RedefineClasses might
 315       // be reading it.
 316       current_thread->set_env(nullptr);
 317   )
 318 }
 319 
 320 // ------------------------------------------------------------------
 321 // Cache Jvmti state
 322 bool ciEnv::cache_jvmti_state() {
 323   VM_ENTRY_MARK;
 324   // Get Jvmti capabilities under lock to get consistent values.
 325   MutexLocker mu(JvmtiThreadState_lock);

 358   if (!_jvmti_can_get_owned_monitor_info &&
 359       JvmtiExport::can_get_owned_monitor_info()) {
 360     return true;
 361   }
 362   if (!_jvmti_can_walk_any_space &&
 363       JvmtiExport::can_walk_any_space()) {
 364     return true;
 365   }
 366 
 367   return false;
 368 }
 369 
 370 // ------------------------------------------------------------------
 371 // Cache DTrace flags
 372 void ciEnv::cache_dtrace_flags() {
 373   // Need lock?
 374   _dtrace_method_probes = DTraceMethodProbes;
 375   _dtrace_alloc_probes  = DTraceAllocProbes;
 376 }
 377 























 378 ciInstanceKlass* ciEnv::get_box_klass_for_primitive_type(BasicType type) {
 379   switch (type) {
 380     case T_BOOLEAN: return Boolean_klass();
 381     case T_BYTE   : return Byte_klass();
 382     case T_CHAR   : return Character_klass();
 383     case T_SHORT  : return Short_klass();
 384     case T_INT    : return Integer_klass();
 385     case T_LONG   : return Long_klass();
 386     case T_FLOAT  : return Float_klass();
 387     case T_DOUBLE : return Double_klass();
 388 
 389     default:
 390       assert(false, "not a primitive: %s", type2name(type));
 391       return nullptr;
 392   }
 393 }
 394 
 395 ciInstance* ciEnv::ArrayIndexOutOfBoundsException_instance() {
 396   if (_ArrayIndexOutOfBoundsException_instance == nullptr) {
 397     VM_ENTRY_MARK;
 398     _ArrayIndexOutOfBoundsException_instance = get_object(Universe::array_index_oob_exception_instance())->as_instance();

 399   }
 400   return _ArrayIndexOutOfBoundsException_instance;
 401 }
 402 ciInstance* ciEnv::ArrayStoreException_instance() {
 403   if (_ArrayStoreException_instance == nullptr) {
 404     VM_ENTRY_MARK;
 405     _ArrayStoreException_instance = get_object(Universe::array_store_exception_instance())->as_instance();

 406   }
 407   return _ArrayStoreException_instance;
 408 }
 409 ciInstance* ciEnv::ClassCastException_instance() {
 410   if (_ClassCastException_instance == nullptr) {
 411     VM_ENTRY_MARK;
 412     _ClassCastException_instance = get_object(Universe::class_cast_exception_instance())->as_instance();

 413   }
 414   return _ClassCastException_instance;
 415 }
 416 
 417 ciInstance* ciEnv::the_null_string() {
 418   if (_the_null_string == nullptr) {
 419     VM_ENTRY_MARK;
 420     _the_null_string = get_object(Universe::the_null_string())->as_instance();
 421   }
 422   return _the_null_string;
 423 }
 424 
 425 ciInstance* ciEnv::the_min_jint_string() {
 426   if (_the_min_jint_string == nullptr) {
 427     VM_ENTRY_MARK;
 428     _the_min_jint_string = get_object(Universe::the_min_jint_string())->as_instance();
 429   }
 430   return _the_min_jint_string;
 431 }
 432 

 973       _name_buffer =
 974         (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len);
 975       _name_buffer_len = req_len;
 976     }
 977   }
 978   return _name_buffer;
 979 }
 980 
 981 // ------------------------------------------------------------------
 982 // ciEnv::is_in_vm
 983 bool ciEnv::is_in_vm() {
 984   return JavaThread::current()->thread_state() == _thread_in_vm;
 985 }
 986 
 987 // ------------------------------------------------------------------
 988 // ciEnv::validate_compile_task_dependencies
 989 //
 990 // Check for changes during compilation (e.g. class loads, evolution,
 991 // breakpoints, call site invalidation).
 992 void ciEnv::validate_compile_task_dependencies(ciMethod* target) {
 993   assert(!failing(), "should not call this when failing");
 994 
 995   Dependencies::DepType result = dependencies()->validate_dependencies(_task);
 996   if (result != Dependencies::end_marker) {
 997     if (result == Dependencies::call_site_target_value) {
 998       _inc_decompile_count_on_failure = false;
 999       record_failure("call site target change");
1000     } else if (Dependencies::is_klass_type(result)) {
1001       record_failure("concurrent class loading");
1002     } else {
1003       record_failure("invalid non-klass dependency");
1004     }
1005   }
1006 }
1007 
1008 // ------------------------------------------------------------------
1009 // ciEnv::register_method
1010 void ciEnv::register_method(ciMethod* target,
1011                             int entry_bci,
1012                             CodeOffsets* offsets,
1013                             int orig_pc_offset,
1014                             CodeBuffer* code_buffer,
1015                             int frame_words,
1016                             OopMapSet* oop_map_set,
1017                             ExceptionHandlerTable* handler_table,
1018                             ImplicitExceptionTable* inc_table,
1019                             AbstractCompiler* compiler,
1020                             bool has_clinit_barriers,
1021                             bool for_preload,
1022                             bool has_unsafe_access,
1023                             bool has_wide_vectors,
1024                             bool has_monitors,
1025                             int immediate_oops_patched,
1026                             bool install_code,
1027                             RTMState  rtm_state,
1028                             SCCEntry* scc_entry) {
1029   VM_ENTRY_MARK;
1030   nmethod* nm = nullptr;
1031   {
1032     methodHandle method(THREAD, target->get_Method());
1033     bool preload = task()->preload(); // Code is preloaded before Java method execution
1034 
1035     // We require method counters to store some method state (max compilation levels) required by the compilation policy.
1036     if (!preload && method->get_method_counters(THREAD) == nullptr) {
1037       record_failure("can't create method counters");
1038       // All buffers in the CodeBuffer are allocated in the CodeCache.
1039       // If the code buffer is created on each compile attempt
1040       // as in C2, then it must be freed.
1041       // But keep shared code.
1042       code_buffer->free_blob();
1043       return;
1044     }
1045 
1046     // Check if memory should be freed before allocation
1047     CodeCache::gc_on_allocation();
1048 
1049     // To prevent compile queue updates.
1050     MutexLocker locker(THREAD, MethodCompileQueue_lock);
1051 
1052     // Prevent InstanceKlass::add_to_hierarchy from running
1053     // and invalidating our dependencies until we install this method.
1054     // No safepoints are allowed. Otherwise, class redefinition can occur in between.
1055     MutexLocker ml(Compile_lock);
1056     NoSafepointVerifier nsv;
1057 
1058     if (scc_entry != nullptr && scc_entry->not_entrant()) {
1059       // This shared code was marked invalid while it was loaded
1060       code_buffer->free_blob();
1061       return;
1062     }
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 (!preload && !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() && (scc_entry == nullptr)) {
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     if (!failing() && install_code) {
1092       // Check for {class loads, evolution, breakpoints, ...} during compilation
1093       validate_compile_task_dependencies(target);
1094       if (failing() && preload) {
1095         ResourceMark rm;
1096         char *method_name = method->name_and_sig_as_C_string();
1097         log_warning(scc)("preload code for '%s' failed dependency check", method_name);
1098       }
1099     }
1100 #if INCLUDE_RTM_OPT
1101     if (!failing() && (rtm_state != NoRTM) &&
1102         (method()->method_data() != nullptr) &&
1103         (method()->method_data()->rtm_state() != rtm_state)) {
1104       // Preemptive decompile if rtm state was changed.
1105       record_failure("RTM state change invalidated rtm code");
1106     }
1107 #endif
1108 
1109     if (failing()) {
1110       // While not a true deoptimization, it is a preemptive decompile.
1111       MethodData* mdo = method()->method_data();
1112       if (mdo != nullptr && _inc_decompile_count_on_failure) {
1113         mdo->inc_decompile_count();
1114       }
1115 
1116       // All buffers in the CodeBuffer are allocated in the CodeCache.
1117       // If the code buffer is created on each compile attempt
1118       // as in C2, then it must be freed.
1119       code_buffer->free_blob();
1120       return;
1121     }
1122 
1123     assert(offsets->value(CodeOffsets::Deopt) != -1, "must have deopt entry");
1124     assert(offsets->value(CodeOffsets::Exceptions) != -1, "must have exception entry");
1125 
1126     if (rtm_state == NoRTM && scc_entry == nullptr) {
1127       scc_entry = SCCache::store_nmethod(method,
1128                              compile_id(),
1129                              entry_bci,
1130                              offsets,
1131                              orig_pc_offset,
1132                              debug_info(), dependencies(), code_buffer,
1133                              frame_words, oop_map_set,
1134                              handler_table, inc_table,
1135                              compiler,
1136                              CompLevel(task()->comp_level()),
1137                              has_clinit_barriers,
1138                              for_preload,
1139                              has_unsafe_access,
1140                              has_wide_vectors,
1141                              has_monitors);
1142       if (scc_entry != nullptr) {
1143         scc_entry->set_inlined_bytecodes(num_inlined_bytecodes());
1144         if (has_clinit_barriers) {
1145           set_scc_clinit_barriers_entry(scc_entry); // Record it
1146           // Build second version of code without class initialization barriers
1147           code_buffer->free_blob();
1148           return;
1149         } else if (!for_preload) {
1150           SCCEntry* previous_entry = scc_clinit_barriers_entry();
1151           scc_entry->set_next(previous_entry); // Link it for case of deoptimization
1152         }
1153       }
1154     }
1155     if (install_code) {
1156       nm =  nmethod::new_nmethod(method,
1157                                  compile_id(),
1158                                  entry_bci,
1159                                  offsets,
1160                                  orig_pc_offset,
1161                                  debug_info(), dependencies(), code_buffer,
1162                                  frame_words, oop_map_set,
1163                                  handler_table, inc_table,
1164                                  compiler, CompLevel(task()->comp_level()),
1165                                  scc_entry);
1166     }
1167     // Free codeBlobs
1168     code_buffer->free_blob();
1169 
1170     if (nm != nullptr) {
1171       nm->set_has_unsafe_access(has_unsafe_access);
1172       nm->set_has_wide_vectors(has_wide_vectors);
1173       nm->set_has_monitors(has_monitors);
1174       nm->set_preloaded(preload);
1175       nm->set_has_clinit_barriers(has_clinit_barriers);
1176       assert(!method->is_synchronized() || nm->has_monitors(), "");
1177 #if INCLUDE_RTM_OPT
1178       nm->set_rtm_state(rtm_state);
1179 #endif
1180 
1181       if (entry_bci == InvocationEntryBci) {
1182         if (TieredCompilation || SCCache::is_on_for_read()) {
1183           // If there is an old version we're done with it
1184           CompiledMethod* old = method->code();
1185           if (TraceMethodReplacement && old != nullptr) {
1186             ResourceMark rm;
1187             char *method_name = method->name_and_sig_as_C_string();
1188             tty->print_cr("Replacing method %s", method_name);
1189           }
1190           if (old != nullptr) {
1191             old->make_not_used();
1192           }
1193         }
1194 
1195         LogTarget(Info, nmethod, install) lt;
1196         if (lt.is_enabled()) {
1197           ResourceMark rm;
1198           char *method_name = method->name_and_sig_as_C_string();
1199           lt.print("Installing method (L%d) %s id=%d scc=%s%s%u",
1200                     task()->comp_level(), method_name, compile_id(),
1201                     task()->is_scc() ? "A" : "", preload ? "P" : "",
1202                     (scc_entry != nullptr ? scc_entry->offset() : 0));
1203         }
1204         // Allow the code to be executed
1205         MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1206         if (nm->make_in_use()) {
1207 #ifdef ASSERT
1208           BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
1209           if (bs_nm != nullptr && bs_nm->supports_entry_barrier(nm)) {
1210             if (!bs_nm->is_armed(nm)) {
1211               log_info(init)("nmethod %d %d not armed", nm->compile_id(), nm->comp_level());
1212             }
1213           }
1214 #endif // ASSERT
1215           if (preload) {
1216             method->set_preload_code(nm);
1217           }
1218           if (!preload || target->holder()->is_linked()) {
1219             method->set_code(method, nm);
1220           }
1221         }
1222       } else {
1223         LogTarget(Info, nmethod, install) lt;
1224         if (lt.is_enabled()) {
1225           ResourceMark rm;
1226           char *method_name = method->name_and_sig_as_C_string();
1227           lt.print("Installing osr method (L%d) %s @ %d id=%u scc=%s%u",
1228                    task()->comp_level(), method_name, entry_bci, compile_id(),
1229                    task()->is_scc() ? "A" : "",
1230                    (scc_entry != nullptr ? scc_entry->offset() : 0));
1231         }
1232         MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag);
1233         if (nm->make_in_use()) {
1234           method->method_holder()->add_osr_nmethod(nm);
1235         }
1236       }
1237     }
1238   }
1239 
1240   NoSafepointVerifier nsv;
1241   if (nm != nullptr) {
1242     // Compilation succeeded, post what we know about it
1243     nm->post_compiled_method(task());
1244     task()->set_num_inlined_bytecodes(num_inlined_bytecodes());
1245   } else if (install_code) {
1246     // The CodeCache is full.
1247     record_failure("code cache is full");
1248   } else {
1249     task()->set_num_inlined_bytecodes(num_inlined_bytecodes());
1250   }
1251 
1252   // safepoints are allowed again
1253 }
1254 
1255 // ------------------------------------------------------------------
1256 // ciEnv::find_system_klass
1257 ciKlass* ciEnv::find_system_klass(ciSymbol* klass_name) {
1258   VM_ENTRY_MARK;
1259   return get_klass_by_name_impl(nullptr, constantPoolHandle(), klass_name, false);
1260 }
1261 
1262 // ------------------------------------------------------------------
1263 // ciEnv::comp_level
1264 int ciEnv::comp_level() {
1265   if (task() == nullptr)  return CompilationPolicy::highest_compile_level();
1266   return task()->comp_level();
1267 }
1268 
1269 // ------------------------------------------------------------------
1270 // ciEnv::compile_id
1271 int ciEnv::compile_id() {
1272   if (task() == nullptr)  return 0;
1273   return task()->compile_id();
1274 }
1275 
1276 // ------------------------------------------------------------------
1277 // ciEnv::notice_inlined_method()
1278 void ciEnv::notice_inlined_method(ciMethod* method) {
1279   _num_inlined_bytecodes += method->code_size_for_inlining();
1280   CompileTrainingData* tdata = task()->training_data();
1281   if (tdata != nullptr) {
1282     GUARDED_VM_ENTRY({
1283       methodHandle mh(Thread::current(), method->get_Method());
1284       tdata->notice_inlined_method(task(), mh);
1285     });
1286   }
1287 }
1288 
1289 // ------------------------------------------------------------------
1290 // ciEnv::num_inlined_bytecodes()
1291 int ciEnv::num_inlined_bytecodes() const {
1292   return _num_inlined_bytecodes;
1293 }
1294 
1295 // ------------------------------------------------------------------
1296 // ciEnv::record_failure()
1297 void ciEnv::record_failure(const char* reason) {
1298   if (_failure_reason == nullptr) {
1299     // Record the first failure reason.
1300     _failure_reason = reason;
1301   }
1302 }
1303 
1304 void ciEnv::report_failure(const char* reason) {
1305   EventCompilationFailure event;
1306   if (event.should_commit()) {

1789         fileStream replay_data_stream(inline_data_file, /*need_close=*/true);
1790         GUARDED_VM_ENTRY(
1791           MutexLocker ml(Compile_lock);
1792           dump_replay_data_version(&replay_data_stream);
1793           dump_compile_data(&replay_data_stream);
1794         )
1795         replay_data_stream.flush();
1796         tty->print("# Compiler inline data is saved as: ");
1797         tty->print_cr("%s", buffer);
1798       } else {
1799         tty->print_cr("# Can't open file to dump inline data.");
1800         close(fd);
1801       }
1802     }
1803   }
1804 }
1805 
1806 void ciEnv::dump_replay_data_version(outputStream* out) {
1807   out->print_cr("version %d", REPLAY_VERSION);
1808 }
1809 
1810 bool ciEnv::is_precompiled() {
1811   return (task() != nullptr) && (task()->compile_reason() == CompileTask::Reason_Precompile          ||
1812                                  task()->compile_reason() == CompileTask::Reason_PrecompileForPreload);
1813 }
1814 
1815 bool ciEnv::is_fully_initialized(InstanceKlass* ik) {
1816   assert(is_precompiled(), "");
1817   if (task()->method()->method_holder() == ik) {
1818     return true; // FIXME: may be too strong; being_initialized, at least
1819   }
1820   switch (task()->compile_reason()) {
1821     case CompileTask::Reason_Precompile: {
1822       // check init dependencies
1823       MethodTrainingData* mtd = TrainingData::lookup_for(task()->method());
1824       if (mtd != nullptr) {
1825         CompileTrainingData* ctd = mtd->last_toplevel_compile(task()->comp_level());
1826         if (ctd != nullptr) {
1827           for (int i = 0; i < ctd->init_dep_count(); i++) {
1828             KlassTrainingData* ktd = ctd->init_dep(i);
1829             if (ktd->has_holder() && (ktd->holder() == ik)) {
1830               log_trace(precompile)("%d: init_dependency: %s: %s", task()->compile_id(), InstanceKlass::state2name(ik->init_state()), ik->external_name());
1831               return true; // init dependency present
1832             }
1833           }
1834         }
1835       }
1836       return false; // no init dependency
1837     }
1838     case CompileTask::Reason_PrecompileForPreload: {
1839       // FIXME: assumes that all shared classes are initialized
1840       if (ik->is_shared()) {
1841         return true; // class init barriers
1842       }
1843       if (CDSConfig::is_dumping_final_static_archive() && ArchiveBuilder::is_active() &&
1844           ArchiveBuilder::current()->has_been_archived((address)ik)) {
1845         return true; // class init barriers
1846       }
1847       return false;
1848     }
1849     default: fatal("%s", CompileTask::reason_name(task()->compile_reason()));
1850   }
1851   return false;
1852 }
1853 
1854 InstanceKlass::ClassState ciEnv::compute_init_state_for_precompiled(InstanceKlass* ik) {
1855   ASSERT_IN_VM;
1856   assert(is_precompiled(), "");
1857   ResourceMark rm;
1858   if (is_fully_initialized(ik)) {
1859     log_trace(precompile)("%d: fully_initialized: %s", task()->compile_id(), ik->external_name());
1860     return InstanceKlass::ClassState::fully_initialized;
1861   } else if (MetaspaceObj::is_shared(ik)) {
1862     guarantee(ik->is_loaded(), ""); // FIXME: assumes pre-loading by CDS; ik->is_linked() requires pre-linking
1863     log_trace(precompile)("%d: %s: %s", task()->compile_id(), InstanceKlass::state2name(ik->init_state()), ik->external_name());
1864     return ik->init_state(); // not yet initialized
1865   } else if (CDSConfig::is_dumping_final_static_archive() && ArchiveBuilder::is_active()) {
1866     if (!ArchiveBuilder::current()->has_been_archived((address)ik)) {
1867       fatal("New workflow: should not compile code for unarchived class: %s", ik->external_name());
1868     }
1869     guarantee(ik->is_loaded(), "");
1870     log_trace(precompile)("%d: %s: %s", task()->compile_id(), InstanceKlass::state2name(ik->init_state()), ik->external_name());
1871     return ik->init_state(); // not yet initialized
1872   } else {
1873     // Not present in the archive.
1874     fatal("unloaded: %s", ik->external_name());
1875 //    guarantee(SystemDictionaryShared::lookup_init_state(ik) == ik->init_state(), "");
1876     log_trace(precompile)("%d: allocated: %s", task()->compile_id(), ik->external_name());
1877     return InstanceKlass::ClassState::allocated; // not yet linked
1878   }
1879 }
< prev index next >