src/share/vm/runtime/advancedThresholdPolicy.cpp

Print this page
rev 4616 : Fixes fill up of code cache: added command line parameter which defines a
threshold (percentage of used code cache) at which the threshold for
C1 recompilation is increased.


  51     int loglog_cpu = log2_intptr(MAX2(log_cpu, 1));
  52     count = MAX2(log_cpu * loglog_cpu, 1) * 3 / 2;
  53   }
  54 
  55   set_c1_count(MAX2(count / 3, 1));
  56   set_c2_count(MAX2(count - count / 3, 1));
  57 
  58   // Some inlining tuning
  59 #ifdef X86
  60   if (FLAG_IS_DEFAULT(InlineSmallCode)) {
  61     FLAG_SET_DEFAULT(InlineSmallCode, 2000);
  62   }
  63 #endif
  64 
  65 #ifdef SPARC
  66   if (FLAG_IS_DEFAULT(InlineSmallCode)) {
  67     FLAG_SET_DEFAULT(InlineSmallCode, 2500);
  68   }
  69 #endif
  70 
  71 
  72   set_start_time(os::javaTimeMillis());
  73 }
  74 
  75 // update_rate() is called from select_task() while holding a compile queue lock.
  76 void AdvancedThresholdPolicy::update_rate(jlong t, Method* m) {
  77   JavaThread* THREAD = JavaThread::current();
  78   if (is_old(m)) {
  79     // We don't remove old methods from the queue,
  80     // so we can just zero the rate.
  81     m->set_rate(0, THREAD);
  82     return;
  83   }
  84 
  85   // We don't update the rate if we've just came out of a safepoint.
  86   // delta_s is the time since last safepoint in milliseconds.
  87   jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint();
  88   jlong delta_t = t - (m->prev_time() != 0 ? m->prev_time() : start_time()); // milliseconds since the last measurement
  89   // How many events were there since the last time?
  90   int event_count = m->invocation_count() + m->backedge_count();
  91   int delta_e = event_count - m->prev_event_count();


 188       }
 189     }
 190     task = next_task;
 191   }
 192 
 193   if (max_task->comp_level() == CompLevel_full_profile && TieredStopAtLevel > CompLevel_full_profile
 194       && is_method_profiled(max_method)) {
 195     max_task->set_comp_level(CompLevel_limited_profile);
 196     if (PrintTieredEvents) {
 197       print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
 198     }
 199   }
 200 
 201   return max_task;
 202 }
 203 
 204 double AdvancedThresholdPolicy::threshold_scale(CompLevel level, int feedback_k) {
 205   double queue_size = CompileBroker::queue_size(level);
 206   int comp_count = compiler_count(level);
 207   double k = queue_size / (feedback_k * comp_count) + 1;











 208   return k;
 209 }
 210 
 211 // Call and loop predicates determine whether a transition to a higher
 212 // compilation level should be performed (pointers to predicate functions
 213 // are passed to common()).
 214 // Tier?LoadFeedback is basically a coefficient that determines of
 215 // how many methods per compiler thread can be in the queue before
 216 // the threshold values double.
 217 bool AdvancedThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) {
 218   switch(cur_level) {
 219   case CompLevel_none:
 220   case CompLevel_limited_profile: {
 221     double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback);
 222     return loop_predicate_helper<CompLevel_none>(i, b, k);
 223   }
 224   case CompLevel_full_profile: {
 225     double k = threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback);
 226     return loop_predicate_helper<CompLevel_full_profile>(i, b, k);
 227   }




  51     int loglog_cpu = log2_intptr(MAX2(log_cpu, 1));
  52     count = MAX2(log_cpu * loglog_cpu, 1) * 3 / 2;
  53   }
  54 
  55   set_c1_count(MAX2(count / 3, 1));
  56   set_c2_count(MAX2(count - count / 3, 1));
  57 
  58   // Some inlining tuning
  59 #ifdef X86
  60   if (FLAG_IS_DEFAULT(InlineSmallCode)) {
  61     FLAG_SET_DEFAULT(InlineSmallCode, 2000);
  62   }
  63 #endif
  64 
  65 #ifdef SPARC
  66   if (FLAG_IS_DEFAULT(InlineSmallCode)) {
  67     FLAG_SET_DEFAULT(InlineSmallCode, 2500);
  68   }
  69 #endif
  70 
  71   set_increase_threshold_at_ratio();
  72   set_start_time(os::javaTimeMillis());
  73 }
  74 
  75 // update_rate() is called from select_task() while holding a compile queue lock.
  76 void AdvancedThresholdPolicy::update_rate(jlong t, Method* m) {
  77   JavaThread* THREAD = JavaThread::current();
  78   if (is_old(m)) {
  79     // We don't remove old methods from the queue,
  80     // so we can just zero the rate.
  81     m->set_rate(0, THREAD);
  82     return;
  83   }
  84 
  85   // We don't update the rate if we've just came out of a safepoint.
  86   // delta_s is the time since last safepoint in milliseconds.
  87   jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint();
  88   jlong delta_t = t - (m->prev_time() != 0 ? m->prev_time() : start_time()); // milliseconds since the last measurement
  89   // How many events were there since the last time?
  90   int event_count = m->invocation_count() + m->backedge_count();
  91   int delta_e = event_count - m->prev_event_count();


 188       }
 189     }
 190     task = next_task;
 191   }
 192 
 193   if (max_task->comp_level() == CompLevel_full_profile && TieredStopAtLevel > CompLevel_full_profile
 194       && is_method_profiled(max_method)) {
 195     max_task->set_comp_level(CompLevel_limited_profile);
 196     if (PrintTieredEvents) {
 197       print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
 198     }
 199   }
 200 
 201   return max_task;
 202 }
 203 
 204 double AdvancedThresholdPolicy::threshold_scale(CompLevel level, int feedback_k) {
 205   double queue_size = CompileBroker::queue_size(level);
 206   int comp_count = compiler_count(level);
 207   double k = queue_size / (feedback_k * comp_count) + 1;
 208 
 209   // Increase C1 compile threshold when the code cache is filled more
 210   // than specified by IncreaseFirstTierCompileThresholdAt percentage.
 211   // The main intention is to keep enough free space for C2 compiled code
 212   // to achieve peak performance if the code cache is under stress.
 213   if ((TieredStopAtLevel == CompLevel_full_optimization) && (level != CompLevel_full_optimization))  {
 214     double current_reverse_free_ratio = CodeCache::reverse_free_ratio();
 215     if (current_reverse_free_ratio > _increase_threshold_at_ratio) {
 216       k *= exp(current_reverse_free_ratio - _increase_threshold_at_ratio);
 217     }
 218   }
 219   return k;
 220 }
 221 
 222 // Call and loop predicates determine whether a transition to a higher
 223 // compilation level should be performed (pointers to predicate functions
 224 // are passed to common()).
 225 // Tier?LoadFeedback is basically a coefficient that determines of
 226 // how many methods per compiler thread can be in the queue before
 227 // the threshold values double.
 228 bool AdvancedThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) {
 229   switch(cur_level) {
 230   case CompLevel_none:
 231   case CompLevel_limited_profile: {
 232     double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback);
 233     return loop_predicate_helper<CompLevel_none>(i, b, k);
 234   }
 235   case CompLevel_full_profile: {
 236     double k = threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback);
 237     return loop_predicate_helper<CompLevel_full_profile>(i, b, k);
 238   }