Skip to content

Commit

Permalink
Verify flag constraints and provide suggestion value
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyilin committed Oct 22, 2024
1 parent 84dfd49 commit 3554430
Show file tree
Hide file tree
Showing 8 changed files with 573 additions and 154 deletions.
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/cms/jvmFlagConstraintsCMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
static JVMFlag::Error ParallelGCThreadsAndCMSWorkQueueDrainThreshold(uint threads, uintx threshold, bool verbose) {
// CMSWorkQueueDrainThreshold is verified to be less than max_juint
if (UseConcMarkSweepGC && (threads > (uint)(max_jint / (uint)threshold))) {
if (VerifyFlagConstraints) {
//JVMFlag::printError(true, "ParallelGCThreads:"UINT32_FORMAT"\n", )
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"ParallelGCThreads (" UINT32_FORMAT ") or CMSWorkQueueDrainThreshold ("
UINTX_FORMAT ") is too large\n",
Expand Down
87 changes: 67 additions & 20 deletions src/hotspot/share/gc/g1/jvmFlagConstraintsG1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,61 @@
#include "utilities/globalDefinitions.hpp"

JVMFlag::Error G1RSetRegionEntriesConstraintFunc(intx value, bool verbose) {
JVMFlag::printError(true, "G1RSetRegionEntriesConstraintFunc\n");

if (!UseG1GC) return JVMFlag::SUCCESS;
// Default value of G1RSetRegionEntries=0 means will be set ergonomically.
// Minimum value is 1.
if (FLAG_IS_CMDLINE(G1RSetRegionEntries) && (value < 1)) {
JVMFlag::printError(verbose,
"G1RSetRegionEntries (" INTX_FORMAT ") must be "
"greater than or equal to 1\n",
value);
return JVMFlag::VIOLATES_CONSTRAINT;
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "G1RSetRegionEntries:1\n");
return JVMFlag::SUCCESS;
}
else
{
JVMFlag::printError(verbose,
"G1RSetRegionEntries (" INTX_FORMAT ") must be "
"greater than or equal to 1\n",
value);
return JVMFlag::VIOLATES_CONSTRAINT;
}
} else {
return JVMFlag::SUCCESS;
}
}

JVMFlag::Error G1RSetSparseRegionEntriesConstraintFunc(intx value, bool verbose) {
JVMFlag::printError(true, "G1RSetSparseRegionEntriesConstraintFunc\n");
if (!UseG1GC) return JVMFlag::SUCCESS;
// Default value of G1RSetSparseRegionEntries=0 means will be set ergonomically.
// Minimum value is 1.
if (FLAG_IS_CMDLINE(G1RSetSparseRegionEntries) && (value < 1)) {
JVMFlag::printError(verbose,
"G1RSetSparseRegionEntries (" INTX_FORMAT ") must be "
"greater than or equal to 1\n",
value);
return JVMFlag::VIOLATES_CONSTRAINT;
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "G1RSetSparseRegionEntries:1\n");
return JVMFlag::SUCCESS;
}
else
{
JVMFlag::printError(verbose,
"G1RSetSparseRegionEntries (" INTX_FORMAT ") must be "
"greater than or equal to 1\n",
value);
return JVMFlag::VIOLATES_CONSTRAINT;
}
} else {
return JVMFlag::SUCCESS;
}
}

JVMFlag::Error G1HeapRegionSizeConstraintFunc(size_t value, bool verbose) {
JVMFlag::printError(true, "G1HeapRegionSizeConstraintFunc\n");
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)
{
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 @@ -76,10 +95,13 @@ JVMFlag::Error G1HeapRegionSizeConstraintFunc(size_t value, bool verbose) {
}

JVMFlag::Error G1NewSizePercentConstraintFunc(uintx value, bool verbose) {
JVMFlag::printError(true, "G1NewSizePercentConstraintFunc\n");
if (!UseG1GC) return JVMFlag::SUCCESS;

if (value > G1MaxNewSizePercent) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "G1MaxNewSizePercent:"UINTX_FORMAT"\n", G1MaxNewSizePercent);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"G1NewSizePercent (" UINTX_FORMAT ") must be "
"less than or equal to G1MaxNewSizePercent (" UINTX_FORMAT ")\n",
Expand All @@ -91,10 +113,13 @@ JVMFlag::Error G1NewSizePercentConstraintFunc(uintx value, bool verbose) {
}

JVMFlag::Error G1MaxNewSizePercentConstraintFunc(uintx value, bool verbose) {
JVMFlag::printError(true, "G1MaxNewSizePercentConstraintFunc\n");
if (!UseG1GC) return JVMFlag::SUCCESS;

if (value < G1NewSizePercent) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "G1MaxNewSizePercent:"UINTX_FORMAT"\n", G1NewSizePercent);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"G1MaxNewSizePercent (" UINTX_FORMAT ") must be "
"greater than or equal to G1NewSizePercent (" UINTX_FORMAT ")\n",
Expand All @@ -106,8 +131,12 @@ JVMFlag::Error G1MaxNewSizePercentConstraintFunc(uintx value, bool verbose) {
}

JVMFlag::Error MaxGCPauseMillisConstraintFuncG1(uintx value, bool verbose) {
JVMFlag::printError(true, "MaxGCPauseMillisConstraintFuncG1\n");
if (UseG1GC && FLAG_IS_CMDLINE(MaxGCPauseMillis) && (value >= GCPauseIntervalMillis)) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "MaxGCPauseMillis:"UINTX_FORMAT"\n", (GCPauseIntervalMillis-1));
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"MaxGCPauseMillis (" UINTX_FORMAT ") must be "
"less than GCPauseIntervalMillis (" UINTX_FORMAT ")\n",
Expand All @@ -119,10 +148,14 @@ JVMFlag::Error MaxGCPauseMillisConstraintFuncG1(uintx value, bool verbose) {
}

JVMFlag::Error GCPauseIntervalMillisConstraintFuncG1(uintx value, bool verbose) {
JVMFlag::printError(true, "GCPauseIntervalMillisConstraintFuncG1\n");
if (UseG1GC) {
if (FLAG_IS_CMDLINE(GCPauseIntervalMillis)) {
if (value < 1) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "GCPauseIntervalMillis:"UINTX_FORMAT"\n", 1);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"GCPauseIntervalMillis (" UINTX_FORMAT ") must be "
"greater than or equal to 1\n",
Expand All @@ -131,13 +164,23 @@ JVMFlag::Error GCPauseIntervalMillisConstraintFuncG1(uintx value, bool verbose)
}

if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "GCPauseIntervalMillis:MaxGCPauseMillis\n");
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"GCPauseIntervalMillis cannot be set "
"without setting MaxGCPauseMillis\n");
return JVMFlag::VIOLATES_CONSTRAINT;
}

