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 "runtime/arguments.hpp"
  27 #include "runtime/commandLineFlagConstraintsGC.hpp"
  28 #include "runtime/globals.hpp"
  29 #include "runtime/java.hpp"
  30 #include "runtime/os.hpp"
  31 #include "utilities/defaultStream.hpp"
  32 
  33 #if INCLUDE_ALL_GCS
  34 #include "gc/g1/g1_globals.hpp"
  35 #endif // INCLUDE_ALL_GCS
  36 #ifdef COMPILER1
  37 #include "c1/c1_globals.hpp"
  38 #endif // COMPILER1
  39 #ifdef COMPILER2
  40 #include "opto/c2_globals.hpp"
  41 #endif // COMPILER2
  42 
  43 Flag::Error MinHeapFreeRatioConstraintFunc(bool verbose, uintx* value) {
  44   if ((CommandLineFlags::finishedInitializing() == true) && (*value > MaxHeapFreeRatio)) {
  45     if (verbose == true) {
  46       jio_fprintf(defaultStream::error_stream(),
  47                   "MinHeapFreeRatio (" UINTX_FORMAT ") must be less than or "
  48                   "equal to MaxHeapFreeRatio (" UINTX_FORMAT ")\n",
  49                   *value, MaxHeapFreeRatio);
  50     }
  51     return Flag::VIOLATES_CONSTRAINT;
  52   } else {
  53     return Flag::SUCCESS;
  54   }
  55 }
  56 
  57 Flag::Error MaxHeapFreeRatioConstraintFunc(bool verbose, uintx* value) {
  58   if ((CommandLineFlags::finishedInitializing() == true) && (*value < MinHeapFreeRatio)) {
  59     if (verbose == true) {
  60       jio_fprintf(defaultStream::error_stream(),
  61                   "MaxHeapFreeRatio (" UINTX_FORMAT ") must be greater than or "
  62                   "equal to MinHeapFreeRatio (" UINTX_FORMAT ")\n",
  63                   *value, MinHeapFreeRatio);
  64     }
  65     return Flag::VIOLATES_CONSTRAINT;
  66   } else {
  67     return Flag::SUCCESS;
  68   }
  69 }
  70 
  71 Flag::Error MinMetaspaceFreeRatioConstraintFunc(bool verbose, uintx* value) {
  72   if ((CommandLineFlags::finishedInitializing() == true) && (*value > MaxMetaspaceFreeRatio)) {
  73     if (verbose == true) {
  74       jio_fprintf(defaultStream::error_stream(),
  75                   "MinMetaspaceFreeRatio (" UINTX_FORMAT ") must be less than or "
  76                   "equal to MaxMetaspaceFreeRatio (" UINTX_FORMAT ")\n",
  77                   *value, MaxMetaspaceFreeRatio);
  78     }
  79     return Flag::VIOLATES_CONSTRAINT;
  80   } else {
  81     return Flag::SUCCESS;
  82   }
  83 }
  84 
  85 Flag::Error MaxMetaspaceFreeRatioConstraintFunc(bool verbose, uintx* value) {
  86   if ((CommandLineFlags::finishedInitializing() == true) && (*value < MinMetaspaceFreeRatio)) {
  87     if (verbose == true) {
  88       jio_fprintf(defaultStream::error_stream(),
  89                   "MaxMetaspaceFreeRatio (" UINTX_FORMAT ") must be greater than or "
  90                   "equal to MinMetaspaceFreeRatio (" UINTX_FORMAT ")\n",
  91                   *value, MinMetaspaceFreeRatio);
  92     }
  93     return Flag::VIOLATES_CONSTRAINT;
  94   } else {
  95     return Flag::SUCCESS;
  96   }
  97 }
  98 
  99 // GC workaround for "-XX:+UseConcMarkSweepGC"
 100 // which sets InitialTenuringThreshold to 7 but leaves MaxTenuringThreshold remaining at 6
 101 // and therefore would invalidate the constraint
 102 #define UseConcMarkSweepGCWorkaroundIfNeeded(initial, max) { \
 103   if ((initial == 7) && (max == 6)) { \
 104     return Flag::SUCCESS; \
 105   } \
 106 }
 107 
 108 Flag::Error InitialTenuringThresholdConstraintFunc(bool verbose, uintx* value) {
 109   UseConcMarkSweepGCWorkaroundIfNeeded(*value, MaxTenuringThreshold);
 110 
 111   if ((CommandLineFlags::finishedInitializing() == true) && (*value > MaxTenuringThreshold)) {
 112     if (verbose == true) {
 113       jio_fprintf(defaultStream::error_stream(),
 114                   "InitialTenuringThreshold (" UINTX_FORMAT ") must be less than or "
 115                   "equal to MaxTenuringThreshold (" UINTX_FORMAT ")\n",
 116                   *value, MaxTenuringThreshold);
 117     }
 118     return Flag::VIOLATES_CONSTRAINT;
 119   } else {
 120     return Flag::SUCCESS;
 121   }
 122 }
 123 
 124 Flag::Error MaxTenuringThresholdConstraintFunc(bool verbose, uintx* value) {
 125   UseConcMarkSweepGCWorkaroundIfNeeded(InitialTenuringThreshold, *value);
 126 
 127   if ((CommandLineFlags::finishedInitializing() == true) && (*value < InitialTenuringThreshold)) {
 128     if (verbose == true) {
 129       jio_fprintf(defaultStream::error_stream(),
 130                   "MaxTenuringThreshold (" UINTX_FORMAT ") must be greater than or "
 131                   "equal to InitialTenuringThreshold (" UINTX_FORMAT ")\n",
 132                   *value, InitialTenuringThreshold);
 133     }
 134     return Flag::VIOLATES_CONSTRAINT;
 135   } else {
 136     return Flag::SUCCESS;
 137   }
 138 }
 139 
 140 #if INCLUDE_ALL_GCS
 141 
 142 Flag::Error G1NewSizePercentConstraintFunc(bool verbose, uintx* value) {
 143   if ((CommandLineFlags::finishedInitializing() == true) && (*value > G1MaxNewSizePercent)) {
 144     if (verbose == true) {
 145       jio_fprintf(defaultStream::error_stream(),
 146                   "G1NewSizePercent (" UINTX_FORMAT ") must be less than or "
 147                   "equal to G1MaxNewSizePercent (" UINTX_FORMAT ")\n",
 148                   *value, G1MaxNewSizePercent);
 149     }
 150     return Flag::VIOLATES_CONSTRAINT;
 151   } else {
 152     return Flag::SUCCESS;
 153   }
 154 }
 155 
 156 Flag::Error G1MaxNewSizePercentConstraintFunc(bool verbose, uintx* value) {
 157   if ((CommandLineFlags::finishedInitializing() == true) && (*value < G1NewSizePercent)) {
 158     if (verbose == true) {
 159       jio_fprintf(defaultStream::error_stream(),
 160                   "G1MaxNewSizePercent (" UINTX_FORMAT ") must be greater than or "
 161                   "equal to G1NewSizePercent (" UINTX_FORMAT ")\n",
 162                   *value, G1NewSizePercent);
 163     }
 164     return Flag::VIOLATES_CONSTRAINT;
 165   } else {
 166     return Flag::SUCCESS;
 167   }
 168 }
 169 
 170 #endif // INCLUDE_ALL_GCS
 171 
 172 Flag::Error CMSOldPLABMinConstraintFunc(bool verbose, size_t* value) {
 173   if ((CommandLineFlags::finishedInitializing() == true) && (*value > CMSOldPLABMax)) {
 174     if (verbose == true) {
 175       jio_fprintf(defaultStream::error_stream(),
 176                   "CMSOldPLABMin (" SIZE_FORMAT ") must be less than or "
 177                   "equal to CMSOldPLABMax (" SIZE_FORMAT ")\n",
 178                   *value, CMSOldPLABMax);
 179     }
 180     return Flag::VIOLATES_CONSTRAINT;
 181   } else {
 182     return Flag::SUCCESS;
 183   }
 184 }
 185 
 186 Flag::Error CMSOldPLABMaxConstraintFunc(bool verbose, size_t* value) {
 187   if ((CommandLineFlags::finishedInitializing() == true) && (*value < CMSOldPLABMax)) {
 188     if (verbose == true) {
 189       jio_fprintf(defaultStream::error_stream(),
 190                   "CMSOldPLABMax (" SIZE_FORMAT ") must be greater than or "
 191                   "equal to CMSOldPLABMax (" SIZE_FORMAT ")\n",
 192                   *value, CMSOldPLABMax);
 193     }
 194     return Flag::VIOLATES_CONSTRAINT;
 195   } else {
 196     return Flag::SUCCESS;
 197   }
 198 }
 199 
 200 Flag::Error CMSPrecleanDenominatorConstraintFunc(bool verbose, uintx* value) {
 201   if ((CommandLineFlags::finishedInitializing() == true) && (*value <= CMSPrecleanNumerator)) {
 202     if (verbose == true) {
 203       jio_fprintf(defaultStream::error_stream(),
 204                   "CMSPrecleanDenominator (" UINTX_FORMAT ") must be strickly greater than "
 205                   "CMSPrecleanNumerator (" UINTX_FORMAT ")\n",
 206                   *value, CMSPrecleanNumerator);
 207     }
 208     return Flag::VIOLATES_CONSTRAINT;
 209   } else {
 210     return Flag::SUCCESS;
 211   }
 212 }
 213 
 214 Flag::Error CMSPrecleanNumeratorConstraintFunc(bool verbose, uintx* value) {
 215   if ((CommandLineFlags::finishedInitializing() == true) && (*value > (CMSPrecleanDenominator - 1))) {
 216     if (verbose == true) {
 217       jio_fprintf(defaultStream::error_stream(),
 218                   "CMSPrecleanNumerator (" UINTX_FORMAT ") must be less than or "
 219                   "equal to CMSPrecleanDenominator - 1 (" UINTX_FORMAT ")\n", *value,
 220                   CMSPrecleanDenominator - 1);
 221     }
 222     return Flag::VIOLATES_CONSTRAINT;
 223   } else {
 224     return Flag::SUCCESS;
 225   }
 226 }
 227 
 228 Flag::Error SurvivorAlignmentInBytesConstraintFunc(bool verbose, intx* value) {
 229   if (CommandLineFlags::finishedInitializing() == true) {
 230     if (*value != 0) {
 231       if (!is_power_of_2(*value)) {
 232         if (verbose == true) {
 233           jio_fprintf(defaultStream::error_stream(),
 234                     "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be power of 2\n",
 235                     *value);
 236         }
 237         return Flag::VIOLATES_CONSTRAINT;
 238       }
 239       if (*value < ObjectAlignmentInBytes) {
 240         if (verbose == true) {
 241           jio_fprintf(defaultStream::error_stream(),
 242                     "SurvivorAlignmentInBytes (" INTX_FORMAT ") must be greater than or "
 243                     "equal to ObjectAlignmentInBytes (" INTX_FORMAT ") \n",
 244                     *value, ObjectAlignmentInBytes);
 245         }
 246         return Flag::VIOLATES_CONSTRAINT;
 247       }
 248     }
 249   }
 250   return Flag::SUCCESS;
 251 }