8222145: Add -XX:SoftMaxHeapSize flag
authorpliden
Fri, 07 Jun 2019 11:19:34 +0200
changeset 55283 4556dd808daa
parent 55282 07ff89762205
child 55284 38006f020b94
8222145: Add -XX:SoftMaxHeapSize flag Reviewed-by: eosterlund, tschatzl
src/hotspot/share/gc/shared/gcArguments.cpp
src/hotspot/share/gc/shared/gc_globals.hpp
src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp
src/hotspot/share/gc/shared/jvmFlagConstraintsGC.hpp
test/hotspot/jtreg/gc/arguments/TestSoftMaxHeapSizeFlag.java
test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/TestOptionsWithRangesDynamic.java
test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOption.java
--- a/src/hotspot/share/gc/shared/gcArguments.cpp	Fri Jun 07 11:19:34 2019 +0200
+++ b/src/hotspot/share/gc/shared/gcArguments.cpp	Fri Jun 07 11:19:34 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -191,6 +191,10 @@
     }
   }
 
+  if (FLAG_IS_DEFAULT(SoftMaxHeapSize)) {
+    FLAG_SET_ERGO(SoftMaxHeapSize, MaxHeapSize);
+  }
+
   FLAG_SET_ERGO(MinHeapDeltaBytes, align_up(MinHeapDeltaBytes, SpaceAlignment));
 
   DEBUG_ONLY(assert_flags();)
--- a/src/hotspot/share/gc/shared/gc_globals.hpp	Fri Jun 07 11:19:34 2019 +0200
+++ b/src/hotspot/share/gc/shared/gc_globals.hpp	Fri Jun 07 11:19:34 2019 +0200
@@ -721,6 +721,10 @@
           "Maximum heap size (in bytes)")                                   \
           constraint(MaxHeapSizeConstraintFunc,AfterErgo)                   \
                                                                             \
+  manageable(size_t, SoftMaxHeapSize, 0,                                    \
+          "Soft limit for maximum heap size (in bytes)")                    \
+          constraint(SoftMaxHeapSizeConstraintFunc,AfterMemoryInit)         \
+                                                                            \
   product(size_t, OldSize, ScaleForWordSize(4*M),                           \
           "Initial tenured generation size (in bytes)")                     \
           range(0, max_uintx)                                               \
--- a/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp	Fri Jun 07 11:19:34 2019 +0200
+++ b/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp	Fri Jun 07 11:19:34 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -332,6 +332,15 @@
   return status;
 }
 
