1 /* 2 * Copyright (c) 2015, 2017, 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 "code/relocInfo.hpp" 27 #include "compiler/compilerDefinitions.hpp" 28 #include "oops/metadata.hpp" 29 #include "runtime/os.hpp" 30 #include "interpreter/invocationCounter.hpp" 31 #include "runtime/arguments.hpp" 32 #include "runtime/commandLineFlagConstraintsCompiler.hpp" 33 #include "runtime/commandLineFlagRangeList.hpp" 34 #include "runtime/globals.hpp" 35 #include "runtime/globals_extension.hpp" 36 #include "utilities/defaultStream.hpp" 37 38 Flag::Error AliasLevelConstraintFunc(intx value, bool verbose) { 39 if ((value <= 1) && (Arguments::mode() == Arguments::_comp || Arguments::mode() == Arguments::_mixed)) { 40 CommandLineError::print(verbose, 41 "AliasLevel (" INTX_FORMAT ") is not " 42 "compatible with -Xcomp or -Xmixed\n", 43 value); 44 return Flag::VIOLATES_CONSTRAINT; 45 } else { 46 return Flag::SUCCESS; 47 } 48 } 49 50 /** 51 * Validate the minimum number of compiler threads needed to run the 52 * JVM. The following configurations are possible. 53 * 54 * 1) The JVM is build using an interpreter only. As a result, the minimum number of 55 * compiler threads is 0. 56 * 2) The JVM is build using the compiler(s) and tiered compilation is disabled. As 57 * a result, either C1 or C2 is used, so the minimum number of compiler threads is 1. 58 * 3) The JVM is build using the compiler(s) and tiered compilation is enabled. However, 59 * the option "TieredStopAtLevel < CompLevel_full_optimization". As a result, only 60 * C1 can be used, so the minimum number of compiler threads is 1. 61 * 4) The JVM is build using the compilers and tiered compilation is enabled. The option 62 * 'TieredStopAtLevel = CompLevel_full_optimization' (the default value). As a result, 63 * the minimum number of compiler threads is 2. 64 */ 65 Flag::Error CICompilerCountConstraintFunc(intx value, bool verbose) { 66 int min_number_of_compiler_threads = 0; 67 #if !defined(COMPILER1) && !defined(COMPILER2) && !defined(SHARK) && !INCLUDE_JVMCI 68 // case 1 69 #else 70 if (!TieredCompilation || (TieredStopAtLevel < CompLevel_full_optimization)) { 71 min_number_of_compiler_threads = 1; // case 2 or case 3 72 } else { 73 min_number_of_compiler_threads = 2; // case 4 (tiered) 74 } 75 #endif 76 77 // The default CICompilerCount's value is CI_COMPILER_COUNT. 78 // With a client VM, -XX:+TieredCompilation causes TieredCompilation 79 // to be true here (the option is validated later) and 80 // min_number_of_compiler_threads to exceed CI_COMPILER_COUNT. 81 min_number_of_compiler_threads = MIN2(min_number_of_compiler_threads, CI_COMPILER_COUNT); 82 83 if (value < (intx)min_number_of_compiler_threads) { 84 CommandLineError::print(verbose, 85 "CICompilerCount (" INTX_FORMAT ") must be " 86 "at least %d \n", 87 value, min_number_of_compiler_threads); 88 return Flag::VIOLATES_CONSTRAINT; 89 } else { 90 return Flag::SUCCESS; 91 } 92 } 93 94 Flag::Error AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose) { 95 if (value < 0 || value > 512) { 96 CommandLineError::print(verbose, 97 "AllocatePrefetchDistance (" INTX_FORMAT ") must be " 98 "between 0 and " INTX_FORMAT "\n", 99 AllocatePrefetchDistance, 512); 100 return Flag::VIOLATES_CONSTRAINT; 101 } 102 103 return Flag::SUCCESS; 104 } 105 106 Flag::Error AllocatePrefetchStepSizeConstraintFunc(intx value, bool verbose) { 107 if (AllocatePrefetchStyle == 3) { 108 if (value % wordSize != 0) { 109 CommandLineError::print(verbose, 110 "AllocatePrefetchStepSize (" INTX_FORMAT ") must be multiple of %d\n", 111 value, wordSize); 112 return Flag::VIOLATES_CONSTRAINT; 113 } 114 } 115 return Flag::SUCCESS; 116 } 117 118 Flag::Error AllocatePrefetchInstrConstraintFunc(intx value, bool verbose) { 119 intx max_value = max_intx; 120 #if defined(SPARC) 121 max_value = 1; 122 #elif defined(X86) 123 max_value = 3; 124 #endif 125 if (value < 0 || value > max_value) { 126 CommandLineError::print(verbose, 127 "AllocatePrefetchInstr (" INTX_FORMAT ") must be " 128 "between 0 and " INTX_FORMAT "\n", value, max_value); 129 return Flag::VIOLATES_CONSTRAINT; 130 } 131 132 return Flag::SUCCESS; 133 } 134 135 Flag::Error CompileThresholdConstraintFunc(intx value, bool verbose) { 136 if (value < 0 || value > INT_MAX >> InvocationCounter::count_shift) { 137 CommandLineError::print(verbose, 138 "CompileThreshold (" INTX_FORMAT ") " 139 "must be between 0 and %d\n", 140 value, 141 INT_MAX >> InvocationCounter::count_shift); 142 return Flag::VIOLATES_CONSTRAINT; 143 } 144 145 return Flag::SUCCESS; 146 } 147 148 Flag::Error OnStackReplacePercentageConstraintFunc(intx value, bool verbose) { 149 int backward_branch_limit; 150 if (ProfileInterpreter) { 151 if (OnStackReplacePercentage < InterpreterProfilePercentage) { 152 CommandLineError::print(verbose, 153 "OnStackReplacePercentage (" INTX_FORMAT ") must be " 154 "larger than InterpreterProfilePercentage (" INTX_FORMAT ")\n", 155 OnStackReplacePercentage, InterpreterProfilePercentage); 156 return Flag::VIOLATES_CONSTRAINT; 157 } 158 159 backward_branch_limit = ((CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100) 160 << InvocationCounter::count_shift; 161 162 if (backward_branch_limit < 0) { 163 CommandLineError::print(verbose, 164 "CompileThreshold * (InterpreterProfilePercentage - OnStackReplacePercentage) / 100 = " 165 INTX_FORMAT " " 166 "must be between 0 and " INTX_FORMAT ", try changing " 167 "CompileThreshold, InterpreterProfilePercentage, and/or OnStackReplacePercentage\n", 168 (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100, 169 INT_MAX >> InvocationCounter::count_shift); 170 return Flag::VIOLATES_CONSTRAINT; 171 } 172 } else { 173 if (OnStackReplacePercentage < 0 ) { 174 CommandLineError::print(verbose, 175 "OnStackReplacePercentage (" INTX_FORMAT ") must be " 176 "non-negative\n", OnStackReplacePercentage); 177 return Flag::VIOLATES_CONSTRAINT; 178 } 179 180 backward_branch_limit = ((CompileThreshold * OnStackReplacePercentage) / 100) 181 << InvocationCounter::count_shift; 182 183 if (backward_branch_limit < 0) { 184 CommandLineError::print(verbose, 185 "CompileThreshold * OnStackReplacePercentage / 100 = " INTX_FORMAT " " 186 "must be between 0 and " INTX_FORMAT ", try changing " 187 "CompileThreshold and/or OnStackReplacePercentage\n", 188 (CompileThreshold * OnStackReplacePercentage) / 100, 189 INT_MAX >> InvocationCounter::count_shift); 190 return Flag::VIOLATES_CONSTRAINT; 191 } 192 } 193 return Flag::SUCCESS; 194 } 195 196 Flag::Error CodeCacheSegmentSizeConstraintFunc(uintx value, bool verbose) { 197 if (CodeCacheSegmentSize < (uintx)CodeEntryAlignment) { 198 CommandLineError::print(verbose, 199 "CodeCacheSegmentSize (" UINTX_FORMAT ") must be " 200 "larger than or equal to CodeEntryAlignment (" INTX_FORMAT ") " 201 "to align entry points\n", 202 CodeCacheSegmentSize, CodeEntryAlignment); 203 return Flag::VIOLATES_CONSTRAINT; 204 } 205 206 if (CodeCacheSegmentSize < sizeof(jdouble)) { 207 CommandLineError::print(verbose, 208 "CodeCacheSegmentSize (" UINTX_FORMAT ") must be " 209 "at least " SIZE_FORMAT " to align constants\n", 210 CodeCacheSegmentSize, sizeof(jdouble)); 211 return Flag::VIOLATES_CONSTRAINT; 212 } 213 214 #ifdef COMPILER2 215 if (CodeCacheSegmentSize < (uintx)OptoLoopAlignment) { 216 CommandLineError::print(verbose, 217 "CodeCacheSegmentSize (" UINTX_FORMAT ") must be " 218 "larger than or equal to OptoLoopAlignment (" INTX_FORMAT ") " 219 "to align inner loops\n", 220 CodeCacheSegmentSize, OptoLoopAlignment); 221 return Flag::VIOLATES_CONSTRAINT; 222 } 223 #endif 224 225 return Flag::SUCCESS; 226 } 227 228 Flag::Error CompilerThreadPriorityConstraintFunc(intx value, bool verbose) { 229 #ifdef SOLARIS 230 if ((value < MinimumPriority || value > MaximumPriority) && 231 (value != -1) && (value != -FXCriticalPriority)) { 232 CommandLineError::print(verbose, 233 "CompileThreadPriority (" INTX_FORMAT ") must be " 234 "between %d and %d inclusively or -1 (means no change) " 235 "or %d (special value for critical thread class/priority)\n", 236 value, MinimumPriority, MaximumPriority, -FXCriticalPriority); 237 return Flag::VIOLATES_CONSTRAINT; 238 } 239 #endif 240 241 return Flag::SUCCESS; 242 } 243 244 Flag::Error CodeEntryAlignmentConstraintFunc(intx value, bool verbose) { 245 #ifdef SPARC 246 if (CodeEntryAlignment % relocInfo::addr_unit() != 0) { 247 CommandLineError::print(verbose, 248 "CodeEntryAlignment (" INTX_FORMAT ") must be " 249 "multiple of NOP size\n", CodeEntryAlignment); 250 return Flag::VIOLATES_CONSTRAINT; 251 } 252 #endif 253 254 if (!is_power_of_2(value)) { 255 CommandLineError::print(verbose, 256 "CodeEntryAlignment (" INTX_FORMAT ") must be " 257 "a power of two\n", CodeEntryAlignment); 258 return Flag::VIOLATES_CONSTRAINT; 259 } 260 261 if (CodeEntryAlignment < 16) { 262 CommandLineError::print(verbose, 263 "CodeEntryAlignment (" INTX_FORMAT ") must be " 264 "greater than or equal to %d\n", 265 CodeEntryAlignment, 16); 266 return Flag::VIOLATES_CONSTRAINT; 267 } 268 269 return Flag::SUCCESS; 270 } 271 272 Flag::Error OptoLoopAlignmentConstraintFunc(intx value, bool verbose) { 273 if (!is_power_of_2(value)) { 274 CommandLineError::print(verbose, 275 "OptoLoopAlignment (" INTX_FORMAT ") " 276 "must be a power of two\n", 277 value); 278 return Flag::VIOLATES_CONSTRAINT; 279 } 280 281 // Relevant on ppc, s390, sparc. Will be optimized where 282 // addr_unit() == 1. 283 if (OptoLoopAlignment % relocInfo::addr_unit() != 0) { 284 CommandLineError::print(verbose, 285 "OptoLoopAlignment (" INTX_FORMAT ") must be " 286 "multiple of NOP size (%d)\n", 287 value, relocInfo::addr_unit()); 288 return Flag::VIOLATES_CONSTRAINT; 289 } 290 291 return Flag::SUCCESS; 292 } 293 294 Flag::Error ArraycopyDstPrefetchDistanceConstraintFunc(uintx value, bool verbose) { 295 if (value >= 4032) { 296 CommandLineError::print(verbose, 297 "ArraycopyDstPrefetchDistance (" UINTX_FORMAT ") must be" 298 "between 0 and 4031\n", value); 299 return Flag::VIOLATES_CONSTRAINT; 300 } 301 302 return Flag::SUCCESS; 303 } 304 305 Flag::Error ArraycopySrcPrefetchDistanceConstraintFunc(uintx value, bool verbose) { 306 if (value >= 4032) { 307 CommandLineError::print(verbose, 308 "ArraycopySrcPrefetchDistance (" UINTX_FORMAT ") must be" 309 "between 0 and 4031\n", value); 310 return Flag::VIOLATES_CONSTRAINT; 311 } 312 313 return Flag::SUCCESS; 314 } 315 316 Flag::Error TypeProfileLevelConstraintFunc(uintx value, bool verbose) { 317 for (int i = 0; i < 3; i++) { 318 if (value % 10 > 2) { 319 CommandLineError::print(verbose, 320 "Invalid value (" UINTX_FORMAT ") " 321 "in TypeProfileLevel at position %d\n", value, i); 322 return Flag::VIOLATES_CONSTRAINT; 323 } 324 value = value / 10; 325 } 326 327 return Flag::SUCCESS; 328 } 329 330 Flag::Error InitArrayShortSizeConstraintFunc(intx value, bool verbose) { 331 if (value % BytesPerLong != 0) { 332 return Flag::VIOLATES_CONSTRAINT; 333 } else { 334 return Flag::SUCCESS; 335 } 336 } 337 338 #ifdef COMPILER2 339 Flag::Error InteriorEntryAlignmentConstraintFunc(intx value, bool verbose) { 340 if (InteriorEntryAlignment > CodeEntryAlignment) { 341 CommandLineError::print(verbose, 342 "InteriorEntryAlignment (" INTX_FORMAT ") must be " 343 "less than or equal to CodeEntryAlignment (" INTX_FORMAT ")\n", 344 InteriorEntryAlignment, CodeEntryAlignment); 345 return Flag::VIOLATES_CONSTRAINT; 346 } 347 348 #ifdef SPARC 349 if (InteriorEntryAlignment % relocInfo::addr_unit() != 0) { 350 CommandLineError::print(verbose, 351 "InteriorEntryAlignment (" INTX_FORMAT ") must be " 352 "multiple of NOP size\n"); 353 return Flag::VIOLATES_CONSTRAINT; 354 } 355 #endif 356 357 if (!is_power_of_2(value)) { 358 CommandLineError::print(verbose, 359 "InteriorEntryAlignment (" INTX_FORMAT ") must be " 360 "a power of two\n", InteriorEntryAlignment); 361 return Flag::VIOLATES_CONSTRAINT; 362 } 363 364 int minimum_alignment = 16; 365 #if defined(SPARC) || (defined(X86) && !defined(AMD64)) 366 minimum_alignment = 4; 367 #elif defined(S390) 368 minimum_alignment = 2; 369 #endif 370 371 if (InteriorEntryAlignment < minimum_alignment) { 372 CommandLineError::print(verbose, 373 "InteriorEntryAlignment (" INTX_FORMAT ") must be " 374 "greater than or equal to %d\n", 375 InteriorEntryAlignment, minimum_alignment); 376 return Flag::VIOLATES_CONSTRAINT; 377 } 378 379 return Flag::SUCCESS; 380 } 381 382 Flag::Error NodeLimitFudgeFactorConstraintFunc(intx value, bool verbose) { 383 if (value < MaxNodeLimit * 2 / 100 || value > MaxNodeLimit * 40 / 100) { 384 CommandLineError::print(verbose, 385 "NodeLimitFudgeFactor must be between 2%% and 40%% " 386 "of MaxNodeLimit (" INTX_FORMAT ")\n", 387 MaxNodeLimit); 388 return Flag::VIOLATES_CONSTRAINT; 389 } 390 391 return Flag::SUCCESS; 392 } 393 #endif // COMPILER2 394 395 Flag::Error RTMTotalCountIncrRateConstraintFunc(int value, bool verbose) { 396 #if INCLUDE_RTM_OPT 397 if (UseRTMLocking && !is_power_of_2(RTMTotalCountIncrRate)) { 398 CommandLineError::print(verbose, 399 "RTMTotalCountIncrRate (" INTX_FORMAT 400 ") must be a power of 2, resetting it to 64\n", 401 RTMTotalCountIncrRate); 402 FLAG_SET_DEFAULT(RTMTotalCountIncrRate, 64); 403 } 404 #endif 405 406 return Flag::SUCCESS; 407 }