8167353: [JVMCI] JVMCI re-initialization check is in the wrong location
authordnsimon
Fri, 07 Oct 2016 15:40:34 -0700
changeset 41690 038f2064e729
parent 41689 ec4a65c134b4
child 41691 1be281ee5de4
8167353: [JVMCI] JVMCI re-initialization check is in the wrong location Reviewed-by: kvn, twisti
hotspot/src/share/vm/classfile/systemDictionary.hpp
hotspot/src/share/vm/jvmci/jvmciRuntime.cpp
hotspot/src/share/vm/jvmci/systemDictionary_jvmci.hpp
hotspot/src/share/vm/jvmci/vmSymbols_jvmci.hpp
--- a/hotspot/src/share/vm/classfile/systemDictionary.hpp	Thu Oct 06 09:36:23 2016 +0000
+++ b/hotspot/src/share/vm/classfile/systemDictionary.hpp	Fri Oct 07 15:40:34 2016 -0700
@@ -226,7 +226,7 @@
     WKID_LIMIT,
 
 #if INCLUDE_JVMCI
-    FIRST_JVMCI_WKID = WK_KLASS_ENUM_NAME(HotSpotCompiledCode_klass),
+    FIRST_JVMCI_WKID = WK_KLASS_ENUM_NAME(JVMCI_klass),
     LAST_JVMCI_WKID  = WK_KLASS_ENUM_NAME(Value_klass),
 #endif
 
--- a/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Thu Oct 06 09:36:23 2016 +0000
+++ b/hotspot/src/share/vm/jvmci/jvmciRuntime.cpp	Fri Oct 07 15:40:34 2016 -0700
@@ -640,8 +640,6 @@
 JVM_END
 
 Handle JVMCIRuntime::callStatic(const char* className, const char* methodName, const char* signature, JavaCallArguments* args, TRAPS) {
-  guarantee(!_HotSpotJVMCIRuntime_initialized, "cannot reinitialize HotSpotJVMCIRuntime");
-
   TempNewSymbol name = SymbolTable::new_symbol(className, CHECK_(Handle()));
   KlassHandle klass = SystemDictionary::resolve_or_fail(name, true, CHECK_(Handle()));
   TempNewSymbol runtime = SymbolTable::new_symbol(methodName, CHECK_(Handle()));
@@ -656,42 +654,37 @@
 }
 
 void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) {
-  if (JNIHandles::resolve(_HotSpotJVMCIRuntime_instance) == NULL) {
-    ResourceMark rm;
-#ifdef ASSERT
-    // This should only be called in the context of the JVMCI class being initialized
-    TempNewSymbol name = SymbolTable::new_symbol("jdk/vm/ci/runtime/JVMCI", CHECK);
-    Klass* k = SystemDictionary::resolve_or_null(name, CHECK);
-    instanceKlassHandle klass = InstanceKlass::cast(k);
-    assert(klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD),
-           "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization");
-#endif
+  guarantee(!_HotSpotJVMCIRuntime_initialized, "cannot reinitialize HotSpotJVMCIRuntime");
+  JVMCIRuntime::initialize_well_known_classes(CHECK);
+  // This should only be called in the context of the JVMCI class being initialized
+  instanceKlassHandle klass = InstanceKlass::cast(SystemDictionary::JVMCI_klass());
+  guarantee(klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD),
+         "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization");
 
