diff --git a/src/hotspot/share/gc/g1/jvmFlagConstraintsG1.cpp b/src/hotspot/share/gc/g1/jvmFlagConstraintsG1.cpp index d77b1265a56..d31910f5ba4 100644 --- a/src/hotspot/share/gc/g1/jvmFlagConstraintsG1.cpp +++ b/src/hotspot/share/gc/g1/jvmFlagConstraintsG1.cpp @@ -93,8 +93,7 @@ JVMFlag::Error G1HeapRegionSizeConstraintFunc(size_t value, bool verbose) { JVMFlag::Error G1NewSizePercentConstraintFunc(uintx value, bool verbose) { if (!UseG1GC) return JVMFlag::SUCCESS; if (value > G1MaxNewSizePercent) { - if (VerifyFlagConstraints) - { + if (VerifyFlagConstraints) { G1NewSizePercent = G1MaxNewSizePercent; JVMFlag::printError(true, "G1NewSizePercent:"UINTX_FORMAT"\n", G1MaxNewSizePercent); return JVMFlag::SUCCESS; @@ -112,8 +111,7 @@ JVMFlag::Error G1NewSizePercentConstraintFunc(uintx value, bool verbose) { JVMFlag::Error G1MaxNewSizePercentConstraintFunc(uintx value, bool verbose) { if (!UseG1GC) return JVMFlag::SUCCESS; if (value < G1NewSizePercent) { - if (VerifyFlagConstraints) - { + if (VerifyFlagConstraints) { G1MaxNewSizePercent = G1NewSizePercent; JVMFlag::printError(true, "G1MaxNewSizePercent:"UINTX_FORMAT"\n", G1NewSizePercent); return JVMFlag::SUCCESS; @@ -130,8 +128,7 @@ JVMFlag::Error G1MaxNewSizePercentConstraintFunc(uintx value, bool verbose) { JVMFlag::Error MaxGCPauseMillisConstraintFuncG1(uintx value, bool verbose) { if (UseG1GC && FLAG_IS_CMDLINE(MaxGCPauseMillis) && (value >= GCPauseIntervalMillis)) { - if (VerifyFlagConstraints) - { + if (VerifyFlagConstraints) { if (GCPauseIntervalMillis <= 1) { GCPauseIntervalMillis = 2; JVMFlag::printError(true, "GCPauseIntervalMillis:"UINTX_FORMAT"\n", GCPauseIntervalMillis); diff --git a/src/hotspot/share/gc/parallel/jvmFlagConstraintsParallel.cpp b/src/hotspot/share/gc/parallel/jvmFlagConstraintsParallel.cpp index 91ababb4d23..78d269b6909 100644 --- a/src/hotspot/share/gc/parallel/jvmFlagConstraintsParallel.cpp +++ b/src/hotspot/share/gc/parallel/jvmFlagConstraintsParallel.cpp @@ -32,7 +32,8 @@ JVMFlag::Error ParallelGCThreadsConstraintFuncParallel(uint value, bool verbose) // So can't exceed with "max_jint" if (UseParallelGC && (value > (uint)max_jint)) { if (VerifyFlagConstraints) { - JVMFlag::printError(true, "ParallelGCThreads:"UINT32_FORMAT"\n", max_jint); + ParallelGCThreads = max_jint; + JVMFlag::printError(true, "ParallelGCThreads:"UINT32_FORMAT"\n", ParallelGCThreads); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, @@ -48,7 +49,8 @@ JVMFlag::Error InitialTenuringThresholdConstraintFuncParallel(uintx value, bool // InitialTenuringThreshold is only used for ParallelGC. if (UseParallelGC && (value > MaxTenuringThreshold)) { if (VerifyFlagConstraints) { - JVMFlag::printError(true, "InitialTenuringThreshold"UINTX_FORMAT"\n", MaxTenuringThreshold); + InitialTenuringThreshold = MaxTenuringThreshold; + JVMFlag::printError(true, "InitialTenuringThreshold"UINTX_FORMAT"\n", InitialTenuringThreshold); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, @@ -65,6 +67,7 @@ JVMFlag::Error MaxTenuringThresholdConstraintFuncParallel(uintx value, bool verb // we don't need to compare InitialTenuringThreshold with MaxTenuringThreshold. if (UseParallelGC && (value < InitialTenuringThreshold)) { if (VerifyFlagConstraints) { + MaxTenuringThreshold = InitialTenuringThreshold; JVMFlag::printError(true, "MaxTenuringThreshold"UINTX_FORMAT"\n", InitialTenuringThreshold); return JVMFlag::SUCCESS; } diff --git a/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp b/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp index 197d16806ac..693cbcde199 100644 --- a/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp +++ b/src/hotspot/share/gc/shared/jvmFlagConstraintsGC.cpp @@ -87,7 +87,8 @@ JVMFlag::Error ConcGCThreadsConstraintFunc(uint value, bool verbose) { if ((GCConfig::is_gc_selected(CollectedHeap::CMS) || GCConfig::is_gc_selected(CollectedHeap::G1)) && (value > ParallelGCThreads)) { if (VerifyFlagConstraints) { - JVMFlag::printError(true, "ConcGCThreads"UINT32_FORMAT"\n", ParallelGCThreads); + ConcGCThreads = ParallelGCThreads; + JVMFlag::printError(true, "ConcGCThreads"UINT32_FORMAT"\n", ConcGCThreads); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, @@ -596,32 +597,33 @@ JVMFlag::Error MaxMetaspaceSizeConstraintFunc(size_t value, bool verbose) { JVMFlag::Error SurvivorAlignmentInBytesConstraintFunc(intx value, bool verbose) { if (value != 0) { bool verifyFailed = false; - if (!is_power_of_2(value)) { + if (value < ObjectAlignmentInBytes) { if (VerifyFlagConstraints) { verifyFailed = true; - int logValue = log2_intptr(value); - value = (intx)pow(2, logValue); + value = ObjectAlignmentInBytes; } else { JVMFlag::printError(verbose, "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be " - "power of 2\n", - value); + "greater than or equal to ObjectAlignmentInBytes (" INTX_FORMAT ")\n", + value, ObjectAlignmentInBytes); return JVMFlag::VIOLATES_CONSTRAINT; } } - if (value < ObjectAlignmentInBytes) { + if (!is_power_of_2(value)) { if (VerifyFlagConstraints) { verifyFailed = true; - value = ObjectAlignmentInBytes; + int logValue = log2_intptr(value); + value = (intx)pow(2, logValue); } else { JVMFlag::printError(verbose, "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be " - "greater than or equal to ObjectAlignmentInBytes (" INTX_FORMAT ")\n", - value, ObjectAlignmentInBytes); + "power of 2\n", + value); return JVMFlag::VIOLATES_CONSTRAINT; } } if (verifyFailed) { + SurvivorAlignmentInBytes = value; JVMFlag::printError(true, "SurvivorAlignmentInBytes:"INTX_FORMAT"\n", value); } } diff --git a/src/hotspot/share/runtime/flags/jvmFlag.cpp b/src/hotspot/share/runtime/flags/jvmFlag.cpp index 630c8becd97..a449f49d7ce 100644 --- a/src/hotspot/share/runtime/flags/jvmFlag.cpp +++ b/src/hotspot/share/runtime/flags/jvmFlag.cpp @@ -1086,11 +1086,16 @@ JVMFlag::Error JVMFlag::intAtPut(JVMFlag* flag, int* value, JVMFlag::Flags origi if (flag == NULL) return JVMFlag::INVALID_FLAG; if (!flag->is_int()) return JVMFlag::WRONG_FORMAT; name = flag->_name; + int old_value = flag->get_int(); JVMFlag::Error check = apply_constraint_and_check_range_int(name, *value, !JVMFlagConstraintList::validated_after_ergo()); if (check != JVMFlag::SUCCESS) return check; - int old_value = flag->get_int(); + trace_flag_changed(name, old_value, *value, origin); - check = flag->set_int(*value); + if (VerifyFlagConstraints && old_value != flag->get_int()) { + check = JVMFlag::SUCCESS; + } else { + check = flag->set_int(*value); + } *value = old_value; flag->set_origin(origin); return check; @@ -1135,11 +1140,16 @@ JVMFlag::Error JVMFlag::uintAtPut(JVMFlag* flag, uint* value, JVMFlag::Flags ori if (flag == NULL) return JVMFlag::INVALID_FLAG; if (!flag->is_uint()) return JVMFlag::WRONG_FORMAT; name = flag->_name; + uint old_value = flag->get_uint(); JVMFlag::Error check = apply_constraint_and_check_range_uint(name, *value, !JVMFlagConstraintList::validated_after_ergo()); if (check != JVMFlag::SUCCESS) return check; - uint old_value = flag->get_uint(); + trace_flag_changed(name, old_value, *value, origin); - check = flag->set_uint(*value); + if (VerifyFlagConstraints && old_value != flag->get_uint()) { + check = JVMFlag::SUCCESS; + } else { + check = flag->set_uint(*value); + } *value = old_value; flag->set_origin(origin); return check; @@ -1184,11 +1194,16 @@ JVMFlag::Error JVMFlag::intxAtPut(JVMFlag* flag, intx* value, JVMFlag::Flags ori if (flag == NULL) return JVMFlag::INVALID_FLAG; if (!flag->is_intx()) return JVMFlag::WRONG_FORMAT; name = flag->_name; + intx old_value = flag->get_intx(); JVMFlag::Error check = apply_constraint_and_check_range_intx(name, *value, !JVMFlagConstraintList::validated_after_ergo()); if (check != JVMFlag::SUCCESS) return check; - intx old_value = flag->get_intx(); + trace_flag_changed(name, old_value, *value, origin); - check = flag->set_intx(*value); + if (VerifyFlagConstraints && old_value != flag->get_intx()) { + check = JVMFlag::SUCCESS; + } else { + check = flag->set_intx(*value); + } *value = old_value; flag->set_origin(origin); return check; @@ -1233,11 +1248,15 @@ JVMFlag::Error JVMFlag::uintxAtPut(JVMFlag* flag, uintx* value, JVMFlag::Flags o if (flag == NULL) return JVMFlag::INVALID_FLAG; if (!flag->is_uintx()) return JVMFlag::WRONG_FORMAT; name = flag->_name; + uintx old_value = flag->get_uintx(); JVMFlag::Error check = apply_constraint_and_check_range_uintx(name, *value, !JVMFlagConstraintList::validated_after_ergo()); if (check != JVMFlag::SUCCESS) return check; - uintx old_value = flag->get_uintx(); trace_flag_changed(name, old_value, *value, origin); - check = flag->set_uintx(*value); + if (VerifyFlagConstraints && old_value != flag->get_uintx()) { + check = JVMFlag::SUCCESS; + } else { + check = flag->set_uintx(*value); + } *value = old_value; flag->set_origin(origin); return check; @@ -1282,11 +1301,15 @@ JVMFlag::Error JVMFlag::uint64_tAtPut(JVMFlag* flag, uint64_t* value, JVMFlag::F if (flag == NULL) return JVMFlag::INVALID_FLAG; if (!flag->is_uint64_t()) return JVMFlag::WRONG_FORMAT; name = flag->_name; + uint64_t old_value = flag->get_uint64_t(); JVMFlag::Error check = apply_constraint_and_check_range_uint64_t(name, *value, !JVMFlagConstraintList::validated_after_ergo()); if (check != JVMFlag::SUCCESS) return check; - uint64_t old_value = flag->get_uint64_t(); trace_flag_changed(name, old_value, *value, origin); - check = flag->set_uint64_t(*value); + if (VerifyFlagConstraints && old_value != flag->get_uint64_t()) { + check = JVMFlag::SUCCESS; + } else { + check = flag->set_uint64_t(*value); + } *value = old_value; flag->set_origin(origin); return check; @@ -1332,11 +1355,15 @@ JVMFlag::Error JVMFlag::size_tAtPut(JVMFlag* flag, size_t* value, JVMFlag::Flags if (flag == NULL) return JVMFlag::INVALID_FLAG; if (!flag->is_size_t()) return JVMFlag::WRONG_FORMAT; name = flag->_name; + size_t old_value = flag->get_size_t(); JVMFlag::Error check = apply_constraint_and_check_range_size_t(name, *value, !JVMFlagConstraintList::validated_after_ergo()); if (check != JVMFlag::SUCCESS) return check; - size_t old_value = flag->get_size_t(); trace_flag_changed(name, old_value, *value, origin); - check = flag->set_size_t(*value); + if (VerifyFlagConstraints && old_value != flag->get_size_t()) { + check = JVMFlag::SUCCESS; + } else { + check = flag->set_size_t(*value); + } *value = old_value; flag->set_origin(origin); return check; @@ -1381,11 +1408,16 @@ JVMFlag::Error JVMFlag::doubleAtPut(JVMFlag* flag, double* value, JVMFlag::Flags if (flag == NULL) return JVMFlag::INVALID_FLAG; if (!flag->is_double()) return JVMFlag::WRONG_FORMAT; name = flag->_name; + double old_value = flag->get_double(); JVMFlag::Error check = apply_constraint_and_check_range_double(name, *value, !JVMFlagConstraintList::validated_after_ergo()); if (check != JVMFlag::SUCCESS) return check; - double old_value = flag->get_double(); + trace_flag_changed(name, old_value, *value, origin); - check = flag->set_double(*value); + if (VerifyFlagConstraints && old_value != flag->get_double()) { + check = JVMFlag::SUCCESS; + } else { + check = flag->set_double(*value); + } *value = old_value; flag->set_origin(origin); return check; diff --git a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp index fa085c2d1c1..a7b0c4b4005 100644 --- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp +++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp @@ -104,7 +104,7 @@ JVMFlag::Error CICompilerCountConstraintFunc(intx value, bool verbose) { JVMFlag::Error AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose) { if (value < 0 || value > 512) { if (VerifyFlagConstraints) { - AllocatePrefetchDistance = value < 0 ? 0 : 512; + AllocatePrefetchDistance = value < 0 ? 1 : 512; JVMFlag::printError(true, "AllocatePrefetchDistance:" INTX_FORMAT "\n", AllocatePrefetchDistance); return JVMFlag::SUCCESS; } @@ -246,63 +246,36 @@ JVMFlag::Error OnStackReplacePercentageConstraintFunc(intx value, bool verbose) } JVMFlag::Error CodeCacheSegmentSizeConstraintFunc(uintx value, bool verbose) { - bool verifyFailed = false; - uintx max = 0; + // Don't apply VerifyFlagConstraints here because CodeCacheSegmentSize is not production parameter. if (CodeCacheSegmentSize < (uintx)CodeEntryAlignment) { - if (VerifyFlagConstraints) - { - verifyFailed = true; - max = CodeEntryAlignment; - } - else - { - JVMFlag::printError(verbose, + JVMFlag::printError(verbose, "CodeCacheSegmentSize (" UINTX_FORMAT ") must be " "larger than or equal to CodeEntryAlignment (" INTX_FORMAT ") " "to align entry points\n", CodeCacheSegmentSize, CodeEntryAlignment); - return JVMFlag::VIOLATES_CONSTRAINT; - } + return JVMFlag::VIOLATES_CONSTRAINT; } if (CodeCacheSegmentSize < sizeof(jdouble)) { - if (VerifyFlagConstraints) - { - verifyFailed = true; - max = sizeof(jdouble) >= max ? sizeof(jdouble) : max; - } - else - { - JVMFlag::printError(verbose, + JVMFlag::printError(verbose, "CodeCacheSegmentSize (" UINTX_FORMAT ") must be " "at least " SIZE_FORMAT " to align constants\n", CodeCacheSegmentSize, sizeof(jdouble)); - return JVMFlag::VIOLATES_CONSTRAINT; - } + return JVMFlag::VIOLATES_CONSTRAINT; } #ifdef COMPILER2 if (CodeCacheSegmentSize < (uintx)OptoLoopAlignment) { - if (VerifyFlagConstraints) - { - verifyFailed = true; - max = (uintx)OptoLoopAlignment > max ? (uintx)OptoLoopAlignment : max; - } - else - { - JVMFlag::printError(verbose, + + JVMFlag::printError(verbose, "CodeCacheSegmentSize (" UINTX_FORMAT ") must be " "larger than or equal to OptoLoopAlignment (" INTX_FORMAT ") " "to align inner loops\n", CodeCacheSegmentSize, OptoLoopAlignment); - return JVMFlag::VIOLATES_CONSTRAINT; - } + return JVMFlag::VIOLATES_CONSTRAINT; + } #endif - if (verifyFailed) - { - JVMFlag::printError(true, "CodeCacheSegmentSize:"UINTX_FORMAT"\n", max); - } return JVMFlag::SUCCESS; } @@ -323,6 +296,7 @@ JVMFlag::Error CompilerThreadPriorityConstraintFunc(intx value, bool verbose) { } JVMFlag::Error CodeEntryAlignmentConstraintFunc(intx value, bool verbose) { + // Don't apply VerifyFlagConstraints here because CodeEntryAlignment is not production parameter. #ifdef SPARC if (CodeEntryAlignment % relocInfo::addr_unit() != 0) { JVMFlag::printError(verbose, @@ -331,42 +305,20 @@ JVMFlag::Error CodeEntryAlignmentConstraintFunc(intx value, bool verbose) { return JVMFlag::VIOLATES_CONSTRAINT; } #endif - bool verifyFailed = false; if (!is_power_of_2(value)) { - if (VerifyFlagConstraints) - { - verifyFailed = true; - int logValue = log2_intptr(value); - value = (intx)pow(2, logValue); - } - else - { JVMFlag::printError(verbose, "CodeEntryAlignment (" INTX_FORMAT ") must be " "a power of two\n", CodeEntryAlignment); return JVMFlag::VIOLATES_CONSTRAINT; } - } if (value < 16) { - if (VerifyFlagConstraints) - { - value = 16; - } - else - { JVMFlag::printError(verbose, "CodeEntryAlignment (" INTX_FORMAT ") must be " "greater than or equal to %d\n", CodeEntryAlignment, 16); return JVMFlag::VIOLATES_CONSTRAINT; - } - } - - if (verifyFailed) - { - JVMFlag::printError(true, "CodeEntryAlignment:" INTX_FORMAT "\n", value); } return JVMFlag::SUCCESS; @@ -375,14 +327,11 @@ JVMFlag::Error CodeEntryAlignmentConstraintFunc(intx value, bool verbose) { JVMFlag::Error OptoLoopAlignmentConstraintFunc(intx value, bool verbose) { bool verifyFailed = false; if (!is_power_of_2(value)) { - if (VerifyFlagConstraints) - { + if (VerifyFlagConstraints) { verifyFailed = true; int logValue = log2_intptr(value); value = (intx)pow(2, logValue); - } - else - { + } else { JVMFlag::printError(verbose, "OptoLoopAlignment (" INTX_FORMAT ") " "must be a power of two\n", @@ -393,16 +342,12 @@ JVMFlag::Error OptoLoopAlignmentConstraintFunc(intx value, bool verbose) { // Relevant on ppc, s390, sparc. Will be optimized where // addr_unit() == 1. - if (value % relocInfo::addr_unit() != 0) - { - if (VerifyFlagConstraints) - { + if (value % relocInfo::addr_unit() != 0) { + if (VerifyFlagConstraints) { verifyFailed = true; int remainder = value % relocInfo::addr_unit(); value = value - remainder; - } - else - { + } else { JVMFlag::printError(verbose, "OptoLoopAlignment (" INTX_FORMAT ") must be " "multiple of NOP size (%d)\n", @@ -411,8 +356,8 @@ JVMFlag::Error OptoLoopAlignmentConstraintFunc(intx value, bool verbose) { } } - if (verifyFailed) - { + if (verifyFailed) { + OptoLoopAlignment = value; JVMFlag::printError(verbose, "OptoLoopAlignment:" INTX_FORMAT "\n", value); } @@ -420,12 +365,8 @@ JVMFlag::Error OptoLoopAlignmentConstraintFunc(intx value, bool verbose) { } JVMFlag::Error ArraycopyDstPrefetchDistanceConstraintFunc(uintx value, bool verbose) { + // Don't apply VerifyFlagConstraints here because ArraycopyDstPrefetchDistance is Sparc platform only if (value >= 4032) { - if (VerifyFlagConstraints) - { - JVMFlag::printError(true, "ArraycopyDstPrefetchDistance:" UINTX_FORMAT "\n", 4031); - return JVMFlag::SUCCESS; - } JVMFlag::printError(verbose, "ArraycopyDstPrefetchDistance (" UINTX_FORMAT ") must be" "between 0 and 4031\n", value); @@ -436,13 +377,8 @@ JVMFlag::Error ArraycopyDstPrefetchDistanceConstraintFunc(uintx value, bool verb } JVMFlag::Error ArraycopySrcPrefetchDistanceConstraintFunc(uintx value, bool verbose) { - JVMFlag::printError(true, "ArraycopySrcPrefetchDistanceConstraintFunc\n"); + // Don't apply VerifyFlagConstraints here because ArraycopySrcPrefetchDistance is Sparc platform only if (value >= 4032) { - if (VerifyFlagConstraints) - { - JVMFlag::printError(true, "ArraycopySrcPrefetchDistance:" UINTX_FORMAT "\n", 4031); - return JVMFlag::SUCCESS; - } JVMFlag::printError(verbose, "ArraycopySrcPrefetchDistance (" UINTX_FORMAT ") must be" "between 0 and 4031\n", value); @@ -457,8 +393,7 @@ JVMFlag::Error TypeProfileLevelConstraintFunc(uintx value, bool verbose) { int suggested[3]; for (int i = 0; i < 3; i++) { if (value % 10 > 2) { - if (VerifyFlagConstraints) - { + if (VerifyFlagConstraints) { verifyFailed = true; suggested[i] = 2; } else { @@ -474,17 +409,15 @@ JVMFlag::Error TypeProfileLevelConstraintFunc(uintx value, bool verbose) { value = value / 10; } if (verifyFailed) { - JVMFlag::printError(true, "TypeProfileLevel:" UINTX_FORMAT "\n", (suggested[0] + suggested[1]*10 + suggested[2]*100)); + uintx suggestedValue = suggested[0] + suggested[1]*10 + suggested[2]*100; + TypeProfileLevel = suggestedValue; + JVMFlag::printError(true, "TypeProfileLevel:" UINTX_FORMAT "\n", suggestedValue); } return JVMFlag::SUCCESS; } JVMFlag::Error InitArrayShortSizeConstraintFunc(intx value, bool verbose) { if (value % BytesPerLong != 0) { - if (VerifyFlagConstraints) { - JVMFlag::printError(true, "InitArrayShortSize:"INTX_FORMAT"\n", (value - BytesPerLong)); - return JVMFlag::SUCCESS; - } return JVMFlag::VIOLATES_CONSTRAINT; } else { return JVMFlag::SUCCESS; @@ -551,6 +484,7 @@ JVMFlag::Error InteriorEntryAlignmentConstraintFunc(intx value, bool verbose) { } if(verifyFailed) { + InteriorEntryAlignment = value; JVMFlag::printError(true, "InteriorEntryAlignment:"INTX_FORMAT"\n", value); } @@ -560,8 +494,9 @@ JVMFlag::Error InteriorEntryAlignmentConstraintFunc(intx value, bool verbose) { JVMFlag::Error NodeLimitFudgeFactorConstraintFunc(intx value, bool verbose) { if (value < MaxNodeLimit * 2 / 100 || value > MaxNodeLimit * 40 / 100) { if (VerifyFlagConstraints) { - JVMFlag::printError(true, "NodeLimitFudgeFactor:"INTX_FORMAT"\n", - ((value < MaxNodeLimit * 2 / 100)? (MaxNodeLimit * 2 / 100): (MaxNodeLimit * 40 / 100))); + intx limit = (value < MaxNodeLimit * 2 / 100)? (MaxNodeLimit * 2 / 100): (MaxNodeLimit * 40 / 100); + NodeLimitFudgeFactor = limit; + JVMFlag::printError(true, "NodeLimitFudgeFactor:"INTX_FORMAT"\n", limit); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, diff --git a/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp b/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp index 9160068e0be..655a816b2e1 100644 --- a/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp +++ b/src/hotspot/share/runtime/flags/jvmFlagConstraintsRuntime.cpp @@ -34,14 +34,11 @@ JVMFlag::Error ObjectAlignmentInBytesConstraintFunc(intx value, bool verbose) { bool verifyFailed = false; if (!is_power_of_2(value)) { - if (VerifyFlagConstraints) - { + if (VerifyFlagConstraints) { verifyFailed = true; int logValue = log2_intptr(value); value = (intx)pow(2, logValue); - } - else - { + } else { JVMFlag::printError(verbose, "ObjectAlignmentInBytes (" INTX_FORMAT ") must be " "power of 2\n", @@ -51,21 +48,20 @@ JVMFlag::Error ObjectAlignmentInBytesConstraintFunc(intx value, bool verbose) { } // In case page size is very small. if (value >= (intx)os::vm_page_size()) { - if (VerifyFlagConstraints) - { - JVMFlag::printError(true, "ObjectAlignmentInBytes:" INTX_FORMAT "\n", (intx)(os::vm_page_size()/2)); - return JVMFlag::SUCCESS; - } - JVMFlag::printError(verbose, + if (VerifyFlagConstraints) { + verifyFailed = true; + value = (intx)(os::vm_page_size()/2); + } else { + JVMFlag::printError(verbose, "ObjectAlignmentInBytes (" INTX_FORMAT ") must be " "less than page size (" INTX_FORMAT ")\n", value, (intx)os::vm_page_size()); - return JVMFlag::VIOLATES_CONSTRAINT; + return JVMFlag::VIOLATES_CONSTRAINT; + } } - if (verifyFailed) - { + if (verifyFailed) { + ObjectAlignmentInBytes = value; JVMFlag::printError(true, "ObjectAlignmentInBytes:" INTX_FORMAT "\n", value); - return JVMFlag::SUCCESS; } return JVMFlag::SUCCESS; } @@ -74,10 +70,10 @@ JVMFlag::Error ObjectAlignmentInBytesConstraintFunc(intx value, bool verbose) { // It is sufficient to check against the largest type size. JVMFlag::Error ContendedPaddingWidthConstraintFunc(intx value, bool verbose) { if ((value % BytesPerLong) != 0) { - if (VerifyFlagConstraints) - { + if (VerifyFlagConstraints) { int remainder = value % BytesPerLong; - JVMFlag::printError(true, "ContendedPaddingWidth:" INTX_FORMAT "\n", (value - remainder)); + ContendedPaddingWidth = value - remainder; + JVMFlag::printError(true, "ContendedPaddingWidth:" INTX_FORMAT "\n", ContendedPaddingWidth); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, @@ -92,8 +88,8 @@ JVMFlag::Error ContendedPaddingWidthConstraintFunc(intx value, bool verbose) { JVMFlag::Error BiasedLockingBulkRebiasThresholdFunc(intx value, bool verbose) { if (value > BiasedLockingBulkRevokeThreshold) { - if (VerifyFlagConstraints) - { + if (VerifyFlagConstraints) { + BiasedLockingBulkRebiasThreshold = BiasedLockingBulkRevokeThreshold; JVMFlag::printError(true, "BiasedLockingBulkRebiasThreshold:" INTX_FORMAT "\n", BiasedLockingBulkRevokeThreshold); return JVMFlag::SUCCESS; } @@ -109,10 +105,10 @@ JVMFlag::Error BiasedLockingBulkRebiasThresholdFunc(intx value, bool verbose) { JVMFlag::Error BiasedLockingStartupDelayFunc(intx value, bool verbose) { if ((value % PeriodicTask::interval_gran) != 0) { - if (VerifyFlagConstraints) - { + if (VerifyFlagConstraints) { int remainder = value % PeriodicTask::interval_gran; - JVMFlag::printError(true, "BiasedLockingStartupDelay:" INTX_FORMAT "\n", (value - remainder)); + BiasedLockingStartupDelay = value - remainder; + JVMFlag::printError(true, "BiasedLockingStartupDelay:" INTX_FORMAT "\n", BiasedLockingStartupDelay); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, @@ -127,9 +123,9 @@ JVMFlag::Error BiasedLockingStartupDelayFunc(intx value, bool verbose) { JVMFlag::Error BiasedLockingBulkRevokeThresholdFunc(intx value, bool verbose) { if (value < BiasedLockingBulkRebiasThreshold) { - if (VerifyFlagConstraints) - { - JVMFlag::printError(true, "BiasedLockingBulkRevokeThreshold:" INTX_FORMAT "\n", BiasedLockingBulkRebiasThreshold); + if (VerifyFlagConstraints) { + BiasedLockingBulkRevokeThreshold = BiasedLockingBulkRebiasThreshold; + JVMFlag::printError(true, "BiasedLockingBulkRevokeThreshold:" INTX_FORMAT "\n", BiasedLockingBulkRevokeThreshold); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, @@ -138,9 +134,9 @@ JVMFlag::Error BiasedLockingBulkRevokeThresholdFunc(intx value, bool verbose) { value, BiasedLockingBulkRebiasThreshold); return JVMFlag::VIOLATES_CONSTRAINT; } else if ((double)value/(double)BiasedLockingDecayTime > 0.1) { - if (VerifyFlagConstraints) - { - JVMFlag::printError(true, "BiasedLockingBulkRevokeThreshold:" INTX_FORMAT "\n", (BiasedLockingDecayTime * 0.1)); + if (VerifyFlagConstraints) { + BiasedLockingBulkRevokeThreshold = (intx)(BiasedLockingDecayTime * 0.1); + JVMFlag::printError(true, "BiasedLockingBulkRevokeThreshold:" INTX_FORMAT "\n", BiasedLockingBulkRevokeThreshold); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, @@ -156,9 +152,9 @@ JVMFlag::Error BiasedLockingBulkRevokeThresholdFunc(intx value, bool verbose) { JVMFlag::Error BiasedLockingDecayTimeFunc(intx value, bool verbose) { if (BiasedLockingBulkRebiasThreshold/(double)value > 0.1) { - if (VerifyFlagConstraints) - { - JVMFlag::printError(true, "BiasedLockingDecayTime:" INTX_FORMAT "\n", (BiasedLockingBulkRebiasThreshold * 10)); + if (VerifyFlagConstraints) { + BiasedLockingDecayTime = BiasedLockingBulkRebiasThreshold * 10; + JVMFlag::printError(true, "BiasedLockingDecayTime:"INTX_FORMAT"\n", BiasedLockingDecayTime); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, @@ -174,10 +170,10 @@ JVMFlag::Error BiasedLockingDecayTimeFunc(intx value, bool verbose) { JVMFlag::Error PerfDataSamplingIntervalFunc(intx value, bool verbose) { if ((value % PeriodicTask::interval_gran != 0)) { - if (VerifyFlagConstraints) - { + if (VerifyFlagConstraints) { int remainder = value % PeriodicTask::interval_gran; - JVMFlag::printError(true, "PerfDataSamplingInterval:" INTX_FORMAT "\n", (value - remainder)); + PerfDataSamplingInterval = value - remainder; + JVMFlag::printError(true, "PerfDataSamplingInterval:"INTX_FORMAT"\n", PerfDataSamplingInterval); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, @@ -193,10 +189,9 @@ JVMFlag::Error PerfDataSamplingIntervalFunc(intx value, bool verbose) { JVMFlag::Error ThreadLocalHandshakesConstraintFunc(bool value, bool verbose) { if (value) { if (!SafepointMechanism::supports_thread_local_poll()) { - if (VerifyFlagConstraints) - { - int remainder = value % PeriodicTask::interval_gran; - JVMFlag::printError(true, "ThreadLocalHandshakes:unsupported\n"); + if (VerifyFlagConstraints) { + VerifyFlagConstraints = false; + JVMFlag::printError(true, "ThreadLocalHandshakes:false\n"); return JVMFlag::SUCCESS; } JVMFlag::printError(verbose, "ThreadLocalHandshakes not yet supported on this platform\n"); diff --git a/test/hotspot/jtreg/sanity/VerifyFlagConstraintsTests.java b/test/hotspot/jtreg/sanity/VerifyFlagConstraintsTests.java index 100b4604686..1703942a69c 100644 --- a/test/hotspot/jtreg/sanity/VerifyFlagConstraintsTests.java +++ b/test/hotspot/jtreg/sanity/VerifyFlagConstraintsTests.java @@ -25,7 +25,6 @@ import jdk.test.lib.process.OutputAnalyzer; import jdk.test.lib.process.ProcessTools; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -33,7 +32,6 @@ * @test * @summary make sure various basic java options work * @library /test/lib - * * @run driver sanity.VerifyFlagConstraintsTests */ public class VerifyFlagConstraintsTests { @@ -46,47 +44,120 @@ public static void main(String[] args) throws Exception { "-XX:AllocatePrefetchStyle=3") .testEq("MaxGCPauseMillis", "1") .testEq("GCPauseIntervalMillis", "2") - .testEq("AllocatePrefetchDistance", "0") - .testEq("AllocatePrefetchStepSize", "24"); + .testEq("AllocatePrefetchDistance", "1") + .testEq("AllocatePrefetchStepSize", "24") + .testWithSuggested(); - FlagConstraintTester.create().run(" -XX:CompileThreshold=268435456", - "-XX:OnStackReplacePercentage=40").testEq("CompileThreshold", "268435455"); + FlagConstraintTester.create().run("-XX:InteriorEntryAlignment=99", + "-XX:OptoLoopAlignment=9") + .testEq("InteriorEntryAlignment", "32") + .testEq("OptoLoopAlignment", "8") + .testWithSuggested(); - FlagConstraintTester.create().run(" -XX:CompileThreshold=268435456") + FlagConstraintTester.create().run("-XX:CompileThreshold=268435456") .testEq("CompileThreshold", "268435455") - .testEq("OnStackReplacePercentage", "34"); + .testEq("OnStackReplacePercentage", "34") + .testWithSuggested(); + + FlagConstraintTester.create().run("-XX:ObjectAlignmentInBytes=99") + .testEq("ObjectAlignmentInBytes", "64") + .testWithSuggested(); + + FlagConstraintTester.create().run("-XX:TypeProfileLevel=123") + .testEq("TypeProfileLevel", "122") + .testWithSuggested(); + + FlagConstraintTester.create().run("-XX:TypeProfileLevel=333") + .testEq("TypeProfileLevel", "222") + .testWithSuggested(); + + FlagConstraintTester.create().run("-XX:BiasedLockingBulkRebiasThreshold=250", + "-XX:BiasedLockingBulkRevokeThreshold=249", + "-XX:BiasedLockingDecayTime=2500") + .testWithSuggested(); + + FlagConstraintTester.create().run("-XX:BiasedLockingStartupDelay=99") + .testEq("BiasedLockingStartupDelay", "90") + .testWithSuggested(); + } static class FlagConstraintTester { - private String[] enableArgs = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+VerifyFlagConstraints"}; - private Map verifiedContents = new HashMap<>(); + private static String[] enableArgs = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+VerifyFlagConstraints"}; + private Map suggestedArgs = new HashMap<>(); + private Map inputArgs = new HashMap<>(); public static FlagConstraintTester create() { return new FlagConstraintTester(); } public FlagConstraintTester run(String... flags) throws Exception { + OutputAnalyzer outputAnalyzer = doRun(flags, true); + extractSuggestions(outputAnalyzer); + return this; + } + + private OutputAnalyzer doRun(String[] flags, boolean updateInputs) 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]; + if (updateInputs) { + String[] values = flags[i].split("="); + String key; + String value; + if (values.length == 1) { + // case of -XX:+SomeOpt + key = values[0].substring(5); + value = String.valueOf(values[0].charAt(4)); + } else { + key = values[0].substring(4); + value = values[1]; + } + inputArgs.put(key, value); + } } OutputAnalyzer outputAnalyzer = ProcessTools.executeTestJvm(cmds); - outputAnalyzer.shouldHaveExitValue(0); System.out.println(outputAnalyzer.getOutput()); + outputAnalyzer.shouldHaveExitValue(0); + return outputAnalyzer; + } + + private void extractSuggestions(OutputAnalyzer outputAnalyzer) { 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]); + suggestedArgs.put(rets[0], rets[1]); } - return this; + } + + /** + * Start JVM with suggested flags again. This time there should be no suggestion anymore. + * + * @throws Exception + */ + public void testWithSuggested() throws Exception { + suggestedArgs.entrySet().forEach(suggested -> + inputArgs.put(suggested.getKey(), suggested.getValue()) + ); + String[] args = inputArgs.entrySet().stream().map(entry -> { + if (entry.getValue().equals("-") || entry.getValue().equalsIgnoreCase("false")) { + return "-XX:-" + entry.getKey(); + } + if (entry.getValue().equals("+") || entry.getValue().equalsIgnoreCase("true")) { + return "-XX:+" + entry.getKey(); + } + return "-XX:" + entry.getKey() + "=" + entry.getValue(); + }).toArray(String[]::new); + OutputAnalyzer outputAnalyzer = doRun(args, false); + outputAnalyzer.shouldBeEmpty(); } public FlagConstraintTester testEq(String param, String expected) { - Asserts.assertEquals(expected, verifiedContents.get(param)); + Asserts.assertEquals(expected, suggestedArgs.get(param)); return this; } }