1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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/threadLocalAllocBuffer.hpp"
  29 #include "runtime/arguments.hpp"
  30 #include "runtime/commandLineFlagConstraintsGC.hpp"
  31 #include "runtime/commandLineFlagRangeList.hpp"
  32 #include "runtime/globals.hpp"
  33 #include "runtime/globals_extension.hpp"
  34 #include "utilities/defaultStream.hpp"
  35 
  36 #if INCLUDE_ALL_GCS
  37 #include "gc/g1/g1_globals.hpp"
  38 #include "gc/g1/heapRegionBounds.inline.hpp"
  39 #include "gc/shared/plab.hpp"
  40 #endif // INCLUDE_ALL_GCS
  41 #ifdef COMPILER1
  42 #include "c1/c1_globals.hpp"
  43 #endif // COMPILER1
  44 #ifdef COMPILER2
  45 #include "opto/c2_globals.hpp"
  46 #endif // COMPILER2
  47 
  48 #if INCLUDE_ALL_GCS
  49 static Flag::Error ParallelGCThreadsAndCMSWorkQueueDrainThreshold(uint threads, uintx threshold, bool verbose) {
  50   // CMSWorkQueueDrainThreshold is verified to be less than max_juint
  51   if (UseConcMarkSweepGC && (threads > (uint)(max_jint / (uint)threshold))) {
  52     CommandLineError::print(verbose,
  53                             "ParallelGCThreads (" UINT32_FORMAT ") or CMSWorkQueueDrainThreshold ("
  54                             UINTX_FORMAT ") is too large\n",
  55                             threads, threshold);
  56     return Flag::VIOLATES_CONSTRAINT;
  57   }
  58   return Flag::SUCCESS;
  59 }
  60 #endif
  61 
  62 // As ParallelGCThreads differs among GC modes, we need constraint function.
  63 Flag::Error ParallelGCThreadsConstraintFunc(uint value, bool verbose) {
  64   Flag::Error status = Flag::SUCCESS;
  65 
  66 #if INCLUDE_ALL_GCS
  67   // Parallel GC passes ParallelGCThreads when creating GrowableArray as 'int' type parameter.
  68   // So can't exceed with "max_jint"
  69   if (UseParallelGC && (value > (uint)max_jint)) {
  70     CommandLineError::print(verbose,
  71                             "ParallelGCThreads (" UINT32_FORMAT ") must be "
  72                             "less than or equal to " UINT32_FORMAT " for Parallel GC\n",
  73                             value, max_jint);
  74     return Flag::VIOLATES_CONSTRAINT;
  75   }
  76   // To avoid overflow at ParScanClosure::do_oop_work.
  77   if (UseConcMarkSweepGC && (value > (max_jint / 10))) {
  78     CommandLineError::print(verbose,
  79                             "ParallelGCThreads (" UINT32_FORMAT ") must be "
  80                             "less than or equal to " UINT32_FORMAT " for CMS GC\n",
  81                             value, (max_jint / 10));
  82     return Flag::VIOLATES_CONSTRAINT;
  83   }
  84   status = ParallelGCThreadsAndCMSWorkQueueDrainThreshold(value, CMSWorkQueueDrainThreshold, verbose);
  85 #endif
  86   return status;
  87 }
  88 
  89 // As ConcGCThreads should be smaller than ParallelGCThreads,
  90 // we need constraint function.
  91 Flag::Error ConcGCThreadsConstraintFunc(uint value, bool verbose) {
  92 #if INCLUDE_ALL_GCS
  93   // CMS and G1 GCs use ConcGCThreads.
  94   if ((UseConcMarkSweepGC || UseG1GC) && (value > ParallelGCThreads)) {
  95     CommandLineError::print(verbose,
  96                             "ConcGCThreads (" UINT32_FORMAT ") must be "
  97                             "less than or equal to ParallelGCThreads (" UINT32_FORMAT ")\n",
  98                             value, ParallelGCThreads);
  99     return Flag::VIOLATES_CONSTRAINT;
 100   }
 101 #endif
 102   return Flag::SUCCESS;
 103 }
 104 
 105 static Flag::Error MinPLABSizeBounds(const char* name, size_t value, bool verbose) {
 106 #if INCLUDE_ALL_GCS
 107   if ((UseConcMarkSweepGC || UseG1GC) && (value < PLAB::min_size())) {
 108     CommandLineError::print(verbose,
 109                             "%s (" SIZE_FORMAT ") must be "
 110                             "greater than or equal to ergonomic PLAB minimum size (" SIZE_FORMAT ")\n",
 111                             name, value, PLAB::min_size());
 112     return Flag::VIOLATES_CONSTRAINT;
 113   }
 114 #endif // INCLUDE_ALL_GCS
 115   return Flag::SUCCESS;
 116 }
 117 
 118 static Flag::Error MaxPLABSizeBounds(const char* name, size_t value, bool verbose) {
 119 #if INCLUDE_ALL_GCS
 120   if ((UseConcMarkSweepGC || UseG1GC) && (value > PLAB::max_size())) {
 121     CommandLineError::print(verbose,
 122                             "%s (" SIZE_FORMAT ") must be "
 123                             "less than or equal to ergonomic PLAB maximum size (" SIZE_FORMAT ")\n",
 124                             name, value, PLAB::min_size());
 125     return Flag::VIOLATES_CONSTRAINT;
 126   }
 127 #endif // INCLUDE_ALL_GCS
 128   return Flag::SUCCESS;
 129 }
 130 
 131 static Flag::Error MinMaxPLABSizeBounds(const char* name, size_t value, bool verbose) {
 132   Flag::Error status = MinPLABSizeBounds(name, value, verbose);
 133 
 134   if (status == Flag::SUCCESS) {
 135     return MaxPLABSizeBounds(name, value, verbose);
 136   }
 137   return status;
 138 }
 139 
 140 Flag::Error YoungPLABSizeConstraintFunc(size_t value, bool verbose) {
 141   return MinMaxPLABSizeBounds("YoungPLABSize", value, verbose);
 142 }
 143 
 144 Flag::Error OldPLABSizeConstraintFunc(size_t value, bool verbose) {
 145   Flag::Error status = Flag::SUCCESS;
 146 
 147 #if INCLUDE_ALL_GCS
 148   if (UseConcMarkSweepGC) {
 149     if (value == 0) {
 150       CommandLineError::print(verbose,
 151                               "OldPLABSize (" SIZE_FORMAT ") must be greater than 0",
 152                               value);
 153       return Flag::VIOLATES_CONSTRAINT;
 154     }
 155     // For CMS, OldPLABSize is the number of free blocks of a given size that are used when
 156     // replenishing the local per-worker free list caches.
 157     // For more details, please refer to Arguments::set_cms_and_parnew_gc_flags().
 158     status = MaxPLABSizeBounds("OldPLABSize", value, verbose);
 159   } else {
 160     status = MinMaxPLABSizeBounds("OldPLABSize", value, verbose);
 161   }
 162 #endif
 163   return status;
 164 }
 165 
 166 Flag::Error MinHeapFreeRatioConstraintFunc(uintx value, bool verbose) {
 167   if (value > MaxHeapFreeRatio) {
 168     CommandLineError::print(verbose,
 169                             "MinHeapFreeRatio (" UINTX_FORMAT ") must be "
 170                             "less than or equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n",
 171                             value, MaxHeapFreeRatio);
 172     return Flag::VIOLATES_CONSTRAINT;
 173   } else {
 174     return Flag::SUCCESS;
 175   }
 176 }
 177 
 178 Flag::Error MaxHeapFreeRatioConstraintFunc(uintx value, bool verbose) {
 179   if (value < MinHeapFreeRatio) {
 180     CommandLineError::print(verbose,
 181                             "MaxHeapFreeRatio (" UINTX_FORMAT ") must be "
 182                             "greater than or equal to MinHeapFreeRatio (" UINTX_FORMAT ")\n",
 183                             value, MinHeapFreeRatio);
 184     return Flag::VIOLATES_CONSTRAINT;
 185   } else {
 186     return Flag::SUCCESS;
 187   }
 188 }
 189 
 190 static Flag::Error CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(size_t maxHeap, intx softRef, bool verbose) {
 191   if ((softRef > 0) && ((maxHeap / M) > (max_uintx / softRef))) {
 192     CommandLineError::print(verbose,
 193                             "MaxHeapSize (" SIZE_FORMAT ") or SoftRefLRUPolicyMSPerMB "
 194                             "(" INTX_FORMAT ") is too large\n",
 195                             maxHeap, softRef);
 196     return Flag::VIOLATES_CONSTRAINT;
 197   } else {
 198     return Flag::SUCCESS;
 199   }
 200 }
 201 
 202 Flag::Error SoftRefLRUPolicyMSPerMBConstraintFunc(intx value, bool verbose) {
 203   return CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(MaxHeapSize, value, verbose);
 204 }
 205 
 206 Flag::Error MinMetaspaceFreeRatioConstraintFunc(uintx value, bool verbose) {
 207   if (value > MaxMetaspaceFreeRatio) {
 208     CommandLineError::print(verbose,
 209                             "MinMetaspaceFreeRatio (" UINTX_FORMAT ") must be "
 210                             "less than or equal to MaxMetaspaceFreeRatio (" UINTX_FORMAT ")\n",
 211                             value, MaxMetaspaceFreeRatio);
 212     return Flag::VIOLATES_CONSTRAINT;
 213   } else {
 214     return Flag::SUCCESS;
 215   }
 216 }
 217 
 218 Flag::Error MaxMetaspaceFreeRatioConstraintFunc(uintx value, bool verbose) {
 219   if (value < MinMetaspaceFreeRatio) {
 220     CommandLineError::print(verbose,
 221                             "MaxMetaspaceFreeRatio (" UINTX_FORMAT ") must be "
 222                             "greater than or equal to MinMetaspaceFreeRatio (" UINTX_FORMAT ")\n",
 223                             value, MinMetaspaceFreeRatio);
 224     return Flag::VIOLATES_CONSTRAINT;
 225   } else {
 226     return Flag::SUCCESS;
 227   }
 228 }
 229 
 230 Flag::Error InitialTenuringThresholdConstraintFunc(uintx value, bool verbose) {
 231 #if INCLUDE_ALL_GCS
 232   // InitialTenuringThreshold is only used for ParallelGC.
 233   if (UseParallelGC && (value > MaxTenuringThreshold)) {
 234       CommandLineError::print(verbose,
 235                               "InitialTenuringThreshold (" UINTX_FORMAT ") must be "
 236                               "less than or equal to MaxTenuringThreshold (" UINTX_FORMAT ")\n",
 237                               value, MaxTenuringThreshold);
 238       return Flag::VIOLATES_CONSTRAINT;
 239   }
 240 #endif
 241   return Flag::SUCCESS;
 242 }
 243 
 244 Flag::Error MaxTenuringThresholdConstraintFunc(uintx value, bool verbose) {
 245 #if INCLUDE_ALL_GCS
 246   // As only ParallelGC uses InitialTenuringThreshold,
 247   // we don't need to compare InitialTenuringThreshold with MaxTenuringThreshold.
 248   if (UseParallelGC && (value < InitialTenuringThreshold)) {
 249     CommandLineError::print(verbose,
 250                             "MaxTenuringThreshold (" UINTX_FORMAT ") must be "
 251                             "greater than or equal to InitialTenuringThreshold (" UINTX_FORMAT ")\n",
 252                             value, InitialTenuringThreshold);
 253     return Flag::VIOLATES_CONSTRAINT;
 254   }
 255 #endif
 256 
 257   // MaxTenuringThreshold=0 means NeverTenure=false && AlwaysTenure=true
 258   if ((value == 0) && (NeverTenure || !AlwaysTenure)) {
 259     CommandLineError::print(verbose,
 260                             "MaxTenuringThreshold (0) should match to NeverTenure=false "
 261                             "&& AlwaysTenure=true. But we have NeverTenure=%s "
 262                             "AlwaysTenure=%s\n",
 263                             NeverTenure ? "true" : "false",
 264                             AlwaysTenure ? "true" : "false");
 265     return Flag::VIOLATES_CONSTRAINT;
 266   }
 267   return Flag::SUCCESS;
 268 }
 269 
 270 #if INCLUDE_ALL_GCS
 271 Flag::Error G1RSetRegionEntriesConstraintFunc(intx value, bool verbose) {
 272   if (!UseG1GC) return Flag::SUCCESS;
 273 
 274   // Default value of G1RSetRegionEntries=0 means will be set ergonomically.
 275   // Minimum value is 1.
 276   if (FLAG_IS_CMDLINE(G1RSetRegionEntries) && (value < 1)) {
 277     CommandLineError::print(verbose,
 278                             "G1RSetRegionEntries (" INTX_FORMAT ") must be "
 279                             "greater than or equal to 1\n",
 280                             value);
 281     return Flag::VIOLATES_CONSTRAINT;
 282   } else {
 283     return Flag::SUCCESS;
 284   }
 285 }
 286 
 287 Flag::Error G1RSetSparseRegionEntriesConstraintFunc(intx value, bool verbose) {
 288   if (!UseG1GC) return Flag::SUCCESS;
 289 
 290   // Default value of G1RSetSparseRegionEntries=0 means will be set ergonomically.
 291   // Minimum value is 1.
 292   if (FLAG_IS_CMDLINE(G1RSetSparseRegionEntries) && (value < 1)) {
 293     CommandLineError::print(verbose,
 294                             "G1RSetSparseRegionEntries (" INTX_FORMAT ") must be "
 295                             "greater than or equal to 1\n",
 296                             value);
 297     return Flag::VIOLATES_CONSTRAINT;
 298   } else {
 299     return Flag::SUCCESS;
 300   }
 301 }
 302 
 303 Flag::Error G1YoungSurvRateNumRegionsSummaryConstraintFunc(intx value, bool verbose) {
 304   if (!UseG1GC) return Flag::SUCCESS;
 305 
 306   if (value > (intx)HeapRegionBounds::target_number()) {
 307     CommandLineError::print(verbose,
 308                             "G1YoungSurvRateNumRegionsSummary (" INTX_FORMAT ") must be "
 309                             "less than or equal to region amount (" SIZE_FORMAT ")\n",
 310                             value, HeapRegionBounds::target_number());
 311     return Flag::VIOLATES_CONSTRAINT;
 312   } else {
 313     return Flag::SUCCESS;
 314   }
 315 }
 316 
 317 Flag::Error G1HeapRegionSizeConstraintFunc(size_t value, bool verbose) {
 318   if (!UseG1GC) return Flag::SUCCESS;
 319 
 320   // Default value of G1HeapRegionSize=0 means will be set ergonomically.
 321   if (FLAG_IS_CMDLINE(G1HeapRegionSize) && (value < HeapRegionBounds::min_size())) {
 322     CommandLineError::print(verbose,
 323                             "G1HeapRegionSize (" SIZE_FORMAT ") must be "
 324                             "greater than or equal to ergonomic heap region minimum size\n",
 325                             value);
 326     return Flag::VIOLATES_CONSTRAINT;
 327   } else {
 328     return Flag::SUCCESS;
 329   }
 330 }
 331 
 332 Flag::Error G1NewSizePercentConstraintFunc(uintx value, bool verbose) {
 333   if (!UseG1GC) return Flag::SUCCESS;
 334 
 335   if (value > G1MaxNewSizePercent) {
 336     CommandLineError::print(verbose,
 337                             "G1NewSizePercent (" UINTX_FORMAT ") must be "
 338                             "less than or equal to G1MaxNewSizePercent (" UINTX_FORMAT ")\n",
 339                             value, G1MaxNewSizePercent);
 340     return Flag::VIOLATES_CONSTRAINT;
 341   } else {
 342     return Flag::SUCCESS;
 343   }
 344 }
 345 
 346 Flag::Error G1MaxNewSizePercentConstraintFunc(uintx value, bool verbose) {
 347   if (!UseG1GC) return Flag::SUCCESS;
 348 
 349   if (value < G1NewSizePercent) {
 350     CommandLineError::print(verbose,
 351                             "G1MaxNewSizePercent (" UINTX_FORMAT ") must be "
 352                             "greater than or equal to G1NewSizePercent (" UINTX_FORMAT ")\n",
 353                             value, G1NewSizePercent);
 354     return Flag::VIOLATES_CONSTRAINT;
 355   } else {
 356     return Flag::SUCCESS;
 357   }
 358 }
 359 #endif // INCLUDE_ALL_GCS
 360 
 361 Flag::Error ParGCStridesPerThreadConstraintFunc(uintx value, bool verbose) {
 362 #if INCLUDE_ALL_GCS
 363   if (UseConcMarkSweepGC && (value > ((uintx)max_jint / (uintx)ParallelGCThreads))) {
 364     CommandLineError::print(verbose,
 365                             "ParGCStridesPerThread (" UINTX_FORMAT ") must be "
 366                             "less than or equal to ergonomic maximum (" UINTX_FORMAT ")\n",
 367                             value, ((uintx)max_jint / (uintx)ParallelGCThreads));
 368     return Flag::VIOLATES_CONSTRAINT;
 369   }
 370 #endif
 371   return Flag::SUCCESS;
 372 }
 373 
 374 Flag::Error CMSOldPLABMinConstraintFunc(size_t value, bool verbose) {
 375   Flag::Error status = Flag::SUCCESS;
 376 
 377 #if INCLUDE_ALL_GCS
 378   if (UseConcMarkSweepGC) {
 379     if (value > CMSOldPLABMax) {
 380       CommandLineError::print(verbose,
 381                               "CMSOldPLABMin (" SIZE_FORMAT ") must be "
 382                               "less than or equal to CMSOldPLABMax (" SIZE_FORMAT ")\n",
 383                               value, CMSOldPLABMax);
 384       return Flag::VIOLATES_CONSTRAINT;
 385     }
 386     status = MaxPLABSizeBounds("CMSOldPLABMin", value, verbose);
 387   }
 388 #endif
 389   return status;
 390 }
 391 
 392 Flag::Error CMSOldPLABMaxConstraintFunc(size_t value, bool verbose) {
 393   Flag::Error status = Flag::SUCCESS;
 394 
 395 #if INCLUDE_ALL_GCS
 396   if (UseConcMarkSweepGC) {
 397     status = MaxPLABSizeBounds("CMSOldPLABMax", value, verbose);
 398   }
 399 #endif
 400   return status;
 401 }
 402 
 403 Flag::Error CMSPrecleanDenominatorConstraintFunc(uintx value, bool verbose) {
 404 #if INCLUDE_ALL_GCS
 405   if (UseConcMarkSweepGC && (value <= CMSPrecleanNumerator)) {
 406     CommandLineError::print(verbose,
 407                             "CMSPrecleanDenominator (" UINTX_FORMAT ") must be "
 408                             "strickly greater than CMSPrecleanNumerator (" UINTX_FORMAT ")\n",
 409                             value, CMSPrecleanNumerator);
 410     return Flag::VIOLATES_CONSTRAINT;
 411   }
 412 #endif
 413   return Flag::SUCCESS;
 414 }
 415 
 416 Flag::Error CMSPrecleanNumeratorConstraintFunc(uintx value, bool verbose) {
 417 #if INCLUDE_ALL_GCS
 418   if (UseConcMarkSweepGC && (value >= CMSPrecleanDenominator)) {
 419     CommandLineError::print(verbose,
 420                             "CMSPrecleanNumerator (" UINTX_FORMAT ") must be "
 421                             "less than CMSPrecleanDenominator (" UINTX_FORMAT ")\n",
 422                             value, CMSPrecleanDenominator);
 423     return Flag::VIOLATES_CONSTRAINT;
 424   }
 425 #endif
 426   return Flag::SUCCESS;
 427 }
 428 
 429 Flag::Error CMSWorkQueueDrainThresholdConstraintFunc(uintx value, bool verbose) {
 430 #if INCLUDE_ALL_GCS
 431   if (UseConcMarkSweepGC) {
 432     return ParallelGCThreadsAndCMSWorkQueueDrainThreshold(ParallelGCThreads, value, verbose);
 433   }
 434 #endif
 435   return Flag::SUCCESS;  
 436 }
 437 
 438 Flag::Error MaxGCPauseMillisConstraintFunc(uintx value, bool verbose) {
 439 #if INCLUDE_ALL_GCS
 440   if (UseG1GC && FLAG_IS_CMDLINE(MaxGCPauseMillis) && (value >= GCPauseIntervalMillis)) {
 441     CommandLineError::print(verbose,
 442                             "MaxGCPauseMillis (" UINTX_FORMAT ") must be "
 443                             "less than GCPauseIntervalMillis (" UINTX_FORMAT ")\n",
 444                             value, GCPauseIntervalMillis);
 445     return Flag::VIOLATES_CONSTRAINT;
 446   }
 447 #endif
 448 
 449   return Flag::SUCCESS;
 450 }
 451 
 452 Flag::Error GCPauseIntervalMillisConstraintFunc(uintx value, bool verbose) {
 453 #if INCLUDE_ALL_GCS
 454   if (UseG1GC) {
 455     if (FLAG_IS_CMDLINE(GCPauseIntervalMillis)) {
 456       if (value < 1) {
 457         CommandLineError::print(verbose,
 458                                 "GCPauseIntervalMillis (" UINTX_FORMAT ") must be "
 459                                 "greater than or equal to 1\n",
 460                                 value);
 461         return Flag::VIOLATES_CONSTRAINT;
 462       }
 463       if (value <= MaxGCPauseMillis) {
 464         CommandLineError::print(verbose,
 465                                 "GCPauseIntervalMillis (" UINTX_FORMAT ") must be "
 466                                 "greater than MaxGCPauseMillis (" UINTX_FORMAT ")\n",
 467                                 value, MaxGCPauseMillis);
 468         return Flag::VIOLATES_CONSTRAINT;
 469       }
 470     }
 471   }
 472 #endif
 473   return Flag::SUCCESS;
 474 }
 475 
 476 Flag::Error InitialBootClassLoaderMetaspaceSizeConstraintFunc(size_t value, bool verbose) {
 477   size_t aligned_max = (size_t)align_size_down(max_uintx/2, Metaspace::reserve_alignment_words());
 478   if (value > aligned_max) {
 479     CommandLineError::print(verbose,
 480                             "InitialBootClassLoaderMetaspaceSize (" SIZE_FORMAT ") must be "
 481                             "less than or equal to aligned maximum value (" SIZE_FORMAT ")\n",
 482                             value, aligned_max);
 483     return Flag::VIOLATES_CONSTRAINT;
 484   }
 485   return Flag::SUCCESS;
 486 }
 487 
 488 static Flag::Error MaxSizeForHeapAlignment(const char* name, size_t value, bool verbose) {
 489   // For G1 GC, we don't know until G1CollectorPolicy is created.
 490   size_t heap_alignment;
 491 
 492 #if INCLUDE_ALL_GCS
 493   if (UseG1GC) {
 494     heap_alignment = HeapRegionBounds::max_size();
 495   } else 
 496 #endif
 497   {
 498     heap_alignment = CollectorPolicy::compute_heap_alignment();
 499   }
 500   
 501   // Not to overflow 'align_size_up(value, _heap_alignment) used from CollectorPolicy::initialize_flags()'.
 502   size_t aligned_max = ((max_uintx - heap_alignment) & ~(heap_alignment-1));
 503   if (value > aligned_max) {
 504     CommandLineError::print(verbose,
 505                             "%s (" SIZE_FORMAT ") must be "
 506                             "less than or equal to aligned maximum value (" SIZE_FORMAT ")\n",
 507                             name, value, aligned_max);
 508     return Flag::VIOLATES_CONSTRAINT;
 509   }
 510   return Flag::SUCCESS;
 511 }
 512 
 513 Flag::Error InitialHeapSizeConstraintFunc(size_t value, bool verbose) {
 514   return MaxSizeForHeapAlignment("InitialHeapSize", value, verbose);
 515 }
 516 
 517 Flag::Error MaxHeapSizeConstraintFunc(size_t value, bool verbose) {
 518   Flag::Error status = MaxSizeForHeapAlignment("MaxHeapSize", value, verbose);
 519 
 520   if (status == Flag::SUCCESS) {
 521     status = CheckMaxHeapSizeAndSoftRefLRUPolicyMSPerMB(value, SoftRefLRUPolicyMSPerMB, verbose);
 522   }
 523   return status;
 524 }
 525 
 526 Flag::Error NewSizeConstraintFunc(size_t value, bool verbose) {
 527 #ifdef _LP64
 528 #if INCLUDE_ALL_GCS
 529   // Overflow would happen for uint type variable of YoungGenSizer::_min_desired_young_length
 530   // when the value to be assigned exceeds uint range.
 531   // i.e. result of '(uint)(NewSize / region size(1~32MB))'
 532   // So maximum of NewSize should be 'max_juint * 1M'
 533   if (UseG1GC && (value > (max_juint * 1 * M))) {
 534     CommandLineError::print(verbose,
 535                             "NewSize (" SIZE_FORMAT ") must be less than ergonomic maximum value\n",
 536                             value);
 537     return Flag::VIOLATES_CONSTRAINT;
 538   }
 539 #endif // INCLUDE_ALL_GCS
 540 #endif // _LP64
 541   return Flag::SUCCESS;
 542 }
 543 
 544 Flag::Error MinTLABSizeConstraintFunc(size_t value, bool verbose) {
 545   // At least, alignment reserve area is needed.
 546   if (value < ThreadLocalAllocBuffer::alignment_reserve_in_bytes()) {
 547     CommandLineError::print(verbose,
 548                             "MinTLABSize (" SIZE_FORMAT ") must be "
 549                             "greater than or equal to reserved area in TLAB (" SIZE_FORMAT ")\n",
 550                             value, ThreadLocalAllocBuffer::alignment_reserve_in_bytes());
 551     return Flag::VIOLATES_CONSTRAINT;
 552   } else {
 553     return Flag::SUCCESS;
 554   }
 555 }
 556 
 557 Flag::Error TLABSizeConstraintFunc(size_t value, bool verbose) {
 558   // Skip for default value of zero which means set ergonomically.
 559   if (FLAG_IS_CMDLINE(TLABSize)) {
 560     if (value < MinTLABSize) {
 561       CommandLineError::print(verbose,
 562                               "TLABSize (" SIZE_FORMAT ") must be "
 563                               "greater than or equal to MinTLABSize (" SIZE_FORMAT ")\n",
 564                               value, MinTLABSize);
 565       return Flag::VIOLATES_CONSTRAINT;
 566     }
 567     if (value > (ThreadLocalAllocBuffer::max_size() * HeapWordSize)) {
 568       CommandLineError::print(verbose,
 569                               "TLABSize (" SIZE_FORMAT ") must be "
 570                               "less than or equal to ergonomic TLAB maximum size (" SIZE_FORMAT ")\n",
 571                               value, (ThreadLocalAllocBuffer::max_size() * HeapWordSize));
 572       return Flag::VIOLATES_CONSTRAINT;
 573     }
 574   }
 575   return Flag::SUCCESS;
 576 }
 577 
 578 Flag::Error SurvivorRatioConstraintFunc(uintx value, bool verbose) {
 579   if (FLAG_IS_CMDLINE(SurvivorRatio) &&
 580       (value > (MaxHeapSize / Universe::heap()->collector_policy()->space_alignment()))) {
 581     CommandLineError::print(verbose,
 582                             "SurvivorRatio (" UINTX_FORMAT ") must be "
 583                             "less than or equal to ergonomic SurvivorRatio maximum (" SIZE_FORMAT ")\n",
 584                             value,
 585                             (MaxHeapSize / Universe::heap()->collector_policy()->space_alignment()));
 586     return Flag::VIOLATES_CONSTRAINT;
 587   } else {
 588     return Flag::SUCCESS;
 589   }
 590 }
 591 
 592 Flag::Error MetaspaceSizeConstraintFunc(size_t value, bool verbose) {
 593   if (value > MaxMetaspaceSize) {
 594     CommandLineError::print(verbose,
 595                             "MetaspaceSize (" SIZE_FORMAT ") must be "
 596                             "less than or equal to MaxMetaspaceSize (" SIZE_FORMAT ")\n",
 597                             value, MaxMetaspaceSize);
 598     return Flag::VIOLATES_CONSTRAINT;
 599   } else {
 600     return Flag::SUCCESS;
 601   }
 602 }
 603 
 604 Flag::Error MaxMetaspaceSizeConstraintFunc(size_t value, bool verbose) {
 605   if (value < MetaspaceSize) {
 606     CommandLineError::print(verbose,
 607                             "MaxMetaspaceSize (" SIZE_FORMAT ") must be "
 608                             "greater than or equal to MetaspaceSize (" SIZE_FORMAT ")\n",
 609                             value, MaxMetaspaceSize);
 610     return Flag::VIOLATES_CONSTRAINT;
 611   } else {
 612     return Flag::SUCCESS;
 613   }
 614 }
 615 
 616 Flag::Error SurvivorAlignmentInBytesConstraintFunc(intx value, bool verbose) {
 617   if (value != 0) {
 618     if (!is_power_of_2(value)) {
 619       CommandLineError::print(verbose,
 620                               "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be "
 621                               "power of 2\n",
 622                               value);
 623       return Flag::VIOLATES_CONSTRAINT;
 624     }
 625     if (value < ObjectAlignmentInBytes) {
 626       CommandLineError::print(verbose,
 627                               "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be "
 628                               "greater than or equal to ObjectAlignmentInBytes (" INTX_FORMAT ")\n",
 629                               value, ObjectAlignmentInBytes);
 630       return Flag::VIOLATES_CONSTRAINT;
 631     }
 632   }
 633   return Flag::SUCCESS;
 634 }