+JVMFlag::Error SoftMaxHeapSizeConstraintFunc(size_t value, bool verbose) {
+  if (value > MaxHeapSize) {
+    JVMFlag::printError(verbose, "SoftMaxHeapSize must be less than or equal to the maximum heap size\n");
+    return JVMFlag::VIOLATES_CONSTRAINT;
+  }
+
+  return JVMFlag::SUCCESS;
+}
+
 JVMFlag::Error HeapBaseMinAddressConstraintFunc(size_t value, bool verbose) {
   // If an overflow happened in Arguments::set_heap_size(), MaxHeapSize will have too large a value.
   // Check for this by ensuring that MaxHeapSize plus the requested min base address still fit within max_uintx.
--- a/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.hpp	Fri Jun 07 11:19:34 2019 +0200
+++ b/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.hpp	Fri Jun 07 11:19:34 2019 +0200
@@ -61,6 +61,7 @@
 JVMFlag::Error InitialBootClassLoaderMetaspaceSizeConstraintFunc(size_t value, bool verbose);
 JVMFlag::Error InitialHeapSizeConstraintFunc(size_t value, bool verbose);
 JVMFlag::Error MaxHeapSizeConstraintFunc(size_t value, bool verbose);
+JVMFlag::Error SoftMaxHeapSizeConstraintFunc(size_t value, bool verbose);
 JVMFlag::Error HeapBaseMinAddressConstraintFunc(size_t value, bool verbose);
 JVMFlag::Error NewSizeConstraintFunc(size_t value, bool verbose);
 JVMFlag::Error MinTLABSizeConstraintFunc(size_t value, bool verbose);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/gc/arguments/TestSoftMaxHeapSizeFlag.java	Fri Jun 07 11:19:34 2019 +0200
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+package gc.arguments;
+
+/*
+ * @test TestSoftMaxHeapSizeFlag
+ * @key gc
+ * @library /test/lib
+ * @modules java.base/jdk.internal.misc
+ *          java.management
+ * @run main/othervm gc.arguments.TestSoftMaxHeapSizeFlag
+ */
+
+import jdk.test.lib.process.ProcessTools;
+
+public class TestSoftMaxHeapSizeFlag {
+    private static final long Xms              = 200 * 1024 * 1024;
+    private static final long Xmx              = 300 * 1024 * 1024;
+    private static final long greaterThanXmx   = Xmx + 1;
+    private static final long betweenXmsAndXmx = (Xms + Xmx) / 2;
+
+    public static void main(String args[]) throws Exception {
+        // Test default value
+        ProcessTools.executeTestJvm(new String[]{ "-Xms" + Xms, "-Xmx" + Xmx,
+                                                  "-XX:+PrintFlagsFinal", "-version" })
+                    .shouldMatch("SoftMaxHeapSize[ ]+=[ ]+" + Xmx)
+                    .shouldHaveExitValue(0);
+
+        // Test setting small value
+        ProcessTools.executeTestJvm(new String[]{ "-Xms" + Xms, "-Xmx" + Xmx,
+                                                  "-XX:SoftMaxHeapSize=" + Xms,
+                                                  "-XX:+PrintFlagsFinal", "-version" })
+                    .shouldMatch("SoftMaxHeapSize[ ]+=[ ]+" + Xms)
+                    .shouldHaveExitValue(0);
+
+        // Test setting middle value
+        ProcessTools.executeTestJvm(new String[]{ "-Xms" + Xms, "-Xmx" + Xmx,
+                                                  "-XX:SoftMaxHeapSize=" + betweenXmsAndXmx,
+                                                  "-XX:+PrintFlagsFinal", "-version" })
+                    .shouldMatch("SoftMaxHeapSize[ ]+=[ ]+" + betweenXmsAndXmx)
+                    .shouldHaveExitValue(0);
+
+        // Test setting largest value
+        ProcessTools.executeTestJvm(new String[]{ "-Xms" + Xms, "-Xmx" + Xmx,
+                                                  "-XX:SoftMaxHeapSize=" + Xmx,
+                                                  "-XX:+PrintFlagsFinal", "-version" })
+                    .shouldMatch("SoftMaxHeapSize[ ]+=[ ]+" + Xmx)
+                    .shouldHaveExitValue(0);
+
+        // Test setting a too large value
+        ProcessTools.executeTestJvm(new String[]{ "-Xms" + Xms, "-Xmx" + Xmx,
+                                                  "-XX:SoftMaxHeapSize=" + greaterThanXmx,
+                                                  "-XX:+PrintFlagsFinal", "-version" })
+                    .shouldContain("SoftMaxHeapSize must be less than or equal to the maximum heap size")
+                    .shouldHaveExitValue(1);
+    }
+}
--- a/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/TestOptionsWithRangesDynamic.java	Fri Jun 07 11:19:34 2019 +0200
+++ b/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/TestOptionsWithRangesDynamic.java	Fri Jun 07 11:19:34 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -38,13 +38,29 @@
 
 public class TestOptionsWithRangesDynamic {
 
+    private static List<JVMOption> allWriteableOptions;
+
+    private static void excludeTestRange(String optionName) {
+        for (JVMOption option: allWriteableOptions) {
+            if (option.getName().equals(optionName)) {
+                option.excludeTestMinRange();
+                option.excludeTestMaxRange();
+                break;
+            }
+        }
+    }
+
     public static void main(String[] args) throws Exception {
         int failedTests;
-        List<JVMOption> allWriteableOptions;
 
         /* Get only writeable options */
         allWriteableOptions = JVMOptionsUtils.getOptionsWithRange(origin -> (origin.contains("manageable") || origin.contains("rw")));
 
+        /*
+         * Exclude SoftMaxHeapSize as its valid range is only known at runtime.
+         */
+        excludeTestRange("SoftMaxHeapSize");
+
         Asserts.assertGT(allWriteableOptions.size(), 0, "Options with ranges not found!");
 
         System.out.println("Test " + allWriteableOptions.size() + " writeable options with ranges. Start test!");
--- a/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOption.java	Fri Jun 07 11:19:34 2019 +0200
+++ b/test/hotspot/jtreg/runtime/CommandLine/OptionsValidation/common/optionsvalidation/JVMOption.java	Fri Jun 07 11:19:34 2019 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -146,7 +146,7 @@
      *
      * @return name of the option
      */
-    final String getName() {
+    public final String getName() {
         return name;
     }