changeset 22734:ab84ba890aa4

8142511: must eagerly initialize classes with static fields accessed by JVMCI native code
author Doug Simon <doug.simon@oracle.com>
date Thu, 12 Nov 2015 21:35:35 +0100
parents 732763293625
children c2b84783a4a4
files src/share/vm/jvmci/jvmciCompiler.cpp src/share/vm/jvmci/jvmciJavaClasses.cpp src/share/vm/jvmci/jvmciJavaClasses.hpp src/share/vm/jvmci/jvmciRuntime.cpp
diffstat 4 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/jvmci/jvmciCompiler.cpp	Thu Nov 12 20:03:43 2015 +0100
+++ b/src/share/vm/jvmci/jvmciCompiler.cpp	Thu Nov 12 21:35:35 2015 +0100
@@ -127,7 +127,7 @@
   }
 
   JVMCIRuntime::ensure_jvmci_class_loader_is_initialized();
-  jvmci_compute_offsets();
+  jvmci_compute_offsets(THREAD);
   HandleMark hm;
   ResourceMark rm;
   Handle receiver = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK_ABORT);
--- a/src/share/vm/jvmci/jvmciJavaClasses.cpp	Thu Nov 12 20:03:43 2015 +0100
+++ b/src/share/vm/jvmci/jvmciJavaClasses.cpp	Thu Nov 12 21:35:35 2015 +0100
@@ -22,13 +22,15 @@
  */
 
 #include "precompiled.hpp"
+#include "utilities/exceptions.hpp"
 #include "jvmci/jvmciJavaClasses.hpp"
 #include "runtime/jniHandles.hpp"
 #include "classfile/symbolTable.hpp"
+
 // This function is similar to javaClasses.cpp, it computes the field offset of a (static or instance) field.
 // It looks up the name and signature symbols without creating new ones, all the symbols of these classes need to be already loaded.
 
-void compute_offset(int &dest_offset, Klass* klass, const char* name, const char* signature, bool static_field) {
+void compute_offset(int &dest_offset, Klass* klass, const char* name, const char* signature, bool static_field, TRAPS) {
   InstanceKlass* ik = InstanceKlass::cast(klass);
   Symbol* name_symbol = SymbolTable::probe(name, (int)strlen(name));
   Symbol* signature_symbol = SymbolTable::probe(signature, (int)strlen(signature));
@@ -47,6 +49,11 @@
   guarantee(fd.is_static() == static_field, "static/instance mismatch");
   dest_offset = fd.offset();
   assert(dest_offset != 0, "must be valid offset");
+  if (static_field) {
+    // Must ensure classes for static fields are initialized as the
+    // accessor itself does not include a class initialization check.
+    ik->initialize(CHECK);
+  }
 }
 
 // This piece of macro magic creates the contents of the jvmci_compute_offsets method that initializes the field indices of all the access classes.
@@ -55,7 +62,7 @@
 
 #define END_CLASS }
 
-#define FIELD(klass, name, signature, static_field) compute_offset(klass::_##name##_offset, k, #name, signature, static_field);
+#define FIELD(klass, name, signature, static_field) compute_offset(klass::_##name##_offset, k, #name, signature, static_field, CHECK);
 #define CHAR_FIELD(klass, name) FIELD(klass, name, "C", false)
 #define INT_FIELD(klass, name) FIELD(klass, name, "I", false)
 #define BOOLEAN_FIELD(klass, name) FIELD(klass, name, "Z", false)
@@ -67,7 +74,7 @@
 #define STATIC_BOOLEAN_FIELD(klass, name) FIELD(klass, name, "Z", true)
 
 
-void jvmci_compute_offsets() {
+void jvmci_compute_offsets(TRAPS) {
   COMPILER_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, FLOAT_FIELD, OOP_FIELD, OOP_FIELD, OOP_FIELD, STATIC_OOP_FIELD, STATIC_OOP_FIELD, STATIC_INT_FIELD, STATIC_BOOLEAN_FIELD)
 }
 
--- a/src/share/vm/jvmci/jvmciJavaClasses.hpp	Thu Nov 12 20:03:43 2015 +0100
+++ b/src/share/vm/jvmci/jvmciJavaClasses.hpp	Thu Nov 12 21:35:35 2015 +0100
@@ -24,7 +24,7 @@
 #ifndef SHARE_VM_JVMCI_JVMCIJAVACLASSES_HPP
 #define SHARE_VM_JVMCI_JVMCIJAVACLASSES_HPP
 
-void jvmci_compute_offsets();
+void jvmci_compute_offsets(TRAPS);
 
 #include "classfile/systemDictionary.hpp"
 #include "oops/instanceMirrorKlass.hpp"
@@ -372,6 +372,6 @@
 #undef STATIC_BOOLEAN_FIELD
 #undef EMPTY_CAST
 
-void compute_offset(int &dest_offset, Klass* klass, const char* name, const char* signature, bool static_field);
+void compute_offset(int &dest_offset, Klass* klass, const char* name, const char* signature, bool static_field, TRAPS);
 
 #endif // SHARE_VM_JVMCI_JVMCIJAVACLASSES_HPP
--- a/src/share/vm/jvmci/jvmciRuntime.cpp	Thu Nov 12 20:03:43 2015 +0100
+++ b/src/share/vm/jvmci/jvmciRuntime.cpp	Thu Nov 12 21:35:35 2015 +0100
@@ -808,7 +808,7 @@
     ResourceMark rm;
     HandleMark hm;
 
-    jvmci_compute_offsets();
+    jvmci_compute_offsets(thread);
 
     // Ensure _non_oop_bits is initialized
     Universe::non_oop_word();
@@ -945,7 +945,7 @@
       const char* name = p->key() + OPTION_PREFIX_LEN;
       if (strcmp(name, "PrintFlags") == 0 || strcmp(name, "ShowFlags") == 0) {
         JVMCIRuntime::ensure_jvmci_class_loader_is_initialized();
-        jvmci_compute_offsets();
+        jvmci_compute_offsets(THREAD);
         HandleMark hm;
         ResourceMark rm;
         JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK);