changeset 24143:15ab3e226b0d

set +UseJVMCICompiler ergonomically if jvmci.class.path.append is defined or there is at least one jar file in jre/lib/jvmci apart from the JVMCI API jars
author Doug Simon <doug.simon@oracle.com>
date Thu, 15 Jun 2017 01:01:04 +0200
parents 96668c601751
children b0077339d77e
files jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/JVMCIClassLoaderFactory.java mx.jvmci/mx_jvmci.py src/share/vm/jvmci/jvmci_globals.cpp src/share/vm/jvmci/jvmci_globals.hpp src/share/vm/runtime/arguments.cpp
diffstat 5 files changed, 94 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/JVMCIClassLoaderFactory.java	Wed Jun 14 20:27:54 2017 +0200
+++ b/jvmci/jdk.vm.ci.services/src/jdk/vm/ci/services/JVMCIClassLoaderFactory.java	Thu Jun 15 01:01:04 2017 +0200
@@ -37,9 +37,10 @@
 
 /**
  * Utility called from the VM to create and register a separate class loader for loading JVMCI
- * classes (i.e., those in found in {@code <java.home>/lib/jvmci/*.jar)} as well as those available
- * on the class path in the {@code "jvmci.class.path.append"} system property. The JVMCI class
- * loader can optionally be given a parent other than the boot class loader as specified by
+ * classes. The core JVMCI classes are in {@code lib/jvmci/jvmci-api.jar} and
+ * {@code lib/jvmci/jvmci-hotspot.jar}. The JVMCI compiler classes are in {@code lib/jvmci/*.jar)}
+ * and the class path specified by the {@code "jvmci.class.path.append"} system property. The JVMCI
+ * class loader can optionally be given a parent other than the boot class loader as specified by
  * {@link #getJVMCIParentClassLoader(Path)}.
  */
 class JVMCIClassLoaderFactory {
@@ -107,7 +108,7 @@
                         }
                         throw new InternalError(errorMsg);
                     }
-                    urls[i] = path.toFile().toURI().toURL();
+                    urls[i] = path.toUri().toURL();
                 } catch (MalformedURLException e) {
                     throw new InternalError(e);
                 }
@@ -118,36 +119,48 @@
         return null;
     }
 
