Skip to content

Commit

Permalink
Add jtreg test
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyilin committed Oct 25, 2024
1 parent 3554430 commit 2d7ef1f
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 69 deletions.
51 changes: 29 additions & 22 deletions src/hotspot/share/gc/g1/jvmFlagConstraintsG1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ JVMFlag::Error G1RSetRegionEntriesConstraintFunc(intx value, bool verbose) {
// Default value of G1RSetRegionEntries=0 means will be set ergonomically.
// Minimum value is 1.
if (FLAG_IS_CMDLINE(G1RSetRegionEntries) && (value < 1)) {
if (VerifyFlagConstraints)
{
if (VerifyFlagConstraints) {
G1RSetRegionEntries = 1;
JVMFlag::printError(true, "G1RSetRegionEntries:1\n");
return JVMFlag::SUCCESS;
}
else
{
} else {
JVMFlag::printError(verbose,
"G1RSetRegionEntries (" INTX_FORMAT ") must be "
"greater than or equal to 1\n",
Expand All @@ -57,13 +55,11 @@ JVMFlag::Error G1RSetSparseRegionEntriesConstraintFunc(intx value, bool verbose)
// Default value of G1RSetSparseRegionEntries=0 means will be set ergonomically.
// Minimum value is 1.
if (FLAG_IS_CMDLINE(G1RSetSparseRegionEntries) && (value < 1)) {
if (VerifyFlagConstraints)
{
if (VerifyFlagConstraints) {
G1RSetSparseRegionEntries = 1;
JVMFlag::printError(true, "G1RSetSparseRegionEntries:1\n");
return JVMFlag::SUCCESS;
}
else
{
} else {
JVMFlag::printError(verbose,
"G1RSetSparseRegionEntries (" INTX_FORMAT ") must be "
"greater than or equal to 1\n",
Expand All @@ -79,11 +75,11 @@ JVMFlag::Error G1HeapRegionSizeConstraintFunc(size_t value, bool verbose) {
if (!UseG1GC) return JVMFlag::SUCCESS;
// Default value of G1HeapRegionSize=0 means will be set ergonomically.
if (FLAG_IS_CMDLINE(G1HeapRegionSize) && (value < HeapRegionBounds::min_size())) {
if (VerifyFlagConstraints)
{
if (VerifyFlagConstraints) {
G1HeapRegionSize = HeapRegionBounds::min_size();
JVMFlag::printError(true, "G1HeapRegionSize:"SIZE_FORMAT"\n", HeapRegionBounds::min_size());
return JVMFlag::SUCCESS;
}
}
JVMFlag::printError(verbose,
"G1HeapRegionSize (" SIZE_FORMAT ") must be "
"greater than or equal to ergonomic heap region minimum size\n",
Expand All @@ -99,7 +95,8 @@ JVMFlag::Error G1NewSizePercentConstraintFunc(uintx value, bool verbose) {
if (value > G1MaxNewSizePercent) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "G1MaxNewSizePercent:"UINTX_FORMAT"\n", G1MaxNewSizePercent);
G1NewSizePercent = G1MaxNewSizePercent;
JVMFlag::printError(true, "G1NewSizePercent:"UINTX_FORMAT"\n", G1MaxNewSizePercent);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
Expand All @@ -117,6 +114,7 @@ JVMFlag::Error G1MaxNewSizePercentConstraintFunc(uintx value, bool verbose) {
if (value < G1NewSizePercent) {
if (VerifyFlagConstraints)
{
G1MaxNewSizePercent = G1NewSizePercent;
JVMFlag::printError(true, "G1MaxNewSizePercent:"UINTX_FORMAT"\n", G1NewSizePercent);
return JVMFlag::SUCCESS;
}
Expand All @@ -134,7 +132,12 @@ JVMFlag::Error MaxGCPauseMillisConstraintFuncG1(uintx value, bool verbose) {
if (UseG1GC && FLAG_IS_CMDLINE(MaxGCPauseMillis) && (value >= GCPauseIntervalMillis)) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "MaxGCPauseMillis:"UINTX_FORMAT"\n", (GCPauseIntervalMillis-1));
if (GCPauseIntervalMillis <= 1) {
GCPauseIntervalMillis = 2;
JVMFlag::printError(true, "GCPauseIntervalMillis:"UINTX_FORMAT"\n", GCPauseIntervalMillis);
}
JVMFlag::printError(true, "MaxGCPauseMillis:"UINTX_FORMAT"\n", (GCPauseIntervalMillis - 1));
MaxGCPauseMillis = GCPauseIntervalMillis - 1;
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
Expand All @@ -150,15 +153,15 @@ JVMFlag::Error MaxGCPauseMillisConstraintFuncG1(uintx value, bool verbose) {
JVMFlag::Error GCPauseIntervalMillisConstraintFuncG1(uintx value, bool verbose) {
if (UseG1GC) {
if (FLAG_IS_CMDLINE(GCPauseIntervalMillis)) {
if (value < 1) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "GCPauseIntervalMillis:"UINTX_FORMAT"\n", 1);
if (value <= 1) {
if (VerifyFlagConstraints) {
GCPauseIntervalMillis = 2;
JVMFlag::printError(true, "GCPauseIntervalMillis:"UINTX_FORMAT"\n", 2);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"GCPauseIntervalMillis (" UINTX_FORMAT ") must be "
"greater than or equal to 1\n",
"greater than 1\n",
value);
return JVMFlag::VIOLATES_CONSTRAINT;
}
Expand All @@ -176,8 +179,11 @@ JVMFlag::Error GCPauseIntervalMillisConstraintFuncG1(uintx value, bool verbose)
}

if (value <= MaxGCPauseMillis) {
if (VerifyFlagConstraints)
{
if (VerifyFlagConstraints) {
if (MaxGCPauseMillis == max_uintx - 1) {
MaxGCPauseMillis = MaxGCPauseMillis - 1;
}
GCPauseIntervalMillis = MaxGCPauseMillis + 1;
JVMFlag::printError(true, "GCPauseIntervalMillis:"UINTX_FORMAT"\n", (MaxGCPauseMillis + 1));
return JVMFlag::SUCCESS;
}
Expand All @@ -202,6 +208,7 @@ JVMFlag::Error NewSizeConstraintFuncG1(size_t value, bool verbose) {
if (UseG1GC && (value > (max_juint * 1 * M))) {
if (VerifyFlagConstraints)
{
NewSize = max_juint * 1 * M;
JVMFlag::printError(true, "NewSize:"SIZE_FORMAT"\n", (max_juint * 1 * M));
return JVMFlag::SUCCESS;
}
Expand Down
79 changes: 32 additions & 47 deletions src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

JVMFlag::Error AliasLevelConstraintFunc(intx value, bool verbose) {
if ((value <= 1) && (Arguments::mode() == Arguments::_comp || Arguments::mode() == Arguments::_mixed)) {
if (VerifyFlagConstraints)
{
if (VerifyFlagConstraints) {
AliasLevel = 2;
JVMFlag::printError(true, "AliasLevel:2\n");
return JVMFlag::SUCCESS;
}
Expand Down Expand Up @@ -86,8 +86,8 @@ JVMFlag::Error CICompilerCountConstraintFunc(intx value, bool verbose) {
min_number_of_compiler_threads = MIN2(min_number_of_compiler_threads, CI_COMPILER_COUNT);

if (value < (intx)min_number_of_compiler_threads) {
if (VerifyFlagConstraints)
{
if (VerifyFlagConstraints) {
CICompilerCount = min_number_of_compiler_threads;
JVMFlag::printError(true, "CICompilerCount:"INTX_FORMAT"\n", min_number_of_compiler_threads);
return JVMFlag::SUCCESS;
}
Expand All @@ -103,18 +103,9 @@ JVMFlag::Error CICompilerCountConstraintFunc(intx value, bool verbose) {

JVMFlag::Error AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose) {
if (value < 0 || value > 512) {
if (VerifyFlagConstraints)
{
int suggestValue;
if (value < 0)
{
suggestValue = 0;
}
else
{
suggestValue = 512;
}
JVMFlag::printError(true, "AllocatePrefetchDistance:" INTX_FORMAT "\n", suggestValue);
if (VerifyFlagConstraints) {
AllocatePrefetchDistance = value < 0 ? 0 : 512;
JVMFlag::printError(true, "AllocatePrefetchDistance:" INTX_FORMAT "\n", AllocatePrefetchDistance);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
Expand All @@ -129,12 +120,11 @@ JVMFlag::Error AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose)

JVMFlag::Error AllocatePrefetchStepSizeConstraintFunc(intx value, bool verbose) {
if (AllocatePrefetchStyle == 3) {
if (value % wordSize != 0)
{
if (VerifyFlagConstraints)
{
if (value % wordSize != 0) {
if (VerifyFlagConstraints) {
int remainder = value % wordSize;
JVMFlag::printError(true, "AllocatePrefetchStepSize:" INTX_FORMAT "\n", (value - remainder));
AllocatePrefetchStepSize = value - remainder;
JVMFlag::printError(true, "AllocatePrefetchStepSize:" INTX_FORMAT "\n", AllocatePrefetchStepSize);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
Expand All @@ -154,9 +144,9 @@ JVMFlag::Error AllocatePrefetchInstrConstraintFunc(intx value, bool verbose) {
max_value = 3;
#endif
if (value < 0 || value > max_value) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "AllocatePrefetchInstr:" INTX_FORMAT "\n", (value < 0 ? 0 : max_value));
if (VerifyFlagConstraints) {
AllocatePrefetchInstr = value < 0 ? 0 : max_value;
JVMFlag::printError(true, "AllocatePrefetchInstr:" INTX_FORMAT "\n", AllocatePrefetchInstr);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
Expand All @@ -170,9 +160,9 @@ JVMFlag::Error AllocatePrefetchInstrConstraintFunc(intx value, bool verbose) {

JVMFlag::Error CompileThresholdConstraintFunc(intx value, bool verbose) {
if (value < 0 || value > INT_MAX >> InvocationCounter::count_shift) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "CompileThreshold:" INTX_FORMAT "\n", (value < 0 ? 0 : INT_MAX >> InvocationCounter::count_shift));
if (VerifyFlagConstraints) {
CompileThreshold = value < 0 ? 0 : INT_MAX >> InvocationCounter::count_shift;
JVMFlag::printError(true, "CompileThreshold:" INTX_FORMAT "\n", CompileThreshold);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
Expand All @@ -190,30 +180,25 @@ JVMFlag::Error OnStackReplacePercentageConstraintFunc(intx value, bool verbose)
int backward_branch_limit;
if (ProfileInterpreter) {
if (OnStackReplacePercentage < InterpreterProfilePercentage) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true,
"OnStackReplacePercentage:"INTX_FORMAT"\n", InterpreterProfilePercentage);
if (VerifyFlagConstraints) {
OnStackReplacePercentage = InterpreterProfilePercentage;
JVMFlag::printError(true, "OnStackReplacePercentage:"INTX_FORMAT"\n", OnStackReplacePercentage);
return JVMFlag::SUCCESS;
}
else
{
JVMFlag::printError(verbose,
JVMFlag::printError(verbose,
"OnStackReplacePercentage (" INTX_FORMAT ") must be "
"larger than InterpreterProfilePercentage (" INTX_FORMAT ")\n",
OnStackReplacePercentage, InterpreterProfilePercentage);
return JVMFlag::VIOLATES_CONSTRAINT;
}
return JVMFlag::VIOLATES_CONSTRAINT;
}

//InvocationCounter::count_shift = 3
backward_branch_limit = ((CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100)
<< InvocationCounter::count_shift;

if (backward_branch_limit < 0) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true,
"OnStackReplacePercentage:"INTX_FORMAT"\n", ((INT_MAX >> InvocationCounter::count_shift) / CompileThreshold + InterpreterProfilePercentage));
if (VerifyFlagConstraints) {
OnStackReplacePercentage = (INT_MAX >> InvocationCounter::count_shift) / CompileThreshold + InterpreterProfilePercentage;
JVMFlag::printError(true, "OnStackReplacePercentage:"INTX_FORMAT"\n", OnStackReplacePercentage);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
Expand All @@ -227,10 +212,10 @@ JVMFlag::Error OnStackReplacePercentageConstraintFunc(intx value, bool verbose)
}
} else {
if (OnStackReplacePercentage < 0 ) {
if (VerifyFlagConstraints)
{
if (VerifyFlagConstraints) {
OnStackReplacePercentage = 0;
JVMFlag::printError(true,
"OnStackReplacePercentage:"INTX_FORMAT"\n", 0);
"OnStackReplacePercentage:"INTX_FORMAT"\n", OnStackReplacePercentage);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
Expand All @@ -243,9 +228,9 @@ JVMFlag::Error OnStackReplacePercentageConstraintFunc(intx value, bool verbose)
<< InvocationCounter::count_shift;

if (backward_branch_limit < 0) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "OnStackReplacePercentage:"INTX_FORMAT"\n", ((INT_MAX >> InvocationCounter::count_shift) / CompileThreshold));
if (VerifyFlagConstraints) {
OnStackReplacePercentage = (INT_MAX >> InvocationCounter::count_shift) / CompileThreshold;
JVMFlag::printError(true, "OnStackReplacePercentage:"INTX_FORMAT"\n", OnStackReplacePercentage);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
Expand Down
93 changes: 93 additions & 0 deletions test/hotspot/jtreg/sanity/VerifyFlagConstraintsTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2024 Alibaba Group Holding Limited. 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. Alibaba designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/

package sanity;

import jdk.test.lib.Asserts;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/*
* @test
* @summary make sure various basic java options work
* @library /test/lib
*
* @run driver sanity.VerifyFlagConstraintsTests
*/
public class VerifyFlagConstraintsTests {
public static void main(String[] args) throws Exception {
FlagConstraintTester.create().run("-XX:+UseG1GC",
"-XX:MaxGCPauseMillis=18446744073709551614",
"-XX:GCPauseIntervalMillis=0",
"-XX:AllocatePrefetchDistance=-1",
"-XX:AllocatePrefetchStepSize=29",
"-XX:AllocatePrefetchStyle=3")
.testEq("MaxGCPauseMillis", "1")
.testEq("GCPauseIntervalMillis", "2")
.testEq("AllocatePrefetchDistance", "0")
.testEq("AllocatePrefetchStepSize", "24");

FlagConstraintTester.create().run(" -XX:CompileThreshold=268435456",
"-XX:OnStackReplacePercentage=40").testEq("CompileThreshold", "268435455");

FlagConstraintTester.create().run(" -XX:CompileThreshold=268435456")
.testEq("CompileThreshold", "268435455")
.testEq("OnStackReplacePercentage", "34");
}

static class FlagConstraintTester {
private String[] enableArgs = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+VerifyFlagConstraints"};
private Map<String, String> verifiedContents = new HashMap<>();

public static FlagConstraintTester create() {
return new FlagConstraintTester();
}

public FlagConstraintTester run(String... flags) throws Exception {
String[] cmds = new String[flags.length + 2];
cmds[0] = enableArgs[0];
cmds[1] = enableArgs[1];
for (int i = 0; i < flags.length; i++) {
cmds[i + 2] = flags[i];
}
OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(cmds);
outputAnalyzer.shouldHaveExitValue(0);
System.out.println(outputAnalyzer.getOutput());
for (String line : outputAnalyzer.asLines()) {
String[] rets = line.split(":");
if (rets.length != 2) {
throw new RuntimeException("Expect 2 entries in the result of flag verifying, but is " + line);
}
verifiedContents.put(rets[0], rets[1]);
}
return this;
}

public FlagConstraintTester testEq(String param, String expected) {
Asserts.assertEquals(expected, verifiedContents.get(param));
return this;
}
}
}

0 comments on commit 2d7ef1f

Please sign in to comment.