8222145: Add -XX:SoftMaxHeapSize flag

Reviewed-by: eosterlund, tschatzl
This commit is contained in:
Per Lidén 2019-06-07 11:19:34 +02:00
parent bfc30c8dbc
commit a6aa1030b4
7 changed files with 118 additions and 6 deletions
src/hotspot/share/gc/shared
test/hotspot/jtreg
gc/arguments
runtime/CommandLine/OptionsValidation

@ -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 @@ void GCArguments::initialize_heap_flags_and_sizes() {
}
}
if (FLAG_IS_DEFAULT(SoftMaxHeapSize)) {
FLAG_SET_ERGO(SoftMaxHeapSize, MaxHeapSize);
}
FLAG_SET_ERGO(MinHeapDeltaBytes, align_up(MinHeapDeltaBytes, SpaceAlignment));
DEBUG_ONLY(assert_flags();)

@ -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) \

@ -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 @@ JVMFlag::Error MaxHeapSizeConstraintFunc(size_t value, bool verbose) {
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.

@ -61,6 +61,7 @@ JVMFlag::Error GCPauseIntervalMillisConstraintFunc(uintx value, bool verbose);
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);

@ -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);
}
}

@ -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 @@ import optionsvalidation.JVMOptionsUtils;
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!");

@ -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 @@ public abstract class JVMOption {
*
* @return name of the option
*/
final String getName() {
public final String getName() {
return name;
}