8232118: Add JVM option to enable JVMCI compilers in product mode
authorbobv
Mon, 28 Oct 2019 16:06:08 +0000
changeset 58821 5ec8aeda451e
parent 58819 ef8be51fff48
child 58822 9d95d8a8b750
8232118: Add JVM option to enable JVMCI compilers in product mode Reviewed-by: kvn, dholmes
src/hotspot/share/jvmci/jvmci_globals.cpp
src/hotspot/share/jvmci/jvmci_globals.hpp
src/hotspot/share/runtime/arguments.cpp
src/hotspot/share/runtime/flags/jvmFlag.cpp
src/hotspot/share/runtime/flags/jvmFlag.hpp
--- a/src/hotspot/share/jvmci/jvmci_globals.cpp	Mon Oct 28 11:33:28 2019 -0400
+++ b/src/hotspot/share/jvmci/jvmci_globals.cpp	Mon Oct 28 16:06:08 2019 +0000
@@ -57,6 +57,7 @@
 
   JVMCI_FLAG_CHECKED(UseJVMCICompiler)
   JVMCI_FLAG_CHECKED(EnableJVMCI)
+  JVMCI_FLAG_CHECKED(EnableJVMCIProduct)
 
   CHECK_NOT_SET(BootstrapJVMCI,   UseJVMCICompiler)
   CHECK_NOT_SET(PrintBootstrap,   UseJVMCICompiler)
@@ -64,6 +65,14 @@
   CHECK_NOT_SET(JVMCIHostThreads, UseJVMCICompiler)
 
   if (UseJVMCICompiler) {
+    if (FLAG_IS_DEFAULT(UseJVMCINativeLibrary) && !UseJVMCINativeLibrary) {
+      char path[JVM_MAXPATHLEN];
+      if (os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), JVMCI_SHARED_LIBRARY_NAME)) {
+        // If a JVMCI native library is present,
+        // we enable UseJVMCINativeLibrary by default.
+        FLAG_SET_DEFAULT(UseJVMCINativeLibrary, true);
+      }
+    }
     if (!FLAG_IS_DEFAULT(EnableJVMCI) && !EnableJVMCI) {
       jio_fprintf(defaultStream::error_stream(),
           "Improperly specified VM option UseJVMCICompiler: EnableJVMCI cannot be disabled\n");
@@ -122,6 +131,47 @@
   return true;
 }
 
