11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/shared/collectedHeap.hpp" 27 #include "gc/shared/collectorPolicy.hpp" 28 #include "gc/shared/genCollectedHeap.hpp" 29 #include "gc/shared/threadLocalAllocBuffer.hpp" 30 #include "runtime/arguments.hpp" 31 #include "runtime/commandLineFlagConstraintsGC.hpp" 32 #include "runtime/commandLineFlagRangeList.hpp" 33 #include "runtime/globals.hpp" 34 #include "runtime/globals_extension.hpp" 35 #include "runtime/thread.inline.hpp" 36 #include "utilities/align.hpp" 37 #include "utilities/defaultStream.hpp" 38 39 #if INCLUDE_ALL_GCS 40 #include "gc/cms/concurrentMarkSweepGeneration.inline.hpp" 41 #include "gc/g1/g1_globals.hpp" 42 #include "gc/g1/heapRegionBounds.inline.hpp" 43 #include "gc/shared/plab.hpp" 44 #endif // INCLUDE_ALL_GCS 45 #ifdef COMPILER1 46 #include "c1/c1_globals.hpp" 47 #endif // COMPILER1 48 #ifdef COMPILER2 49 #include "opto/c2_globals.hpp" 50 #endif // COMPILER2 51 52 // Some flags that have default values that indicate that the 53 // JVM should automatically determine an appropriate value 54 // for that flag. In those cases it is only appropriate for the 55 // constraint checking to be done if the user has specified the 56 // value(s) of the flag(s) on the command line. In the constraint 57 // checking functions, FLAG_IS_CMDLINE() is used to check if 58 // the flag has been set by the user and so should be checked. 59 60 #if INCLUDE_ALL_GCS 61 static Flag::Error ParallelGCThreadsAndCMSWorkQueueDrainThreshold(uint threads, uintx threshold, bool verbose) { 62 // CMSWorkQueueDrainThreshold is verified to be less than max_juint 63 if (UseConcMarkSweepGC && (threads > (uint)(max_jint / (uint)threshold))) { 64 CommandLineError::print(verbose, 65 "ParallelGCThreads (" UINT32_FORMAT ") or CMSWorkQueueDrainThreshold (" 66 UINTX_FORMAT ") is too large\n", 67 threads, threshold); 68 return Flag::VIOLATES_CONSTRAINT; 69 } 70 return Flag::SUCCESS; 71 } 72 #endif 73 74 // As ParallelGCThreads differs among GC modes, we need constraint function. 75 Flag::Error ParallelGCThreadsConstraintFunc(uint value, bool verbose) { 76 Flag::Error status = Flag::SUCCESS; 77 78 #if INCLUDE_ALL_GCS 79 // Parallel GC passes ParallelGCThreads when creating GrowableArray as 'int' type parameter. 80 // So can't exceed with "max_jint" 81 if (UseParallelGC && (value > (uint)max_jint)) { 82 CommandLineError::print(verbose, 83 "ParallelGCThreads (" UINT32_FORMAT ") must be " 84 "less than or equal to " UINT32_FORMAT " for Parallel GC\n", 85 value, max_jint); 86 return Flag::VIOLATES_CONSTRAINT; 87 } 88 // To avoid overflow at ParScanClosure::do_oop_work. 89 if (UseConcMarkSweepGC && (value > (max_jint / 10))) { 90 CommandLineError::print(verbose, 91 "ParallelGCThreads (" UINT32_FORMAT ") must be " 92 "less than or equal to " UINT32_FORMAT " for CMS GC\n", 93 value, (max_jint / 10)); 94 return Flag::VIOLATES_CONSTRAINT; 95 } 96 status = ParallelGCThreadsAndCMSWorkQueueDrainThreshold(value, CMSWorkQueueDrainThreshold, verbose); 97 #endif 98 return status; 99 } 100 101 // As ConcGCThreads should be smaller than ParallelGCThreads, 102 // we need constraint function. 103 Flag::Error ConcGCThreadsConstraintFunc(uint value, bool verbose) { 104 #if INCLUDE_ALL_GCS 105 // CMS and G1 GCs use ConcGCThreads. 106 if ((UseConcMarkSweepGC || UseG1GC) && (value > ParallelGCThreads)) { 107 CommandLineError::print(verbose, 108 "ConcGCThreads (" UINT32_FORMAT ") must be " 109 "less than or equal to ParallelGCThreads (" UINT32_FORMAT ")\n", 110 value, ParallelGCThreads); 111 return Flag::VIOLATES_CONSTRAINT; 112 } 113 #endif 114 return Flag::SUCCESS; 115 } 116 117 static Flag::Error MinPLABSizeBounds(const char* name, size_t value, bool verbose) { 118 #if INCLUDE_ALL_GCS 119 if ((UseConcMarkSweepGC || UseG1GC || UseParallelGC) && (value < PLAB::min_size())) { 120 CommandLineError::print(verbose, 121 "%s (" SIZE_FORMAT ") must be " 122 "greater than or equal to ergonomic PLAB minimum size (" SIZE_FORMAT ")\n", 123 name, value, PLAB::min_size()); 124 return Flag::VIOLATES_CONSTRAINT; 125 } 126 #endif // INCLUDE_ALL_GCS 127 return Flag::SUCCESS; 128 } 129 130 static Flag::Error MaxPLABSizeBounds(const char* name, size_t value, bool verbose) { 131 #if INCLUDE_ALL_GCS 132 if ((UseConcMarkSweepGC || UseG1GC || UseParallelGC) && (value > PLAB::max_size())) { 133 CommandLineError::print(verbose, 134 "%s (" SIZE_FORMAT ") must be " 135 "less than or equal to ergonomic PLAB maximum size (" SIZE_FORMAT ")\n", 136 name, value, PLAB::max_size()); 137 return Flag::VIOLATES_CONSTRAINT; 138 } 139 #endif // INCLUDE_ALL_GCS 140 return Flag::SUCCESS; 141 } 142 143 static Flag::Error MinMaxPLABSizeBounds(const char* name, size_t value, bool verbose) { 144 Flag::Error status = MinPLABSizeBounds(name, value, verbose); 145 146 if (status == Flag::SUCCESS) { 147 return MaxPLABSizeBounds(name, value, verbose); 148 } 149 return status; 150 } 151 152 Flag::Error YoungPLABSizeConstraintFunc(size_t value, bool verbose) { 153 return MinMaxPLABSizeBounds("YoungPLABSize", value, verbose); 154 } 155 156 Flag::Error OldPLABSizeConstraintFunc(size_t value, bool verbose) { 157 Flag::Error status = Flag::SUCCESS; 158 159 #if INCLUDE_ALL_GCS 160 if (UseConcMarkSweepGC) { 161 if (value == 0) { 162 CommandLineError::print(verbose, 163 "OldPLABSize (" SIZE_FORMAT ") must be greater than 0", 164 value); 165 return Flag::VIOLATES_CONSTRAINT; 166 } 167 // For CMS, OldPLABSize is the number of free blocks of a given size that are used when 168 // replenishing the local per-worker free list caches. 169 // For more details, please refer to Arguments::set_cms_and_parnew_gc_flags(). 170 status = MaxPLABSizeBounds("OldPLABSize", value, verbose); 171 } else { 172 status = MinMaxPLABSizeBounds("OldPLABSize", value, verbose); 173 } 174 #endif 175 return status; 176 } 177 178 Flag::Error MinHeapFreeRatioConstraintFunc(uintx value, bool verbose) { 179 if (value > MaxHeapFreeRatio) { 180 CommandLineError::print(verbose, 181 "MinHeapFreeRatio (" UINTX_FORMAT ") must be " 182 "less than or equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n", 183 value, MaxHeapFreeRatio); 184 return Flag::VIOLATES_CONSTRAINT; 185 } else { 186 return Flag::SUCCESS; 187 } 188 } 189 190 Flag::Error MaxHeapFreeRatioConstraintFunc(uintx value, bool verbose) { 191 if (value < MinHeapFreeRatio) { 192 CommandLineError::print(verbose, 193 "MaxHeapFreeRatio (" UINTX_FORMAT ") must be " 194 "greater than or equal to MinHeapFreeRatio (" UINTX_FORMAT ")\n", 195 value, MinHeapFreeRatio); 196 return Flag::VIOLATES_CONSTRAINT; 197 } else { 198 return Flag::SUCCESS; 199 } 200 } 201 202 static Flag::Error CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(size_t maxHeap, intx softRef, bool verbose) { 203 if ((softRef > 0) && ((maxHeap / M) > (max_uintx / softRef))) { 204 CommandLineError::print(verbose, 205 "Desired lifetime of SoftReferences cannot be expressed correctly. " 206 "MaxHeapSize (" SIZE_FORMAT ") or SoftRefLRUPolicyMSPerMB " 207 "(" INTX_FORMAT ") is too large\n", 208 maxHeap, softRef); 209 return Flag::VIOLATES_CONSTRAINT; 210 } else { 211 return Flag::SUCCESS; 212 } 213 } 214 215 Flag::Error SoftRefLRUPolicyMSPerMBConstraintFunc(intx value, bool verbose) { 216 return CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(MaxHeapSize, value, verbose); 217 } 218 219 Flag::Error MinMetaspaceFreeRatioConstraintFunc(uintx value, bool verbose) { 220 if (value > MaxMetaspaceFreeRatio) { 221 CommandLineError::print(verbose, 222 "MinMetaspaceFreeRatio (" UINTX_FORMAT ") must be " 223 "less than or equal to MaxMetaspaceFreeRatio (" UINTX_FORMAT ")\n", 224 value, MaxMetaspaceFreeRatio); 225 return Flag::VIOLATES_CONSTRAINT; 226 } else { 227 return Flag::SUCCESS; 228 } 229 } 230 231 Flag::Error MaxMetaspaceFreeRatioConstraintFunc(uintx value, bool verbose) { 232 if (value < MinMetaspaceFreeRatio) { 233 CommandLineError::print(verbose, 234 "MaxMetaspaceFreeRatio (" UINTX_FORMAT ") must be " 235 "greater than or equal to MinMetaspaceFreeRatio (" UINTX_FORMAT ")\n", 236 value, MinMetaspaceFreeRatio); 237 return Flag::VIOLATES_CONSTRAINT; 238 } else { 239 return Flag::SUCCESS; 240 } 241 } 242 243 Flag::Error InitialTenuringThresholdConstraintFunc(uintx value, bool verbose) { 244 #if INCLUDE_ALL_GCS 245 // InitialTenuringThreshold is only used for ParallelGC. 246 if (UseParallelGC && (value > MaxTenuringThreshold)) { 247 CommandLineError::print(verbose, 248 "InitialTenuringThreshold (" UINTX_FORMAT ") must be " 249 "less than or equal to MaxTenuringThreshold (" UINTX_FORMAT ")\n", 250 value, MaxTenuringThreshold); 251 return Flag::VIOLATES_CONSTRAINT; 252 } 253 #endif 254 return Flag::SUCCESS; 255 } 256 257 Flag::Error MaxTenuringThresholdConstraintFunc(uintx value, bool verbose) { 258 #if INCLUDE_ALL_GCS 259 // As only ParallelGC uses InitialTenuringThreshold, 260 // we don't need to compare InitialTenuringThreshold with MaxTenuringThreshold. 261 if (UseParallelGC && (value < InitialTenuringThreshold)) { 262 CommandLineError::print(verbose, 263 "MaxTenuringThreshold (" UINTX_FORMAT ") must be " 264 "greater than or equal to InitialTenuringThreshold (" UINTX_FORMAT ")\n", 265 value, InitialTenuringThreshold); 266 return Flag::VIOLATES_CONSTRAINT; 267 } 268 #endif 269 270 // MaxTenuringThreshold=0 means NeverTenure=false && AlwaysTenure=true 271 if ((value == 0) && (NeverTenure || !AlwaysTenure)) { 272 CommandLineError::print(verbose, 273 "MaxTenuringThreshold (0) should match to NeverTenure=false " 274 "&& AlwaysTenure=true. But we have NeverTenure=%s " 275 "AlwaysTenure=%s\n", 276 NeverTenure ? "true" : "false", 277 AlwaysTenure ? "true" : "false"); 278 return Flag::VIOLATES_CONSTRAINT; 279 } 280 return Flag::SUCCESS; 281 } 282 283 #if INCLUDE_ALL_GCS 284 Flag::Error G1RSetRegionEntriesConstraintFunc(intx value, bool verbose) { 285 if (!UseG1GC) return Flag::SUCCESS; 286 287 // Default value of G1RSetRegionEntries=0 means will be set ergonomically. 288 // Minimum value is 1. 289 if (FLAG_IS_CMDLINE(G1RSetRegionEntries) && (value < 1)) { 290 CommandLineError::print(verbose, 291 "G1RSetRegionEntries (" INTX_FORMAT ") must be " 292 "greater than or equal to 1\n", 293 value); 294 return Flag::VIOLATES_CONSTRAINT; 295 } else { 296 return Flag::SUCCESS; 297 } 298 } 299 300 Flag::Error G1RSetSparseRegionEntriesConstraintFunc(intx value, bool verbose) { 301 if (!UseG1GC) return Flag::SUCCESS; 302 303 // Default value of G1RSetSparseRegionEntries=0 means will be set ergonomically. 304 // Minimum value is 1. 305 if (FLAG_IS_CMDLINE(G1RSetSparseRegionEntries) && (value < 1)) { 306 CommandLineError::print(verbose, 307 "G1RSetSparseRegionEntries (" INTX_FORMAT ") must be " 308 "greater than or equal to 1\n", 309 value); 310 return Flag::VIOLATES_CONSTRAINT; 311 } else { 312 return Flag::SUCCESS; 313 } 314 } 315 316 Flag::Error G1HeapRegionSizeConstraintFunc(size_t value, bool verbose) { 317 if (!UseG1GC) return Flag::SUCCESS; 318 319 // Default value of G1HeapRegionSize=0 means will be set ergonomically. 320 if (FLAG_IS_CMDLINE(G1HeapRegionSize) && (value < HeapRegionBounds::min_size())) { 321 CommandLineError::print(verbose, 322 "G1HeapRegionSize (" SIZE_FORMAT ") must be " 323 "greater than or equal to ergonomic heap region minimum size\n", 324 value); 325 return Flag::VIOLATES_CONSTRAINT; 326 } else { 327 return Flag::SUCCESS; 328 } 329 } 330 331 Flag::Error G1NewSizePercentConstraintFunc(uintx value, bool verbose) { 332 if (!UseG1GC) return Flag::SUCCESS; 333 334 if (value > G1MaxNewSizePercent) { 335 CommandLineError::print(verbose, 336 "G1NewSizePercent (" UINTX_FORMAT ") must be " 337 "less than or equal to G1MaxNewSizePercent (" UINTX_FORMAT ")\n", 338 value, G1MaxNewSizePercent); 339 return Flag::VIOLATES_CONSTRAINT; 340 } else { 341 return Flag::SUCCESS; 342 } 343 } 344 345 Flag::Error G1MaxNewSizePercentConstraintFunc(uintx value, bool verbose) { 346 if (!UseG1GC) return Flag::SUCCESS; 347 348 if (value < G1NewSizePercent) { 349 CommandLineError::print(verbose, 350 "G1MaxNewSizePercent (" UINTX_FORMAT ") must be " 351 "greater than or equal to G1NewSizePercent (" UINTX_FORMAT ")\n", 352 value, G1NewSizePercent); 353 return Flag::VIOLATES_CONSTRAINT; 354 } else { 355 return Flag::SUCCESS; 356 } 357 } 358 #endif // INCLUDE_ALL_GCS 359 360 Flag::Error ParGCStridesPerThreadConstraintFunc(uintx value, bool verbose) { 361 #if INCLUDE_ALL_GCS 362 if (UseConcMarkSweepGC && (value > ((uintx)max_jint / (uintx)ParallelGCThreads))) { 363 CommandLineError::print(verbose, 364 "ParGCStridesPerThread (" UINTX_FORMAT ") must be " 365 "less than or equal to ergonomic maximum (" UINTX_FORMAT ")\n", 366 value, ((uintx)max_jint / (uintx)ParallelGCThreads)); 367 return Flag::VIOLATES_CONSTRAINT; 368 } 369 #endif 370 return Flag::SUCCESS; 371 } 372 373 Flag::Error ParGCCardsPerStrideChunkConstraintFunc(intx value, bool verbose) { 374 #if INCLUDE_ALL_GCS 375 if (UseConcMarkSweepGC) { 376 // ParGCCardsPerStrideChunk should be compared with card table size. 377 size_t heap_size = Universe::heap()->reserved_region().word_size(); 378 CardTableRS* ct = GenCollectedHeap::heap()->rem_set(); 379 size_t card_table_size = ct->cards_required(heap_size) - 1; // Valid card table size 380 381 if ((size_t)value > card_table_size) { 382 CommandLineError::print(verbose, 383 "ParGCCardsPerStrideChunk (" INTX_FORMAT ") is too large for the heap size and " 384 "must be less than or equal to card table size (" SIZE_FORMAT ")\n", 385 value, card_table_size); 386 return Flag::VIOLATES_CONSTRAINT; 387 } 388 389 // ParGCCardsPerStrideChunk is used with n_strides(ParallelGCThreads*ParGCStridesPerThread) 390 // from CardTableRS::process_stride(). Note that ParGCStridesPerThread is already checked 391 // not to make an overflow with ParallelGCThreads from its constraint function. 392 uintx n_strides = ParallelGCThreads * ParGCStridesPerThread; 393 uintx ergo_max = max_uintx / n_strides; 394 if ((uintx)value > ergo_max) { 395 CommandLineError::print(verbose, 396 "ParGCCardsPerStrideChunk (" INTX_FORMAT ") must be " 397 "less than or equal to ergonomic maximum (" UINTX_FORMAT ")\n", 398 value, ergo_max); 399 return Flag::VIOLATES_CONSTRAINT; 400 } 401 } 402 #endif 403 return Flag::SUCCESS; 404 } 405 406 Flag::Error CMSOldPLABMinConstraintFunc(size_t value, bool verbose) { 407 Flag::Error status = Flag::SUCCESS; 408 409 #if INCLUDE_ALL_GCS 410 if (UseConcMarkSweepGC) { 411 if (value > CMSOldPLABMax) { 412 CommandLineError::print(verbose, 413 "CMSOldPLABMin (" SIZE_FORMAT ") must be " 414 "less than or equal to CMSOldPLABMax (" SIZE_FORMAT ")\n", 415 value, CMSOldPLABMax); 416 return Flag::VIOLATES_CONSTRAINT; 417 } 418 status = MaxPLABSizeBounds("CMSOldPLABMin", value, verbose); 419 } 420 #endif 421 return status; 422 } 423 424 Flag::Error CMSOldPLABMaxConstraintFunc(size_t value, bool verbose) { 425 Flag::Error status = Flag::SUCCESS; 426 427 #if INCLUDE_ALL_GCS 428 if (UseConcMarkSweepGC) { 429 status = MaxPLABSizeBounds("CMSOldPLABMax", value, verbose); 430 } 431 #endif 432 return status; 433 } 434 435 Flag::Error MarkStackSizeConstraintFunc(size_t value, bool verbose) { 436 if (value > MarkStackSizeMax) { 437 CommandLineError::print(verbose, 438 "MarkStackSize (" SIZE_FORMAT ") must be " 439 "less than or equal to MarkStackSizeMax (" SIZE_FORMAT ")\n", 440 value, MarkStackSizeMax); 441 return Flag::VIOLATES_CONSTRAINT; 442 } else { 443 return Flag::SUCCESS; 444 } 445 } 446 447 static Flag::Error CMSReservedAreaConstraintFunc(const char* name, size_t value, bool verbose) { 448 #if INCLUDE_ALL_GCS 449 if (UseConcMarkSweepGC) { 450 ConcurrentMarkSweepGeneration* cms = (ConcurrentMarkSweepGeneration*)GenCollectedHeap::heap()->old_gen(); 451 const size_t ergo_max = cms->cmsSpace()->max_flag_size_for_task_size(); 452 if (value > ergo_max) { 453 CommandLineError::print(verbose, 454 "%s (" SIZE_FORMAT ") must be " 455 "less than or equal to ergonomic maximum (" SIZE_FORMAT ") " 456 "which is based on the maximum size of the old generation of the Java heap\n", 457 name, value, ergo_max); 458 return Flag::VIOLATES_CONSTRAINT; 459 } 460 } 461 #endif 462 463 return Flag::SUCCESS; 464 } 465 466 Flag::Error CMSRescanMultipleConstraintFunc(size_t value, bool verbose) { 467 Flag::Error status = CMSReservedAreaConstraintFunc("CMSRescanMultiple", value, verbose); 468 469 #if INCLUDE_ALL_GCS 470 if (status == Flag::SUCCESS && UseConcMarkSweepGC) { 471 // CMSParRemarkTask::do_dirty_card_rescan_tasks requires CompactibleFreeListSpace::rescan_task_size() 472 // to be aligned to CardTable::card_size * BitsPerWord. 473 // Note that rescan_task_size() will be aligned if CMSRescanMultiple is a multiple of 'HeapWordSize' 474 // because rescan_task_size() is CardTable::card_size / HeapWordSize * BitsPerWord. 475 if (value % HeapWordSize != 0) { 476 CommandLineError::print(verbose, 477 "CMSRescanMultiple (" SIZE_FORMAT ") must be " 478 "a multiple of " SIZE_FORMAT "\n", 479 value, HeapWordSize); 480 status = Flag::VIOLATES_CONSTRAINT; 481 } 482 } 483 #endif 484 485 return status; 486 } 487 488 Flag::Error CMSConcMarkMultipleConstraintFunc(size_t value, bool verbose) { 489 return CMSReservedAreaConstraintFunc("CMSConcMarkMultiple", value, verbose); 490 } 491 492 Flag::Error CMSPrecleanDenominatorConstraintFunc(uintx value, bool verbose) { 493 #if INCLUDE_ALL_GCS 494 if (UseConcMarkSweepGC && (value <= CMSPrecleanNumerator)) { 495 CommandLineError::print(verbose, 496 "CMSPrecleanDenominator (" UINTX_FORMAT ") must be " 497 "strickly greater than CMSPrecleanNumerator (" UINTX_FORMAT ")\n", 498 value, CMSPrecleanNumerator); 499 return Flag::VIOLATES_CONSTRAINT; 500 } 501 #endif 502 return Flag::SUCCESS; 503 } 504 505 Flag::Error CMSPrecleanNumeratorConstraintFunc(uintx value, bool verbose) { 506 #if INCLUDE_ALL_GCS 507 if (UseConcMarkSweepGC && (value >= CMSPrecleanDenominator)) { 508 CommandLineError::print(verbose, 509 "CMSPrecleanNumerator (" UINTX_FORMAT ") must be " 510 "less than CMSPrecleanDenominator (" UINTX_FORMAT ")\n", 511 value, CMSPrecleanDenominator); 512 return Flag::VIOLATES_CONSTRAINT; 513 } 514 #endif 515 return Flag::SUCCESS; 516 } 517 518 Flag::Error CMSSamplingGrainConstraintFunc(uintx value, bool verbose) { 519 #if INCLUDE_ALL_GCS 520 if (UseConcMarkSweepGC) { 521 size_t max_capacity = GenCollectedHeap::heap()->young_gen()->max_capacity(); 522 if (value > max_uintx - max_capacity) { 523 CommandLineError::print(verbose, 524 "CMSSamplingGrain (" UINTX_FORMAT ") must be " 525 "less than or equal to ergonomic maximum (" SIZE_FORMAT ")\n", 526 value, max_uintx - max_capacity); 527 return Flag::VIOLATES_CONSTRAINT; 528 } 529 } 530 #endif 531 return Flag::SUCCESS; 532 } 533 534 Flag::Error CMSWorkQueueDrainThresholdConstraintFunc(uintx value, bool verbose) { 535 #if INCLUDE_ALL_GCS 536 if (UseConcMarkSweepGC) { 537 return ParallelGCThreadsAndCMSWorkQueueDrainThreshold(ParallelGCThreads, value, verbose); 538 } 539 #endif 540 return Flag::SUCCESS; 541 } 542 543 Flag::Error CMSBitMapYieldQuantumConstraintFunc(size_t value, bool verbose) { 544 #if INCLUDE_ALL_GCS 545 // Skip for current default value. 546 if (UseConcMarkSweepGC && FLAG_IS_CMDLINE(CMSBitMapYieldQuantum)) { 547 // CMSBitMapYieldQuantum should be compared with mark bitmap size. 548 ConcurrentMarkSweepGeneration* cms = (ConcurrentMarkSweepGeneration*)GenCollectedHeap::heap()->old_gen(); 549 size_t bitmap_size = cms->collector()->markBitMap()->sizeInWords(); 550 551 if (value > bitmap_size) { 552 CommandLineError::print(verbose, 553 "CMSBitMapYieldQuantum (" SIZE_FORMAT ") must " 554 "be less than or equal to bitmap size (" SIZE_FORMAT ") " 555 "whose size corresponds to the size of old generation of the Java heap\n", 556 value, bitmap_size); 557 return Flag::VIOLATES_CONSTRAINT; 558 } 559 } 560 #endif 561 return Flag::SUCCESS; 562 } 563 564 Flag::Error MaxGCPauseMillisConstraintFunc(uintx value, bool verbose) { 565 #if INCLUDE_ALL_GCS 566 if (UseG1GC && FLAG_IS_CMDLINE(MaxGCPauseMillis) && (value >= GCPauseIntervalMillis)) { 567 CommandLineError::print(verbose, 568 "MaxGCPauseMillis (" UINTX_FORMAT ") must be " 569 "less than GCPauseIntervalMillis (" UINTX_FORMAT ")\n", 570 value, GCPauseIntervalMillis); 571 return Flag::VIOLATES_CONSTRAINT; 572 } 573 #endif 574 575 return Flag::SUCCESS; 576 } 577 578 Flag::Error GCPauseIntervalMillisConstraintFunc(uintx value, bool verbose) { 579 #if INCLUDE_ALL_GCS 580 if (UseG1GC) { 581 if (FLAG_IS_CMDLINE(GCPauseIntervalMillis)) { 582 if (value < 1) { 583 CommandLineError::print(verbose, 584 "GCPauseIntervalMillis (" UINTX_FORMAT ") must be " 585 "greater than or equal to 1\n", 586 value); 587 return Flag::VIOLATES_CONSTRAINT; 588 } 589 590 if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) { 591 CommandLineError::print(verbose, 592 "GCPauseIntervalMillis cannot be set " 593 "without setting MaxGCPauseMillis\n"); 594 return Flag::VIOLATES_CONSTRAINT; 595 } 596 597 if (value <= MaxGCPauseMillis) { 598 CommandLineError::print(verbose, 599 "GCPauseIntervalMillis (" UINTX_FORMAT ") must be " 600 "greater than MaxGCPauseMillis (" UINTX_FORMAT ")\n", 601 value, MaxGCPauseMillis); 602 return Flag::VIOLATES_CONSTRAINT; 603 } 604 } 605 } 606 #endif 607 return Flag::SUCCESS; 608 } 609 610 Flag::Error InitialBootClassLoaderMetaspaceSizeConstraintFunc(size_t value, bool verbose) { 611 size_t aligned_max = align_down(max_uintx/2, Metaspace::reserve_alignment_words()); 612 if (value > aligned_max) { 613 CommandLineError::print(verbose, 614 "InitialBootClassLoaderMetaspaceSize (" SIZE_FORMAT ") must be " 615 "less than or equal to aligned maximum value (" SIZE_FORMAT ")\n", 616 value, aligned_max); 617 return Flag::VIOLATES_CONSTRAINT; 618 } 619 return Flag::SUCCESS; 620 } 621 622 // To avoid an overflow by 'align_up(value, alignment)'. 623 static Flag::Error MaxSizeForAlignment(const char* name, size_t value, size_t alignment, bool verbose) { 624 size_t aligned_max = ((max_uintx - alignment) & ~(alignment-1)); 625 if (value > aligned_max) { 626 CommandLineError::print(verbose, 627 "%s (" SIZE_FORMAT ") must be " 628 "less than or equal to aligned maximum value (" SIZE_FORMAT ")\n", 629 name, value, aligned_max); 630 return Flag::VIOLATES_CONSTRAINT; 631 } 632 return Flag::SUCCESS; 633 } 634 635 static Flag::Error MaxSizeForHeapAlignment(const char* name, size_t value, bool verbose) { 636 // For G1 GC, we don't know until G1CollectorPolicy is created. 637 size_t heap_alignment; 638 639 #if INCLUDE_ALL_GCS 640 if (UseG1GC) { 641 heap_alignment = HeapRegionBounds::max_size(); 642 } else 643 #endif 644 { 645 heap_alignment = CollectorPolicy::compute_heap_alignment(); 646 } 647 648 return MaxSizeForAlignment(name, value, heap_alignment, verbose); 649 } 650 651 Flag::Error InitialHeapSizeConstraintFunc(size_t value, bool verbose) { 652 return MaxSizeForHeapAlignment("InitialHeapSize", value, verbose); 653 } 654 655 Flag::Error MaxHeapSizeConstraintFunc(size_t value, bool verbose) { 656 Flag::Error status = MaxSizeForHeapAlignment("MaxHeapSize", value, verbose); 657 658 if (status == Flag::SUCCESS) { 659 status = CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(value, SoftRefLRUPolicyMSPerMB, verbose); 660 } 661 return status; 662 } 663 664 Flag::Error HeapBaseMinAddressConstraintFunc(size_t value, bool verbose) { 665 // If an overflow happened in Arguments::set_heap_size(), MaxHeapSize will have too large a value. 666 // Check for this by ensuring that MaxHeapSize plus the requested min base address still fit within max_uintx. 667 if (UseCompressedOops && FLAG_IS_ERGO(MaxHeapSize) && (value > (max_uintx - MaxHeapSize))) { 668 CommandLineError::print(verbose, 669 "HeapBaseMinAddress (" SIZE_FORMAT ") or MaxHeapSize (" SIZE_FORMAT ") is too large. " 670 "Sum of them must be less than or equal to maximum of size_t (" SIZE_FORMAT ")\n", 671 value, MaxHeapSize, max_uintx); 672 return Flag::VIOLATES_CONSTRAINT; 673 } 674 675 return MaxSizeForHeapAlignment("HeapBaseMinAddress", value, verbose); 676 } 677 678 Flag::Error NewSizeConstraintFunc(size_t value, bool verbose) { 679 #ifdef _LP64 680 #if INCLUDE_ALL_GCS 681 // Overflow would happen for uint type variable of YoungGenSizer::_min_desired_young_length 682 // when the value to be assigned exceeds uint range. 683 // i.e. result of '(uint)(NewSize / region size(1~32MB))' 684 // So maximum of NewSize should be 'max_juint * 1M' 685 if (UseG1GC && (value > (max_juint * 1 * M))) { 686 CommandLineError::print(verbose, 687 "NewSize (" SIZE_FORMAT ") must be less than ergonomic maximum value\n", 688 value); 689 return Flag::VIOLATES_CONSTRAINT; 690 } 691 #endif // INCLUDE_ALL_GCS 692 #endif // _LP64 693 return Flag::SUCCESS; 694 } 695 696 Flag::Error MinTLABSizeConstraintFunc(size_t value, bool verbose) { 697 // At least, alignment reserve area is needed. 698 if (value < ThreadLocalAllocBuffer::alignment_reserve_in_bytes()) { 699 CommandLineError::print(verbose, 700 "MinTLABSize (" SIZE_FORMAT ") must be " 701 "greater than or equal to reserved area in TLAB (" SIZE_FORMAT ")\n", 702 value, ThreadLocalAllocBuffer::alignment_reserve_in_bytes()); 703 return Flag::VIOLATES_CONSTRAINT; 704 } 705 if (value > (ThreadLocalAllocBuffer::max_size() * HeapWordSize)) { 706 CommandLineError::print(verbose, 707 "MinTLABSize (" SIZE_FORMAT ") must be " 708 "less than or equal to ergonomic TLAB maximum (" SIZE_FORMAT ")\n", 709 value, ThreadLocalAllocBuffer::max_size() * HeapWordSize); 710 return Flag::VIOLATES_CONSTRAINT; 711 } 712 return Flag::SUCCESS; 713 } 714 715 Flag::Error TLABSizeConstraintFunc(size_t value, bool verbose) { 716 // Skip for default value of zero which means set ergonomically. 717 if (FLAG_IS_CMDLINE(TLABSize)) { 718 if (value < MinTLABSize) { 719 CommandLineError::print(verbose, 720 "TLABSize (" SIZE_FORMAT ") must be " 721 "greater than or equal to MinTLABSize (" SIZE_FORMAT ")\n", 722 value, MinTLABSize); 723 return Flag::VIOLATES_CONSTRAINT; 724 } 725 if (value > (ThreadLocalAllocBuffer::max_size() * HeapWordSize)) { 726 CommandLineError::print(verbose, 727 "TLABSize (" SIZE_FORMAT ") must be " 728 "less than or equal to ergonomic TLAB maximum size (" SIZE_FORMAT ")\n", 729 value, (ThreadLocalAllocBuffer::max_size() * HeapWordSize)); 730 return Flag::VIOLATES_CONSTRAINT; 731 } 732 } 733 return Flag::SUCCESS; 734 } 735 736 // We will protect overflow from ThreadLocalAllocBuffer::record_slow_allocation(), 737 // so AfterMemoryInit type is enough to check. 738 Flag::Error TLABWasteIncrementConstraintFunc(uintx value, bool verbose) { 739 if (UseTLAB) { 740 size_t refill_waste_limit = Thread::current()->tlab().refill_waste_limit(); 741 742 // Compare with 'max_uintx' as ThreadLocalAllocBuffer::_refill_waste_limit is 'size_t'. 743 if (refill_waste_limit > (max_uintx - value)) { 744 CommandLineError::print(verbose, 745 "TLABWasteIncrement (" UINTX_FORMAT ") must be " 746 "less than or equal to ergonomic TLAB waste increment maximum size(" SIZE_FORMAT ")\n", 747 value, (max_uintx - refill_waste_limit)); 748 return Flag::VIOLATES_CONSTRAINT; 749 } 750 } 751 return Flag::SUCCESS; 752 } 753 754 Flag::Error SurvivorRatioConstraintFunc(uintx value, bool verbose) { 755 if (FLAG_IS_CMDLINE(SurvivorRatio) && 756 (value > (MaxHeapSize / Universe::heap()->collector_policy()->space_alignment()))) { 757 CommandLineError::print(verbose, 758 "SurvivorRatio (" UINTX_FORMAT ") must be " 759 "less than or equal to ergonomic SurvivorRatio maximum (" SIZE_FORMAT ")\n", 760 value, 761 (MaxHeapSize / Universe::heap()->collector_policy()->space_alignment())); 762 return Flag::VIOLATES_CONSTRAINT; 763 } else { 764 return Flag::SUCCESS; 765 } 766 } 767 768 Flag::Error MetaspaceSizeConstraintFunc(size_t value, bool verbose) { 769 if (value > MaxMetaspaceSize) { 770 CommandLineError::print(verbose, 771 "MetaspaceSize (" SIZE_FORMAT ") must be " 772 "less than or equal to MaxMetaspaceSize (" SIZE_FORMAT ")\n", 773 value, MaxMetaspaceSize); 774 return Flag::VIOLATES_CONSTRAINT; 775 } else { 776 return Flag::SUCCESS; 777 } 778 } 779 780 Flag::Error MaxMetaspaceSizeConstraintFunc(size_t value, bool verbose) { 781 if (value < MetaspaceSize) { 782 CommandLineError::print(verbose, 783 "MaxMetaspaceSize (" SIZE_FORMAT ") must be " 784 "greater than or equal to MetaspaceSize (" SIZE_FORMAT ")\n", 785 value, MaxMetaspaceSize); 786 return Flag::VIOLATES_CONSTRAINT; 787 } else { 788 return Flag::SUCCESS; 789 } 790 } 791 792 Flag::Error SurvivorAlignmentInBytesConstraintFunc(intx value, bool verbose) { 793 if (value != 0) { 794 if (!is_power_of_2(value)) { 795 CommandLineError::print(verbose, 796 "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be " 797 "power of 2\n", 798 value); 799 return Flag::VIOLATES_CONSTRAINT; 800 } 801 if (value < ObjectAlignmentInBytes) { 802 CommandLineError::print(verbose, 803 "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be " 804 "greater than or equal to ObjectAlignmentInBytes (" INTX_FORMAT ")\n", 805 value, ObjectAlignmentInBytes); 806 return Flag::VIOLATES_CONSTRAINT; 807 } 808 } 809 return Flag::SUCCESS; 810 } | 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "gc/shared/collectedHeap.hpp" 27 #include "gc/shared/collectorPolicy.hpp" 28 #include "gc/shared/genCollectedHeap.hpp" 29 #include "gc/shared/threadLocalAllocBuffer.hpp" 30 #include "runtime/arguments.hpp" 31 #include "runtime/jvmFlagConstraintsGC.hpp" 32 #include "runtime/jvmFlagRangeList.hpp" 33 #include "runtime/thread.inline.hpp" 34 #include "utilities/align.hpp" 35 #include "utilities/defaultStream.hpp" 36 37 #if INCLUDE_ALL_GCS 38 #include "gc/cms/concurrentMarkSweepGeneration.inline.hpp" 39 #include "gc/g1/g1_globals.hpp" 40 #include "gc/g1/heapRegionBounds.inline.hpp" 41 #include "gc/shared/plab.hpp" 42 #endif // INCLUDE_ALL_GCS 43 #ifdef COMPILER1 44 #include "c1/c1_globals.hpp" 45 #endif // COMPILER1 46 #ifdef COMPILER2 47 #include "opto/c2_globals.hpp" 48 #endif // COMPILER2 49 50 // Some flags that have default values that indicate that the 51 // JVM should automatically determine an appropriate value 52 // for that flag. In those cases it is only appropriate for the 53 // constraint checking to be done if the user has specified the 54 // value(s) of the flag(s) on the command line. In the constraint 55 // checking functions, FLAG_IS_CMDLINE() is used to check if 56 // the flag has been set by the user and so should be checked. 57 58 #if INCLUDE_ALL_GCS 59 static JVMFlag::Error ParallelGCThreadsAndCMSWorkQueueDrainThreshold(uint threads, uintx threshold, bool verbose) { 60 // CMSWorkQueueDrainThreshold is verified to be less than max_juint 61 if (UseConcMarkSweepGC && (threads > (uint)(max_jint / (uint)threshold))) { 62 CommandLineError::print(verbose, 63 "ParallelGCThreads (" UINT32_FORMAT ") or CMSWorkQueueDrainThreshold (" 64 UINTX_FORMAT ") is too large\n", 65 threads, threshold); 66 return JVMFlag::VIOLATES_CONSTRAINT; 67 } 68 return JVMFlag::SUCCESS; 69 } 70 #endif 71 72 // As ParallelGCThreads differs among GC modes, we need constraint function. 73 JVMFlag::Error ParallelGCThreadsConstraintFunc(uint value, bool verbose) { 74 JVMFlag::Error status = JVMFlag::SUCCESS; 75 76 #if INCLUDE_ALL_GCS 77 // Parallel GC passes ParallelGCThreads when creating GrowableArray as 'int' type parameter. 78 // So can't exceed with "max_jint" 79 if (UseParallelGC && (value > (uint)max_jint)) { 80 CommandLineError::print(verbose, 81 "ParallelGCThreads (" UINT32_FORMAT ") must be " 82 "less than or equal to " UINT32_FORMAT " for Parallel GC\n", 83 value, max_jint); 84 return JVMFlag::VIOLATES_CONSTRAINT; 85 } 86 // To avoid overflow at ParScanClosure::do_oop_work. 87 if (UseConcMarkSweepGC && (value > (max_jint / 10))) { 88 CommandLineError::print(verbose, 89 "ParallelGCThreads (" UINT32_FORMAT ") must be " 90 "less than or equal to " UINT32_FORMAT " for CMS GC\n", 91 value, (max_jint / 10)); 92 return JVMFlag::VIOLATES_CONSTRAINT; 93 } 94 status = ParallelGCThreadsAndCMSWorkQueueDrainThreshold(value, CMSWorkQueueDrainThreshold, verbose); 95 #endif 96 return status; 97 } 98 99 // As ConcGCThreads should be smaller than ParallelGCThreads, 100 // we need constraint function. 101 JVMFlag::Error ConcGCThreadsConstraintFunc(uint value, bool verbose) { 102 #if INCLUDE_ALL_GCS 103 // CMS and G1 GCs use ConcGCThreads. 104 if ((UseConcMarkSweepGC || UseG1GC) && (value > ParallelGCThreads)) { 105 CommandLineError::print(verbose, 106 "ConcGCThreads (" UINT32_FORMAT ") must be " 107 "less than or equal to ParallelGCThreads (" UINT32_FORMAT ")\n", 108 value, ParallelGCThreads); 109 return JVMFlag::VIOLATES_CONSTRAINT; 110 } 111 #endif 112 return JVMFlag::SUCCESS; 113 } 114 115 static JVMFlag::Error MinPLABSizeBounds(const char* name, size_t value, bool verbose) { 116 #if INCLUDE_ALL_GCS 117 if ((UseConcMarkSweepGC || UseG1GC || UseParallelGC) && (value < PLAB::min_size())) { 118 CommandLineError::print(verbose, 119 "%s (" SIZE_FORMAT ") must be " 120 "greater than or equal to ergonomic PLAB minimum size (" SIZE_FORMAT ")\n", 121 name, value, PLAB::min_size()); 122 return JVMFlag::VIOLATES_CONSTRAINT; 123 } 124 #endif // INCLUDE_ALL_GCS 125 return JVMFlag::SUCCESS; 126 } 127 128 static JVMFlag::Error MaxPLABSizeBounds(const char* name, size_t value, bool verbose) { 129 #if INCLUDE_ALL_GCS 130 if ((UseConcMarkSweepGC || UseG1GC || UseParallelGC) && (value > PLAB::max_size())) { 131 CommandLineError::print(verbose, 132 "%s (" SIZE_FORMAT ") must be " 133 "less than or equal to ergonomic PLAB maximum size (" SIZE_FORMAT ")\n", 134 name, value, PLAB::max_size()); 135 return JVMFlag::VIOLATES_CONSTRAINT; 136 } 137 #endif // INCLUDE_ALL_GCS 138 return JVMFlag::SUCCESS; 139 } 140 141 static JVMFlag::Error MinMaxPLABSizeBounds(const char* name, size_t value, bool verbose) { 142 JVMFlag::Error status = MinPLABSizeBounds(name, value, verbose); 143 144 if (status == JVMFlag::SUCCESS) { 145 return MaxPLABSizeBounds(name, value, verbose); 146 } 147 return status; 148 } 149 150 JVMFlag::Error YoungPLABSizeConstraintFunc(size_t value, bool verbose) { 151 return MinMaxPLABSizeBounds("YoungPLABSize", value, verbose); 152 } 153 154 JVMFlag::Error OldPLABSizeConstraintFunc(size_t value, bool verbose) { 155 JVMFlag::Error status = JVMFlag::SUCCESS; 156 157 #if INCLUDE_ALL_GCS 158 if (UseConcMarkSweepGC) { 159 if (value == 0) { 160 CommandLineError::print(verbose, 161 "OldPLABSize (" SIZE_FORMAT ") must be greater than 0", 162 value); 163 return JVMFlag::VIOLATES_CONSTRAINT; 164 } 165 // For CMS, OldPLABSize is the number of free blocks of a given size that are used when 166 // replenishing the local per-worker free list caches. 167 // For more details, please refer to Arguments::set_cms_and_parnew_gc_flags(). 168 status = MaxPLABSizeBounds("OldPLABSize", value, verbose); 169 } else { 170 status = MinMaxPLABSizeBounds("OldPLABSize", value, verbose); 171 } 172 #endif 173 return status; 174 } 175 176 JVMFlag::Error MinHeapFreeRatioConstraintFunc(uintx value, bool verbose) { 177 if (value > MaxHeapFreeRatio) { 178 CommandLineError::print(verbose, 179 "MinHeapFreeRatio (" UINTX_FORMAT ") must be " 180 "less than or equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n", 181 value, MaxHeapFreeRatio); 182 return JVMFlag::VIOLATES_CONSTRAINT; 183 } else { 184 return JVMFlag::SUCCESS; 185 } 186 } 187 188 JVMFlag::Error MaxHeapFreeRatioConstraintFunc(uintx value, bool verbose) { 189 if (value < MinHeapFreeRatio) { 190 CommandLineError::print(verbose, 191 "MaxHeapFreeRatio (" UINTX_FORMAT ") must be " 192 "greater than or equal to MinHeapFreeRatio (" UINTX_FORMAT ")\n", 193 value, MinHeapFreeRatio); 194 return JVMFlag::VIOLATES_CONSTRAINT; 195 } else { 196 return JVMFlag::SUCCESS; 197 } 198 } 199 200 static JVMFlag::Error CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(size_t maxHeap, intx softRef, bool verbose) { 201 if ((softRef > 0) && ((maxHeap / M) > (max_uintx / softRef))) { 202 CommandLineError::print(verbose, 203 "Desired lifetime of SoftReferences cannot be expressed correctly. " 204 "MaxHeapSize (" SIZE_FORMAT ") or SoftRefLRUPolicyMSPerMB " 205 "(" INTX_FORMAT ") is too large\n", 206 maxHeap, softRef); 207 return JVMFlag::VIOLATES_CONSTRAINT; 208 } else { 209 return JVMFlag::SUCCESS; 210 } 211 } 212 213 JVMFlag::Error SoftRefLRUPolicyMSPerMBConstraintFunc(intx value, bool verbose) { 214 return CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(MaxHeapSize, value, verbose); 215 } 216 217 JVMFlag::Error MinMetaspaceFreeRatioConstraintFunc(uintx value, bool verbose) { 218 if (value > MaxMetaspaceFreeRatio) { 219 CommandLineError::print(verbose, 220 "MinMetaspaceFreeRatio (" UINTX_FORMAT ") must be " 221 "less than or equal to MaxMetaspaceFreeRatio (" UINTX_FORMAT ")\n", 222 value, MaxMetaspaceFreeRatio); 223 return JVMFlag::VIOLATES_CONSTRAINT; 224 } else { 225 return JVMFlag::SUCCESS; 226 } 227 } 228 229 JVMFlag::Error MaxMetaspaceFreeRatioConstraintFunc(uintx value, bool verbose) { 230 if (value < MinMetaspaceFreeRatio) { 231 CommandLineError::print(verbose, 232 "MaxMetaspaceFreeRatio (" UINTX_FORMAT ") must be " 233 "greater than or equal to MinMetaspaceFreeRatio (" UINTX_FORMAT ")\n", 234 value, MinMetaspaceFreeRatio); 235 return JVMFlag::VIOLATES_CONSTRAINT; 236 } else { 237 return JVMFlag::SUCCESS; 238 } 239 } 240 241 JVMFlag::Error InitialTenuringThresholdConstraintFunc(uintx value, bool verbose) { 242 #if INCLUDE_ALL_GCS 243 // InitialTenuringThreshold is only used for ParallelGC. 244 if (UseParallelGC && (value > MaxTenuringThreshold)) { 245 CommandLineError::print(verbose, 246 "InitialTenuringThreshold (" UINTX_FORMAT ") must be " 247 "less than or equal to MaxTenuringThreshold (" UINTX_FORMAT ")\n", 248 value, MaxTenuringThreshold); 249 return JVMFlag::VIOLATES_CONSTRAINT; 250 } 251 #endif 252 return JVMFlag::SUCCESS; 253 } 254 255 JVMFlag::Error MaxTenuringThresholdConstraintFunc(uintx value, bool verbose) { 256 #if INCLUDE_ALL_GCS 257 // As only ParallelGC uses InitialTenuringThreshold, 258 // we don't need to compare InitialTenuringThreshold with MaxTenuringThreshold. 259 if (UseParallelGC && (value < InitialTenuringThreshold)) { 260 CommandLineError::print(verbose, 261 "MaxTenuringThreshold (" UINTX_FORMAT ") must be " 262 "greater than or equal to InitialTenuringThreshold (" UINTX_FORMAT ")\n", 263 value, InitialTenuringThreshold); 264 return JVMFlag::VIOLATES_CONSTRAINT; 265 } 266 #endif 267 268 // MaxTenuringThreshold=0 means NeverTenure=false && AlwaysTenure=true 269 if ((value == 0) && (NeverTenure || !AlwaysTenure)) { 270 CommandLineError::print(verbose, 271 "MaxTenuringThreshold (0) should match to NeverTenure=false " 272 "&& AlwaysTenure=true. But we have NeverTenure=%s " 273 "AlwaysTenure=%s\n", 274 NeverTenure ? "true" : "false", 275 AlwaysTenure ? "true" : "false"); 276 return JVMFlag::VIOLATES_CONSTRAINT; 277 } 278 return JVMFlag::SUCCESS; 279 } 280 281 #if INCLUDE_ALL_GCS 282 JVMFlag::Error G1RSetRegionEntriesConstraintFunc(intx value, bool verbose) { 283 if (!UseG1GC) return JVMFlag::SUCCESS; 284 285 // Default value of G1RSetRegionEntries=0 means will be set ergonomically. 286 // Minimum value is 1. 287 if (FLAG_IS_CMDLINE(G1RSetRegionEntries) && (value < 1)) { 288 CommandLineError::print(verbose, 289 "G1RSetRegionEntries (" INTX_FORMAT ") must be " 290 "greater than or equal to 1\n", 291 value); 292 return JVMFlag::VIOLATES_CONSTRAINT; 293 } else { 294 return JVMFlag::SUCCESS; 295 } 296 } 297 298 JVMFlag::Error G1RSetSparseRegionEntriesConstraintFunc(intx value, bool verbose) { 299 if (!UseG1GC) return JVMFlag::SUCCESS; 300 301 // Default value of G1RSetSparseRegionEntries=0 means will be set ergonomically. 302 // Minimum value is 1. 303 if (FLAG_IS_CMDLINE(G1RSetSparseRegionEntries) && (value < 1)) { 304 CommandLineError::print(verbose, 305 "G1RSetSparseRegionEntries (" INTX_FORMAT ") must be " 306 "greater than or equal to 1\n", 307 value); 308 return JVMFlag::VIOLATES_CONSTRAINT; 309 } else { 310 return JVMFlag::SUCCESS; 311 } 312 } 313 314 JVMFlag::Error G1HeapRegionSizeConstraintFunc(size_t value, bool verbose) { 315 if (!UseG1GC) return JVMFlag::SUCCESS; 316 317 // Default value of G1HeapRegionSize=0 means will be set ergonomically. 318 if (FLAG_IS_CMDLINE(G1HeapRegionSize) && (value < HeapRegionBounds::min_size())) { 319 CommandLineError::print(verbose, 320 "G1HeapRegionSize (" SIZE_FORMAT ") must be " 321 "greater than or equal to ergonomic heap region minimum size\n", 322 value); 323 return JVMFlag::VIOLATES_CONSTRAINT; 324 } else { 325 return JVMFlag::SUCCESS; 326 } 327 } 328 329 JVMFlag::Error G1NewSizePercentConstraintFunc(uintx value, bool verbose) { 330 if (!UseG1GC) return JVMFlag::SUCCESS; 331 332 if (value > G1MaxNewSizePercent) { 333 CommandLineError::print(verbose, 334 "G1NewSizePercent (" UINTX_FORMAT ") must be " 335 "less than or equal to G1MaxNewSizePercent (" UINTX_FORMAT ")\n", 336 value, G1MaxNewSizePercent); 337 return JVMFlag::VIOLATES_CONSTRAINT; 338 } else { 339 return JVMFlag::SUCCESS; 340 } 341 } 342 343 JVMFlag::Error G1MaxNewSizePercentConstraintFunc(uintx value, bool verbose) { 344 if (!UseG1GC) return JVMFlag::SUCCESS; 345 346 if (value < G1NewSizePercent) { 347 CommandLineError::print(verbose, 348 "G1MaxNewSizePercent (" UINTX_FORMAT ") must be " 349 "greater than or equal to G1NewSizePercent (" UINTX_FORMAT ")\n", 350 value, G1NewSizePercent); 351 return JVMFlag::VIOLATES_CONSTRAINT; 352 } else { 353 return JVMFlag::SUCCESS; 354 } 355 } 356 #endif // INCLUDE_ALL_GCS 357 358 JVMFlag::Error ParGCStridesPerThreadConstraintFunc(uintx value, bool verbose) { 359 #if INCLUDE_ALL_GCS 360 if (UseConcMarkSweepGC && (value > ((uintx)max_jint / (uintx)ParallelGCThreads))) { 361 CommandLineError::print(verbose, 362 "ParGCStridesPerThread (" UINTX_FORMAT ") must be " 363 "less than or equal to ergonomic maximum (" UINTX_FORMAT ")\n", 364 value, ((uintx)max_jint / (uintx)ParallelGCThreads)); 365 return JVMFlag::VIOLATES_CONSTRAINT; 366 } 367 #endif 368 return JVMFlag::SUCCESS; 369 } 370 371 JVMFlag::Error ParGCCardsPerStrideChunkConstraintFunc(intx value, bool verbose) { 372 #if INCLUDE_ALL_GCS 373 if (UseConcMarkSweepGC) { 374 // ParGCCardsPerStrideChunk should be compared with card table size. 375 size_t heap_size = Universe::heap()->reserved_region().word_size(); 376 CardTableRS* ct = GenCollectedHeap::heap()->rem_set(); 377 size_t card_table_size = ct->cards_required(heap_size) - 1; // Valid card table size 378 379 if ((size_t)value > card_table_size) { 380 CommandLineError::print(verbose, 381 "ParGCCardsPerStrideChunk (" INTX_FORMAT ") is too large for the heap size and " 382 "must be less than or equal to card table size (" SIZE_FORMAT ")\n", 383 value, card_table_size); 384 return JVMFlag::VIOLATES_CONSTRAINT; 385 } 386 387 // ParGCCardsPerStrideChunk is used with n_strides(ParallelGCThreads*ParGCStridesPerThread) 388 // from CardTableRS::process_stride(). Note that ParGCStridesPerThread is already checked 389 // not to make an overflow with ParallelGCThreads from its constraint function. 390 uintx n_strides = ParallelGCThreads * ParGCStridesPerThread; 391 uintx ergo_max = max_uintx / n_strides; 392 if ((uintx)value > ergo_max) { 393 CommandLineError::print(verbose, 394 "ParGCCardsPerStrideChunk (" INTX_FORMAT ") must be " 395 "less than or equal to ergonomic maximum (" UINTX_FORMAT ")\n", 396 value, ergo_max); 397 return JVMFlag::VIOLATES_CONSTRAINT; 398 } 399 } 400 #endif 401 return JVMFlag::SUCCESS; 402 } 403 404 JVMFlag::Error CMSOldPLABMinConstraintFunc(size_t value, bool verbose) { 405 JVMFlag::Error status = JVMFlag::SUCCESS; 406 407 #if INCLUDE_ALL_GCS 408 if (UseConcMarkSweepGC) { 409 if (value > CMSOldPLABMax) { 410 CommandLineError::print(verbose, 411 "CMSOldPLABMin (" SIZE_FORMAT ") must be " 412 "less than or equal to CMSOldPLABMax (" SIZE_FORMAT ")\n", 413 value, CMSOldPLABMax); 414 return JVMFlag::VIOLATES_CONSTRAINT; 415 } 416 status = MaxPLABSizeBounds("CMSOldPLABMin", value, verbose); 417 } 418 #endif 419 return status; 420 } 421 422 JVMFlag::Error CMSOldPLABMaxConstraintFunc(size_t value, bool verbose) { 423 JVMFlag::Error status = JVMFlag::SUCCESS; 424 425 #if INCLUDE_ALL_GCS 426 if (UseConcMarkSweepGC) { 427 status = MaxPLABSizeBounds("CMSOldPLABMax", value, verbose); 428 } 429 #endif 430 return status; 431 } 432 433 JVMFlag::Error MarkStackSizeConstraintFunc(size_t value, bool verbose) { 434 if (value > MarkStackSizeMax) { 435 CommandLineError::print(verbose, 436 "MarkStackSize (" SIZE_FORMAT ") must be " 437 "less than or equal to MarkStackSizeMax (" SIZE_FORMAT ")\n", 438 value, MarkStackSizeMax); 439 return JVMFlag::VIOLATES_CONSTRAINT; 440 } else { 441 return JVMFlag::SUCCESS; 442 } 443 } 444 445 static JVMFlag::Error CMSReservedAreaConstraintFunc(const char* name, size_t value, bool verbose) { 446 #if INCLUDE_ALL_GCS 447 if (UseConcMarkSweepGC) { 448 ConcurrentMarkSweepGeneration* cms = (ConcurrentMarkSweepGeneration*)GenCollectedHeap::heap()->old_gen(); 449 const size_t ergo_max = cms->cmsSpace()->max_flag_size_for_task_size(); 450 if (value > ergo_max) { 451 CommandLineError::print(verbose, 452 "%s (" SIZE_FORMAT ") must be " 453 "less than or equal to ergonomic maximum (" SIZE_FORMAT ") " 454 "which is based on the maximum size of the old generation of the Java heap\n", 455 name, value, ergo_max); 456 return JVMFlag::VIOLATES_CONSTRAINT; 457 } 458 } 459 #endif 460 461 return JVMFlag::SUCCESS; 462 } 463 464 JVMFlag::Error CMSRescanMultipleConstraintFunc(size_t value, bool verbose) { 465 JVMFlag::Error status = CMSReservedAreaConstraintFunc("CMSRescanMultiple", value, verbose); 466 467 #if INCLUDE_ALL_GCS 468 if (status == JVMFlag::SUCCESS && UseConcMarkSweepGC) { 469 // CMSParRemarkTask::do_dirty_card_rescan_tasks requires CompactibleFreeListSpace::rescan_task_size() 470 // to be aligned to CardTable::card_size * BitsPerWord. 471 // Note that rescan_task_size() will be aligned if CMSRescanMultiple is a multiple of 'HeapWordSize' 472 // because rescan_task_size() is CardTable::card_size / HeapWordSize * BitsPerWord. 473 if (value % HeapWordSize != 0) { 474 CommandLineError::print(verbose, 475 "CMSRescanMultiple (" SIZE_FORMAT ") must be " 476 "a multiple of " SIZE_FORMAT "\n", 477 value, HeapWordSize); 478 status = JVMFlag::VIOLATES_CONSTRAINT; 479 } 480 } 481 #endif 482 483 return status; 484 } 485 486 JVMFlag::Error CMSConcMarkMultipleConstraintFunc(size_t value, bool verbose) { 487 return CMSReservedAreaConstraintFunc("CMSConcMarkMultiple", value, verbose); 488 } 489 490 JVMFlag::Error CMSPrecleanDenominatorConstraintFunc(uintx value, bool verbose) { 491 #if INCLUDE_ALL_GCS 492 if (UseConcMarkSweepGC && (value <= CMSPrecleanNumerator)) { 493 CommandLineError::print(verbose, 494 "CMSPrecleanDenominator (" UINTX_FORMAT ") must be " 495 "strickly greater than CMSPrecleanNumerator (" UINTX_FORMAT ")\n", 496 value, CMSPrecleanNumerator); 497 return JVMFlag::VIOLATES_CONSTRAINT; 498 } 499 #endif 500 return JVMFlag::SUCCESS; 501 } 502 503 JVMFlag::Error CMSPrecleanNumeratorConstraintFunc(uintx value, bool verbose) { 504 #if INCLUDE_ALL_GCS 505 if (UseConcMarkSweepGC && (value >= CMSPrecleanDenominator)) { 506 CommandLineError::print(verbose, 507 "CMSPrecleanNumerator (" UINTX_FORMAT ") must be " 508 "less than CMSPrecleanDenominator (" UINTX_FORMAT ")\n", 509 value, CMSPrecleanDenominator); 510 return JVMFlag::VIOLATES_CONSTRAINT; 511 } 512 #endif 513 return JVMFlag::SUCCESS; 514 } 515 516 JVMFlag::Error CMSSamplingGrainConstraintFunc(uintx value, bool verbose) { 517 #if INCLUDE_ALL_GCS 518 if (UseConcMarkSweepGC) { 519 size_t max_capacity = GenCollectedHeap::heap()->young_gen()->max_capacity(); 520 if (value > max_uintx - max_capacity) { 521 CommandLineError::print(verbose, 522 "CMSSamplingGrain (" UINTX_FORMAT ") must be " 523 "less than or equal to ergonomic maximum (" SIZE_FORMAT ")\n", 524 value, max_uintx - max_capacity); 525 return JVMFlag::VIOLATES_CONSTRAINT; 526 } 527 } 528 #endif 529 return JVMFlag::SUCCESS; 530 } 531 532 JVMFlag::Error CMSWorkQueueDrainThresholdConstraintFunc(uintx value, bool verbose) { 533 #if INCLUDE_ALL_GCS 534 if (UseConcMarkSweepGC) { 535 return ParallelGCThreadsAndCMSWorkQueueDrainThreshold(ParallelGCThreads, value, verbose); 536 } 537 #endif 538 return JVMFlag::SUCCESS; 539 } 540 541 JVMFlag::Error CMSBitMapYieldQuantumConstraintFunc(size_t value, bool verbose) { 542 #if INCLUDE_ALL_GCS 543 // Skip for current default value. 544 if (UseConcMarkSweepGC && FLAG_IS_CMDLINE(CMSBitMapYieldQuantum)) { 545 // CMSBitMapYieldQuantum should be compared with mark bitmap size. 546 ConcurrentMarkSweepGeneration* cms = (ConcurrentMarkSweepGeneration*)GenCollectedHeap::heap()->old_gen(); 547 size_t bitmap_size = cms->collector()->markBitMap()->sizeInWords(); 548 549 if (value > bitmap_size) { 550 CommandLineError::print(verbose, 551 "CMSBitMapYieldQuantum (" SIZE_FORMAT ") must " 552 "be less than or equal to bitmap size (" SIZE_FORMAT ") " 553 "whose size corresponds to the size of old generation of the Java heap\n", 554 value, bitmap_size); 555 return JVMFlag::VIOLATES_CONSTRAINT; 556 } 557 } 558 #endif 559 return JVMFlag::SUCCESS; 560 } 561 562 JVMFlag::Error MaxGCPauseMillisConstraintFunc(uintx value, bool verbose) { 563 #if INCLUDE_ALL_GCS 564 if (UseG1GC && FLAG_IS_CMDLINE(MaxGCPauseMillis) && (value >= GCPauseIntervalMillis)) { 565 CommandLineError::print(verbose, 566 "MaxGCPauseMillis (" UINTX_FORMAT ") must be " 567 "less than GCPauseIntervalMillis (" UINTX_FORMAT ")\n", 568 value, GCPauseIntervalMillis); 569 return JVMFlag::VIOLATES_CONSTRAINT; 570 } 571 #endif 572 573 return JVMFlag::SUCCESS; 574 } 575 576 JVMFlag::Error GCPauseIntervalMillisConstraintFunc(uintx value, bool verbose) { 577 #if INCLUDE_ALL_GCS 578 if (UseG1GC) { 579 if (FLAG_IS_CMDLINE(GCPauseIntervalMillis)) { 580 if (value < 1) { 581 CommandLineError::print(verbose, 582 "GCPauseIntervalMillis (" UINTX_FORMAT ") must be " 583 "greater than or equal to 1\n", 584 value); 585 return JVMFlag::VIOLATES_CONSTRAINT; 586 } 587 588 if (FLAG_IS_DEFAULT(MaxGCPauseMillis)) { 589 CommandLineError::print(verbose, 590 "GCPauseIntervalMillis cannot be set " 591 "without setting MaxGCPauseMillis\n"); 592 return JVMFlag::VIOLATES_CONSTRAINT; 593 } 594 595 if (value <= MaxGCPauseMillis) { 596 CommandLineError::print(verbose, 597 "GCPauseIntervalMillis (" UINTX_FORMAT ") must be " 598 "greater than MaxGCPauseMillis (" UINTX_FORMAT ")\n", 599 value, MaxGCPauseMillis); 600 return JVMFlag::VIOLATES_CONSTRAINT; 601 } 602 } 603 } 604 #endif 605 return JVMFlag::SUCCESS; 606 } 607 608 JVMFlag::Error InitialBootClassLoaderMetaspaceSizeConstraintFunc(size_t value, bool verbose) { 609 size_t aligned_max = align_down(max_uintx/2, Metaspace::reserve_alignment_words()); 610 if (value > aligned_max) { 611 CommandLineError::print(verbose, 612 "InitialBootClassLoaderMetaspaceSize (" SIZE_FORMAT ") must be " 613 "less than or equal to aligned maximum value (" SIZE_FORMAT ")\n", 614 value, aligned_max); 615 return JVMFlag::VIOLATES_CONSTRAINT; 616 } 617 return JVMFlag::SUCCESS; 618 } 619 620 // To avoid an overflow by 'align_up(value, alignment)'. 621 static JVMFlag::Error MaxSizeForAlignment(const char* name, size_t value, size_t alignment, bool verbose) { 622 size_t aligned_max = ((max_uintx - alignment) & ~(alignment-1)); 623 if (value > aligned_max) { 624 CommandLineError::print(verbose, 625 "%s (" SIZE_FORMAT ") must be " 626 "less than or equal to aligned maximum value (" SIZE_FORMAT ")\n", 627 name, value, aligned_max); 628 return JVMFlag::VIOLATES_CONSTRAINT; 629 } 630 return JVMFlag::SUCCESS; 631 } 632 633 static JVMFlag::Error MaxSizeForHeapAlignment(const char* name, size_t value, bool verbose) { 634 // For G1 GC, we don't know until G1CollectorPolicy is created. 635 size_t heap_alignment; 636 637 #if INCLUDE_ALL_GCS 638 if (UseG1GC) { 639 heap_alignment = HeapRegionBounds::max_size(); 640 } else 641 #endif 642 { 643 heap_alignment = CollectorPolicy::compute_heap_alignment(); 644 } 645 646 return MaxSizeForAlignment(name, value, heap_alignment, verbose); 647 } 648 649 JVMFlag::Error InitialHeapSizeConstraintFunc(size_t value, bool verbose) { 650 return MaxSizeForHeapAlignment("InitialHeapSize", value, verbose); 651 } 652 653 JVMFlag::Error MaxHeapSizeConstraintFunc(size_t value, bool verbose) { 654 JVMFlag::Error status = MaxSizeForHeapAlignment("MaxHeapSize", value, verbose); 655 656 if (status == JVMFlag::SUCCESS) { 657 status = CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(value, SoftRefLRUPolicyMSPerMB, verbose); 658 } 659 return status; 660 } 661 662 JVMFlag::Error HeapBaseMinAddressConstraintFunc(size_t value, bool verbose) { 663 // If an overflow happened in Arguments::set_heap_size(), MaxHeapSize will have too large a value. 664 // Check for this by ensuring that MaxHeapSize plus the requested min base address still fit within max_uintx. 665 if (UseCompressedOops && FLAG_IS_ERGO(MaxHeapSize) && (value > (max_uintx - MaxHeapSize))) { 666 CommandLineError::print(verbose, 667 "HeapBaseMinAddress (" SIZE_FORMAT ") or MaxHeapSize (" SIZE_FORMAT ") is too large. " 668 "Sum of them must be less than or equal to maximum of size_t (" SIZE_FORMAT ")\n", 669 value, MaxHeapSize, max_uintx); 670 return JVMFlag::VIOLATES_CONSTRAINT; 671 } 672 673 return MaxSizeForHeapAlignment("HeapBaseMinAddress", value, verbose); 674 } 675 676 JVMFlag::Error NewSizeConstraintFunc(size_t value, bool verbose) { 677 #ifdef _LP64 678 #if INCLUDE_ALL_GCS 679 // Overflow would happen for uint type variable of YoungGenSizer::_min_desired_young_length 680 // when the value to be assigned exceeds uint range. 681 // i.e. result of '(uint)(NewSize / region size(1~32MB))' 682 // So maximum of NewSize should be 'max_juint * 1M' 683 if (UseG1GC && (value > (max_juint * 1 * M))) { 684 CommandLineError::print(verbose, 685 "NewSize (" SIZE_FORMAT ") must be less than ergonomic maximum value\n", 686 value); 687 return JVMFlag::VIOLATES_CONSTRAINT; 688 } 689 #endif // INCLUDE_ALL_GCS 690 #endif // _LP64 691 return JVMFlag::SUCCESS; 692 } 693 694 JVMFlag::Error MinTLABSizeConstraintFunc(size_t value, bool verbose) { 695 // At least, alignment reserve area is needed. 696 if (value < ThreadLocalAllocBuffer::alignment_reserve_in_bytes()) { 697 CommandLineError::print(verbose, 698 "MinTLABSize (" SIZE_FORMAT ") must be " 699 "greater than or equal to reserved area in TLAB (" SIZE_FORMAT ")\n", 700 value, ThreadLocalAllocBuffer::alignment_reserve_in_bytes()); 701 return JVMFlag::VIOLATES_CONSTRAINT; 702 } 703 if (value > (ThreadLocalAllocBuffer::max_size() * HeapWordSize)) { 704 CommandLineError::print(verbose, 705 "MinTLABSize (" SIZE_FORMAT ") must be " 706 "less than or equal to ergonomic TLAB maximum (" SIZE_FORMAT ")\n", 707 value, ThreadLocalAllocBuffer::max_size() * HeapWordSize); 708 return JVMFlag::VIOLATES_CONSTRAINT; 709 } 710 return JVMFlag::SUCCESS; 711 } 712 713 JVMFlag::Error TLABSizeConstraintFunc(size_t value, bool verbose) { 714 // Skip for default value of zero which means set ergonomically. 715 if (FLAG_IS_CMDLINE(TLABSize)) { 716 if (value < MinTLABSize) { 717 CommandLineError::print(verbose, 718 "TLABSize (" SIZE_FORMAT ") must be " 719 "greater than or equal to MinTLABSize (" SIZE_FORMAT ")\n", 720 value, MinTLABSize); 721 return JVMFlag::VIOLATES_CONSTRAINT; 722 } 723 if (value > (ThreadLocalAllocBuffer::max_size() * HeapWordSize)) { 724 CommandLineError::print(verbose, 725 "TLABSize (" SIZE_FORMAT ") must be " 726 "less than or equal to ergonomic TLAB maximum size (" SIZE_FORMAT ")\n", 727 value, (ThreadLocalAllocBuffer::max_size() * HeapWordSize)); 728 return JVMFlag::VIOLATES_CONSTRAINT; 729 } 730 } 731 return JVMFlag::SUCCESS; 732 } 733 734 // We will protect overflow from ThreadLocalAllocBuffer::record_slow_allocation(), 735 // so AfterMemoryInit type is enough to check. 736 JVMFlag::Error TLABWasteIncrementConstraintFunc(uintx value, bool verbose) { 737 if (UseTLAB) { 738 size_t refill_waste_limit = Thread::current()->tlab().refill_waste_limit(); 739 740 // Compare with 'max_uintx' as ThreadLocalAllocBuffer::_refill_waste_limit is 'size_t'. 741 if (refill_waste_limit > (max_uintx - value)) { 742 CommandLineError::print(verbose, 743 "TLABWasteIncrement (" UINTX_FORMAT ") must be " 744 "less than or equal to ergonomic TLAB waste increment maximum size(" SIZE_FORMAT ")\n", 745 value, (max_uintx - refill_waste_limit)); 746 return JVMFlag::VIOLATES_CONSTRAINT; 747 } 748 } 749 return JVMFlag::SUCCESS; 750 } 751 752 JVMFlag::Error SurvivorRatioConstraintFunc(uintx value, bool verbose) { 753 if (FLAG_IS_CMDLINE(SurvivorRatio) && 754 (value > (MaxHeapSize / Universe::heap()->collector_policy()->space_alignment()))) { 755 CommandLineError::print(verbose, 756 "SurvivorRatio (" UINTX_FORMAT ") must be " 757 "less than or equal to ergonomic SurvivorRatio maximum (" SIZE_FORMAT ")\n", 758 value, 759 (MaxHeapSize / Universe::heap()->collector_policy()->space_alignment())); 760 return JVMFlag::VIOLATES_CONSTRAINT; 761 } else { 762 return JVMFlag::SUCCESS; 763 } 764 } 765 766 JVMFlag::Error MetaspaceSizeConstraintFunc(size_t value, bool verbose) { 767 if (value > MaxMetaspaceSize) { 768 CommandLineError::print(verbose, 769 "MetaspaceSize (" SIZE_FORMAT ") must be " 770 "less than or equal to MaxMetaspaceSize (" SIZE_FORMAT ")\n", 771 value, MaxMetaspaceSize); 772 return JVMFlag::VIOLATES_CONSTRAINT; 773 } else { 774 return JVMFlag::SUCCESS; 775 } 776 } 777 778 JVMFlag::Error MaxMetaspaceSizeConstraintFunc(size_t value, bool verbose) { 779 if (value < MetaspaceSize) { 780 CommandLineError::print(verbose, 781 "MaxMetaspaceSize (" SIZE_FORMAT ") must be " 782 "greater than or equal to MetaspaceSize (" SIZE_FORMAT ")\n", 783 value, MaxMetaspaceSize); 784 return JVMFlag::VIOLATES_CONSTRAINT; 785 } else { 786 return JVMFlag::SUCCESS; 787 } 788 } 789 790 JVMFlag::Error SurvivorAlignmentInBytesConstraintFunc(intx value, bool verbose) { 791 if (value != 0) { 792 if (!is_power_of_2(value)) { 793 CommandLineError::print(verbose, 794 "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be " 795 "power of 2\n", 796 value); 797 return JVMFlag::VIOLATES_CONSTRAINT; 798 } 799 if (value < ObjectAlignmentInBytes) { 800 CommandLineError::print(verbose, 801 "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be " 802 "greater than or equal to ObjectAlignmentInBytes (" INTX_FORMAT ")\n", 803 value, ObjectAlignmentInBytes); 804 return JVMFlag::VIOLATES_CONSTRAINT; 805 } 806 } 807 return JVMFlag::SUCCESS; 808 } |