8012371: Adjust Tiered compile threshold according to available space in code cache
authoranoll
Thu, 16 May 2013 15:46:49 +0200
changeset 17617 4e330bce1812
parent 17596 cc309911da72
child 17619 4fd15e9e97f2
child 17620 67820da7568e
8012371: Adjust Tiered compile threshold according to available space in code cache Summary: Added command line parameter to define a threshold at which C1 compilation threshold for is increased. Reviewed-by: kvn, iveresov
hotspot/src/share/vm/code/codeCache.cpp
hotspot/src/share/vm/code/codeCache.hpp
hotspot/src/share/vm/runtime/advancedThresholdPolicy.cpp
hotspot/src/share/vm/runtime/advancedThresholdPolicy.hpp
hotspot/src/share/vm/runtime/arguments.cpp
hotspot/src/share/vm/runtime/globals.hpp
--- a/hotspot/src/share/vm/code/codeCache.cpp	Fri May 17 09:10:04 2013 -0700
+++ b/hotspot/src/share/vm/code/codeCache.cpp	Thu May 16 15:46:49 2013 +0200
@@ -622,6 +622,15 @@
   return (address)_heap->high();
 }
 
+/**
+ * Returns the reverse free ratio. E.g., if 25% (1/4) of the code cache
+ * is free, reverse_free_ratio() returns 4.
+ */
+double CodeCache::reverse_free_ratio() {
+  double unallocated_capacity = (double)(CodeCache::unallocated_capacity() - CodeCacheMinimumFreeSpace);
+  double max_capacity = (double)CodeCache::max_capacity();
+  return max_capacity / unallocated_capacity;
+}
 
 void icache_init();
 
--- a/hotspot/src/share/vm/code/codeCache.hpp	Fri May 17 09:10:04 2013 -0700
+++ b/hotspot/src/share/vm/code/codeCache.hpp	Thu May 16 15:46:49 2013 +0200
@@ -163,6 +163,7 @@
   static size_t  max_capacity()                  { return _heap->max_capacity(); }
   static size_t  unallocated_capacity()          { return _heap->unallocated_capacity(); }
   static bool    needs_flushing()                { return unallocated_capacity() < CodeCacheFlushingMinimumFreeSpace; }
+  static double  reverse_free_ratio();
 
   static bool needs_cache_clean()                { return _needs_cache_clean; }
   static void set_needs_cache_clean(bool v)      { _needs_cache_clean = v;    }
--- a/hotspot/src/share/vm/runtime/advancedThresholdPolicy.cpp	Fri May 17 09:10:04 2013 -0700
+++ b/hotspot/src/share/vm/runtime/advancedThresholdPolicy.cpp	Thu May 16 15:46:49 2013 +0200
@@ -68,7 +68,7 @@
   }
 #endif
 
-
+  set_increase_threshold_at_ratio();
   set_start_time(os::javaTimeMillis());
 }
 
@@ -205,6 +205,17 @@
   double queue_size = CompileBroker::queue_size(level);
   int comp_count = compiler_count(level);
   double k = queue_size / (feedback_k * comp_count) + 1;
+
+  // Increase C1 compile threshold when the code cache is filled more
+  // than specified by IncreaseFirstTierCompileThresholdAt percentage.
+  // The main intention is to keep enough free space for C2 compiled code
+  // to achieve peak performance if the code cache is under stress.
+  if ((TieredStopAtLevel == CompLevel_full_optimization) && (level != CompLevel_full_optimization))  {
+    double current_reverse_free_ratio = CodeCache::reverse_free_ratio();
+    if (current_reverse_free_ratio > _increase_threshold_at_ratio) {
+      k *= exp(current_reverse_free_ratio - _increase_threshold_at_ratio);
+    }
+  }
   return k;
 }
 
--- a/hotspot/src/share/vm/runtime/advancedThresholdPolicy.hpp	Fri May 17 09:10:04 2013 -0700
+++ b/hotspot/src/share/vm/runtime/advancedThresholdPolicy.hpp	Thu May 16 15:46:49 2013 +0200
@@ -201,9 +201,12 @@
   // Is method profiled enough?
   bool is_method_profiled(Method* method);
 
+  double _increase_threshold_at_ratio;
+
 protected:
   void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level);
 
+  void set_increase_threshold_at_ratio() { _increase_threshold_at_ratio = 100 / (100 - (double)IncreaseFirstTierCompileThresholdAt); }
   void set_start_time(jlong t) { _start_time = t;    }
   jlong start_time() const     { return _start_time; }
 
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Fri May 17 09:10:04 2013 -0700
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Thu May 16 15:46:49 2013 +0200
@@ -2629,6 +2629,16 @@
         return JNI_EINVAL;
       }
       FLAG_SET_CMDLINE(uintx, ReservedCodeCacheSize, (uintx)long_ReservedCodeCacheSize);
+      //-XX:IncreaseFirstTierCompileThresholdAt=
+      } else if (match_option(option, "-XX:IncreaseFirstTierCompileThresholdAt=", &tail)) {
+        uintx uint_IncreaseFirstTierCompileThresholdAt = 0;
+        if (!parse_uintx(tail, &uint_IncreaseFirstTierCompileThresholdAt, 0) || uint_IncreaseFirstTierCompileThresholdAt > 99) {
+          jio_fprintf(defaultStream::error_stream(),
+                      "Invalid value for IncreaseFirstTierCompileThresholdAt: %s. Should be between 0 and 99.\n",
+                      option->optionString);
+          return JNI_EINVAL;
+        }
+        FLAG_SET_CMDLINE(uintx, IncreaseFirstTierCompileThresholdAt, (uintx)uint_IncreaseFirstTierCompileThresholdAt);
     // -green
     } else if (match_option(option, "-green", &tail)) {
       jio_fprintf(defaultStream::error_stream(),
--- a/hotspot/src/share/vm/runtime/globals.hpp	Fri May 17 09:10:04 2013 -0700
+++ b/hotspot/src/share/vm/runtime/globals.hpp	Thu May 16 15:46:49 2013 +0200
@@ -3436,6 +3436,10 @@
           "Start profiling in interpreter if the counters exceed tier 3"    \
           "thresholds by the specified percentage")                         \
                                                                             \
+  product(uintx, IncreaseFirstTierCompileThresholdAt, 50,                   \
+          "Increase the compile threshold for C1 compilation if the code"   \
+          "cache is filled by the specified percentage.")                   \
+                                                                            \
   product(intx, TieredRateUpdateMinTime, 1,                                 \
           "Minimum rate sampling interval (in milliseconds)")               \
                                                                             \