8187315: [JVMCI] hosted use of JVMCI can crash VM under -Xint
authordnsimon
Mon, 06 Nov 2017 21:38:42 +0100
changeset 47796 47629b00daa9
parent 47795 5a69ba3a4fd1
child 47797 d20059c27430
8187315: [JVMCI] hosted use of JVMCI can crash VM under -Xint Reviewed-by: kvn, dlong
src/hotspot/share/jvmci/jvmciCompiler.hpp
src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
src/hotspot/share/jvmci/jvmciRuntime.cpp
src/hotspot/share/prims/jni.cpp
--- a/src/hotspot/share/jvmci/jvmciCompiler.hpp	Mon Nov 06 17:56:29 2017 +0100
+++ b/src/hotspot/share/jvmci/jvmciCompiler.hpp	Mon Nov 06 21:38:42 2017 +0100
@@ -55,10 +55,13 @@
 public:
   JVMCICompiler();
 
-  static JVMCICompiler* instance(TRAPS) {
+  static JVMCICompiler* instance(bool require_non_null, TRAPS) {
     if (!EnableJVMCI) {
       THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVMCI is not enabled")
     }
+    if (_instance == NULL && require_non_null) {
+      THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "The JVMCI compiler instance has not been created");
+    }
     return _instance;
   }
 
--- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Mon Nov 06 17:56:29 2017 +0100
+++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp	Mon Nov 06 21:38:42 2017 +0100
@@ -1018,7 +1018,7 @@
   Handle installed_code_handle(THREAD, JNIHandles::resolve(installed_code));
   Handle speculation_log_handle(THREAD, JNIHandles::resolve(speculation_log));
 
-  JVMCICompiler* compiler = JVMCICompiler::instance(CHECK_JNI_ERR);
+  JVMCICompiler* compiler = JVMCICompiler::instance(true, CHECK_JNI_ERR);
 
   TraceTime install_time("installCode", JVMCICompiler::codeInstallTimer());
   bool is_immutable_PIC = HotSpotCompiledCode::isImmutablePIC(compiled_code_handle) > 0;
@@ -1136,7 +1136,7 @@
 C2V_END
 
 C2V_VMENTRY(void, resetCompilationStatistics, (JNIEnv *jniEnv, jobject))
-  JVMCICompiler* compiler = JVMCICompiler::instance(CHECK);
+  JVMCICompiler* compiler = JVMCICompiler::instance(true, CHECK);
   CompilerStatistics* stats = compiler->stats();
   stats->_standard.reset();
   stats->_osr.reset();
--- a/src/hotspot/share/jvmci/jvmciRuntime.cpp	Mon Nov 06 17:56:29 2017 +0100
+++ b/src/hotspot/share/jvmci/jvmciRuntime.cpp	Mon Nov 06 21:38:42 2017 +0100
@@ -821,7 +821,7 @@
 }
 
 CompLevel JVMCIRuntime::adjust_comp_level_inner(const methodHandle& method, bool is_osr, CompLevel level, JavaThread* thread) {
-  JVMCICompiler* compiler = JVMCICompiler::instance(thread);
+  JVMCICompiler* compiler = JVMCICompiler::instance(false, thread);
   if (compiler != NULL && compiler->is_bootstrapping()) {
     return level;
   }
--- a/src/hotspot/share/prims/jni.cpp	Mon Nov 06 17:56:29 2017 +0100
+++ b/src/hotspot/share/prims/jni.cpp	Mon Nov 06 21:38:42 2017 +0100
@@ -3949,7 +3949,7 @@
         // JVMCI is initialized on a CompilerThread
         if (BootstrapJVMCI) {
           JavaThread* THREAD = thread;
-          JVMCICompiler* compiler = JVMCICompiler::instance(CATCH);
+          JVMCICompiler* compiler = JVMCICompiler::instance(true, CATCH);
           compiler->bootstrap(THREAD);
           if (HAS_PENDING_EXCEPTION) {
             HandleMark hm;