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