src/share/vm/runtime/advancedThresholdPolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/runtime

src/share/vm/runtime/advancedThresholdPolicy.cpp

Print this page
rev 6404 : 8023461: Thread holding lock at safepoint that vm can block on: MethodCompileQueue_lock
Reviewed-by: kvn, iveresov
rev 6405 : imported patch stale_task
rev 6406 : [mq]: stale_task.1


  58 
  59   // Some inlining tuning
  60 #ifdef X86
  61   if (FLAG_IS_DEFAULT(InlineSmallCode)) {
  62     FLAG_SET_DEFAULT(InlineSmallCode, 2000);
  63   }
  64 #endif
  65 
  66 #ifdef SPARC
  67   if (FLAG_IS_DEFAULT(InlineSmallCode)) {
  68     FLAG_SET_DEFAULT(InlineSmallCode, 2500);
  69   }
  70 #endif
  71 
  72   set_increase_threshold_at_ratio();
  73   set_start_time(os::javaTimeMillis());
  74 }
  75 
  76 // update_rate() is called from select_task() while holding a compile queue lock.
  77 void AdvancedThresholdPolicy::update_rate(jlong t, Method* m) {
  78   JavaThread* THREAD = JavaThread::current();



  79   if (is_old(m)) {
  80     // We don't remove old methods from the queue,
  81     // so we can just zero the rate.
  82     m->set_rate(0, THREAD);
  83     return;
  84   }
  85 
  86   // We don't update the rate if we've just came out of a safepoint.
  87   // delta_s is the time since last safepoint in milliseconds.
  88   jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint();
  89   jlong delta_t = t - (m->prev_time() != 0 ? m->prev_time() : start_time()); // milliseconds since the last measurement
  90   // How many events were there since the last time?
  91   int event_count = m->invocation_count() + m->backedge_count();
  92   int delta_e = event_count - m->prev_event_count();
  93 
  94   // We should be running for at least 1ms.
  95   if (delta_s >= TieredRateUpdateMinTime) {
  96     // And we must've taken the previous point at least 1ms before.
  97     if (delta_t >= TieredRateUpdateMinTime && delta_e > 0) {
  98       m->set_prev_time(t, THREAD);
  99       m->set_prev_event_count(event_count, THREAD);
 100       m->set_rate((float)delta_e / (float)delta_t, THREAD); // Rate is events per millisecond
 101     } else
 102       if (delta_t > TieredRateUpdateMaxTime && delta_e == 0) {
 103         // If nothing happened for 25ms, zero the rate. Don't modify prev values.
 104         m->set_rate(0, THREAD);

 105       }
 106   }
 107 }
 108 
 109 // Check if this method has been stale from a given number of milliseconds.
 110 // See select_task().
 111 bool AdvancedThresholdPolicy::is_stale(jlong t, jlong timeout, Method* m) {
 112   jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint();
 113   jlong delta_t = t - m->prev_time();
 114   if (delta_t > timeout && delta_s > timeout) {
 115     int event_count = m->invocation_count() + m->backedge_count();
 116     int delta_e = event_count - m->prev_event_count();
 117     // Return true if there were no events.
 118     return delta_e == 0;
 119   }
 120   return false;
 121 }
 122 
 123 // We don't remove old methods from the compile queue even if they have
 124 // very low activity. See select_task().


 147 // Is method profiled enough?
 148 bool AdvancedThresholdPolicy::is_method_profiled(Method* method) {
 149   MethodData* mdo = method->method_data();
 150   if (mdo != NULL) {
 151     int i = mdo->invocation_count_delta();
 152     int b = mdo->backedge_count_delta();
 153     return call_predicate_helper<CompLevel_full_profile>(i, b, 1);
 154   }
 155   return false;
 156 }
 157 
 158 // Called with the queue locked and with at least one element
 159 CompileTask* AdvancedThresholdPolicy::select_task(CompileQueue* compile_queue) {
 160   CompileTask *max_task = NULL;
 161   Method* max_method = NULL;
 162   jlong t = os::javaTimeMillis();
 163   // Iterate through the queue and find a method with a maximum rate.
 164   for (CompileTask* task = compile_queue->first(); task != NULL;) {
 165     CompileTask* next_task = task->next();
 166     Method* method = task->method();
 167     MethodData* mdo = method->method_data();
 168     update_rate(t, method);
 169     if (max_task == NULL) {
 170       max_task = task;
 171       max_method = method;
 172     } else {
 173       // If a method has been stale for some time, remove it from the queue.
 174       if (is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) {
 175         if (PrintTieredEvents) {
 176           print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level());
 177         }
 178         CompileTaskWrapper ctw(task); // Frees the task
 179         compile_queue->remove(task);
 180         method->clear_queued_for_compilation();
 181         task = next_task;
 182         continue;
 183       }
 184 
 185       // Select a method with a higher rate
 186       if (compare_methods(method, max_method)) {
 187         max_task = task;
 188         max_method = method;
 189       }
 190     }
 191     task = next_task;
 192   }
 193 
 194   if (max_task->comp_level() == CompLevel_full_profile && TieredStopAtLevel > CompLevel_full_profile
 195       && is_method_profiled(max_method)) {
 196     max_task->set_comp_level(CompLevel_limited_profile);
 197     if (PrintTieredEvents) {
 198       print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
 199     }




  58 
  59   // Some inlining tuning
  60 #ifdef X86
  61   if (FLAG_IS_DEFAULT(InlineSmallCode)) {
  62     FLAG_SET_DEFAULT(InlineSmallCode, 2000);
  63   }
  64 #endif
  65 
  66 #ifdef SPARC
  67   if (FLAG_IS_DEFAULT(InlineSmallCode)) {
  68     FLAG_SET_DEFAULT(InlineSmallCode, 2500);
  69   }
  70 #endif
  71 
  72   set_increase_threshold_at_ratio();
  73   set_start_time(os::javaTimeMillis());
  74 }
  75 
  76 // update_rate() is called from select_task() while holding a compile queue lock.
  77 void AdvancedThresholdPolicy::update_rate(jlong t, Method* m) {
  78   // Skip update if counters are absent.
  79   // Can't allocate them since we are holding compile queue lock.
  80   if (m->method_counters() == NULL)  return;
  81 
  82   if (is_old(m)) {
  83     // We don't remove old methods from the queue,
  84     // so we can just zero the rate.
  85     m->set_rate(0);
  86     return;
  87   }
  88 
  89   // We don't update the rate if we've just came out of a safepoint.
  90   // delta_s is the time since last safepoint in milliseconds.
  91   jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint();
  92   jlong delta_t = t - (m->prev_time() != 0 ? m->prev_time() : start_time()); // milliseconds since the last measurement
  93   // How many events were there since the last time?
  94   int event_count = m->invocation_count() + m->backedge_count();
  95   int delta_e = event_count - m->prev_event_count();
  96 
  97   // We should be running for at least 1ms.
  98   if (delta_s >= TieredRateUpdateMinTime) {
  99     // And we must've taken the previous point at least 1ms before.
 100     if (delta_t >= TieredRateUpdateMinTime && delta_e > 0) {
 101       m->set_prev_time(t);
 102       m->set_prev_event_count(event_count);
 103       m->set_rate((float)delta_e / (float)delta_t); // Rate is events per millisecond
 104     } else {
 105       if (delta_t > TieredRateUpdateMaxTime && delta_e == 0) {
 106         // If nothing happened for 25ms, zero the rate. Don't modify prev values.
 107         m->set_rate(0);
 108       }
 109     }
 110   }
 111 }
 112 
 113 // Check if this method has been stale from a given number of milliseconds.
 114 // See select_task().
 115 bool AdvancedThresholdPolicy::is_stale(jlong t, jlong timeout, Method* m) {
 116   jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint();
 117   jlong delta_t = t - m->prev_time();
 118   if (delta_t > timeout && delta_s > timeout) {
 119     int event_count = m->invocation_count() + m->backedge_count();
 120     int delta_e = event_count - m->prev_event_count();
 121     // Return true if there were no events.
 122     return delta_e == 0;
 123   }
 124   return false;
 125 }
 126 
 127 // We don't remove old methods from the compile queue even if they have
 128 // very low activity. See select_task().


 151 // Is method profiled enough?
 152 bool AdvancedThresholdPolicy::is_method_profiled(Method* method) {
 153   MethodData* mdo = method->method_data();
 154   if (mdo != NULL) {
 155     int i = mdo->invocation_count_delta();
 156     int b = mdo->backedge_count_delta();
 157     return call_predicate_helper<CompLevel_full_profile>(i, b, 1);
 158   }
 159   return false;
 160 }
 161 
 162 // Called with the queue locked and with at least one element
 163 CompileTask* AdvancedThresholdPolicy::select_task(CompileQueue* compile_queue) {
 164   CompileTask *max_task = NULL;
 165   Method* max_method = NULL;
 166   jlong t = os::javaTimeMillis();
 167   // Iterate through the queue and find a method with a maximum rate.
 168   for (CompileTask* task = compile_queue->first(); task != NULL;) {
 169     CompileTask* next_task = task->next();
 170     Method* method = task->method();

 171     update_rate(t, method);
 172     if (max_task == NULL) {
 173       max_task = task;
 174       max_method = method;
 175     } else {
 176       // If a method has been stale for some time, remove it from the queue.
 177       if (is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) {
 178         if (PrintTieredEvents) {
 179           print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level());
 180         }
 181         compile_queue->remove_and_mark_stale(task);

 182         method->clear_queued_for_compilation();
 183         task = next_task;
 184         continue;
 185       }
 186 
 187       // Select a method with a higher rate
 188       if (compare_methods(method, max_method)) {
 189         max_task = task;
 190         max_method = method;
 191       }
 192     }
 193     task = next_task;
 194   }
 195 
 196   if (max_task->comp_level() == CompLevel_full_profile && TieredStopAtLevel > CompLevel_full_profile
 197       && is_method_profiled(max_method)) {
 198     max_task->set_comp_level(CompLevel_limited_profile);
 199     if (PrintTieredEvents) {
 200       print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
 201     }


src/share/vm/runtime/advancedThresholdPolicy.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File