8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library

Reviewed-by: dnsimon, never, stefank, rehn, neliasso, dholmes, kbarrett, coleenp
This commit is contained in:
Vladimir Kozlov 2019-05-01 12:31:29 -07:00
parent f9bbbb6e27
commit e9c523ae5f
173 changed files with 12881 additions and 5297 deletions

View file

@ -22,19 +22,10 @@
*/
#include "precompiled.hpp"
#include "jvm.h"
#include "compiler/compileBroker.hpp"
#include "classfile/moduleEntry.hpp"
#include "memory/oopFactory.hpp"
#include "memory/resourceArea.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/handles.hpp"
#include "jvmci/jvmciJavaClasses.hpp"
#include "jvmci/jvmciCompiler.hpp"
#include "jvmci/jvmciEnv.hpp"
#include "jvmci/jvmciRuntime.hpp"
#include "runtime/compilationPolicy.hpp"
#include "runtime/globals_extension.hpp"
#include "runtime/handles.inline.hpp"
JVMCICompiler* JVMCICompiler::_instance = NULL;
@ -104,112 +95,39 @@ void JVMCICompiler::bootstrap(TRAPS) {
tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methods_compiled);
}
_bootstrapping = false;
JVMCIRuntime::bootstrap_finished(CHECK);
JVMCI::compiler_runtime()->bootstrap_finished(CHECK);
}
#define CHECK_EXIT THREAD); \
if (HAS_PENDING_EXCEPTION) { \
char buf[256]; \
jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \
JVMCICompiler::exit_on_pending_exception(PENDING_EXCEPTION, buf); \
return; \
} \
(void)(0
void JVMCICompiler::compile_method(const methodHandle& method, int entry_bci, JVMCIEnv* env) {
JVMCI_EXCEPTION_CONTEXT
bool is_osr = entry_bci != InvocationEntryBci;
if (_bootstrapping && is_osr) {
// no OSR compilations during bootstrap - the compiler is just too slow at this point,
// and we know that there are no endless loops
env->set_failure(true, "No OSR during boostrap");
return;
bool JVMCICompiler::force_comp_at_level_simple(Method *method) {
if (UseJVMCINativeLibrary) {
// This mechanism exists to force compilation of a JVMCI compiler by C1
// to reduces the compilation time spent on the JVMCI compiler itself. In
// +UseJVMCINativeLibrary mode, the JVMCI compiler is AOT compiled.
return false;
}
JVMCIRuntime::initialize_well_known_classes(CHECK_EXIT);
HandleMark hm;
Handle receiver = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK_EXIT);
JavaValue method_result(T_OBJECT);
JavaCallArguments args;
args.push_long((jlong) (address) method());
JavaCalls::call_static(&method_result, SystemDictionary::HotSpotResolvedJavaMethodImpl_klass(),
vmSymbols::fromMetaspace_name(), vmSymbols::method_fromMetaspace_signature(), &args, THREAD);
JavaValue result(T_OBJECT);
if (!HAS_PENDING_EXCEPTION) {
JavaCallArguments args;
args.push_oop(receiver);
args.push_oop(Handle(THREAD, (oop)method_result.get_jobject()));
args.push_int(entry_bci);
args.push_long((jlong) (address) env);
args.push_int(env->task()->compile_id());
JavaCalls::call_special(&result, receiver->klass(),
vmSymbols::compileMethod_name(), vmSymbols::compileMethod_signature(), &args, THREAD);
if (_bootstrapping) {
// When bootstrapping, the JVMCI compiler can compile its own methods.
return false;
}
// An uncaught exception was thrown during compilation. Generally these
// should be handled by the Java code in some useful way but if they leak
// through to here report them instead of dying or silently ignoring them.
if (HAS_PENDING_EXCEPTION) {
Handle exception(THREAD, PENDING_EXCEPTION);
CLEAR_PENDING_EXCEPTION;
java_lang_Throwable::java_printStackTrace(exception, THREAD);
if (HAS_PENDING_EXCEPTION) {
CLEAR_PENDING_EXCEPTION;
}
env->set_failure(false, "unexpected exception thrown");
} else {
oop result_object = (oop) result.get_jobject();
if (result_object != NULL) {
oop failure_message = HotSpotCompilationRequestResult::failureMessage(result_object);
if (failure_message != NULL) {
// Copy failure reason into resource memory first ...
const char* failure_reason = java_lang_String::as_utf8_string(failure_message);
// ... and then into the C heap.
failure_reason = os::strdup(failure_reason, mtCompiler);
bool retryable = HotSpotCompilationRequestResult::retry(result_object) != 0;
env->set_failure(retryable, failure_reason, true);
} else {
if (env->task()->code() == NULL) {
env->set_failure(true, "no nmethod produced");
} else {
env->task()->set_num_inlined_bytecodes(HotSpotCompilationRequestResult::inlinedBytecodes(result_object));
Atomic::inc(&_methods_compiled);
JVMCIRuntime* runtime = JVMCI::compiler_runtime();
if (runtime != NULL && runtime->is_HotSpotJVMCIRuntime_initialized()) {
JavaThread* thread = JavaThread::current();
HandleMark hm(thread);
THREAD_JVMCIENV(thread);
JVMCIObject receiver = runtime->get_HotSpotJVMCIRuntime(JVMCIENV);
objArrayHandle excludeModules(thread, HotSpotJVMCI::HotSpotJVMCIRuntime::excludeFromJVMCICompilation(JVMCIENV, HotSpotJVMCI::resolve(receiver)));
if (excludeModules.not_null()) {
ModuleEntry* moduleEntry = method->method_holder()->module();
for (int i = 0; i < excludeModules->length(); i++) {
if (oopDesc::equals(excludeModules->obj_at(i), moduleEntry->module())) {
return true;
}
}
} else {
assert(false, "JVMCICompiler.compileMethod should always return non-null");
}
}
if (_bootstrapping) {
_bootstrap_compilation_request_handled = true;
}
}
void JVMCICompiler::exit_on_pending_exception(oop exception, const char* message) {
JavaThread* THREAD = JavaThread::current();
CLEAR_PENDING_EXCEPTION;
static volatile int report_error = 0;
if (!report_error && Atomic::cmpxchg(1, &report_error, 0) == 0) {
// Only report an error once
tty->print_raw_cr(message);
Handle ex(THREAD, exception);
java_lang_Throwable::java_printStackTrace(ex, THREAD);
} else {
// Allow error reporting thread to print the stack trace. Windows
// doesn't allow uninterruptible wait for JavaThreads
const bool interruptible = true;
os::sleep(THREAD, 200, interruptible);
}
before_exit(THREAD);
vm_exit(-1);
return false;
}
// Compilation entry point for methods
@ -227,33 +145,3 @@ void JVMCICompiler::print_compilation_timers() {
TRACE_jvmci_1("JVMCICompiler::print_timers");
tty->print_cr(" JVMCI code install time: %6.3f s", _codeInstallTimer.seconds());
}
bool JVMCICompiler::force_comp_at_level_simple(Method *method) {
JVMCI_EXCEPTION_CONTEXT
if (_bootstrapping) {
// When bootstrapping, the JVMCI compiler can compile its own methods.
return false;
}
if (!JVMCIRuntime::is_HotSpotJVMCIRuntime_initialized()) {
// JVMCI cannot participate in compilation scheduling until
// JVMCI is initialized and indicates it wants to participate.
return false;
}
// Support for graal.CompileGraalWithC1Only
HandleMark hm(thread);
jobject runtime = JVMCIRuntime::get_HotSpotJVMCIRuntime_jobject(CATCH);
objArrayHandle excludeFromJVMCICompilation(thread, HotSpotJVMCIRuntime::excludeFromJVMCICompilation(runtime));
if (excludeFromJVMCICompilation.is_null()) {
return false;
}
ModuleEntry *module = method->method_holder()->module();
for (int i = 0; i < excludeFromJVMCICompilation->length(); ++i) {
if (module->module() == excludeFromJVMCICompilation->obj_at(i)) {
return true;
}
}
return false;
}