changeset 60702:f37cc2bd2ebf

8241486: G1/Z give warning when using LoopStripMiningIter and turn off LoopStripMiningIter (0) Reviewed-by: thartmann, kvn
author roland
date Fri, 21 Aug 2020 17:41:57 +0200
parents 986d7d26f9fe
children e3b80847346f
files src/hotspot/share/compiler/compilerDefinitions.cpp src/hotspot/share/opto/c2_globals.hpp src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.hpp test/hotspot/jtreg/compiler/loopstripmining/TestNoWarningLoopStripMiningIterSet.java
diffstat 5 files changed, 99 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/compiler/compilerDefinitions.cpp	Thu Aug 27 10:57:13 2020 +0100
+++ b/src/hotspot/share/compiler/compilerDefinitions.cpp	Fri Aug 21 17:41:57 2020 +0200
@@ -403,17 +403,6 @@
     }
     FLAG_SET_CMDLINE(PostLoopMultiversioning, false);
   }
-  if (UseCountedLoopSafepoints && LoopStripMiningIter == 0) {
-    if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {
-      warning("When counted loop safepoints are enabled, LoopStripMiningIter must be at least 1 (a safepoint every 1 iteration): setting it to 1");
-    }
-    LoopStripMiningIter = 1;
-  } else if (!UseCountedLoopSafepoints && LoopStripMiningIter > 0) {
-    if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {
-      warning("Disabling counted safepoints implies no loop strip mining: setting LoopStripMiningIter to 0");
-    }
-    LoopStripMiningIter = 0;
-  }
 #endif // COMPILER2
 
   if (Arguments::is_interpreter_only()) {
--- a/src/hotspot/share/opto/c2_globals.hpp	Thu Aug 27 10:57:13 2020 +0100
+++ b/src/hotspot/share/opto/c2_globals.hpp	Fri Aug 21 17:41:57 2020 +0200
@@ -762,6 +762,7 @@
   product(uintx, LoopStripMiningIter, 0,                                    \
           "Number of iterations in strip mined loop")                       \
           range(0, max_juint)                                               \
+          constraint(LoopStripMiningIterConstraintFunc, AfterErgo)          \
                                                                             \
   product(uintx, LoopStripMiningIterShortLoop, 0,                           \
           "Loop with fewer iterations are not strip mined")                 \
--- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp	Thu Aug 27 10:57:13 2020 +0100
+++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp	Fri Aug 21 17:41:57 2020 +0200
@@ -379,3 +379,26 @@
 
   return JVMFlag::SUCCESS;
 }
+
+#ifdef COMPILER2
+JVMFlag::Error LoopStripMiningIterConstraintFunc(uintx value, bool verbose) {
+  if (UseCountedLoopSafepoints && LoopStripMiningIter == 0) {
+    if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {
+      JVMFlag::printError(verbose,
+                          "When counted loop safepoints are enabled, "
+                          "LoopStripMiningIter must be at least 1 "
+                          "(a safepoint every 1 iteration): setting it to 1\n");
+    }
+    LoopStripMiningIter = 1;
+  } else if (!UseCountedLoopSafepoints && LoopStripMiningIter > 0) {
+    if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {
+      JVMFlag::printError(verbose,
+                          "Disabling counted safepoints implies no loop strip mining: "
+                          "setting LoopStripMiningIter to 0\n");
+    }
+    LoopStripMiningIter = 0;
+  }
+
+  return JVMFlag::SUCCESS;
+}
+#endif // COMPILER2
--- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.hpp	Thu Aug 27 10:57:13 2020 +0100
+++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.hpp	Fri Aug 21 17:41:57 2020 +0200
@@ -71,4 +71,8 @@
 
 JVMFlag::Error RTMTotalCountIncrRateConstraintFunc(int value, bool verbose);
 
+#ifdef COMPILER2
+JVMFlag::Error LoopStripMiningIterConstraintFunc(uintx value, bool verbose);
+#endif
+
 #endif // SHARE_RUNTIME_FLAGS_JVMFLAGCONSTRAINTSCOMPILER_HPP
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/compiler/loopstripmining/TestNoWarningLoopStripMiningIterSet.java	Fri Aug 21 17:41:57 2020 +0200
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2020, Red Hat, Inc. 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 8241486
+ * @summary G1/Z give warning when using LoopStripMiningIter and turn off LoopStripMiningIter (0)
+ * @requires vm.flavor == "server" & !vm.graal.enabled
+ * @requires vm.gc.G1 & vm.gc.Shenandoah & vm.gc.Z & vm.gc.Epsilon
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ *          java.management
+ * @run driver TestNoWarningLoopStripMiningIterSet
+ */
+
+import jdk.test.lib.Asserts;
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+import java.util.function.Consumer;
+import java.util.Arrays;
+import java.util.List;
+
+public class TestNoWarningLoopStripMiningIterSet {
+    static final String CLSOnLSMEqualZero = "When counted loop safepoints are enabled, LoopStripMiningIter must be at least 1 (a safepoint every 1 iteration): setting it to 1";
+    static final String CLSOffLSMGreaterZero = "Disabling counted safepoints implies no loop strip mining: setting LoopStripMiningIter to 0";
+
+    public static void testWith(Consumer<OutputAnalyzer> check, String msg, boolean cls, int iters, String... args) throws Exception {
+        String[] cmds = new String[args.length + 3];
+        cmds[0] = "-XX:+UnlockExperimentalVMOptions";
+        System.arraycopy(args, 0, cmds, 1, args.length);
+        cmds[args.length + 1] = "-XX:+PrintFlagsFinal";
+        cmds[args.length + 2] = "-version";
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds);
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        output.shouldHaveExitValue(0);
+
+        check.accept(output);
+
+        Asserts.assertEQ(output.firstMatch("(.+?) UseCountedLoopSafepoints.+?= (.+?) (.+?)", 2), Boolean.toString(cls), msg + ", but got wrong CLS");
+        Asserts.assertEQ(output.firstMatch("(.+?) LoopStripMiningIter.+?= (.+?) (.+?)", 2), String.valueOf(iters), msg + ", but got wrong LSM");
+    }
+
+    public static void main(String[] args) throws Exception {
+        for (String gc : List.of("-XX:+UseG1GC", "-XX:+UseZGC", "-XX:+UseShenandoahGC", "-XX:+UseEpsilonGC")) {
+            testWith(output -> output.shouldNotContain(CLSOffLSMGreaterZero), "should have CLS and LSM enabled", true, 100, "-XX:LoopStripMiningIter=100", gc);
+            testWith(output -> output.shouldContain(CLSOffLSMGreaterZero), "should have CLS and LSM disabled", false, 0, "-XX:-UseCountedLoopSafepoints", "-XX:LoopStripMiningIter=100", gc);
+            testWith(output -> output.shouldContain(CLSOnLSMEqualZero), "should have CLS and LSM enabled", true, 1, "-XX:LoopStripMiningIter=0", gc);
+            testWith(output -> output.shouldNotContain(CLSOnLSMEqualZero), "should have CLS and LSM disabled", false, 0, "-XX:-UseCountedLoopSafepoints", "-XX:LoopStripMiningIter=0", gc);
+        }
+    }
+}