changeset 23777:6c8eaf47db9a

added -XX:+JVMCIPrintFlags to support printing of JVMCI flags without having to know how to trigger JVMCI initialization
author Doug Simon <doug.simon@oracle.com>
date Tue, 04 Oct 2016 22:14:32 +0200
parents 450e0bafd83d
children a2051f3fe76b
files jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java jvmci/jdk.vm.ci.runtime/src/jdk/vm/ci/runtime/services/JVMCICompilerFactory.java src/share/vm/compiler/compileBroker.cpp src/share/vm/jvmci/jvmci_globals.cpp src/share/vm/jvmci/jvmci_globals.hpp
diffstat 5 files changed, 65 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java	Tue Oct 04 22:02:07 2016 +0200
+++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotJVMCIRuntime.java	Tue Oct 04 22:14:32 2016 +0200
@@ -89,14 +89,17 @@
      * A list of all supported JVMCI options.
      */
     public enum Option {
+        // @formatter:off
         Compiler(String.class, null, "Selects the system compiler."),
         // Note: The following one is not used (see InitTimer.ENABLED). It is added here
-        // so that -Djvmci.PrintFlags=true shows the option.
-        InitTimer(boolean.class, false, "Specifies if initialization timing is enabled."),
-        PrintConfig(boolean.class, false, "Prints VM configuration available via JVMCI and exits."),
-        PrintFlags(boolean.class, false, "Prints all JVMCI flags and exits."),
-        ShowFlags(boolean.class, false, "Prints all JVMCI flags and continues."),
-        TraceMethodDataFilter(String.class, null, "");
+        // so that -XX:JVMCIPrintFlags shows the option.
+        InitTimer(Boolean.class, false, "Specifies if initialization timing is enabled."),
+        PrintConfig(Boolean.class, false, "Prints VM configuration available via JVMCI and exits."),
+        TraceMethodDataFilter(String.class, null,
+                        "Enables tracing of profiling info when read by JVMCI.",
+                        "Empty value: trace all methods",
+                        "Non-empty value: trace methods whose fully qualified name contains the value.");
+        // @formatter:on
 
         /**
          * The prefix for system properties that are JVMCI options.
@@ -112,14 +115,14 @@
         private Object value;
         private final Object defaultValue;
         private boolean isDefault;
-        private final String help;
+        private final String[] helpLines;
 
-        Option(Class<?> type, Object defaultValue, String help) {
+        Option(Class<?> type, Object defaultValue, String... helpLines) {
             assert Character.isUpperCase(name().charAt(0)) : "Option name must start with upper-case letter: " + name();
             this.type = type;
             this.value = UNINITIALIZED;
             this.defaultValue = defaultValue;
-            this.help = help;
+            this.helpLines = helpLines;
         }
 
         @SuppressFBWarnings(value = "ES_COMPARING_STRINGS_WITH_EQ", justification = "sentinel must be String since it's a static final in an enum")
@@ -130,7 +133,7 @@
                     this.value = defaultValue;
                     this.isDefault = true;
                 } else {
-                    if (type == boolean.class) {
+                    if (type == Boolean.class) {
                         this.value = Boolean.parseBoolean(propertyValue);
                     } else if (type == String.class) {
                         this.value = propertyValue;
@@ -169,11 +172,26 @@
          * @param out stream to print to
          */
         public static void printFlags(PrintStream out) {
-            out.println("[List of JVMCI options]");
-            for (Option option : values()) {
+            out.println("[List of JVMCI options. Set with \"jvmci.\" prefixed system property (e.g., -Djvmci." + InitTimer.name() + "=true)");
+            int typeWidth = 0;
+            int nameWidth = 0;
+            Option[] values = values();
+            for (Option option : values) {
+                typeWidth = Math.max(typeWidth, option.type.getSimpleName().length());
+                nameWidth = Math.max(nameWidth, option.name().length());
+            }
+            for (Option option : values) {
                 Object value = option.getValue();
-                String assign = option.isDefault ? ":=" : " =";
-                out.printf("%9s %-40s %s %-14s %s%n", option.type.getSimpleName(), option, assign, value, option.help);
+                if (value instanceof String) {
+                    value = '"' + String.valueOf(value) + '"';
+                }
+                String assign = option.isDefault ? " =" : ":=";
+                String format = "%" + (typeWidth + 1) + "s %-" + (nameWidth + 1) + "s %s %s%n";
+                out.printf(format, option.type.getSimpleName(), option.name(), assign, value);
+                String helpFormat = "%" + (typeWidth + 1) + "s %s%n";
+                for (String line : option.helpLines) {
+                    out.printf(helpFormat, "", line);
+                }
             }
         }
     }
@@ -260,20 +278,6 @@
 
         metaAccessContext = new HotSpotJVMCIMetaAccessContext();
 
-        boolean printFlags = Option.PrintFlags.getBoolean();
-        boolean showFlags = Option.ShowFlags.getBoolean();
-        if (printFlags || showFlags) {
-            Option.printFlags(System.out);
-            if (printFlags) {
-                System.exit(0);
-            }
-        }
-
-        if (Option.PrintConfig.getBoolean()) {
-            printConfig(configStore, compilerToVm);
-            System.exit(0);
-        }
-
         compilerFactory = HotSpotJVMCICompilerConfig.getCompilerFactory();
         if (compilerFactory instanceof HotSpotJVMCICompilerFactory) {
             hsCompilerFactory = (HotSpotJVMCICompilerFactory) compilerFactory;
@@ -297,6 +301,18 @@
             trivialPrefixes = null;
             compilationLevelAdjustment = config.compLevelAdjustmentNone;
         }
+
+        if (config.getFlag("JVMCIPrintFlags", Boolean.class)) {
+            PrintStream out = new PrintStream(getLogStream());
+            Option.printFlags(out);
+            compilerFactory.printFlags(out);
+            System.exit(0);
+        }
+
+        if (Option.PrintConfig.getBoolean()) {
+            printConfig(configStore, compilerToVm);
+            System.exit(0);
+        }
     }
 
     private JVMCIBackend registerBackend(JVMCIBackend backend) {
--- a/jvmci/jdk.vm.ci.runtime/src/jdk/vm/ci/runtime/services/JVMCICompilerFactory.java	Tue Oct 04 22:02:07 2016 +0200
+++ b/jvmci/jdk.vm.ci.runtime/src/jdk/vm/ci/runtime/services/JVMCICompilerFactory.java	Tue Oct 04 22:14:32 2016 +0200
@@ -22,6 +22,8 @@
  */
 package jdk.vm.ci.runtime.services;
 
+import java.io.PrintStream;
+
 import jdk.vm.ci.runtime.JVMCICompiler;
 import jdk.vm.ci.runtime.JVMCIRuntime;
 import jdk.vm.ci.services.JVMCIPermission;
@@ -70,4 +72,12 @@
      * Create a new instance of a {@link JVMCICompiler}.
      */
     public abstract JVMCICompiler createCompiler(JVMCIRuntime runtime);
+
+    /**
+     * Prints a help message describing the flags supported by this compiler and how to set them.
+     *
+     * @param out where to print the message
+     */
+    public void printFlags(PrintStream out) {
+    }
 }
