22 */ 23 24 #include "precompiled.hpp" 25 #include "memory/oopFactory.hpp" 26 #include "memory/resourceArea.hpp" 27 #include "oops/oop.inline.hpp" 28 #include "runtime/javaCalls.hpp" 29 #include "runtime/handles.hpp" 30 #include "jvmci/jvmciJavaClasses.hpp" 31 #include "jvmci/jvmciCompiler.hpp" 32 #include "jvmci/jvmciEnv.hpp" 33 #include "jvmci/jvmciRuntime.hpp" 34 #include "runtime/compilationPolicy.hpp" 35 #include "runtime/globals_extension.hpp" 36 37 JVMCICompiler* JVMCICompiler::_instance = NULL; 38 elapsedTimer JVMCICompiler::_codeInstallTimer; 39 40 JVMCICompiler::JVMCICompiler() : AbstractCompiler(jvmci) { 41 _bootstrapping = false; 42 _methods_compiled = 0; 43 assert(_instance == NULL, "only one instance allowed"); 44 _instance = this; 45 } 46 47 // Initialization 48 void JVMCICompiler::initialize() { 49 if (!UseCompiler || !EnableJVMCI || !UseJVMCICompiler || !should_perform_init()) { 50 return; 51 } 52 53 set_state(initialized); 54 55 // JVMCI is considered as application code so we need to 56 // stop the VM deferring compilation now. 57 CompilationPolicy::completed_vm_startup(); 58 } 59 60 void JVMCICompiler::bootstrap() { 61 if (Arguments::mode() == Arguments::_int) { 62 // Nothing to do in -Xint mode 63 return; 64 } 65 #ifndef PRODUCT 66 // We turn off CompileTheWorld so that compilation requests are not 67 // ignored during bootstrap or that JVMCI can be compiled by C1/C2. 68 FlagSetting ctwOff(CompileTheWorld, false); 69 #endif 70 71 JavaThread* THREAD = JavaThread::current(); 72 _bootstrapping = true; 73 ResourceMark rm; 74 HandleMark hm; 75 if (PrintBootstrap) { 76 tty->print("Bootstrapping JVMCI"); 77 } 78 jlong start = os::javaTimeMillis(); 79 80 Array<Method*>* objectMethods = SystemDictionary::Object_klass()->methods(); 81 // Initialize compile queue with a selected set of methods. 82 int len = objectMethods->length(); 83 for (int i = 0; i < len; i++) { 84 methodHandle mh = objectMethods->at(i); 85 if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) { 86 ResourceMark rm; 87 int hot_count = 10; // TODO: what's the appropriate value? 88 CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, CompileTask::Reason_Bootstrap, THREAD); 89 } 90 } 91 92 int qsize; 93 bool first_round = true; 94 int z = 0; 95 do { 96 // Loop until there is something in the queue. 97 do { 98 os::sleep(THREAD, 100, true); 99 qsize = CompileBroker::queue_size(CompLevel_full_optimization); 100 } while (first_round && qsize == 0); 101 first_round = false; 102 if (PrintBootstrap) { 103 while (z < (_methods_compiled / 100)) { 104 ++z; 105 tty->print_raw("."); 106 } 107 } 108 } while (qsize != 0); 109 110 if (PrintBootstrap) { 111 tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methods_compiled); 112 } 113 _bootstrapping = false; 114 } 115 116 #define CHECK_ABORT THREAD); \ 117 if (HAS_PENDING_EXCEPTION) { \ 118 char buf[256]; \ 119 jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \ 120 JVMCICompiler::abort_on_pending_exception(PENDING_EXCEPTION, buf); \ 121 return; \ 122 } \ 123 (void)(0 124 125 void JVMCICompiler::compile_method(const methodHandle& method, int entry_bci, JVMCIEnv* env) { 126 JVMCI_EXCEPTION_CONTEXT 127 128 bool is_osr = entry_bci != InvocationEntryBci; 129 if (_bootstrapping && is_osr) { 130 // no OSR compilations during bootstrap - the compiler is just too slow at this point, 131 // and we know that there are no endless loops 132 return; 133 } 169 170 env->set_failure("exception throw", false); 171 } else { 172 oop result_object = (oop) result.get_jobject(); 173 if (result_object != NULL) { 174 oop failure_message = CompilationRequestResult::failureMessage(result_object); 175 if (failure_message != NULL) { 176 const char* failure_reason = java_lang_String::as_utf8_string(failure_message); 177 env->set_failure(failure_reason, CompilationRequestResult::retry(result_object) != 0); 178 } else { 179 if (env->task()->code() == NULL) { 180 env->set_failure("no nmethod produced", true); 181 } else { 182 env->task()->set_num_inlined_bytecodes(CompilationRequestResult::inlinedBytecodes(result_object)); 183 Atomic::inc(&_methods_compiled); 184 } 185 } 186 } else { 187 assert(false, "JVMCICompiler.compileMethod should always return non-null"); 188 } 189 } 190 } 191 192 /** 193 * Aborts the VM due to an unexpected exception. 194 */ 195 void JVMCICompiler::abort_on_pending_exception(Handle exception, const char* message, bool dump_core) { 196 Thread* THREAD = Thread::current(); 197 CLEAR_PENDING_EXCEPTION; 198 199 java_lang_Throwable::java_printStackTrace(exception, THREAD); 200 201 // Give other aborting threads to also print their stack traces. 202 // This can be very useful when debugging class initialization 203 // failures. 204 assert(THREAD->is_Java_thread(), "compiler threads should be Java threads"); 205 const bool interruptible = true; 206 os::sleep(THREAD, 200, interruptible); 207 208 vm_abort(dump_core); | 22 */ 23 24 #include "precompiled.hpp" 25 #include "memory/oopFactory.hpp" 26 #include "memory/resourceArea.hpp" 27 #include "oops/oop.inline.hpp" 28 #include "runtime/javaCalls.hpp" 29 #include "runtime/handles.hpp" 30 #include "jvmci/jvmciJavaClasses.hpp" 31 #include "jvmci/jvmciCompiler.hpp" 32 #include "jvmci/jvmciEnv.hpp" 33 #include "jvmci/jvmciRuntime.hpp" 34 #include "runtime/compilationPolicy.hpp" 35 #include "runtime/globals_extension.hpp" 36 37 JVMCICompiler* JVMCICompiler::_instance = NULL; 38 elapsedTimer JVMCICompiler::_codeInstallTimer; 39 40 JVMCICompiler::JVMCICompiler() : AbstractCompiler(jvmci) { 41 _bootstrapping = false; 42 _bootstrap_compilation_request_handled = false; 43 _methods_compiled = 0; 44 assert(_instance == NULL, "only one instance allowed"); 45 _instance = this; 46 } 47 48 // Initialization 49 void JVMCICompiler::initialize() { 50 if (!UseCompiler || !EnableJVMCI || !UseJVMCICompiler || !should_perform_init()) { 51 return; 52 } 53 54 set_state(initialized); 55 56 // JVMCI is considered as application code so we need to 57 // stop the VM deferring compilation now. 58 CompilationPolicy::completed_vm_startup(); 59 } 60 61 void JVMCICompiler::bootstrap(TRAPS) { 62 if (Arguments::mode() == Arguments::_int) { 63 // Nothing to do in -Xint mode 64 return; 65 } 66 #ifndef PRODUCT 67 // We turn off CompileTheWorld so that compilation requests are not 68 // ignored during bootstrap or that JVMCI can be compiled by C1/C2. 69 FlagSetting ctwOff(CompileTheWorld, false); 70 #endif 71 72 _bootstrapping = true; 73 ResourceMark rm; 74 HandleMark hm; 75 if (PrintBootstrap) { 76 tty->print("Bootstrapping JVMCI"); 77 } 78 jlong start = os::javaTimeMillis(); 79 80 Array<Method*>* objectMethods = SystemDictionary::Object_klass()->methods(); 81 // Initialize compile queue with a selected set of methods. 82 int len = objectMethods->length(); 83 for (int i = 0; i < len; i++) { 84 methodHandle mh = objectMethods->at(i); 85 if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) { 86 ResourceMark rm; 87 int hot_count = 10; // TODO: what's the appropriate value? 88 CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, CompileTask::Reason_Bootstrap, THREAD); 89 } 90 } 91 92 int qsize; 93 bool first_round = true; 94 int z = 0; 95 do { 96 // Loop until there is something in the queue. 97 do { 98 os::sleep(THREAD, 100, true); 99 qsize = CompileBroker::queue_size(CompLevel_full_optimization); 100 } while (!_bootstrap_compilation_request_handled && first_round && qsize == 0); 101 first_round = false; 102 if (PrintBootstrap) { 103 while (z < (_methods_compiled / 100)) { 104 ++z; 105 tty->print_raw("."); 106 } 107 } 108 } while (qsize != 0); 109 110 if (PrintBootstrap) { 111 tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methods_compiled); 112 } 113 _bootstrapping = false; 114 JVMCIRuntime::bootstrap_finished(CHECK); 115 } 116 117 #define CHECK_ABORT THREAD); \ 118 if (HAS_PENDING_EXCEPTION) { \ 119 char buf[256]; \ 120 jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \ 121 JVMCICompiler::abort_on_pending_exception(PENDING_EXCEPTION, buf); \ 122 return; \ 123 } \ 124 (void)(0 125 126 void JVMCICompiler::compile_method(const methodHandle& method, int entry_bci, JVMCIEnv* env) { 127 JVMCI_EXCEPTION_CONTEXT 128 129 bool is_osr = entry_bci != InvocationEntryBci; 130 if (_bootstrapping && is_osr) { 131 // no OSR compilations during bootstrap - the compiler is just too slow at this point, 132 // and we know that there are no endless loops 133 return; 134 } 170 171 env->set_failure("exception throw", false); 172 } else { 173 oop result_object = (oop) result.get_jobject(); 174 if (result_object != NULL) { 175 oop failure_message = CompilationRequestResult::failureMessage(result_object); 176 if (failure_message != NULL) { 177 const char* failure_reason = java_lang_String::as_utf8_string(failure_message); 178 env->set_failure(failure_reason, CompilationRequestResult::retry(result_object) != 0); 179 } else { 180 if (env->task()->code() == NULL) { 181 env->set_failure("no nmethod produced", true); 182 } else { 183 env->task()->set_num_inlined_bytecodes(CompilationRequestResult::inlinedBytecodes(result_object)); 184 Atomic::inc(&_methods_compiled); 185 } 186 } 187 } else { 188 assert(false, "JVMCICompiler.compileMethod should always return non-null"); 189 } 190 } 191 if (_bootstrapping) { 192 _bootstrap_compilation_request_handled = true; 193 } 194 } 195 196 /** 197 * Aborts the VM due to an unexpected exception. 198 */ 199 void JVMCICompiler::abort_on_pending_exception(Handle exception, const char* message, bool dump_core) { 200 Thread* THREAD = Thread::current(); 201 CLEAR_PENDING_EXCEPTION; 202 203 java_lang_Throwable::java_printStackTrace(exception, THREAD); 204 205 // Give other aborting threads to also print their stack traces. 206 // This can be very useful when debugging class initialization 207 // failures. 208 assert(THREAD->is_Java_thread(), "compiler threads should be Java threads"); 209 const bool interruptible = true; 210 os::sleep(THREAD, 200, interruptible); 211 212 vm_abort(dump_core); |