8184349: There should be some verification that EnableJVMCI is disabled if a GC not supporting JVMCI is selected
authorkvn
Fri, 15 Jun 2018 09:16:48 -0700
changeset 50589 e5d741569070
parent 50588 1ab701eb7de4
child 50590 5fa19bad622d
8184349: There should be some verification that EnableJVMCI is disabled if a GC not supporting JVMCI is selected Summary: exit VM with Error when JVMCI does not support seected GC. Reviewed-by: iveresov, thartmann
src/hotspot/share/c1/c1_LIRGenerator.cpp
src/hotspot/share/compiler/compilerDefinitions.cpp
src/hotspot/share/compiler/compilerDefinitions.hpp
src/hotspot/share/gc/z/zArguments.cpp
src/hotspot/share/jvmci/jvmci_globals.cpp
src/hotspot/share/jvmci/jvmci_globals.hpp
src/hotspot/share/oops/methodCounters.hpp
src/hotspot/share/oops/methodData.cpp
src/hotspot/share/runtime/arguments.cpp
src/hotspot/share/runtime/arguments.hpp
test/hotspot/jtreg/compiler/arguments/CheckCompileThresholdScaling.java
test/hotspot/jtreg/gc/stress/gcbasher/TestGCBasherWithZ.java
test/hotspot/jtreg/gc/stress/gcold/TestGCOldWithZ.java
test/hotspot/jtreg/serviceability/sa/TestUniverse.java
test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/TestDriver.java
--- a/src/hotspot/share/c1/c1_LIRGenerator.cpp	Fri Jun 15 08:28:08 2018 -0700
+++ b/src/hotspot/share/c1/c1_LIRGenerator.cpp	Fri Jun 15 09:16:48 2018 -0700
@@ -3245,7 +3245,7 @@
     int freq_log = Tier23InlineeNotifyFreqLog;
     double scale;
     if (_method->has_option_value("CompileThresholdScaling", scale)) {
-      freq_log = Arguments::scaled_freq_log(freq_log, scale);
+      freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);
     }
     increment_event_counter_impl(info, x->inlinee(), LIR_OprFact::intConst(InvocationCounter::count_increment), right_n_bits(freq_log), InvocationEntryBci, false, true);
   }
@@ -3279,7 +3279,7 @@
   // Increment the appropriate invocation/backedge counter and notify the runtime.
   double scale;
   if (_method->has_option_value("CompileThresholdScaling", scale)) {
-    freq_log = Arguments::scaled_freq_log(freq_log, scale);
+    freq_log = CompilerConfig::scaled_freq_log(freq_log, scale);
   }
   increment_event_counter_impl(info, info->scope()->method(), step, right_n_bits(freq_log), bci, backedge, true);
 }
--- a/src/hotspot/share/compiler/compilerDefinitions.cpp	Fri Jun 15 08:28:08 2018 -0700
+++ b/src/hotspot/share/compiler/compilerDefinitions.cpp	Fri Jun 15 09:16:48 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,8 @@
 #include "runtime/globals.hpp"
 #include "runtime/globals_extension.hpp"
 #include "compiler/compilerDefinitions.hpp"
+#include "gc/shared/gcConfig.hpp"
+#include "utilities/defaultStream.hpp"
 
 const char* compilertype2name_tab[compiler_number_of_types] = {
   "",
@@ -60,6 +62,55 @@
 CompMode  Compilation_mode             = CompMode_none;
 #endif
 
+// Returns threshold scaled with CompileThresholdScaling
+intx CompilerConfig::scaled_compile_threshold(intx threshold) {
+  return scaled_compile_threshold(threshold, CompileThresholdScaling);
+}
+
+// Returns freq_log scaled with CompileThresholdScaling
+intx CompilerConfig::scaled_freq_log(intx freq_log) {
+  return scaled_freq_log(freq_log, CompileThresholdScaling);
+}
+
+// Returns threshold scaled with the value of scale.
+// If scale < 0.0, threshold is returned without scaling.
+intx CompilerConfig::scaled_compile_threshold(intx threshold, double scale) {
+  if (scale == 1.0 || scale < 0.0) {
+    return threshold;
+  } else {
+    return (intx)(threshold * scale);
+  }
+}
+
+// Returns freq_log scaled with the value of scale.
+// Returned values are in the range of [0, InvocationCounter::number_of_count_bits + 1].
+// If scale < 0.0, freq_log is returned without scaling.
+intx CompilerConfig::scaled_freq_log(intx freq_log, double scale) {
+  // Check if scaling is necessary or if negative value was specified.
+  if (scale == 1.0 || scale < 0.0) {
+    return freq_log;
+  }
+  // Check values to avoid calculating log2 of 0.
+  if (scale == 0.0 || freq_log == 0) {
+    return 0;
+  }
+  // Determine the maximum notification frequency value currently supported.
+  // The largest mask value that the interpreter/C1 can handle is
+  // of length InvocationCounter::number_of_count_bits. Mask values are always
+  // one bit shorter then the value of the notification frequency. Set
+  // max_freq_bits accordingly.
+  intx max_freq_bits = InvocationCounter::number_of_count_bits + 1;
+  intx scaled_freq = scaled_compile_threshold((intx)1 << freq_log, scale);
+  if (scaled_freq == 0) {
+    // Return 0 right away to avoid calculating log2 of 0.
+    return 0;
+  } else if (scaled_freq > nth_bit(max_freq_bits)) {
+    return max_freq_bits;
+  } else {
+    return log2_intptr(scaled_freq);
+  }
+}
+
 #ifdef TIERED
 void set_client_compilation_mode() {
   Compilation_mode = CompMode_client;
@@ -113,4 +164,284 @@
     FLAG_SET_ERGO(intx, CICompilerCount, 1);
   }
 }
+
+bool compilation_mode_selected() {
+  return !FLAG_IS_DEFAULT(TieredCompilation) ||
+         !FLAG_IS_DEFAULT(TieredStopAtLevel) ||
+         !FLAG_IS_DEFAULT(UseAOT)
+         JVMCI_ONLY(|| !FLAG_IS_DEFAULT(EnableJVMCI)
+                    || !FLAG_IS_DEFAULT(UseJVMCICompiler));
+}
+
+void select_compilation_mode_ergonomically() {
+#if defined(_WINDOWS) && !defined(_LP64)
+  if (FLAG_IS_DEFAULT(NeverActAsServerClassMachine)) {
+    FLAG_SET_ERGO(bool, NeverActAsServerClassMachine, true);
+  }
+#endif
+  if (NeverActAsServerClassMachine) {
+    set_client_compilation_mode();
+  }
+}
+
 #endif // TIERED