--- a/src/share/vm/compiler/compileBroker.cpp	Tue Oct 04 22:02:07 2016 +0200
+++ b/src/share/vm/compiler/compileBroker.cpp	Tue Oct 04 22:14:32 2016 +0200
@@ -944,6 +944,13 @@
 #if INCLUDE_JVMCI
   if (EnableJVMCI) {
     JVMCICompiler* jvmci = new JVMCICompiler();
+    if (JVMCIPrintFlags) {
+      // Initialize JVMCI eagerly if JVMCIPrintFlags is enabled.
+      // The JVMCI Java initialization code will read this flag and
+      // do the printing if it's set.
+      JVMCIRuntime::ensure_jvmci_class_loader_is_initialized();
+      JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK);
+    }
     if (UseJVMCICompiler) {
       _compilers[1] = jvmci;
       if (FLAG_IS_DEFAULT(JVMCIThreads)) {
--- a/src/share/vm/jvmci/jvmci_globals.cpp	Tue Oct 04 22:02:07 2016 +0200
+++ b/src/share/vm/jvmci/jvmci_globals.cpp	Tue Oct 04 22:14:32 2016 +0200
@@ -74,6 +74,7 @@
   CHECK_NOT_SET(JVMCIUseFastLocking,          EnableJVMCI)
   CHECK_NOT_SET(JVMCINMethodSizeLimit,        EnableJVMCI)
   CHECK_NOT_SET(MethodProfileWidth,           EnableJVMCI)
+  CHECK_NOT_SET(JVMCIPrintFlags,              EnableJVMCI)
   CHECK_NOT_SET(TraceUncollectedSpeculations, EnableJVMCI)
 
 #ifndef PRODUCT
--- a/src/share/vm/jvmci/jvmci_globals.hpp	Tue Oct 04 22:02:07 2016 +0200
+++ b/src/share/vm/jvmci/jvmci_globals.hpp	Tue Oct 04 22:14:32 2016 +0200
@@ -52,6 +52,9 @@
   product(bool, UseJVMCICompiler, false,                                    \
           "Use JVMCI as the default compiler")                              \
                                                                             \
+  product(bool, JVMCIPrintFlags, false,                                     \
+          "Prints flags defined by the JVMCI compiler")                     \
+                                                                            \
   product(bool, UseJVMCIClassLoader, true,                                  \
           "Load JVMCI classes with separate class loader")                  \
                                                                             \