-    Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime",
-                               "runtime",
-                               "()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK);
-    objArrayOop trivial_prefixes = HotSpotJVMCIRuntime::trivialPrefixes(result);
-    if (trivial_prefixes != NULL) {
-      char** prefixes = NEW_C_HEAP_ARRAY(char*, trivial_prefixes->length(), mtCompiler);
-      for (int i = 0; i < trivial_prefixes->length(); i++) {
-        oop str = trivial_prefixes->obj_at(i);
-        if (str == NULL) {
-          THROW(vmSymbols::java_lang_NullPointerException());
-        } else {
-          prefixes[i] = strdup(java_lang_String::as_utf8_string(str));
-        }
+  Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime",
+                             "runtime",
+                             "()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK);
+  objArrayOop trivial_prefixes = HotSpotJVMCIRuntime::trivialPrefixes(result);
+  if (trivial_prefixes != NULL) {
+    char** prefixes = NEW_C_HEAP_ARRAY(char*, trivial_prefixes->length(), mtCompiler);
+    for (int i = 0; i < trivial_prefixes->length(); i++) {
+      oop str = trivial_prefixes->obj_at(i);
+      if (str == NULL) {
+        THROW(vmSymbols::java_lang_NullPointerException());
+      } else {
+        prefixes[i] = strdup(java_lang_String::as_utf8_string(str));
       }
-      _trivial_prefixes = prefixes;
-      _trivial_prefixes_count = trivial_prefixes->length();
     }
-    int adjustment = HotSpotJVMCIRuntime::compilationLevelAdjustment(result);
-    assert(adjustment >= JVMCIRuntime::none &&
-           adjustment <= JVMCIRuntime::by_full_signature,
-           "compilation level adjustment out of bounds");
-    _comp_level_adjustment = (CompLevelAdjustment) adjustment;
-    _HotSpotJVMCIRuntime_initialized = true;
-    _HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result());
+    _trivial_prefixes = prefixes;
+    _trivial_prefixes_count = trivial_prefixes->length();
   }
+  int adjustment = HotSpotJVMCIRuntime::compilationLevelAdjustment(result);
+  assert(adjustment >= JVMCIRuntime::none &&
+         adjustment <= JVMCIRuntime::by_full_signature,
+         "compilation level adjustment out of bounds");
+  _comp_level_adjustment = (CompLevelAdjustment) adjustment;
+  _HotSpotJVMCIRuntime_initialized = true;
+  _HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result());
 }
 
 void JVMCIRuntime::initialize_JVMCI(TRAPS) {
--- a/hotspot/src/share/vm/jvmci/systemDictionary_jvmci.hpp	Thu Oct 06 09:36:23 2016 +0000
+++ b/hotspot/src/share/vm/jvmci/systemDictionary_jvmci.hpp	Fri Oct 07 15:40:34 2016 -0700
@@ -29,6 +29,7 @@
 #else
 #define JVMCI_WK_KLASSES_DO(do_klass)                                                                                           \
   /* JVMCI classes. These are loaded on-demand. */                                                                              \
+  do_klass(JVMCI_klass,                                  jdk_vm_ci_runtime_JVMCI,                               Jvmci) \
   do_klass(HotSpotCompiledCode_klass,                    jdk_vm_ci_hotspot_HotSpotCompiledCode,                 Jvmci) \
   do_klass(HotSpotCompiledCode_Comment_klass,            jdk_vm_ci_hotspot_HotSpotCompiledCode_Comment,         Jvmci) \
   do_klass(HotSpotCompiledNmethod_klass,                 jdk_vm_ci_hotspot_HotSpotCompiledNmethod,              Jvmci) \
--- a/hotspot/src/share/vm/jvmci/vmSymbols_jvmci.hpp	Thu Oct 06 09:36:23 2016 +0000
+++ b/hotspot/src/share/vm/jvmci/vmSymbols_jvmci.hpp	Fri Oct 07 15:40:34 2016 -0700
@@ -29,6 +29,7 @@
 #define JVMCI_VM_SYMBOLS_DO(template, do_alias)
 #else
 #define JVMCI_VM_SYMBOLS_DO(template, do_alias)                                                                            \
+  template(jdk_vm_ci_runtime_JVMCI,                               "jdk/vm/ci/runtime/JVMCI")                               \
   template(jdk_vm_ci_hotspot_HotSpotCompiledCode,                 "jdk/vm/ci/hotspot/HotSpotCompiledCode")                 \
   template(jdk_vm_ci_hotspot_HotSpotCompiledCode_Comment,         "jdk/vm/ci/hotspot/HotSpotCompiledCode$Comment")         \
   template(jdk_vm_ci_hotspot_HotSpotCompiledNmethod,              "jdk/vm/ci/hotspot/HotSpotCompiledNmethod")              \