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 AllocatePrefetchDistanceConstraintFunc(intx value, bool verbose) { 93 if (value < 0 || value > 512) { 94 CommandLineError::print(verbose, 95 "AllocatePrefetchDistance (" INTX_FORMAT ") must be " 96 "between 0 and " INTX_FORMAT "\n", 97 AllocatePrefetchDistance, 512); 98 return Flag::VIOLATES_CONSTRAINT; 99 } 100 101 return Flag::SUCCESS; 102 } 103 104 Flag::Error AllocatePrefetchStepSizeConstraintFunc(intx value, bool verbose) { 105 if (AllocatePrefetchStyle == 3) { 106 if (value % wordSize != 0) { 107 CommandLineError::print(verbose, 108 "AllocatePrefetchStepSize (" INTX_FORMAT ") must be multiple of %d\n", 109 value, wordSize); 110 return Flag::VIOLATES_CONSTRAINT; 111 } 112 } 113 return Flag::SUCCESS; 114 } 115 116 Flag::Error AllocatePrefetchInstrConstraintFunc(intx value, bool verbose) { 117 intx max_value = max_intx; 118 #if defined(SPARC) 119 max_value = 1; 120 #elif defined(X86) 121 max_value = 3; 122 #endif 123 if (value < 0 || value > max_value) { 124 CommandLineError::print(verbose, 125 "AllocatePrefetchInstr (" INTX_FORMAT ") must be " 126 "between 0 and " INTX_FORMAT "\n", value, max_value); 127 return Flag::VIOLATES_CONSTRAINT; 128 } 129 130 return Flag::SUCCESS; 131 } 132 133 Flag::Error CompileThresholdConstraintFunc(intx value, bool verbose) { 134 if (value < 0 || value > INT_MAX >> InvocationCounter::count_shift) { 135 CommandLineError::print(verbose, 136 "CompileThreshold (" INTX_FORMAT ") " 137 "must be between 0 and %d\n", 138 value, 139 INT_MAX >> InvocationCounter::count_shift); 140 return Flag::VIOLATES_CONSTRAINT; 141 } 142 143 return Flag::SUCCESS; 144 } 145 146 Flag::Error OnStackReplacePercentageConstraintFunc(intx value, bool verbose) { 147 int backward_branch_limit; 148 if (ProfileInterpreter) { 149 if (OnStackReplacePercentage < InterpreterProfilePercentage) { 150 CommandLineError::print(verbose, 151 "OnStackReplacePercentage (" INTX_FORMAT ") must be " 152 "larger than InterpreterProfilePercentage (" INTX_FORMAT ")\n", 153 OnStackReplacePercentage, InterpreterProfilePercentage); 154 return Flag::VIOLATES_CONSTRAINT; 155 } 156 157 backward_branch_limit = ((CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100) 158 << InvocationCounter::count_shift; 159 160 if (backward_branch_limit < 0) { 161 CommandLineError::print(verbose, 162 "CompileThreshold * (InterpreterProfilePercentage - OnStackReplacePercentage) / 100 = " 163 INTX_FORMAT " " 164 "must be between 0 and " INTX_FORMAT ", try changing " 165 "CompileThreshold, InterpreterProfilePercentage, and/or OnStackReplacePercentage\n", 166 (CompileThreshold * (OnStackReplacePercentage - InterpreterProfilePercentage)) / 100, 167 INT_MAX >> InvocationCounter::count_shift); 168 return Flag::VIOLATES_CONSTRAINT; 169 } 170 } else { 171 if (OnStackReplacePercentage < 0 ) { 172 CommandLineError::print(verbose, 173 "OnStackReplacePercentage (" INTX_FORMAT ") must be " 174 "non-negative\n", OnStackReplacePercentage); 175 return Flag::VIOLATES_CONSTRAINT; 176 } 177 178 backward_branch_limit = ((CompileThreshold * OnStackReplacePercentage) / 100) 179 << InvocationCounter::count_shift; 180 181 if (backward_branch_limit < 0) { 182 CommandLineError::print(verbose, 183 "CompileThreshold * OnStackReplacePercentage / 100 = " INTX_FORMAT " " 184 "must be between 0 and " INTX_FORMAT ", try changing " 185 "CompileThreshold and/or OnStackReplacePercentage\n", 186 (CompileThreshold * OnStackReplacePercentage) / 100, 187 INT_MAX >> InvocationCounter::count_shift); 188 return Flag::VIOLATES_CONSTRAINT; 189 } 190 } 191 return Flag::SUCCESS; 192 } 193 194 Flag::Error CodeCacheSegmentSizeConstraintFunc(uintx value, bool verbose) { 195 if (CodeCacheSegmentSize < (uintx)CodeEntryAlignment) { 196 CommandLineError::print(verbose, 197 "CodeCacheSegmentSize (" UINTX_FORMAT ") must be " 198 "larger than or equal to CodeEntryAlignment (" INTX_FORMAT ") " 199 "to align entry points\n", 200 CodeCacheSegmentSize, CodeEntryAlignment); 201 return Flag::VIOLATES_CONSTRAINT; 202 } 203 204 if (CodeCacheSegmentSize < sizeof(jdouble)) { 205 CommandLineError::print(verbose, 206 "CodeCacheSegmentSize (" UINTX_FORMAT ") must be " 207 "at least " SIZE_FORMAT " to align constants\n", 208 CodeCacheSegmentSize, sizeof(jdouble)); 209 return Flag::VIOLATES_CONSTRAINT; 210 } 211 212 #ifdef COMPILER2 213 if (CodeCacheSegmentSize < (uintx)OptoLoopAlignment) { 214 CommandLineError::print(verbose, 215 "CodeCacheSegmentSize (" UINTX_FORMAT ") must be " 216 "larger than or equal to OptoLoopAlignment (" INTX_FORMAT ") " 217 "to align inner loops\n", 218 CodeCacheSegmentSize, OptoLoopAlignment); 219 return Flag::VIOLATES_CONSTRAINT; 220 } 221 #endif 222 223 return Flag::SUCCESS; 224 } 225 226 Flag::Error CompilerThreadPriorityConstraintFunc(intx value, bool verbose) { 227 #ifdef SOLARIS 228 if ((value < MinimumPriority || value > MaximumPriority) && 229 (value != -1) && (value != -FXCriticalPriority)) { 230 CommandLineError::print(verbose, 231 "CompileThreadPriority (" INTX_FORMAT ") must be " 232 "between %d and %d inclusively or -1 (means no change) " 233 "or %d (special value for critical thread class/priority)\n", 234 value, MinimumPriority, MaximumPriority, -FXCriticalPriority); 235 return Flag::VIOLATES_CONSTRAINT; 236 } 237 #endif 238 239 return Flag::SUCCESS; 240 } 241 242 Flag::Error CodeEntryAlignmentConstraintFunc(intx value, bool verbose) { 243 #ifdef SPARC 244 if (CodeEntryAlignment % relocInfo::addr_unit() != 0) { 245 CommandLineError::print(verbose, 246 "CodeEntryAlignment (" INTX_FORMAT ") must be " 247 "multiple of NOP size\n", CodeEntryAlignment); 248 return Flag::VIOLATES_CONSTRAINT; 249 } 250 #endif 251 252 if (!is_power_of_2(value)) { 253 CommandLineError::print(verbose, 254 "CodeEntryAlignment (" INTX_FORMAT ") must be " 255 "a power of two\n", CodeEntryAlignment); 256 return Flag::VIOLATES_CONSTRAINT; 257 } 258 259 if (CodeEntryAlignment < 16) { 260 CommandLineError::print(verbose, 261 "CodeEntryAlignment (" INTX_FORMAT ") must be " 262 "greater than or equal to %d\n", 263 CodeEntryAlignment, 16); 264 return Flag::VIOLATES_CONSTRAINT; 265 } 266 267 return Flag::SUCCESS; 268 } 269 270 Flag::Error OptoLoopAlignmentConstraintFunc(intx value, bool verbose) { 271 if (!is_power_of_2(value)) { 272 CommandLineError::print(verbose, 273 "OptoLoopAlignment (" INTX_FORMAT ") " 274 "must be a power of two\n", 275 value); 276 return Flag::VIOLATES_CONSTRAINT; 277 } 278 279 #ifdef SPARC 280 if (OptoLoopAlignment % relocInfo::addr_unit() != 0) { 281 CommandLineError::print(verbose, 282 "OptoLoopAlignment (" INTX_FORMAT ") must be " 283 "multiple of NOP size\n"); 284 return Flag::VIOLATES_CONSTRAINT; 285 } 286 #endif 287 288 return Flag::SUCCESS; 289 } 290 291 Flag::Error ArraycopyDstPrefetchDistanceConstraintFunc(uintx value, bool verbose) { 292 if (value != 0) { 293 CommandLineError::print(verbose, 294 "ArraycopyDstPrefetchDistance (" UINTX_FORMAT ") must be 0\n", 295 value); 296 return Flag::VIOLATES_CONSTRAINT; 297 } 298 299 return Flag::SUCCESS; 300 } 301 302 Flag::Error ArraycopySrcPrefetchDistanceConstraintFunc(uintx value, bool verbose) { 303 if (value != 0) { 304 CommandLineError::print(verbose, 305 "ArraycopySrcPrefetchDistance (" UINTX_FORMAT ") must be 0\n", 306 value); 307 return Flag::VIOLATES_CONSTRAINT; 308 } 309 310 return Flag::SUCCESS; 311 } 312 313 Flag::Error TypeProfileLevelConstraintFunc(uintx value, bool verbose) { 314 for (int i = 0; i < 3; i++) { 315 if (value % 10 > 2) { 316 CommandLineError::print(verbose, 317 "Invalid value (" UINTX_FORMAT ") " 318 "in TypeProfileLevel at position %d\n", value, i); 319 return Flag::VIOLATES_CONSTRAINT; 320 } 321 value = value / 10; 322 } 323 324 return Flag::SUCCESS; 325 } 326 327 Flag::Error InitArrayShortSizeConstraintFunc(intx value, bool verbose) { 328 if (value % BytesPerLong != 0) { 329 return Flag::VIOLATES_CONSTRAINT; 330 } else { 331 return Flag::SUCCESS; 332 } 333 } 334 335 #ifdef COMPILER2 336 Flag::Error InteriorEntryAlignmentConstraintFunc(intx value, bool verbose) { 337 if (InteriorEntryAlignment > CodeEntryAlignment) { 338 CommandLineError::print(verbose, 339 "InteriorEntryAlignment (" INTX_FORMAT ") must be " 340 "less than or equal to CodeEntryAlignment (" INTX_FORMAT ")\n", 341 InteriorEntryAlignment, CodeEntryAlignment); 342 return Flag::VIOLATES_CONSTRAINT; 343 } 344 345 #ifdef SPARC 346 if (InteriorEntryAlignment % relocInfo::addr_unit() != 0) { 347 CommandLineError::print(verbose, 348 "InteriorEntryAlignment (" INTX_FORMAT ") must be " 349 "multiple of NOP size\n"); 350 return Flag::VIOLATES_CONSTRAINT; 351 } 352 #endif 353 354 if (!is_power_of_2(value)) { 355 CommandLineError::print(verbose, 356 "InteriorEntryAlignment (" INTX_FORMAT ") must be " 357 "a power of two\n", InteriorEntryAlignment); 358 return Flag::VIOLATES_CONSTRAINT; 359 } 360 361 int minimum_alignment = 16; 362 #if defined(SPARC) || (defined(X86) && !defined(AMD64)) 363 minimum_alignment = 4; 364 #endif 365 366 if (InteriorEntryAlignment < minimum_alignment) { 367 CommandLineError::print(verbose, 368 "InteriorEntryAlignment (" INTX_FORMAT ") must be " 369 "greater than or equal to %d\n", 370 InteriorEntryAlignment, minimum_alignment); 371 return Flag::VIOLATES_CONSTRAINT; 372 } 373 374 return Flag::SUCCESS; 375 } 376 377 Flag::Error NodeLimitFudgeFactorConstraintFunc(intx value, bool verbose) { 378 if (value < MaxNodeLimit * 2 / 100 || value > MaxNodeLimit * 40 / 100) { 379 CommandLineError::print(verbose, 380 "NodeLimitFudgeFactor must be between 2%% and 40%% " 381 "of MaxNodeLimit (" INTX_FORMAT ")\n", 382 MaxNodeLimit); 383 return Flag::VIOLATES_CONSTRAINT; 384 } 385 386 return Flag::SUCCESS; 387 } 388 #endif // COMPILER2