if (value <= MaxGCPauseMillis) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "GCPauseIntervalMillis:"UINTX_FORMAT"\n", (MaxGCPauseMillis + 1));
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"GCPauseIntervalMillis (" UINTX_FORMAT ") must be "
"greater than MaxGCPauseMillis (" UINTX_FORMAT ")\n",
Expand All @@ -151,13 +194,17 @@ JVMFlag::Error GCPauseIntervalMillisConstraintFuncG1(uintx value, bool verbose)
}

JVMFlag::Error NewSizeConstraintFuncG1(size_t value, bool verbose) {
JVMFlag::printError(true, "NewSizeConstraintFuncG1\n");
#ifdef _LP64
// Overflow would happen for uint type variable of YoungGenSizer::_min_desired_young_length
// when the value to be assigned exceeds uint range.
// i.e. result of '(uint)(NewSize / region size(1~32MB))'
// So maximum of NewSize should be 'max_juint * 1M'
if (UseG1GC && (value > (max_juint * 1 * M))) {
if (VerifyFlagConstraints)
{
JVMFlag::printError(true, "NewSize:"SIZE_FORMAT"\n", (max_juint * 1 * M));
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"NewSize (" SIZE_FORMAT ") must be less than ergonomic maximum value\n",
value);
Expand Down
15 changes: 12 additions & 3 deletions src/hotspot/share/gc/parallel/jvmFlagConstraintsParallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
JVMFlag::Error ParallelGCThreadsConstraintFuncParallel(uint value, bool verbose) {
// Parallel GC passes ParallelGCThreads when creating GrowableArray as 'int' type parameter.
// So can't exceed with "max_jint"
JVMFlag::printError(false, "ParallelGCThreadsConstraintFuncParallel\n");
if (UseParallelGC && (value > (uint)max_jint)) {
if (VerifyFlagConstraints) {
JVMFlag::printError(true, "ParallelGCThreads:"UINT32_FORMAT"\n", max_jint);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"ParallelGCThreads (" UINT32_FORMAT ") must be "
"less than or equal to " UINT32_FORMAT " for Parallel GC\n",
Expand All @@ -42,9 +45,12 @@ JVMFlag::Error ParallelGCThreadsConstraintFuncParallel(uint value, bool verbose)
}

JVMFlag::Error InitialTenuringThresholdConstraintFuncParallel(uintx value, bool verbose) {
JVMFlag::printError(false, "InitialTenuringThresholdConstraintFuncParallel\n");
// InitialTenuringThreshold is only used for ParallelGC.
if (UseParallelGC && (value > MaxTenuringThreshold)) {
if (VerifyFlagConstraints) {
JVMFlag::printError(true, "InitialTenuringThreshold"UINTX_FORMAT"\n", MaxTenuringThreshold);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"InitialTenuringThreshold (" UINTX_FORMAT ") must be "
"less than or equal to MaxTenuringThreshold (" UINTX_FORMAT ")\n",
Expand All @@ -55,10 +61,13 @@ JVMFlag::Error InitialTenuringThresholdConstraintFuncParallel(uintx value, bool
}

JVMFlag::Error MaxTenuringThresholdConstraintFuncParallel(uintx value, bool verbose) {
JVMFlag::printError(false, "MaxTenuringThresholdConstraintFuncParallel\n");
// As only ParallelGC uses InitialTenuringThreshold,
// we don't need to compare InitialTenuringThreshold with MaxTenuringThreshold.
if (UseParallelGC && (value < InitialTenuringThreshold)) {
if (VerifyFlagConstraints) {
JVMFlag::printError(true, "MaxTenuringThreshold"UINTX_FORMAT"\n", InitialTenuringThreshold);
return JVMFlag::SUCCESS;
}
JVMFlag::printError(verbose,
"MaxTenuringThreshold (" UINTX_FORMAT ") must be "
"greater than or equal to InitialTenuringThreshold (" UINTX_FORMAT ")\n",
Expand Down
Loading

0 comments on commit 3554430

Please sign in to comment.