changeset 57364:56aa1c3b8659

8235539: [JVMCI] -XX:+EnableJVMCIProduct breaks -XX:-EnableJVMCI Reviewed-by: kvn, thartmann
author dnsimon
date Tue, 10 Dec 2019 09:34:33 -0800
parents daf317439415
children 8375c9115e6d
files src/hotspot/share/jvmci/jvmci_globals.cpp src/hotspot/share/jvmci/jvmci_globals.hpp src/hotspot/share/runtime/arguments.cpp test/hotspot/jtreg/compiler/jvmci/TestEnableJVMCIProduct.java
diffstat 4 files changed, 103 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/jvmci/jvmci_globals.cpp	Tue Dec 10 09:31:40 2019 -0800
+++ b/src/hotspot/share/jvmci/jvmci_globals.cpp	Tue Dec 10 09:34:33 2019 -0800
@@ -55,6 +55,15 @@
     return false;                                      \
   }
 
+  if (EnableJVMCIProduct) {
+    if (FLAG_IS_DEFAULT(EnableJVMCI)) {
+      FLAG_SET_DEFAULT(EnableJVMCI, true);
+    }
+    if (EnableJVMCI && FLAG_IS_DEFAULT(UseJVMCICompiler)) {
+      FLAG_SET_DEFAULT(UseJVMCICompiler, true);
+    }
+  }
+
   JVMCI_FLAG_CHECKED(UseJVMCICompiler)
   JVMCI_FLAG_CHECKED(EnableJVMCI)
   JVMCI_FLAG_CHECKED(EnableJVMCIProduct)
@@ -163,11 +172,11 @@
   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;
-  }
+
+  // Effect of EnableJVMCIProduct on changing defaults of EnableJVMCI
+  // and UseJVMCICompiler is deferred to check_jvmci_flags_are_consistent
+  // so that setting these flags explicitly (e.g. on the command line)
+  // takes precedence.
 
   return true;
 }
--- a/src/hotspot/share/jvmci/jvmci_globals.hpp	Tue Dec 10 09:31:40 2019 -0800
+++ b/src/hotspot/share/jvmci/jvmci_globals.hpp	Tue Dec 10 09:34:33 2019 -0800
@@ -51,8 +51,8 @@
   experimental(bool, EnableJVMCIProduct, false,                             \
           "Allow JVMCI to be used in product mode. This alters a subset of "\
           "JVMCI flags to be non-experimental, defaults UseJVMCICompiler "  \
-          "to true and defaults UseJVMCINativeLibrary to true if a JVMCI "  \
-          "native library is available.")                                   \
+          "and EnableJVMCI to true and defaults UseJVMCINativeLibrary "     \
+          "to true if a JVMCI native library is available.")                \
                                                                             \
   experimental(bool, UseJVMCICompiler, false,                               \
           "Use JVMCI as the default compiler. Defaults to true if "         \
@@ -122,7 +122,7 @@
           "Execute JVMCI Java code from a shared library "                  \
           "instead of loading it from class files and executing it "        \
           "on the HotSpot heap. Defaults to true if EnableJVMCIProduct is " \
-          "true and a JVMCI native library is available.")\
+          "true and a JVMCI native library is available.")                  \
                                                                             \
   NOT_COMPILER2(diagnostic(bool, UseMultiplyToLenIntrinsic, false,          \
           "Enables intrinsification of BigInteger.multiplyToLen()"))        \
--- a/src/hotspot/share/runtime/arguments.cpp	Tue Dec 10 09:31:40 2019 -0800
+++ b/src/hotspot/share/runtime/arguments.cpp	Tue Dec 10 09:34:33 2019 -0800
@@ -3037,6 +3037,12 @@
         return JNI_ERR;
 #endif // INCLUDE_MANAGEMENT
 #if INCLUDE_JVMCI
+    } else if (match_option(option, "-XX:-EnableJVMCIProduct")) {
+      if (EnableJVMCIProduct) {
+        jio_fprintf(defaultStream::error_stream(),
+                  "-XX:-EnableJVMCIProduct cannot come after -XX:+EnableJVMCIProduct\n");
+        return JNI_EINVAL;
+      }
     } else if (match_option(option, "-XX:+EnableJVMCIProduct")) {
       JVMFlag *jvmciFlag = JVMFlag::find_flag("EnableJVMCIProduct");
       // Allow this flag if it has been unlocked.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/jvmci/TestEnableJVMCIProduct.java	Tue Dec 10 09:34:33 2019 -0800
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8235539
+ * @summary Tests effect of -XX:+EnableJVMCIProduct on EnableJVMCI and UseJVMCICompiler
+ * @requires vm.jvmci
+ * @library /test/lib
+ */
+
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+
+public class TestEnableJVMCIProduct {
+
+    static class Expectation {
+        final String name;
+        final String value;
+        final String origin;
+        final String pattern;
+        Expectation(final String name, String value, String origin) {
+            this.name = name;
+            this.value = value;
+            this.origin = origin;
+            this.pattern = "bool +" + name + " += " + value + " +\\{JVMCI product\\} \\{" + origin + "\\}";
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        // Test EnableJVMCIProduct without any other explicit JVMCI option
+        test("-XX:-PrintWarnings",
+            new Expectation("EnableJVMCI", "true", "default"),
+            new Expectation("UseJVMCICompiler", "true", "default"));
+        test("-XX:+UseJVMCICompiler",
+            new Expectation("EnableJVMCI", "true", "default"),
+            new Expectation("UseJVMCICompiler", "true", "command line"));
+        test("-XX:-UseJVMCICompiler",
+            new Expectation("EnableJVMCI", "true", "default"),
+            new Expectation("UseJVMCICompiler", "false", "command line"));
+        test("-XX:+EnableJVMCI",
+            new Expectation("EnableJVMCI", "true", "command line"),
+            new Expectation("UseJVMCICompiler", "true", "default"));
+        test("-XX:-EnableJVMCI",
+            new Expectation("EnableJVMCI", "false", "command line"),
+            new Expectation("UseJVMCICompiler", "false", "default"));
+    }
+
+    static void test(String explicitFlag, Expectation... expectations) throws Exception {
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            "-XX:+UnlockExperimentalVMOptions", "-XX:+EnableJVMCIProduct", "-XX:-UnlockExperimentalVMOptions",
+            explicitFlag,
+            "-XX:+PrintFlagsFinal", "-version");
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        for (Expectation expectation : expectations) {
+            output.stdoutShouldMatch(expectation.pattern);
+        }
+        output.shouldHaveExitValue(0);
+    }
+}