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