+
+void CompilerConfig::set_tiered_flags() {
+  // With tiered, set default policy to SimpleThresholdPolicy, which is 2.
+  if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) {
+    FLAG_SET_DEFAULT(CompilationPolicyChoice, 2);
+  }
+  if (CompilationPolicyChoice < 2) {
+    vm_exit_during_initialization(
+      "Incompatible compilation policy selected", NULL);
+  }
+  // Increase the code cache size - tiered compiles a lot more.
+  if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
+    FLAG_SET_ERGO(uintx, ReservedCodeCacheSize,
+                  MIN2(CODE_CACHE_DEFAULT_LIMIT, ReservedCodeCacheSize * 5));
+  }
+  // Enable SegmentedCodeCache if TieredCompilation is enabled and ReservedCodeCacheSize >= 240M
+  if (FLAG_IS_DEFAULT(SegmentedCodeCache) && ReservedCodeCacheSize >= 240*M) {
+    FLAG_SET_ERGO(bool, SegmentedCodeCache, true);
+  }
+  if (!UseInterpreter) { // -Xcomp
+    Tier3InvokeNotifyFreqLog = 0;
+    Tier4InvocationThreshold = 0;
+  }
+
+  if (CompileThresholdScaling < 0) {
+    vm_exit_during_initialization("Negative value specified for CompileThresholdScaling", NULL);
+  }
+
+  // Scale tiered compilation thresholds.
+  // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves compilation thresholds unchanged.
+  if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) {
+    FLAG_SET_ERGO(intx, Tier0InvokeNotifyFreqLog, scaled_freq_log(Tier0InvokeNotifyFreqLog));
+    FLAG_SET_ERGO(intx, Tier0BackedgeNotifyFreqLog, scaled_freq_log(Tier0BackedgeNotifyFreqLog));
+
+    FLAG_SET_ERGO(intx, Tier3InvocationThreshold, scaled_compile_threshold(Tier3InvocationThreshold));
+    FLAG_SET_ERGO(intx, Tier3MinInvocationThreshold, scaled_compile_threshold(Tier3MinInvocationThreshold));
+    FLAG_SET_ERGO(intx, Tier3CompileThreshold, scaled_compile_threshold(Tier3CompileThreshold));
+    FLAG_SET_ERGO(intx, Tier3BackEdgeThreshold, scaled_compile_threshold(Tier3BackEdgeThreshold));
+
+    // Tier2{Invocation,MinInvocation,Compile,Backedge}Threshold should be scaled here
+    // once these thresholds become supported.
+
+    FLAG_SET_ERGO(intx, Tier2InvokeNotifyFreqLog, scaled_freq_log(Tier2InvokeNotifyFreqLog));
+    FLAG_SET_ERGO(intx, Tier2BackedgeNotifyFreqLog, scaled_freq_log(Tier2BackedgeNotifyFreqLog));
+
+    FLAG_SET_ERGO(intx, Tier3InvokeNotifyFreqLog, scaled_freq_log(Tier3InvokeNotifyFreqLog));
+    FLAG_SET_ERGO(intx, Tier3BackedgeNotifyFreqLog, scaled_freq_log(Tier3BackedgeNotifyFreqLog));
+
+    FLAG_SET_ERGO(intx, Tier23InlineeNotifyFreqLog, scaled_freq_log(Tier23InlineeNotifyFreqLog));
+
+    FLAG_SET_ERGO(intx, Tier4InvocationThreshold, scaled_compile_threshold(Tier4InvocationThreshold));
+    FLAG_SET_ERGO(intx, Tier4MinInvocationThreshold, scaled_compile_threshold(Tier4MinInvocationThreshold));
+    FLAG_SET_ERGO(intx, Tier4CompileThreshold, scaled_compile_threshold(Tier4CompileThreshold));
+    FLAG_SET_ERGO(intx, Tier4BackEdgeThreshold, scaled_compile_threshold(Tier4BackEdgeThreshold));
+  }
+}
+
+#if INCLUDE_JVMCI
+void set_jvmci_specific_flags() {
+  if (UseJVMCICompiler) {
+    Compilation_mode = CompMode_server;
+
+    if (FLAG_IS_DEFAULT(TypeProfileWidth)) {
+      FLAG_SET_DEFAULT(TypeProfileWidth, 8);
+    }
+    if (FLAG_IS_DEFAULT(OnStackReplacePercentage)) {
+      FLAG_SET_DEFAULT(OnStackReplacePercentage, 933);
+    }
+    if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
+      FLAG_SET_DEFAULT(ReservedCodeCacheSize, 64*M);
+    }
+    if (FLAG_IS_DEFAULT(InitialCodeCacheSize)) {
+      FLAG_SET_DEFAULT(InitialCodeCacheSize, 16*M);
+    }
+    if (FLAG_IS_DEFAULT(MetaspaceSize)) {
+      FLAG_SET_DEFAULT(MetaspaceSize, 12*M);
+    }
+    if (FLAG_IS_DEFAULT(NewSizeThreadIncrease)) {
+      FLAG_SET_DEFAULT(NewSizeThreadIncrease, 4*K);
+    }
+    if (TieredStopAtLevel != CompLevel_full_optimization) {
+      // Currently JVMCI compiler can only work at the full optimization level
+      warning("forcing TieredStopAtLevel to full optimization because JVMCI is enabled");
+      FLAG_SET_ERGO(intx, TieredStopAtLevel, CompLevel_full_optimization);
+    }
+    if (FLAG_IS_DEFAULT(TypeProfileLevel)) {
+      FLAG_SET_DEFAULT(TypeProfileLevel, 0);
+    }
+  }
+}
+#endif // INCLUDE_JVMCI
+
+bool CompilerConfig::check_args_consistency(bool status) {
+  // Check lower bounds of the code cache
+  // Template Interpreter code is approximately 3X larger in debug builds.
+  uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3);
+  if (ReservedCodeCacheSize < InitialCodeCacheSize) {
+    jio_fprintf(defaultStream::error_stream(),
+                "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n",
+                ReservedCodeCacheSize/K, InitialCodeCacheSize/K);
+    status = false;
+  } else if (ReservedCodeCacheSize < min_code_cache_size) {
+    jio_fprintf(defaultStream::error_stream(),
+                "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K,
+                min_code_cache_size/K);
+    status = false;
+  } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) {
+    // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported.
+    jio_fprintf(defaultStream::error_stream(),
+                "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M,
+                CODE_CACHE_SIZE_LIMIT/M);
+    status = false;
+  } else if (NonNMethodCodeHeapSize < min_code_cache_size) {
+    jio_fprintf(defaultStream::error_stream(),
+                "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K,
+                min_code_cache_size/K);
+    status = false;
+  }
+
+#ifdef _LP64
+  if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) {
+    warning("The VM option CICompilerCountPerCPU overrides CICompilerCount.");
+  }
+#endif
+
+  if (BackgroundCompilation && (CompileTheWorld || ReplayCompiles)) {
+    if (!FLAG_IS_DEFAULT(BackgroundCompilation)) {
+      warning("BackgroundCompilation disabled due to CompileTheWorld or ReplayCompiles options.");
+    }
+    FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
+  }
+
+#ifdef COMPILER2
+  if (PostLoopMultiversioning && !RangeCheckElimination) {
+    if (!FLAG_IS_DEFAULT(PostLoopMultiversioning)) {
+      warning("PostLoopMultiversioning disabled because RangeCheckElimination is disabled.");
+    }
+    FLAG_SET_CMDLINE(bool, PostLoopMultiversioning, false);
+  }
+  if (UseCountedLoopSafepoints && LoopStripMiningIter == 0) {
+    if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {
+      warning("When counted loop safepoints are enabled, LoopStripMiningIter must be at least 1 (a safepoint every 1 iteration): setting it to 1");
+    }
+    LoopStripMiningIter = 1;
+  } else if (!UseCountedLoopSafepoints && LoopStripMiningIter > 0) {
+    if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {
+      warning("Disabling counted safepoints implies no loop strip mining: setting LoopStripMiningIter to 0");
+    }
+    LoopStripMiningIter = 0;
+  }
+#endif // COMPILER2
+
+  if (Arguments::is_interpreter_only()) {
+    if (UseCompiler) {
+      if (!FLAG_IS_DEFAULT(UseCompiler)) {
+        warning("UseCompiler disabled due to -Xint.");
+      }
+      FLAG_SET_CMDLINE(bool, UseCompiler, false);
+    }
+    if (ProfileInterpreter) {
+      if (!FLAG_IS_DEFAULT(ProfileInterpreter)) {
+        warning("ProfileInterpreter disabled due to -Xint.");
+      }
+      FLAG_SET_CMDLINE(bool, ProfileInterpreter, false);
+    }
+    if (TieredCompilation) {
+      if (!FLAG_IS_DEFAULT(TieredCompilation)) {
+        warning("TieredCompilation disabled due to -Xint.");
+      }
+      FLAG_SET_CMDLINE(bool, TieredCompilation, false);
+    }
+#if INCLUDE_JVMCI
+    if (EnableJVMCI) {
+      if (!FLAG_IS_DEFAULT(EnableJVMCI) || !FLAG_IS_DEFAULT(UseJVMCICompiler)) {
+        warning("JVMCI Compiler disabled due to -Xint.");
+      }
+      FLAG_SET_CMDLINE(bool, EnableJVMCI, false);
+      FLAG_SET_CMDLINE(bool, UseJVMCICompiler, false);
+    }
+#endif
+  } else {
+#if INCLUDE_JVMCI
+    status = status && JVMCIGlobals::check_jvmci_flags_are_consistent();
+#endif
+  }
+  return status;
+}
+
+void CompilerConfig::ergo_initialize() {
+  if (Arguments::is_interpreter_only()) {
+    return; // Nothing to do.
+  }
+
+#ifdef TIERED
+  if (!compilation_mode_selected()) {
+    select_compilation_mode_ergonomically();
+  }
+#endif
+
+#if INCLUDE_JVMCI
+  // Check that JVMCI compiler supports selested GC.
+  // Should be done after GCConfig::initialize() was called.
+  JVMCIGlobals::check_jvmci_supported_gc();
+  set_jvmci_specific_flags();
+#endif
+
+  if (TieredCompilation) {
+    set_tiered_flags();
+  } else {
+    int max_compilation_policy_choice = 1;
+#ifdef COMPILER2
+    if (is_server_compilation_mode_vm()) {
+      max_compilation_policy_choice = 2;
+    }
+#endif
+    // Check if the policy is valid.
+    if (CompilationPolicyChoice >= max_compilation_policy_choice) {
+      vm_exit_during_initialization(
+        "Incompatible compilation policy selected", NULL);
+    }
+    // Scale CompileThreshold
+    // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves CompileThreshold unchanged.
+    if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) {
+      FLAG_SET_ERGO(intx, CompileThreshold, scaled_compile_threshold(CompileThreshold));
+    }
+  }
+
+  if (UseOnStackReplacement && !UseLoopCounter) {
+    warning("On-stack-replacement requires loop counters; enabling loop counters");
+    FLAG_SET_DEFAULT(UseLoopCounter, true);
+  }
+
+#ifdef COMPILER2
+  if (!EliminateLocks) {
+    EliminateNestedLocks = false;
+  }
+  if (!Inline) {
+    IncrementalInline = false;
+  }
+#ifndef PRODUCT
+  if (!IncrementalInline) {
+    AlwaysIncrementalInline = false;
+  }
+  if (PrintIdealGraphLevel > 0) {
+    FLAG_SET_ERGO(bool, PrintIdealGraph, true);
+  }
+#endif
+  if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) {
+    // nothing to use the profiling, turn if off
+    FLAG_SET_DEFAULT(TypeProfileLevel, 0);
+  }
+  if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
+    FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
+  }
+  if (FLAG_IS_DEFAULT(LoopStripMiningIterShortLoop)) {
+    // blind guess
+    LoopStripMiningIterShortLoop = LoopStripMiningIter / 10;
+  }
+#endif // COMPILER2
+}
--- a/src/hotspot/share/compiler/compilerDefinitions.hpp	Fri Jun 15 08:28:08 2018 -0700
+++ b/src/hotspot/share/compiler/compilerDefinitions.hpp	Fri Jun 15 09:16:48 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
 #ifndef SHARE_VM_COMPILER_COMPILERDEFINITIONS_HPP
 #define SHARE_VM_COMPILER_COMPILERDEFINITIONS_HPP
 
