1 /*
   2  * Copyright (c) 2016, 2019, 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/codeCache.hpp"
  27 #include "runtime/globals.hpp"
  28 #include "runtime/globals_extension.hpp"
  29 #include "compiler/compilerDefinitions.hpp"
  30 #include "gc/shared/gcConfig.hpp"
  31 #include "utilities/defaultStream.hpp"
  32 
  33 const char* compilertype2name_tab[compiler_number_of_types] = {
  34   "",
  35   "c1",
  36   "c2",
  37   "jvmci"
  38 };
  39 
  40 #ifdef TIERED
  41 bool CompilationModeFlag::_quick_only = false;
  42 bool CompilationModeFlag::_high_only = false;
  43 bool CompilationModeFlag::_high_only_quick_internal = false;
  44 
  45 
  46 bool CompilationModeFlag::initialize() {
  47   if (CompilationMode != NULL) {
  48     if (strcmp(CompilationMode, "default") == 0) {
  49       // Do nothing, just support the "default" keyword.
  50     } else if (strcmp(CompilationMode, "quick-only") == 0) {
  51       _quick_only = true;
  52     } else if (strcmp(CompilationMode, "high-only") == 0) {
  53       _high_only = true;
  54     } else if (strcmp(CompilationMode, "high-only-quick-internal") == 0) {
  55       _high_only_quick_internal = true;
  56     } else {
  57       jio_fprintf(defaultStream::error_stream(), "Unsupported compilation mode '%s', supported modes are: quick-only, high-only, high-only-quick-internal\n", CompilationMode);
  58       return false;
  59     }
  60   }
  61   return true;
  62 }
  63 
  64 #endif
  65 
  66 #if defined(COMPILER2)
  67 CompLevel  CompLevel_highest_tier      = CompLevel_full_optimization;  // pure C2 and tiered or JVMCI and tiered
  68 #elif defined(COMPILER1)
  69 CompLevel  CompLevel_highest_tier      = CompLevel_simple;             // pure C1 or JVMCI
  70 #else
  71 CompLevel  CompLevel_highest_tier      = CompLevel_none;
  72 #endif
  73 
  74 #if defined(COMPILER2)
  75 CompMode  Compilation_mode             = CompMode_server;
  76 #elif defined(COMPILER1)
  77 CompMode  Compilation_mode             = CompMode_client;
  78 #else
  79 CompMode  Compilation_mode             = CompMode_none;
  80 #endif
  81 
  82 // Returns threshold scaled with CompileThresholdScaling
  83 intx CompilerConfig::scaled_compile_threshold(intx threshold) {
  84   return scaled_compile_threshold(threshold, CompileThresholdScaling);
  85 }
  86 
  87 // Returns freq_log scaled with CompileThresholdScaling
  88 intx CompilerConfig::scaled_freq_log(intx freq_log) {
  89   return scaled_freq_log(freq_log, CompileThresholdScaling);
  90 }
  91 
  92 // Returns threshold scaled with the value of scale.
  93 // If scale < 0.0, threshold is returned without scaling.
  94 intx CompilerConfig::scaled_compile_threshold(intx threshold, double scale) {
  95   if (scale == 1.0 || scale < 0.0) {
  96     return threshold;
  97   } else {
  98     return (intx)(threshold * scale);
  99   }
 100 }
 101 
 102 // Returns freq_log scaled with the value of scale.
 103 // Returned values are in the range of [0, InvocationCounter::number_of_count_bits + 1].
 104 // If scale < 0.0, freq_log is returned without scaling.
 105 intx CompilerConfig::scaled_freq_log(intx freq_log, double scale) {
 106   // Check if scaling is necessary or if negative value was specified.
 107   if (scale == 1.0 || scale < 0.0) {
 108     return freq_log;
 109   }
 110   // Check values to avoid calculating log2 of 0.
 111   if (scale == 0.0 || freq_log == 0) {
 112     return 0;
 113   }
 114   // Determine the maximum notification frequency value currently supported.
 115   // The largest mask value that the interpreter/C1 can handle is
 116   // of length InvocationCounter::number_of_count_bits. Mask values are always
 117   // one bit shorter then the value of the notification frequency. Set
 118   // max_freq_bits accordingly.
 119   intx max_freq_bits = InvocationCounter::number_of_count_bits + 1;
 120   intx scaled_freq = scaled_compile_threshold((intx)1 << freq_log, scale);
 121   if (scaled_freq == 0) {
 122     // Return 0 right away to avoid calculating log2 of 0.
 123     return 0;
 124   } else if (scaled_freq > nth_bit(max_freq_bits)) {
 125     return max_freq_bits;
 126   } else {
 127     return log2_intptr(scaled_freq);
 128   }
 129 }
 130 
 131 #ifdef TIERED
 132 void set_client_compilation_mode() {
 133   Compilation_mode = CompMode_client;
 134   CompLevel_highest_tier = CompLevel_simple;
 135   FLAG_SET_ERGO(TieredCompilation, false);
 136   FLAG_SET_ERGO(ProfileInterpreter, false);
 137 #if INCLUDE_JVMCI
 138   FLAG_SET_ERGO(EnableJVMCI, false);
 139   FLAG_SET_ERGO(UseJVMCICompiler, false);
 140 #endif
 141 #if INCLUDE_AOT
 142   FLAG_SET_ERGO(UseAOT, false);
 143 #endif
 144   if (FLAG_IS_DEFAULT(NeverActAsServerClassMachine)) {
 145     FLAG_SET_ERGO(NeverActAsServerClassMachine, true);
 146   }
 147   if (FLAG_IS_DEFAULT(InitialCodeCacheSize)) {
 148     FLAG_SET_ERGO(InitialCodeCacheSize, 160*K);
 149   }
 150   if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
 151     FLAG_SET_ERGO(ReservedCodeCacheSize, 32*M);
 152   }
 153   if (FLAG_IS_DEFAULT(NonProfiledCodeHeapSize)) {
 154     FLAG_SET_ERGO(NonProfiledCodeHeapSize, 27*M);
 155   }
 156   if (FLAG_IS_DEFAULT(ProfiledCodeHeapSize)) {
 157     FLAG_SET_ERGO(ProfiledCodeHeapSize, 0);
 158   }
 159   if (FLAG_IS_DEFAULT(NonNMethodCodeHeapSize)) {
 160     FLAG_SET_ERGO(NonNMethodCodeHeapSize, 5*M);
 161   }
 162   if (FLAG_IS_DEFAULT(CodeCacheExpansionSize)) {
 163     FLAG_SET_ERGO(CodeCacheExpansionSize, 32*K);
 164   }
 165   if (FLAG_IS_DEFAULT(MetaspaceSize)) {
 166     FLAG_SET_ERGO(MetaspaceSize, MIN2(12*M, MaxMetaspaceSize));
 167   }
 168   if (FLAG_IS_DEFAULT(MaxRAM)) {
 169     // Do not use FLAG_SET_ERGO to update MaxRAM, as this will impact
 170     // heap setting done based on available phys_mem (see Arguments::set_heap_size).
 171     FLAG_SET_DEFAULT(MaxRAM, 1ULL*G);
 172   }
 173   if (FLAG_IS_DEFAULT(CompileThreshold)) {
 174     FLAG_SET_ERGO(CompileThreshold, 1500);
 175   }
 176   if (FLAG_IS_DEFAULT(OnStackReplacePercentage)) {
 177     FLAG_SET_ERGO(OnStackReplacePercentage, 933);
 178   }
 179   if (FLAG_IS_DEFAULT(CICompilerCount)) {
 180     FLAG_SET_ERGO(CICompilerCount, 1);
 181   }
 182 }
 183 
 184 bool compilation_mode_selected() {
 185   return !FLAG_IS_DEFAULT(TieredCompilation) ||
 186          !FLAG_IS_DEFAULT(TieredStopAtLevel) ||
 187          !FLAG_IS_DEFAULT(UseAOT)
 188          JVMCI_ONLY(|| !FLAG_IS_DEFAULT(EnableJVMCI)
 189                     || !FLAG_IS_DEFAULT(UseJVMCICompiler));
 190 }
 191 
 192 void select_compilation_mode_ergonomically() {
 193 #if defined(_WINDOWS) && !defined(_LP64)
 194   if (FLAG_IS_DEFAULT(NeverActAsServerClassMachine)) {
 195     FLAG_SET_ERGO(NeverActAsServerClassMachine, true);
 196   }
 197 #endif
 198   if (NeverActAsServerClassMachine) {
 199     set_client_compilation_mode();
 200   }
 201 }
 202 
 203 
 204 void CompilerConfig::set_tiered_flags() {
 205   // Increase the code cache size - tiered compiles a lot more.
 206   if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
 207     FLAG_SET_ERGO(ReservedCodeCacheSize,
 208                   MIN2(CODE_CACHE_DEFAULT_LIMIT, (size_t)ReservedCodeCacheSize * 5));
 209   }
 210   // Enable SegmentedCodeCache if TieredCompilation is enabled, ReservedCodeCacheSize >= 240M
 211   // and the code cache contains at least 8 pages (segmentation disables advantage of huge pages).
 212   if (FLAG_IS_DEFAULT(SegmentedCodeCache) && ReservedCodeCacheSize >= 240*M &&
 213       8 * CodeCache::page_size() <= ReservedCodeCacheSize) {
 214     FLAG_SET_ERGO(SegmentedCodeCache, true);
 215   }
 216   if (!UseInterpreter) { // -Xcomp
 217     Tier3InvokeNotifyFreqLog = 0;
 218     Tier4InvocationThreshold = 0;
 219   }
 220 
 221   if (CompileThresholdScaling < 0) {
 222     vm_exit_during_initialization("Negative value specified for CompileThresholdScaling", NULL);
 223   }
 224 
 225   if (CompilationModeFlag::disable_intermediate()) {
 226     if (FLAG_IS_DEFAULT(Tier0ProfilingStartPercentage)) {
 227       FLAG_SET_DEFAULT(Tier0ProfilingStartPercentage, 33);
 228     }
 229   }
 230 
 231   // Scale tiered compilation thresholds.
 232   // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves compilation thresholds unchanged.
 233   if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) {
 234     FLAG_SET_ERGO(Tier0InvokeNotifyFreqLog, scaled_freq_log(Tier0InvokeNotifyFreqLog));
 235     FLAG_SET_ERGO(Tier0BackedgeNotifyFreqLog, scaled_freq_log(Tier0BackedgeNotifyFreqLog));
 236 
 237     FLAG_SET_ERGO(Tier3InvocationThreshold, scaled_compile_threshold(Tier3InvocationThreshold));
 238     FLAG_SET_ERGO(Tier3MinInvocationThreshold, scaled_compile_threshold(Tier3MinInvocationThreshold));
 239     FLAG_SET_ERGO(Tier3CompileThreshold, scaled_compile_threshold(Tier3CompileThreshold));
 240     FLAG_SET_ERGO(Tier3BackEdgeThreshold, scaled_compile_threshold(Tier3BackEdgeThreshold));
 241 
 242     // Tier2{Invocation,MinInvocation,Compile,Backedge}Threshold should be scaled here
 243     // once these thresholds become supported.
 244 
 245     FLAG_SET_ERGO(Tier2InvokeNotifyFreqLog, scaled_freq_log(Tier2InvokeNotifyFreqLog));
 246     FLAG_SET_ERGO(Tier2BackedgeNotifyFreqLog, scaled_freq_log(Tier2BackedgeNotifyFreqLog));
 247 
 248     FLAG_SET_ERGO(Tier3InvokeNotifyFreqLog, scaled_freq_log(Tier3InvokeNotifyFreqLog));
 249     FLAG_SET_ERGO(Tier3BackedgeNotifyFreqLog, scaled_freq_log(Tier3BackedgeNotifyFreqLog));
 250 
 251     FLAG_SET_ERGO(Tier23InlineeNotifyFreqLog, scaled_freq_log(Tier23InlineeNotifyFreqLog));
 252 
 253     FLAG_SET_ERGO(Tier4InvocationThreshold, scaled_compile_threshold(Tier4InvocationThreshold));
 254     FLAG_SET_ERGO(Tier4MinInvocationThreshold, scaled_compile_threshold(Tier4MinInvocationThreshold));
 255     FLAG_SET_ERGO(Tier4CompileThreshold, scaled_compile_threshold(Tier4CompileThreshold));
 256     FLAG_SET_ERGO(Tier4BackEdgeThreshold, scaled_compile_threshold(Tier4BackEdgeThreshold));
 257 
 258     if (CompilationModeFlag::disable_intermediate()) {
 259       FLAG_SET_ERGO(Tier40InvocationThreshold, scaled_compile_threshold(Tier40InvocationThreshold));
 260       FLAG_SET_ERGO(Tier40MinInvocationThreshold, scaled_compile_threshold(Tier40MinInvocationThreshold));
 261       FLAG_SET_ERGO(Tier40CompileThreshold, scaled_compile_threshold(Tier40CompileThreshold));
 262       FLAG_SET_ERGO(Tier40BackEdgeThreshold, scaled_compile_threshold(Tier40BackEdgeThreshold));
 263     }
 264 
 265 #if INCLUDE_AOT
 266     if (UseAOT) {
 267       FLAG_SET_ERGO(Tier3AOTInvocationThreshold, scaled_compile_threshold(Tier3AOTInvocationThreshold));
 268       FLAG_SET_ERGO(Tier3AOTMinInvocationThreshold, scaled_compile_threshold(Tier3AOTMinInvocationThreshold));
 269       FLAG_SET_ERGO(Tier3AOTCompileThreshold, scaled_compile_threshold(Tier3AOTCompileThreshold));
 270       FLAG_SET_ERGO(Tier3AOTBackEdgeThreshold, scaled_compile_threshold(Tier3AOTBackEdgeThreshold));
 271 
 272       if (CompilationModeFlag::disable_intermediate()) {
 273         FLAG_SET_ERGO(Tier0AOTInvocationThreshold, scaled_compile_threshold(Tier0AOTInvocationThreshold));
 274         FLAG_SET_ERGO(Tier0AOTMinInvocationThreshold, scaled_compile_threshold(Tier0AOTMinInvocationThreshold));
 275         FLAG_SET_ERGO(Tier0AOTCompileThreshold, scaled_compile_threshold(Tier0AOTCompileThreshold));
 276         FLAG_SET_ERGO(Tier0AOTBackEdgeThreshold, scaled_compile_threshold(Tier0AOTBackEdgeThreshold));
 277       }
 278     }
 279 #endif // INCLUDE_AOT
 280   }
 281 }
 282 
 283 #endif // TIERED
 284 
 285 #if INCLUDE_JVMCI
 286 void set_jvmci_specific_flags() {
 287   if (UseJVMCICompiler) {
 288     Compilation_mode = CompMode_server;
 289 
 290     if (FLAG_IS_DEFAULT(TypeProfileWidth)) {
 291       FLAG_SET_DEFAULT(TypeProfileWidth, 8);
 292     }
 293     if (FLAG_IS_DEFAULT(TypeProfileLevel)) {
 294       FLAG_SET_DEFAULT(TypeProfileLevel, 0);
 295     }
 296 
 297     if (UseJVMCINativeLibrary) {
 298       // SVM compiled code requires more stack space
 299       if (FLAG_IS_DEFAULT(CompilerThreadStackSize)) {
 300         // Duplicate logic in the implementations of os::create_thread
 301         // so that we can then double the computed stack size. Once
 302         // the stack size requirements of SVM are better understood,
 303         // this logic can be pushed down into os::create_thread.
 304         int stack_size = CompilerThreadStackSize;
 305         if (stack_size == 0) {
 306           stack_size = VMThreadStackSize;
 307         }
 308         if (stack_size != 0) {
 309           FLAG_SET_DEFAULT(CompilerThreadStackSize, stack_size * 2);
 310         }
 311       }
 312     } else {
 313 #ifdef TIERED
 314       if (!TieredCompilation) {
 315          warning("Disabling tiered compilation with non-native JVMCI compiler is not recommended. "
 316                  "Turning on tiered compilation and disabling intermediate compilation levels instead. ");
 317          FLAG_SET_ERGO(TieredCompilation, true);
 318          if (CompilationModeFlag::normal()) {
 319            CompilationModeFlag::set_high_only_quick_internal(true);
 320          }
 321          if (CICompilerCount < 2 && CompilationModeFlag::quick_internal()) {
 322             warning("Increasing number of compiler threads for JVMCI compiler.");
 323             FLAG_SET_ERGO(CICompilerCount, 2);
 324          }
 325       }
 326 #else // TIERED
 327       // Adjust the on stack replacement percentage to avoid early
 328       // OSR compilations while JVMCI itself is warming up
 329       if (FLAG_IS_DEFAULT(OnStackReplacePercentage)) {
 330         FLAG_SET_DEFAULT(OnStackReplacePercentage, 933);
 331       }
 332 #endif // !TIERED
 333       // JVMCI needs values not less than defaults
 334       if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
 335         FLAG_SET_DEFAULT(ReservedCodeCacheSize, MAX2(64*M, ReservedCodeCacheSize));
 336       }
 337       if (FLAG_IS_DEFAULT(InitialCodeCacheSize)) {
 338         FLAG_SET_DEFAULT(InitialCodeCacheSize, MAX2(16*M, InitialCodeCacheSize));
 339       }
 340       if (FLAG_IS_DEFAULT(MetaspaceSize)) {
 341         FLAG_SET_DEFAULT(MetaspaceSize, MIN2(MAX2(12*M, MetaspaceSize), MaxMetaspaceSize));
 342       }
 343       if (FLAG_IS_DEFAULT(NewSizeThreadIncrease)) {
 344         FLAG_SET_DEFAULT(NewSizeThreadIncrease, MAX2(4*K, NewSizeThreadIncrease));
 345       }
 346     } // !UseJVMCINativeLibrary
 347   } // UseJVMCICompiler
 348 }
 349 #endif // INCLUDE_JVMCI
 350 
 351 bool CompilerConfig::check_args_consistency(bool status) {
 352   // Check lower bounds of the code cache
 353   // Template Interpreter code is approximately 3X larger in debug builds.
 354   uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3);
 355   if (ReservedCodeCacheSize < InitialCodeCacheSize) {
 356     jio_fprintf(defaultStream::error_stream(),
 357                 "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n",
 358                 ReservedCodeCacheSize/K, InitialCodeCacheSize/K);
 359     status = false;
 360   } else if (ReservedCodeCacheSize < min_code_cache_size) {
 361     jio_fprintf(defaultStream::error_stream(),
 362                 "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K,
 363                 min_code_cache_size/K);
 364     status = false;
 365   } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) {
 366     // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported.
 367     jio_fprintf(defaultStream::error_stream(),
 368                 "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M,
 369                 CODE_CACHE_SIZE_LIMIT/M);
 370     status = false;
 371   } else if (NonNMethodCodeHeapSize < min_code_cache_size) {
 372     jio_fprintf(defaultStream::error_stream(),
 373                 "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K,
 374                 min_code_cache_size/K);
 375     status = false;
 376   }
 377 
 378 #ifdef _LP64
 379   if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) {
 380     warning("The VM option CICompilerCountPerCPU overrides CICompilerCount.");
 381   }
 382 #endif
 383 
 384   if (BackgroundCompilation && ReplayCompiles) {
 385     if (!FLAG_IS_DEFAULT(BackgroundCompilation)) {
 386       warning("BackgroundCompilation disabled due to ReplayCompiles option.");
 387     }
 388     FLAG_SET_CMDLINE(BackgroundCompilation, false);
 389   }
 390 
 391 #ifdef COMPILER2
 392   if (PostLoopMultiversioning && !RangeCheckElimination) {
 393     if (!FLAG_IS_DEFAULT(PostLoopMultiversioning)) {
 394       warning("PostLoopMultiversioning disabled because RangeCheckElimination is disabled.");
 395     }
 396     FLAG_SET_CMDLINE(PostLoopMultiversioning, false);
 397   }
 398   if (UseCountedLoopSafepoints && LoopStripMiningIter == 0) {
 399     if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {
 400       warning("When counted loop safepoints are enabled, LoopStripMiningIter must be at least 1 (a safepoint every 1 iteration): setting it to 1");
 401     }
 402     LoopStripMiningIter = 1;
 403   } else if (!UseCountedLoopSafepoints && LoopStripMiningIter > 0) {
 404     if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {
 405       warning("Disabling counted safepoints implies no loop strip mining: setting LoopStripMiningIter to 0");
 406     }
 407     LoopStripMiningIter = 0;
 408   }
 409 #endif // COMPILER2
 410 
 411   if (Arguments::is_interpreter_only()) {
 412     if (UseCompiler) {
 413       if (!FLAG_IS_DEFAULT(UseCompiler)) {
 414         warning("UseCompiler disabled due to -Xint.");
 415       }
 416       FLAG_SET_CMDLINE(UseCompiler, false);
 417     }
 418     if (ProfileInterpreter) {
 419       if (!FLAG_IS_DEFAULT(ProfileInterpreter)) {
 420         warning("ProfileInterpreter disabled due to -Xint.");
 421       }
 422       FLAG_SET_CMDLINE(ProfileInterpreter, false);
 423     }
 424     if (TieredCompilation) {
 425       if (!FLAG_IS_DEFAULT(TieredCompilation)) {
 426         warning("TieredCompilation disabled due to -Xint.");
 427       }
 428       FLAG_SET_CMDLINE(TieredCompilation, false);
 429     }
 430 #if INCLUDE_JVMCI
 431     if (EnableJVMCI) {
 432       if (!FLAG_IS_DEFAULT(EnableJVMCI) || !FLAG_IS_DEFAULT(UseJVMCICompiler)) {
 433         warning("JVMCI Compiler disabled due to -Xint.");
 434       }
 435       FLAG_SET_CMDLINE(EnableJVMCI, false);
 436       FLAG_SET_CMDLINE(UseJVMCICompiler, false);
 437     }
 438 #endif
 439   } else {
 440 #if INCLUDE_JVMCI
 441     status = status && JVMCIGlobals::check_jvmci_flags_are_consistent();
 442 #endif
 443   }
 444   return status;
 445 }
 446 
 447 void CompilerConfig::ergo_initialize() {
 448   if (Arguments::is_interpreter_only()) {
 449     return; // Nothing to do.
 450   }
 451 
 452 #ifdef TIERED
 453   if (!compilation_mode_selected()) {
 454     select_compilation_mode_ergonomically();
 455   }
 456 #endif
 457 
 458 #if INCLUDE_JVMCI
 459   // Check that JVMCI compiler supports selested GC.
 460   // Should be done after GCConfig::initialize() was called.
 461   JVMCIGlobals::check_jvmci_supported_gc();
 462 
 463   // Do JVMCI specific settings
 464   set_jvmci_specific_flags();
 465 #endif
 466 
 467 #ifdef TIERED
 468   if (TieredCompilation) {
 469     set_tiered_flags();
 470   } else
 471 #endif
 472   {
 473     // Scale CompileThreshold
 474     // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves CompileThreshold unchanged.
 475     if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) {
 476       FLAG_SET_ERGO(CompileThreshold, scaled_compile_threshold(CompileThreshold));
 477     }
 478   }
 479 
 480   if (UseOnStackReplacement && !UseLoopCounter) {
 481     warning("On-stack-replacement requires loop counters; enabling loop counters");
 482     FLAG_SET_DEFAULT(UseLoopCounter, true);
 483   }
 484 
 485 #ifdef COMPILER2
 486   if (!EliminateLocks) {
 487     EliminateNestedLocks = false;
 488   }
 489   if (!Inline) {
 490     IncrementalInline = false;
 491   }
 492 #ifndef PRODUCT
 493   if (!IncrementalInline) {
 494     AlwaysIncrementalInline = false;
 495   }
 496   if (PrintIdealGraphLevel > 0) {
 497     FLAG_SET_ERGO(PrintIdealGraph, true);
 498   }
 499 #endif
 500   if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) {
 501     // nothing to use the profiling, turn if off
 502     FLAG_SET_DEFAULT(TypeProfileLevel, 0);
 503   }
 504   if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
 505     FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
 506   }
 507   if (FLAG_IS_DEFAULT(LoopStripMiningIterShortLoop)) {
 508     // blind guess
 509     LoopStripMiningIterShortLoop = LoopStripMiningIter / 10;
 510   }
 511 #endif // COMPILER2
 512 }