+// Convert JVMCI flags from experimental to product
+bool JVMCIGlobals::enable_jvmci_product_mode(JVMFlag::Flags origin) {
+  const char *JVMCIFlags[] = {
+    "EnableJVMCI",
+    "EnableJVMCIProduct",
+    "UseJVMCICompiler",
+    "JVMCIPrintProperties",
+    "EagerJVMCI",
+    "JVMCIThreads",
+    "JVMCICounterSize",
+    "JVMCICountersExcludeCompiler",
+    "JVMCINMethodSizeLimit",
+    "JVMCILibPath",
+    "JVMCILibDumpJNIConfig",
+    "UseJVMCINativeLibrary",
+    NULL
+  };
+
+  for (int i = 0; JVMCIFlags[i] != NULL; i++) {
+    JVMFlag *jvmciFlag = (JVMFlag *)JVMFlag::find_declared_flag(JVMCIFlags[i]);
+    if (jvmciFlag == NULL) {
+      return false;
+    }
+    jvmciFlag->clear_experimental();
+    jvmciFlag->set_product();
+  }
+
+  bool value = true;
+  JVMFlag *jvmciEnableFlag = JVMFlag::find_flag("EnableJVMCIProduct");
+  if (JVMFlag::boolAtPut(jvmciEnableFlag, &value, origin) != JVMFlag::SUCCESS) {
+    return false;
+  }
+  value = true;
+  JVMFlag *jvmciCompilerFlag = JVMFlag::find_flag("UseJVMCICompiler");
+  if (JVMFlag::boolAtPut(jvmciCompilerFlag, &value, origin) != JVMFlag::SUCCESS) {
+    return false;
+  }
+
+  return true;
+}
+
 void JVMCIGlobals::check_jvmci_supported_gc() {
   if (EnableJVMCI) {
     // Check if selected GC is supported by JVMCI and Java compiler
--- a/src/hotspot/share/jvmci/jvmci_globals.hpp	Mon Oct 28 11:33:28 2019 -0400
+++ b/src/hotspot/share/jvmci/jvmci_globals.hpp	Mon Oct 28 16:06:08 2019 +0000
@@ -25,6 +25,8 @@
 #ifndef SHARE_JVMCI_JVMCI_GLOBALS_HPP
 #define SHARE_JVMCI_JVMCI_GLOBALS_HPP
 
+#include "runtime/flags/jvmFlag.hpp"
+
 class fileStream;
 
 //
@@ -46,6 +48,9 @@
   experimental(bool, EnableJVMCI, false,                                    \
           "Enable JVMCI")                                                   \
                                                                             \
+  experimental(bool, EnableJVMCIProduct, false,                             \
+          "Allow JVMCI to be used in product mode")                         \
+                                                                            \
   experimental(bool, UseJVMCICompiler, false,                               \
           "Use JVMCI as the default compiler")                              \
                                                                             \
@@ -142,6 +147,9 @@
   // returning false.
   static bool check_jvmci_flags_are_consistent();
 
+  // Convert JVMCI experimental flags to product
+  static bool enable_jvmci_product_mode(JVMFlag::Flags);
+
   // Check and exit VM with error if selected GC is not supported by JVMCI.
   static void check_jvmci_supported_gc();
 
--- a/src/hotspot/share/runtime/arguments.cpp	Mon Oct 28 11:33:28 2019 -0400
+++ b/src/hotspot/share/runtime/arguments.cpp	Mon Oct 28 16:06:08 2019 +0000
@@ -2959,6 +2959,22 @@
           "ManagementServer is not supported in this VM.\n");
         return JNI_ERR;
 #endif // INCLUDE_MANAGEMENT
+#if INCLUDE_JVMCI
+    } else if (match_option(option, "-XX:+EnableJVMCIProduct")) {
+      JVMFlag *jvmciFlag = JVMFlag::find_flag("EnableJVMCIProduct");
+      // Allow this flag if it has been unlocked.
+      if (jvmciFlag != NULL && jvmciFlag->is_unlocked()) {
+        if (!JVMCIGlobals::enable_jvmci_product_mode(origin)) {
+          jio_fprintf(defaultStream::error_stream(),
+            "Unable to enable JVMCI in product mode");
+          return JNI_ERR;
+        }
+      }
+      // The flag was locked so process normally to report that error
+      else if (!process_argument("EnableJVMCIProduct", args->ignoreUnrecognized, origin)) {
+        return JNI_EINVAL;
+      }
+#endif // INCLUDE_JVMCI
 #if INCLUDE_JFR
     } else if (match_jfr_option(&option)) {
       return JNI_EINVAL;
--- a/src/hotspot/share/runtime/flags/jvmFlag.cpp	Mon Oct 28 11:33:28 2019 -0400
+++ b/src/hotspot/share/runtime/flags/jvmFlag.cpp	Mon Oct 28 16:06:08 2019 +0000
@@ -359,6 +359,18 @@
   assert(!is_diagnostic(), "sanity");
 }
 
+void JVMFlag::clear_experimental() {
+  assert(is_experimental(), "sanity");
+ _flags = Flags(_flags & ~KIND_EXPERIMENTAL);
+  assert(!is_experimental(), "sanity");
+}
+
+void JVMFlag::set_product() {
+  assert(!is_product(), "sanity");
+ _flags = Flags(_flags | KIND_PRODUCT);
+  assert(is_product(), "sanity");
+}
+
 // Get custom message for this locked flag, or NULL if
 // none is available. Returns message type produced.
 JVMFlag::MsgType JVMFlag::get_locked_message(char* buf, int buflen) const {
--- a/src/hotspot/share/runtime/flags/jvmFlag.hpp	Mon Oct 28 11:33:28 2019 -0400
+++ b/src/hotspot/share/runtime/flags/jvmFlag.hpp	Mon Oct 28 16:06:08 2019 +0000
@@ -207,6 +207,8 @@
   bool is_external() const;
 
   void clear_diagnostic();
+  void clear_experimental();
+  void set_product();
 
   JVMFlag::MsgType get_locked_message(char*, int) const;
   JVMFlag::MsgType get_locked_message_ext(char*, int) const;