-#include "utilities/globalDefinitions.hpp"
+#include "memory/allocation.hpp"
 
 // The (closed set) of concrete compiler classes.
 enum CompilerType {
@@ -75,8 +75,6 @@
   return Compilation_mode == CompMode_client;
 }
 
-extern void set_client_compilation_mode();
-
 inline bool is_c1_compile(int comp_level) {
   return comp_level > CompLevel_none && comp_level < CompLevel_full_optimization;
 }
@@ -109,4 +107,23 @@
 #define RTM_OPT_ONLY(code)
 #endif
 
+class CompilerConfig : public AllStatic {
+public:
+  // Scale compile thresholds
+  // Returns threshold scaled with CompileThresholdScaling
+  static intx scaled_compile_threshold(intx threshold, double scale);
+  static intx scaled_compile_threshold(intx threshold);
+
+  // Returns freq_log scaled with CompileThresholdScaling
+  static intx scaled_freq_log(intx freq_log, double scale);
+  static intx scaled_freq_log(intx freq_log);
+
+  static bool check_args_consistency(bool status);
+
+  static void ergo_initialize();
+
+private:
+  static void set_tiered_flags();
+};
+
 #endif // SHARE_VM_COMPILER_COMPILERDEFINITIONS_HPP
--- a/src/hotspot/share/gc/z/zArguments.cpp	Fri Jun 15 08:28:08 2018 -0700
+++ b/src/hotspot/share/gc/z/zArguments.cpp	Fri Jun 15 09:16:48 2018 -0700
@@ -94,11 +94,6 @@
   // Verification of stacks not (yet) supported, for the same reason
   // we need fixup_partial_loads
   DEBUG_ONLY(FLAG_SET_DEFAULT(VerifyStack, false));
