changeset 10319:91eba9f82325

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
author anoll
date Thu, 16 May 2013 15:46:49 +0200
parents 7ec426e29e4c
children b4907b24ed48 1682bec79205
files src/share/vm/code/codeCache.cpp src/share/vm/code/codeCache.hpp src/share/vm/runtime/advancedThresholdPolicy.cpp src/share/vm/runtime/advancedThresholdPolicy.hpp src/share/vm/runtime/arguments.cpp src/share/vm/runtime/globals.hpp
diffstat 6 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/code/codeCache.cpp	Fri May 17 09:10:04 2013 -0700
+++ b/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/src/share/vm/code/codeCache.hpp	Fri May 17 09:10:04 2013 -0700
+++ b/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/src/share/vm/runtime/advancedThresholdPolicy.cpp	Fri May 17 09:10:04 2013 -0700
+++ b/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/src/share/vm/runtime/advancedThresholdPolicy.hpp	Fri May 17 09:10:04 2013 -0700
+++ b/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/src/share/vm/runtime/arguments.cpp	Fri May 17 09:10:04 2013 -0700
+++ b/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/src/share/vm/runtime/globals.hpp	Fri May 17 09:10:04 2013 -0700
+++ b/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)")               \
                                                                             \