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