-
-  // JVMCI not (yet) supported
-  if (EnableJVMCI) {
-    vm_exit_during_initialization("The flag -XX:+UseZGC can not be combined with -XX:+EnableJVMCI");
-  }
 }
 
 CollectedHeap* ZArguments::create_heap() {
--- a/src/hotspot/share/jvmci/jvmci_globals.cpp	Fri Jun 15 08:28:08 2018 -0700
+++ b/src/hotspot/share/jvmci/jvmci_globals.cpp	Fri Jun 15 09:16:48 2018 -0700
@@ -25,6 +25,7 @@
 #include "precompiled.hpp"
 #include "jvm.h"
 #include "jvmci/jvmci_globals.hpp"
+#include "gc/shared/gcConfig.hpp"
 #include "utilities/defaultStream.hpp"
 #include "runtime/globals_extension.hpp"
 
@@ -113,3 +114,13 @@
 #undef CHECK_NOT_SET
   return true;
 }
+void JVMCIGlobals::check_jvmci_supported_gc() {
+  if (EnableJVMCI) {
+    // Check if selected GC is supported by JVMCI and Java compiler
+    if (!(UseSerialGC || UseParallelGC || UseParallelOldGC || UseG1GC)) {
+      vm_exit_during_initialization("JVMCI Compiler does not support selected GC", GCConfig::hs_err_name());
+      FLAG_SET_DEFAULT(EnableJVMCI, false);
+      FLAG_SET_DEFAULT(UseJVMCICompiler, false);
+    }
+  }
+}
--- a/src/hotspot/share/jvmci/jvmci_globals.hpp	Fri Jun 15 08:28:08 2018 -0700
+++ b/src/hotspot/share/jvmci/jvmci_globals.hpp	Fri Jun 15 09:16:48 2018 -0700
@@ -121,5 +121,8 @@
   // an error message describing the inconsistency is printed before
   // returning false.
   static bool check_jvmci_flags_are_consistent();
+
+  // Check and exit VM with error if selected GC is not supported by JVMCI.
+  static void check_jvmci_supported_gc();
 };
 #endif // SHARE_VM_JVMCI_JVMCIGLOBALS_HPP
--- a/src/hotspot/share/oops/methodCounters.hpp	Fri Jun 15 08:28:08 2018 -0700
+++ b/src/hotspot/share/oops/methodCounters.hpp	Fri Jun 15 09:16:48 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
 #define SHARE_VM_OOPS_METHODCOUNTERS_HPP
 
 #include "oops/metadata.hpp"
+#include "compiler/compilerDefinitions.hpp"
 #include "compiler/compilerOracle.hpp"
 #include "interpreter/invocationCounter.hpp"
 #include "runtime/arguments.hpp"
@@ -96,7 +97,7 @@
     double scale = 1.0;
     CompilerOracle::has_option_value(mh, "CompileThresholdScaling", scale);
 
-    int compile_threshold = Arguments::scaled_compile_threshold(CompileThreshold, scale);
+    int compile_threshold = CompilerConfig::scaled_compile_threshold(CompileThreshold, scale);
     _interpreter_invocation_limit = compile_threshold << InvocationCounter::count_shift;
     if (ProfileInterpreter) {
       // If interpreter profiling is enabled, the backward branch limit
@@ -107,8 +108,8 @@
       _interpreter_backward_branch_limit = ((compile_threshold * OnStackReplacePercentage) / 100) << InvocationCounter::count_shift;
     }
     _interpreter_profile_limit = ((compile_threshold * InterpreterProfilePercentage) / 100) << InvocationCounter::count_shift;
