8231932: Shenandoah: conc/par GC threads ergonomics overrides user settings
authorshade
Mon, 07 Oct 2019 17:12:13 +0200
changeset 58482 b4c660a75b54
parent 58481 48a73ec3a817
child 58483 f48737be4fd7
8231932: Shenandoah: conc/par GC threads ergonomics overrides user settings Reviewed-by: rkennke
src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp
test/hotspot/jtreg/gc/shenandoah/TestGCThreadGroups.java
test/hotspot/jtreg/gc/shenandoah/options/TestThreadCounts.java
test/hotspot/jtreg/gc/shenandoah/options/TestThreadCountsOverride.java
--- a/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp	Mon Oct 07 16:55:24 2019 +0200
+++ b/src/hotspot/share/gc/shenandoah/shenandoahArguments.cpp	Mon Oct 07 17:12:13 2019 +0200
@@ -69,7 +69,8 @@
   // enough, but we also do not want to steal too much CPU from the concurrently running
   // application. Using 1/4 of available threads for concurrent GC seems a good
   // compromise here.
-  if (FLAG_IS_DEFAULT(ConcGCThreads)) {
+  bool ergo_conc = FLAG_IS_DEFAULT(ConcGCThreads);
+  if (ergo_conc) {
     FLAG_SET_DEFAULT(ConcGCThreads, MAX2(1, os::processor_count() / 4));
   }
 
@@ -82,7 +83,8 @@
   // that will overwhelm the OS scheduler. Using 1/2 of available threads seems to be a fair
   // compromise here. Due to implementation constraints, it should not be lower than
   // the number of concurrent threads.
-  if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
+  bool ergo_parallel = FLAG_IS_DEFAULT(ParallelGCThreads);
+  if (ergo_parallel) {
     FLAG_SET_DEFAULT(ParallelGCThreads, MAX2(1, os::processor_count() / 2));
   }
 
@@ -90,9 +92,21 @@
     vm_exit_during_initialization("Shenandoah expects ParallelGCThreads > 0, check -XX:ParallelGCThreads=#");
   }
 
+  // Make sure ergonomic decisions do not break the thread count invariants.
+  // This may happen when user overrides one of the flags, but not the other.
+  // When that happens, we want to adjust the setting that was set ergonomically.
   if (ParallelGCThreads < ConcGCThreads) {
-    warning("Shenandoah expects ConcGCThreads <= ParallelGCThreads, adjusting ParallelGCThreads automatically");
-    FLAG_SET_DEFAULT(ParallelGCThreads, ConcGCThreads);
+    if (ergo_conc && !ergo_parallel) {
+      FLAG_SET_DEFAULT(ConcGCThreads, ParallelGCThreads);
+    } else if (!ergo_conc && ergo_parallel) {
+      FLAG_SET_DEFAULT(ParallelGCThreads, ConcGCThreads);
+    } else if (ergo_conc && ergo_parallel) {
+      // Should not happen, check the ergonomic computation above. Fail with relevant error.
+      vm_exit_during_initialization("Shenandoah thread count ergonomic error");
+    } else {
+      // User settings error, report and ask user to rectify.
+      vm_exit_during_initialization("Shenandoah expects ConcGCThreads <= ParallelGCThreads, check -XX:ParallelGCThreads, -XX:ConcGCThreads");
+    }
   }
 
   if (FLAG_IS_DEFAULT(ParallelRefProcEnabled)) {
--- a/test/hotspot/jtreg/gc/shenandoah/TestGCThreadGroups.java	Mon Oct 07 16:55:24 2019 +0200
+++ b/test/hotspot/jtreg/gc/shenandoah/TestGCThreadGroups.java	Mon Oct 07 17:12:13 2019 +0200
@@ -32,12 +32,6 @@
  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  *      -Dtarget=1000
  *      TestGCThreadGroups
- *
- * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
- *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
- *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
- *      -Dtarget=1000
- *      TestGCThreadGroups
  */
 
 /**
@@ -71,46 +65,22 @@
  *      TestGCThreadGroups
  *
  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
- *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
- *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
- *      -Dtarget=1000
- *      TestGCThreadGroups
- *
- * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  *      -Dtarget=1000
  *      TestGCThreadGroups
  *
  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
- *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
- *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
- *      -Dtarget=1000
- *      TestGCThreadGroups
- *
- * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  *      -Dtarget=100
  *      TestGCThreadGroups
  *
  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
- *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
- *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
- *      -Dtarget=100
- *      TestGCThreadGroups
- *
- * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  *      -Dtarget=100
  *      TestGCThreadGroups
- *
- * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
- *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
- *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
- *      -Dtarget=100
- *      TestGCThreadGroups
  */
 
 /**
@@ -130,18 +100,6 @@
  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  *      -Dtarget=1000
  *      TestGCThreadGroups
- *
- * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
- *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=traversal
- *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
- *      -Dtarget=1000
- *      TestGCThreadGroups
- *
- * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
- *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=traversal -XX:ShenandoahGCHeuristics=aggressive
- *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
- *      -Dtarget=1000
- *      TestGCThreadGroups
 */
 
 public class TestGCThreadGroups {
--- a/test/hotspot/jtreg/gc/shenandoah/options/TestThreadCounts.java	Mon Oct 07 16:55:24 2019 +0200
+++ b/test/hotspot/jtreg/gc/shenandoah/options/TestThreadCounts.java	Mon Oct 07 17:12:13 2019 +0200
@@ -61,7 +61,7 @@
             output.shouldHaveExitValue(1);
         } else if (conc > par) {
             output.shouldContain("Shenandoah expects ConcGCThreads <= ParallelGCThreads");
-            output.shouldHaveExitValue(0);
+            output.shouldHaveExitValue(1);
         } else {
             output.shouldNotContain("Shenandoah expects ConcGCThreads <= ParallelGCThreads");
             output.shouldHaveExitValue(0);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/gc/shenandoah/options/TestThreadCountsOverride.java	Mon Oct 07 17:12:13 2019 +0200
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved.
+ *
+ * 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 TestThreadCountsOverride
+ * @summary Test that Shenandoah GC thread counts are overridable
+ * @key gc
+ * @requires vm.gc.Shenandoah & !vm.graal.enabled
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ *          java.management
+ * @run driver TestThreadCountsOverride
+ */
+
+import jdk.test.lib.process.ProcessTools;
+import jdk.test.lib.process.OutputAnalyzer;
+
+public class TestThreadCountsOverride {
+    public static void main(String[] args) throws Exception {
+        {
+            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+                "-XX:+UnlockDiagnosticVMOptions",
+                "-XX:+UnlockExperimentalVMOptions",
+                "-XX:+UseShenandoahGC",
+                "-XX:ParallelGCThreads=1",
+                "-XX:+PrintFlagsFinal",
+                "-version");
+            OutputAnalyzer output = new OutputAnalyzer(pb.start());
+
+            output.shouldMatch("ParallelGCThreads(.*)= 1 ");
+            output.shouldHaveExitValue(0);
+        }
+
+        {
+            ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+                "-XX:+UnlockDiagnosticVMOptions",
+                "-XX:+UnlockExperimentalVMOptions",
+                "-XX:+UseShenandoahGC",
+                "-XX:ConcGCThreads=1",
+                "-XX:+PrintFlagsFinal",
+                "-version");
+            OutputAnalyzer output = new OutputAnalyzer(pb.start());
+
+            output.shouldMatch("ConcGCThreads(.*)= 1 ");
+            output.shouldHaveExitValue(0);
+        }
+    }
+
+}