+    private static Path ensureExists(Path path) {
+        if (!Files.exists(path)) {
+            throw new InternalError("Required JVMCI jar is missing: " + path);
+        }
+        return path;
+    }
+
     /**
-     * Gets the URLs for all jar files in the {@code jvmciDir} directory as well as the entries
-     * specified by the {@code "jvmci.class.path.append"} system property.
+     * Gets the URLs for the required JVMCI jars, all the other jar files in the {@code jvmciDir}
+     * directory and the entries specified by the {@code "jvmci.class.path.append"} system property.
      */
     private static URL[] getJVMCIJarsUrls(Path jvmciDir) {
         String[] dirEntries = jvmciDir.toFile().list();
-
         String append = VM.getSavedProperty("jvmci.class.path.append");
         String[] appendEntries = append != null ? append.split(File.pathSeparator) : new String[0];
         List<URL> urls = new ArrayList<>(dirEntries.length + appendEntries.length);
 
-        for (String fileName : dirEntries) {
-            if (fileName.endsWith(".jar")) {
-                Path path = jvmciDir.resolve(fileName);
-                if (Files.isDirectory(path)) {
-                    continue;
-                }
-                try {
-                    urls.add(path.toFile().toURI().toURL());
-                } catch (MalformedURLException e) {
-                    throw new InternalError(e);
+        try {
+            urls.add(ensureExists(jvmciDir.resolve("jvmci-api.jar")).toUri().toURL());
+            urls.add(ensureExists(jvmciDir.resolve("jvmci-hotspot.jar")).toUri().toURL());
+
+            for (String e : dirEntries) {
+                if (e.endsWith(".jar")) {
+                    if (!e.equals("jvmci-api.jar") && !e.equals("jvmci-hotspot.jar")) {
+                        urls.add(jvmciDir.resolve(e).toUri().toURL());
+                    }
                 }
             }
-        }
-        for (String path : appendEntries) {
-            try {
-                urls.add(new File(path).toURI().toURL());
-            } catch (MalformedURLException e) {
-                throw new InternalError(e);
+            for (int i = 0; i < appendEntries.length; ++i) {
+                Path path = Paths.get(appendEntries[i]);
+                if (!Files.exists(path)) {
+                    // Unlike the user class path, be strict about this class
+                    // path only referring to existing locations.
+                    String errorMsg = "Entry " + i + " of class path specified by jvmci.class.path.append " +
+                                    "system property refers to a file or directory that does not exist: \"" +
+                                    appendEntries[i] + "\"";
+                    throw new InternalError(errorMsg);
+                }
+                urls.add(path.toUri().toURL());
             }
+        } catch (MalformedURLException e) {
+            throw new InternalError(e);
         }
 
         return urls.toArray(new URL[urls.size()]);
--- a/mx.jvmci/mx_jvmci.py	Wed Jun 14 20:27:54 2017 +0200
+++ b/mx.jvmci/mx_jvmci.py	Thu Jun 15 01:01:04 2017 +0200
@@ -143,13 +143,6 @@
     def deploy(self, jdkDir):
         self._copyToJdk(jdkDir, self.targetDir())
 
-class ExtJDKDeployedDist(JarJDKDeployedDist):
-    def __init__(self, name):
-        JarJDKDeployedDist.__init__(self, name)
-
-    def targetDir(self):
-        return join('jre', 'lib', 'ext')
-
 class LibJDKDeployedDist(JarJDKDeployedDist):
     def __init__(self, name):
         JarJDKDeployedDist.__init__(self, name)
--- a/src/share/vm/jvmci/jvmci_globals.cpp	Wed Jun 14 20:27:54 2017 +0200
+++ b/src/share/vm/jvmci/jvmci_globals.cpp	Thu Jun 15 01:01:04 2017 +0200
@@ -26,6 +26,22 @@
 #include "jvmci/jvmci_globals.hpp"
 #include "utilities/defaultStream.hpp"
 #include "runtime/globals_extension.hpp"
+#include "runtime/arguments.hpp"
+#ifdef TARGET_OS_FAMILY_linux
+# include "os_linux.inline.hpp"
+#endif
+#ifdef TARGET_OS_FAMILY_solaris
+# include "os_solaris.inline.hpp"
+#endif
+#ifdef TARGET_OS_FAMILY_windows
+# include "os_windows.inline.hpp"
+#endif
+#ifdef TARGET_OS_FAMILY_aix
+# include "os_aix.inline.hpp"
+#endif
+#ifdef TARGET_OS_FAMILY_bsd
+# include "os_bsd.inline.hpp"
+#endif
 
 JVMCI_FLAGS(MATERIALIZE_DEVELOPER_FLAG, MATERIALIZE_PD_DEVELOPER_FLAG, MATERIALIZE_PRODUCT_FLAG, MATERIALIZE_PD_PRODUCT_FLAG, MATERIALIZE_NOTPRODUCT_FLAG)
 
@@ -101,6 +117,39 @@
 }
 
 void JVMCIGlobals::set_jvmci_specific_flags() {
+  if (FLAG_IS_DEFAULT(UseJVMCICompiler) && !UseJVMCICompiler) {
+    if (Arguments::get_property("jvmci.class.path.append") != NULL) {
+      // If jvmci.class.path.append is defined then
+      // assume there is a JVMCI compiler.
+      FLAG_SET_ERGO(bool, UseJVMCICompiler, true);
+    } else {
+      // If lib/jvmci contains at least one jar apart from
+      // jvmci-api.jar and jvmci-hotspot.jar, then
+      // assume there is a JVMCI compiler.
+      char jvmciDir[JVM_MAXPATHLEN];
+      const char* fileSep = os::file_separator();
+      jio_snprintf(jvmciDir, sizeof(jvmciDir), "%s%slib%sjvmci", Arguments::get_java_home(), fileSep, fileSep);
+      DIR* dir = os::opendir(jvmciDir);
+      if (dir != NULL) {
+        /* Scan the directory for jars */
+        struct dirent *entry;
+        char *dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(jvmciDir), mtInternal);
+        while ((entry = os::readdir(dir, (dirent *) dbuf)) != NULL) {
+          const char* name = entry->d_name;
+          const char* ext = name + strlen(name) - 4;
+          if (ext > name && os::file_name_strcmp(ext, ".jar") == 0) {
+            if (strcmp(name, "jvmci-api.jar") != 0 && strcmp(name, "jvmci-hotspot.jar") != 0) {
+              FLAG_SET_ERGO(bool, UseJVMCICompiler, true);
+              break;
+            }
+          }
+        }
+        FREE_C_HEAP_ARRAY(char, dbuf, mtInternal);
+        os::closedir(dir);
+      }
+    }
+  }
+
   if (UseJVMCICompiler) {
     if (FLAG_IS_DEFAULT(TypeProfileWidth)) {
       FLAG_SET_DEFAULT(TypeProfileWidth, 8);
--- a/src/share/vm/jvmci/jvmci_globals.hpp	Wed Jun 14 20:27:54 2017 +0200
+++ b/src/share/vm/jvmci/jvmci_globals.hpp	Thu Jun 15 01:01:04 2017 +0200
@@ -49,8 +49,10 @@
   product(bool, EnableJVMCI, true,                                          \
           "Enable JVMCI")                                                   \
                                                                             \
-  product(bool, UseJVMCICompiler, true,                                     \
-          "Use JVMCI as the default compiler")                              \
+  product(bool, UseJVMCICompiler, false,                                    \
+          "Use JVMCI as the default compiler. Ergonomically set to "        \
+          "true if non-core JVMCI jars are in jre/lib/jvmci/ or the "       \
+          "jvmci.class.path.append system property is defined.")            \
                                                                             \
   product(bool, JVMCIPrintProperties, false,                                \
           "Prints properties used by the JVMCI compiler and exits")         \
--- a/src/share/vm/runtime/arguments.cpp	Wed Jun 14 20:27:54 2017 +0200
+++ b/src/share/vm/runtime/arguments.cpp	Thu Jun 15 01:01:04 2017 +0200
@@ -3575,10 +3575,10 @@
 
 #if INCLUDE_JVMCI
   // Append lib/boot/*.jar to boot class path
-  char bootDir[JVM_MAXPATHLEN];
+  char pathBuffer[JVM_MAXPATHLEN];
   const char* fileSep = os::file_separator();
-  jio_snprintf(bootDir, sizeof(bootDir), "%s%slib%sboot", Arguments::get_java_home(), fileSep, fileSep);
-  char* boot_suffix_path = SysClassPath::add_jars_to_path(NULL, bootDir);
+  jio_snprintf(pathBuffer, sizeof(pathBuffer), "%s%slib%sboot", Arguments::get_java_home(), fileSep, fileSep);
+  char* boot_suffix_path = SysClassPath::add_jars_to_path(NULL, pathBuffer);
   if (boot_suffix_path != NULL) {
     scp_p->add_suffix(boot_suffix_path);
     scp_assembly_required = true;
@@ -3586,10 +3586,8 @@
 
   if (!UseJVMCIClassLoader) {
     // Append lib/jvmci/*.jar to boot class path
-    char jvmciDir[JVM_MAXPATHLEN];
-    const char* fileSep = os::file_separator();
-    jio_snprintf(jvmciDir, sizeof(jvmciDir), "%s%slib%sjvmci", Arguments::get_java_home(), fileSep, fileSep);
-    char* jvmci_path = SysClassPath::add_jars_to_path(NULL, jvmciDir);
+    jio_snprintf(pathBuffer, sizeof(pathBuffer), "%s%slib%sjvmci", Arguments::get_java_home(), fileSep, fileSep);
+    char* jvmci_path = SysClassPath::add_jars_to_path(NULL, pathBuffer);
     if (jvmci_path != NULL) {
       scp_p->add_suffix(jvmci_path);
       scp_assembly_required = true;