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