-    _invoke_mask = right_n_bits(Arguments::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
-    _backedge_mask = right_n_bits(Arguments::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
+    _invoke_mask = right_n_bits(CompilerConfig::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
+    _backedge_mask = right_n_bits(CompilerConfig::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
   }
 
  public:
--- a/src/hotspot/share/oops/methodData.cpp	Fri Jun 15 08:28:08 2018 -0700
+++ b/src/hotspot/share/oops/methodData.cpp	Fri Jun 15 09:16:48 2018 -0700
@@ -1217,8 +1217,8 @@
   // Set per-method invoke- and backedge mask.
   double scale = 1.0;
   CompilerOracle::has_option_value(_method, "CompileThresholdScaling", scale);
-  _invoke_mask = right_n_bits(Arguments::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
-  _backedge_mask = right_n_bits(Arguments::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
+  _invoke_mask = right_n_bits(CompilerConfig::scaled_freq_log(Tier0InvokeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
+  _backedge_mask = right_n_bits(CompilerConfig::scaled_freq_log(Tier0BackedgeNotifyFreqLog, scale)) << InvocationCounter::count_shift;
 
   _tenure_traps = 0;
   _num_loops = 0;
--- a/src/hotspot/share/runtime/arguments.cpp	Fri Jun 15 08:28:08 2018 -0700
+++ b/src/hotspot/share/runtime/arguments.cpp	Fri Jun 15 09:16:48 2018 -0700
@@ -1592,101 +1592,6 @@
   }
 }
 
-// Returns threshold scaled with the value of scale.
-// If scale < 0.0, threshold is returned without scaling.
-intx Arguments::scaled_compile_threshold(intx threshold, double scale) {
-  if (scale == 1.0 || scale < 0.0) {
-    return threshold;
-  } else {
-    return (intx)(threshold * scale);
-  }
-}
-
-// Returns freq_log scaled with the value of scale.
-// Returned values are in the range of [0, InvocationCounter::number_of_count_bits + 1].
-// If scale < 0.0, freq_log is returned without scaling.
-intx Arguments::scaled_freq_log(intx freq_log, double scale) {
-  // Check if scaling is necessary or if negative value was specified.
-  if (scale == 1.0 || scale < 0.0) {
-    return freq_log;
-  }
-  // Check values to avoid calculating log2 of 0.
-  if (scale == 0.0 || freq_log == 0) {
-    return 0;
-  }
-  // Determine the maximum notification frequency value currently supported.
-  // The largest mask value that the interpreter/C1 can handle is
-  // of length InvocationCounter::number_of_count_bits. Mask values are always
-  // one bit shorter then the value of the notification frequency. Set
-  // max_freq_bits accordingly.
-  intx max_freq_bits = InvocationCounter::number_of_count_bits + 1;
-  intx scaled_freq = scaled_compile_threshold((intx)1 << freq_log, scale);
-  if (scaled_freq == 0) {
-    // Return 0 right away to avoid calculating log2 of 0.
-    return 0;
-  } else if (scaled_freq > nth_bit(max_freq_bits)) {
-    return max_freq_bits;
-  } else {
-    return log2_intptr(scaled_freq);
-  }
-}
-
-void Arguments::set_tiered_flags() {
-  // With tiered, set default policy to SimpleThresholdPolicy, which is 2.
-  if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) {
-    FLAG_SET_DEFAULT(CompilationPolicyChoice, 2);
-  }
-  if (CompilationPolicyChoice < 2) {
-    vm_exit_during_initialization(
-      "Incompatible compilation policy selected", NULL);
-  }
-  // Increase the code cache size - tiered compiles a lot more.
-  if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
-    FLAG_SET_ERGO(uintx, ReservedCodeCacheSize,
-                  MIN2(CODE_CACHE_DEFAULT_LIMIT, ReservedCodeCacheSize * 5));
-  }
-  // Enable SegmentedCodeCache if TieredCompilation is enabled and ReservedCodeCacheSize >= 240M
-  if (FLAG_IS_DEFAULT(SegmentedCodeCache) && ReservedCodeCacheSize >= 240*M) {
-    FLAG_SET_ERGO(bool, SegmentedCodeCache, true);
-  }
-  if (!UseInterpreter) { // -Xcomp
-    Tier3InvokeNotifyFreqLog = 0;
-    Tier4InvocationThreshold = 0;
-  }
-
-  if (CompileThresholdScaling < 0) {
-    vm_exit_during_initialization("Negative value specified for CompileThresholdScaling", NULL);
-  }
-
-  // Scale tiered compilation thresholds.
-  // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves compilation thresholds unchanged.
-  if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) {
-    FLAG_SET_ERGO(intx, Tier0InvokeNotifyFreqLog, scaled_freq_log(Tier0InvokeNotifyFreqLog));
-    FLAG_SET_ERGO(intx, Tier0BackedgeNotifyFreqLog, scaled_freq_log(Tier0BackedgeNotifyFreqLog));
-
-    FLAG_SET_ERGO(intx, Tier3InvocationThreshold, scaled_compile_threshold(Tier3InvocationThreshold));
-    FLAG_SET_ERGO(intx, Tier3MinInvocationThreshold, scaled_compile_threshold(Tier3MinInvocationThreshold));
-    FLAG_SET_ERGO(intx, Tier3CompileThreshold, scaled_compile_threshold(Tier3CompileThreshold));
-    FLAG_SET_ERGO(intx, Tier3BackEdgeThreshold, scaled_compile_threshold(Tier3BackEdgeThreshold));
-
-    // Tier2{Invocation,MinInvocation,Compile,Backedge}Threshold should be scaled here
-    // once these thresholds become supported.
-
-    FLAG_SET_ERGO(intx, Tier2InvokeNotifyFreqLog, scaled_freq_log(Tier2InvokeNotifyFreqLog));
-    FLAG_SET_ERGO(intx, Tier2BackedgeNotifyFreqLog, scaled_freq_log(Tier2BackedgeNotifyFreqLog));
-
-    FLAG_SET_ERGO(intx, Tier3InvokeNotifyFreqLog, scaled_freq_log(Tier3InvokeNotifyFreqLog));
-    FLAG_SET_ERGO(intx, Tier3BackedgeNotifyFreqLog, scaled_freq_log(Tier3BackedgeNotifyFreqLog));
-
-    FLAG_SET_ERGO(intx, Tier23InlineeNotifyFreqLog, scaled_freq_log(Tier23InlineeNotifyFreqLog));
-
-    FLAG_SET_ERGO(intx, Tier4InvocationThreshold, scaled_compile_threshold(Tier4InvocationThreshold));
-    FLAG_SET_ERGO(intx, Tier4MinInvocationThreshold, scaled_compile_threshold(Tier4MinInvocationThreshold));
-    FLAG_SET_ERGO(intx, Tier4CompileThreshold, scaled_compile_threshold(Tier4CompileThreshold));
-    FLAG_SET_ERGO(intx, Tier4BackEdgeThreshold, scaled_compile_threshold(Tier4BackEdgeThreshold));
-  }
-}
-
 void set_object_alignment() {
   // Object alignment.
   assert(is_power_of_2(ObjectAlignmentInBytes), "ObjectAlignmentInBytes must be power of 2");
@@ -1787,74 +1692,9 @@
                                           CollectorPolicy::compute_heap_alignment());
 }
 
-#ifdef TIERED
-bool Arguments::compilation_mode_selected() {
- return !FLAG_IS_DEFAULT(TieredCompilation) || !FLAG_IS_DEFAULT(TieredStopAtLevel) ||
-        !FLAG_IS_DEFAULT(UseAOT) JVMCI_ONLY(|| !FLAG_IS_DEFAULT(EnableJVMCI) || !FLAG_IS_DEFAULT(UseJVMCICompiler));
-
-}
-
-void Arguments::select_compilation_mode_ergonomically() {
-#if defined(_WINDOWS) && !defined(_LP64)
-  if (FLAG_IS_DEFAULT(NeverActAsServerClassMachine)) {
-    FLAG_SET_ERGO(bool, NeverActAsServerClassMachine, true);
-  }
-#endif
-  if (NeverActAsServerClassMachine) {
-    set_client_compilation_mode();
-  }
-}
-#endif //TIERED
-
-#if INCLUDE_JVMCI
-void Arguments::set_jvmci_specific_flags() {
-  if (UseJVMCICompiler) {
-    if (FLAG_IS_DEFAULT(TypeProfileWidth)) {
-      FLAG_SET_DEFAULT(TypeProfileWidth, 8);
-    }
-    if (FLAG_IS_DEFAULT(OnStackReplacePercentage)) {
-      FLAG_SET_DEFAULT(OnStackReplacePercentage, 933);
-    }
-    if (FLAG_IS_DEFAULT(ReservedCodeCacheSize)) {
-      FLAG_SET_DEFAULT(ReservedCodeCacheSize, 64*M);
-    }
-    if (FLAG_IS_DEFAULT(InitialCodeCacheSize)) {
-      FLAG_SET_DEFAULT(InitialCodeCacheSize, 16*M);
-    }
-    if (FLAG_IS_DEFAULT(MetaspaceSize)) {
-      FLAG_SET_DEFAULT(MetaspaceSize, 12*M);
-    }
-    if (FLAG_IS_DEFAULT(NewSizeThreadIncrease)) {
-      FLAG_SET_DEFAULT(NewSizeThreadIncrease, 4*K);
-    }
-    if (TieredStopAtLevel != CompLevel_full_optimization) {
-      // Currently JVMCI compiler can only work at the full optimization level
-      warning("forcing TieredStopAtLevel to full optimization because JVMCI is enabled");
-      TieredStopAtLevel = CompLevel_full_optimization;
-    }
-    if (FLAG_IS_DEFAULT(TypeProfileLevel)) {
-      FLAG_SET_DEFAULT(TypeProfileLevel, 0);
-    }
-  }
-}
-#endif
-
 jint Arguments::set_ergonomics_flags() {
-#ifdef TIERED
-  if (!compilation_mode_selected()) {
-    select_compilation_mode_ergonomically();
-  }
-#endif
-
   GCConfig::initialize();
 
-#if defined(IA32)
-  // Only server compiler can optimize safepoints well enough.
-  if (!is_server_compilation_mode_vm()) {
-    FLAG_SET_ERGO_IF_DEFAULT(bool, ThreadLocalHandshakes, false);
-  }
-#endif
-
   set_conservative_max_heap_alignment();
 
 #ifndef ZERO
@@ -2185,12 +2025,11 @@
 //===========================================================================================================
 // Parsing of main arguments
 
-#if INCLUDE_JVMCI
-// Check consistency of jvmci vm argument settings.
-bool Arguments::check_jvmci_args_consistency() {
-   return JVMCIGlobals::check_jvmci_flags_are_consistent();
-}
-#endif //INCLUDE_JVMCI
+unsigned int addreads_count = 0;
+unsigned int addexports_count = 0;
+unsigned int addopens_count = 0;
+unsigned int addmods_count = 0;
+unsigned int patch_mod_count = 0;
 
 // Check the consistency of vm_init_args
 bool Arguments::check_vm_args_consistency() {
@@ -2219,52 +2058,17 @@
 #endif
   }
 
+  status = CompilerConfig::check_args_consistency(status);
 #if INCLUDE_JVMCI
-  status = status && check_jvmci_args_consistency();
-
-  if (EnableJVMCI) {
+  if (status && EnableJVMCI) {
     PropertyList_unique_add(&_system_properties, "jdk.internal.vm.ci.enabled", "true",
         AddProperty, UnwriteableProperty, InternalProperty);
-
-    if (!ScavengeRootsInCode) {
-      warning("forcing ScavengeRootsInCode non-zero because JVMCI is enabled");
-      ScavengeRootsInCode = 1;
+    if (!create_numbered_property("jdk.module.addmods", "jdk.internal.vm.ci", addmods_count++)) {
+      return false;
     }
   }
 #endif
 
-  // Check lower bounds of the code cache
-  // Template Interpreter code is approximately 3X larger in debug builds.
-  uint min_code_cache_size = CodeCacheMinimumUseSpace DEBUG_ONLY(* 3);
-  if (ReservedCodeCacheSize < InitialCodeCacheSize) {
-    jio_fprintf(defaultStream::error_stream(),
-                "Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n",
-                ReservedCodeCacheSize/K, InitialCodeCacheSize/K);
-    status = false;
-  } else if (ReservedCodeCacheSize < min_code_cache_size) {
-    jio_fprintf(defaultStream::error_stream(),
-                "Invalid ReservedCodeCacheSize=%dK. Must be at least %uK.\n", ReservedCodeCacheSize/K,
-                min_code_cache_size/K);
-    status = false;
-  } else if (ReservedCodeCacheSize > CODE_CACHE_SIZE_LIMIT) {
-    // Code cache size larger than CODE_CACHE_SIZE_LIMIT is not supported.
-    jio_fprintf(defaultStream::error_stream(),
-                "Invalid ReservedCodeCacheSize=%dM. Must be at most %uM.\n", ReservedCodeCacheSize/M,
-                CODE_CACHE_SIZE_LIMIT/M);
-    status = false;
-  } else if (NonNMethodCodeHeapSize < min_code_cache_size) {
-    jio_fprintf(defaultStream::error_stream(),
-                "Invalid NonNMethodCodeHeapSize=%dK. Must be at least %uK.\n", NonNMethodCodeHeapSize/K,
-                min_code_cache_size/K);
-    status = false;
-  }
-
-#ifdef _LP64
-  if (!FLAG_IS_DEFAULT(CICompilerCount) && !FLAG_IS_DEFAULT(CICompilerCountPerCPU) && CICompilerCountPerCPU) {
-    warning("The VM option CICompilerCountPerCPU overrides CICompilerCount.");
-  }
-#endif
-
 #ifndef SUPPORT_RESERVED_STACK_AREA
   if (StackReservedPages != 0) {
     FLAG_SET_CMDLINE(intx, StackReservedPages, 0);
@@ -2272,37 +2076,6 @@
   }
 #endif
 
-  if (BackgroundCompilation && (CompileTheWorld || ReplayCompiles)) {
-    if (!FLAG_IS_DEFAULT(BackgroundCompilation)) {
-      warning("BackgroundCompilation disabled due to CompileTheWorld or ReplayCompiles options.");
-    }
-    FLAG_SET_CMDLINE(bool, BackgroundCompilation, false);
-  }
-  if (UseCompiler && is_interpreter_only()) {
-    if (!FLAG_IS_DEFAULT(UseCompiler)) {
-      warning("UseCompiler disabled due to -Xint.");
-    }
-    FLAG_SET_CMDLINE(bool, UseCompiler, false);
-  }
-#ifdef COMPILER2
-  if (PostLoopMultiversioning && !RangeCheckElimination) {
-    if (!FLAG_IS_DEFAULT(PostLoopMultiversioning)) {
-      warning("PostLoopMultiversioning disabled because RangeCheckElimination is disabled.");
-    }
-    FLAG_SET_CMDLINE(bool, PostLoopMultiversioning, false);
-  }
-  if (UseCountedLoopSafepoints && LoopStripMiningIter == 0) {
-    if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {
-      warning("When counted loop safepoints are enabled, LoopStripMiningIter must be at least 1 (a safepoint every 1 iteration): setting it to 1");
-    }
-    LoopStripMiningIter = 1;
-  } else if (!UseCountedLoopSafepoints && LoopStripMiningIter > 0) {
-    if (!FLAG_IS_DEFAULT(UseCountedLoopSafepoints) || !FLAG_IS_DEFAULT(LoopStripMiningIter)) {
-      warning("Disabling counted safepoints implies no loop strip mining: setting LoopStripMiningIter to 0");
-    }
-    LoopStripMiningIter = 0;
-  }
-#endif
   if (!FLAG_IS_DEFAULT(AllocateHeapAt)) {
     if ((UseNUMAInterleaving && !FLAG_IS_DEFAULT(UseNUMAInterleaving)) || (UseNUMA && !FLAG_IS_DEFAULT(UseNUMA))) {
       log_warning(arguments) ("NUMA support for Heap depends on the file system when AllocateHeapAt option is used.\n");
@@ -2364,12 +2137,6 @@
   return false;
 }
 
-unsigned int addreads_count = 0;
-unsigned int addexports_count = 0;
-unsigned int addopens_count = 0;
-unsigned int addmods_count = 0;
-unsigned int patch_mod_count = 0;
-
 bool Arguments::create_property(const char* prop_name, const char* prop_value, PropertyInternal internal) {
   size_t prop_len = strlen(prop_name) + strlen(prop_value) + 2;
   char* property = AllocateHeap(prop_len, mtArguments);
@@ -3358,13 +3125,6 @@
     FLAG_SET_DEFAULT(UseLargePages, false);
   }
 
-#elif defined(COMPILER2)
-  if (!FLAG_IS_DEFAULT(OptoLoopAlignment) && FLAG_IS_DEFAULT(MaxLoopPad)) {
-    FLAG_SET_DEFAULT(MaxLoopPad, OptoLoopAlignment-1);
-  }
-#endif
-
-#if !COMPILER2_OR_JVMCI
   UNSUPPORTED_OPTION(ProfileInterpreter);
   NOT_PRODUCT(UNSUPPORTED_OPTION(TraceProfileInterpreter));
 #endif
@@ -3378,19 +3138,6 @@
     return JNI_ERR;
   }
 
-#if INCLUDE_JVMCI
-  if (EnableJVMCI &&
-      !create_numbered_property("jdk.module.addmods", "jdk.internal.vm.ci", addmods_count++)) {
-    return JNI_ENOMEM;
-  }
-#endif
-
-#if INCLUDE_JVMCI
-  if (UseJVMCICompiler) {
-    Compilation_mode = CompMode_server;
-  }
-#endif
-
 #if INCLUDE_CDS
   if (DumpSharedSpaces) {
     // Disable biased locking now as it interferes with the clean up of
@@ -4149,41 +3896,8 @@
   jint result = set_ergonomics_flags();
   if (result != JNI_OK) return result;
 
-#if INCLUDE_JVMCI
-  set_jvmci_specific_flags();
-#endif
-
   set_shared_spaces_flags();
 
-  if (TieredCompilation) {
-    set_tiered_flags();
-  } else {
-    int max_compilation_policy_choice = 1;
-#ifdef COMPILER2
-    if (is_server_compilation_mode_vm()) {
-      max_compilation_policy_choice = 2;
-    }
-#endif
-    // Check if the policy is valid.
-    if (CompilationPolicyChoice >= max_compilation_policy_choice) {
-      vm_exit_during_initialization(
-        "Incompatible compilation policy selected", NULL);
-    }
-    // Scale CompileThreshold
-    // CompileThresholdScaling == 0.0 is equivalent to -Xint and leaves CompileThreshold unchanged.
-    if (!FLAG_IS_DEFAULT(CompileThresholdScaling) && CompileThresholdScaling > 0.0) {
-      FLAG_SET_ERGO(intx, CompileThreshold, scaled_compile_threshold(CompileThreshold));
-    }
-  }
-
-#ifdef COMPILER2
-#ifndef PRODUCT
-  if (PrintIdealGraphLevel > 0) {
-    FLAG_SET_ERGO(bool, PrintIdealGraph, true);
-  }
-#endif
-#endif
-
   // Set heap size based on available physical memory
   set_heap_size();
 
@@ -4192,6 +3906,10 @@
   // Initialize Metaspace flags and alignments
   Metaspace::ergo_initialize();
 
+  // Set compiler flags after GC is selected and GC specific
+  // flags (LoopStripMiningIter) are set.
+  CompilerConfig::ergo_initialize();
+
   // Set bytecode rewriting flags
   set_bytecode_flags();
 
@@ -4229,28 +3947,6 @@
   LP64_ONLY(FLAG_SET_DEFAULT(UseCompressedClassPointers, false));
 #endif // CC_INTERP
 
-#ifdef COMPILER2
-  if (!EliminateLocks) {
-    EliminateNestedLocks = false;
-  }
-  if (!Inline) {
-    IncrementalInline = false;
-  }
-#ifndef PRODUCT
-  if (!IncrementalInline) {
-    AlwaysIncrementalInline = false;
-  }
-#endif
-  if (!UseTypeSpeculation && FLAG_IS_DEFAULT(TypeProfileLevel)) {
-    // nothing to use the profiling, turn if off
-    FLAG_SET_DEFAULT(TypeProfileLevel, 0);
-  }
-  if (FLAG_IS_DEFAULT(LoopStripMiningIterShortLoop)) {
-    // blind guess
-    LoopStripMiningIterShortLoop = LoopStripMiningIter / 10;
-  }
-#endif
-
   if (PrintAssembly && FLAG_IS_DEFAULT(DebugNonSafepoints)) {
     warning("PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output");
     DebugNonSafepoints = true;
@@ -4260,11 +3956,6 @@
     warning("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used");
   }
 
-  if (UseOnStackReplacement && !UseLoopCounter) {
-    warning("On-stack-replacement requires loop counters; enabling loop counters");
-    FLAG_SET_DEFAULT(UseLoopCounter, true);
-  }
-
 #ifndef PRODUCT
   if (!LogVMOutput && FLAG_IS_DEFAULT(LogVMOutput)) {
     if (use_vm_log()) {
@@ -4290,6 +3981,13 @@
   }
 #endif
 
+#if defined(IA32)
+  // Only server compiler can optimize safepoints well enough.
+  if (!is_server_compilation_mode_vm()) {
+    FLAG_SET_ERGO_IF_DEFAULT(bool, ThreadLocalHandshakes, false);
+  }
+#endif
+
   // ThreadLocalHandshakesConstraintFunc handles the constraints.
   if (FLAG_IS_DEFAULT(ThreadLocalHandshakes) || !SafepointMechanism::supports_thread_local_poll()) {
     log_debug(ergo)("ThreadLocalHandshakes %s", ThreadLocalHandshakes ? "enabled." : "disabled.");
--- a/src/hotspot/share/runtime/arguments.hpp	Fri Jun 15 08:28:08 2018 -0700
+++ b/src/hotspot/share/runtime/arguments.hpp	Fri Jun 15 09:16:48 2018 -0700
@@ -372,13 +372,6 @@
   static intx _Tier3InvokeNotifyFreqLog;
   static intx _Tier4InvocationThreshold;
 
-  // Compilation mode.
-  static bool compilation_mode_selected();
-  static void select_compilation_mode_ergonomically();
-
-  // Tiered
-  static void set_tiered_flags();
-
   // GC ergonomics
   static void set_conservative_max_heap_alignment();
   static void set_use_compressed_oops();
@@ -469,18 +462,6 @@
   static void add_string(char*** bldarray, int* count, const char* arg);
   static const char* build_resource_string(char** args, int count);
 
-  static bool methodExists(
-    char* className, char* methodName,
-    int classesNum, char** classes, bool* allMethods,
-    int methodsNum, char** methods, bool* allClasses
-  );
-
-  static void parseOnlyLine(
-    const char* line,
-    short* classesNum, short* classesMax, char*** classes, bool** allMethods,
-    short* methodsNum, short* methodsMax, char*** methods, bool** allClasses
-  );
-
   // Returns true if the flag is obsolete (and not yet expired).
   // In this case the 'version' buffer is filled in with
   // the version number when the flag became obsolete.
@@ -505,38 +486,10 @@
   static const char* handle_aliases_and_deprecation(const char* arg, bool warn);
   static bool lookup_logging_aliases(const char* arg, char* buffer);
   static AliasedLoggingFlag catch_logging_aliases(const char* name, bool on);
-  static short  CompileOnlyClassesNum;
-  static short  CompileOnlyClassesMax;
-  static char** CompileOnlyClasses;
-  static bool*  CompileOnlyAllMethods;
-
-  static short  CompileOnlyMethodsNum;
-  static short  CompileOnlyMethodsMax;
-  static char** CompileOnlyMethods;
-  static bool*  CompileOnlyAllClasses;
-
-  static short  InterpretOnlyClassesNum;
-  static short  InterpretOnlyClassesMax;
-  static char** InterpretOnlyClasses;
-  static bool*  InterpretOnlyAllMethods;
-
-  static bool   CheckCompileOnly;
 
   static char*  SharedArchivePath;
 
  public:
-  // Scale compile thresholds
-  // Returns threshold scaled with CompileThresholdScaling
-  static intx scaled_compile_threshold(intx threshold, double scale);
-  static intx scaled_compile_threshold(intx threshold) {
-    return scaled_compile_threshold(threshold, CompileThresholdScaling);
-  }
-  // Returns freq_log scaled with CompileThresholdScaling
-  static intx scaled_freq_log(intx freq_log, double scale);
-  static intx scaled_freq_log(intx freq_log) {
-    return scaled_freq_log(freq_log, CompileThresholdScaling);
-  }
-
   // Parses the arguments, first phase
   static jint parse(const JavaVMInitArgs* args);
   // Apply ergonomics
@@ -544,11 +497,6 @@
   // Adjusts the arguments after the OS have adjusted the arguments
   static jint adjust_after_os();
 
-#if INCLUDE_JVMCI
-  // Check consistency of jvmci vm argument settings.
-  static bool check_jvmci_args_consistency();
-  static void set_jvmci_specific_flags();
-#endif
   // Check for consistency in the selection of the garbage collector.
   static bool check_gc_consistency();        // Check user-selected gc
   // Check consistency or otherwise of VM argument settings
@@ -622,19 +570,8 @@
   static exit_hook_t     exit_hook()        { return _exit_hook; }
   static vfprintf_hook_t vfprintf_hook()    { return _vfprintf_hook; }
 
-  static bool GetCheckCompileOnly ()        { return CheckCompileOnly; }
-
   static const char* GetSharedArchivePath() { return SharedArchivePath; }
 
-  static bool CompileMethod(char* className, char* methodName) {
-    return
-      methodExists(
-        className, methodName,
-        CompileOnlyClassesNum, CompileOnlyClasses, CompileOnlyAllMethods,
-        CompileOnlyMethodsNum, CompileOnlyMethods, CompileOnlyAllClasses
-      );
-  }
-
   // Java launcher properties
   static void process_sun_java_launcher_properties(JavaVMInitArgs* args);
 
--- a/test/hotspot/jtreg/compiler/arguments/CheckCompileThresholdScaling.java	Fri Jun 15 08:28:08 2018 -0700
+++ b/test/hotspot/jtreg/compiler/arguments/CheckCompileThresholdScaling.java	Fri Jun 15 09:16:48 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -125,7 +125,7 @@
             "interpreted mode"
         },
         {
-            "intx CompileThreshold                         = 0                                      {pd product} {command line, ergonomic}",
+            "intx CompileThreshold                         = 0                                      {pd product} {command line}",
             "double CompileThresholdScaling                  = 0.750000                                  {product} {command line}",
             "interpreted mode"
         }
--- a/test/hotspot/jtreg/gc/stress/gcbasher/TestGCBasherWithZ.java	Fri Jun 15 08:28:08 2018 -0700
+++ b/test/hotspot/jtreg/gc/stress/gcbasher/TestGCBasherWithZ.java	Fri Jun 15 09:16:48 2018 -0700
@@ -28,7 +28,7 @@
  * @test TestGCBasherWithZ
  * @key gc stress
  * @requires vm.gc.Z
- * @requires vm.flavor == "server" & !vm.emulatedClient
+ * @requires vm.flavor == "server" & !vm.emulatedClient & !vm.graal.enabled
  * @summary Stress ZGC
  * @run main/othervm/timeout=200 -Xlog:gc*=info -Xmx384m -server -XX:+UnlockExperimentalVMOptions -XX:+UseZGC TestGCBasherWithZ 120000
  */
--- a/test/hotspot/jtreg/gc/stress/gcold/TestGCOldWithZ.java	Fri Jun 15 08:28:08 2018 -0700
+++ b/test/hotspot/jtreg/gc/stress/gcold/TestGCOldWithZ.java	Fri Jun 15 09:16:48 2018 -0700
@@ -25,7 +25,7 @@
 /*
  * @test TestGCOldWithZ
  * @key gc
- * @requires vm.gc.Z
+ * @requires vm.gc.Z & !vm.graal.enabled
  * @summary Stress the Z
  * @run main/othervm -Xmx384M -XX:+UnlockExperimentalVMOptions -XX:+UseZGC TestGCOldWithZ 50 1 20 10 10000
  * @run main/othervm -Xmx256m -XX:+UnlockExperimentalVMOptions -XX:+UseZGC TestGCOldWithZ 50 5 20 1 5000
--- a/test/hotspot/jtreg/serviceability/sa/TestUniverse.java	Fri Jun 15 08:28:08 2018 -0700
+++ b/test/hotspot/jtreg/serviceability/sa/TestUniverse.java	Fri Jun 15 09:16:48 2018 -0700
@@ -163,8 +163,8 @@
                 if (args[0].equals("withZ")) {
                     test("-XX:+UseZGC");
                 }
+                test("-XX:+UseEpsilonGC");
             }
-            test("-XX:+UseEpsilonGC");
         } catch (Exception e) {
             throw new Error("Test failed with " + e);
         }
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/TestDriver.java	Fri Jun 15 08:28:08 2018 -0700
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/general_functions/GF08/gf08t001/TestDriver.java	Fri Jun 15 09:16:48 2018 -0700
@@ -63,6 +63,8 @@
  *      TestDriver
  */
 
+import sun.hotspot.code.Compiler;
+
 public class TestDriver {
     public static void main(String[] args) throws Exception {
         sun.hotspot.WhiteBox wb = sun.hotspot.WhiteBox.getWhiteBox();
@@ -70,6 +72,12 @@
         Boolean isUseG1GCon = wb.getBooleanVMFlag("UseG1GC");
         Boolean isUseConcMarkSweepGCon = wb.getBooleanVMFlag("UseConcMarkSweepGC");
         Boolean isUseZGCon = wb.getBooleanVMFlag("UseZGC");
+        Boolean isUseEpsilonGCon = wb.getBooleanVMFlag("UseEpsilonGC");
+
+        if (Compiler.isGraalEnabled() &&
+            (isUseConcMarkSweepGCon || isUseZGCon || isUseEpsilonGCon)) {
+            return; // Graal does not support these GCs
+        }
 
         String keyPhrase;
         if ((isExplicitGCInvokesConcurrentOn && (isUseG1GCon || isUseConcMarkSweepGCon)) || isUseZGCon) {