src/share/vm/runtime/advancedThresholdPolicy.cpp

Print this page




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







 200     task = next_task;
 201   }
 202 
 203 #if INCLUDE_JVMCI
 204   if (UseJVMCICompiler) {
 205     if (max_non_jvmci_task != NULL) {
 206       max_task = max_non_jvmci_task;





 207       max_method = max_task->method();
 208     }
 209   }
 210 #endif
 211 
 212   if (max_task->comp_level() == CompLevel_full_profile && TieredStopAtLevel > CompLevel_full_profile
 213       && is_method_profiled(max_method)) {
 214     max_task->set_comp_level(CompLevel_limited_profile);
 215     if (PrintTieredEvents) {
 216       print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
 217     }
 218   }
 219 
 220   return max_task;
 221 }
 222 
 223 double AdvancedThresholdPolicy::threshold_scale(CompLevel level, int feedback_k) {
 224   double queue_size = CompileBroker::queue_size(level);
 225   int comp_count = compiler_count(level);
 226   double k = queue_size / (feedback_k * comp_count) + 1;




 148         return true;
 149       }
 150     }
 151   return false;
 152 }
 153 
 154 // Is method profiled enough?
 155 bool AdvancedThresholdPolicy::is_method_profiled(Method* method) {
 156   MethodData* mdo = method->method_data();
 157   if (mdo != NULL) {
 158     int i = mdo->invocation_count_delta();
 159     int b = mdo->backedge_count_delta();
 160     return call_predicate_helper<CompLevel_full_profile>(i, b, 1, method);
 161   }
 162   return false;
 163 }
 164 
 165 // Called with the queue locked and with at least one element
 166 CompileTask* AdvancedThresholdPolicy::select_task(CompileQueue* compile_queue) {
 167 #if INCLUDE_JVMCI
 168   CompileTask *max_blocking_task = NULL;
 169 #endif
 170   CompileTask *max_task = NULL;
 171   Method* max_method = NULL;
 172   jlong t = os::javaTimeMillis();
 173   // Iterate through the queue and find a method with a maximum rate.
 174   for (CompileTask* task = compile_queue->first(); task != NULL;) {
 175     CompileTask* next_task = task->next();
 176     Method* method = task->method();
 177     update_rate(t, method);
 178     if (max_task == NULL) {
 179       max_task = task;
 180       max_method = method;
 181     } else {
 182       // If a method has been stale for some time, remove it from the queue.
 183       if (is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) {
 184         if (PrintTieredEvents) {
 185           print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level());
 186         }
 187         task->log_task_dequeued("stale");
 188         compile_queue->remove_and_mark_stale(task);
 189         method->clear_queued_for_compilation();
 190         task = next_task;
 191         continue;
 192       }
 193 
 194       // Select a method with a higher rate
 195       if (compare_methods(method, max_method)) {
 196         max_task = task;
 197         max_method = method;
 198       }
 199     }
 200 #ifdef INCLUDE_JVMCI
 201     if (UseJVMCICompiler && task->is_blocking()) {
 202       if (max_blocking_task == NULL || compare_methods(method, max_blocking_task->method())) {
 203         max_blocking_task = task;
 204       }
 205     }
 206 #endif
 207     task = next_task;
 208   }
 209 
 210 #if INCLUDE_JVMCI
 211   if (UseJVMCICompiler) {
 212     if (max_blocking_task != NULL) {
 213       // In blocking compilation mode, the CompileBroker will make
 214       // compilations submitted by a JVMCI compiler thread non-blocking. These
 215       // compilations should be scheduled after all blocking compilations
 216       // to service non-compiler related compilations sooner and reduce the
 217       // chance of such compilations timing out.
 218       max_task = max_blocking_task;
 219       max_method = max_task->method();
 220     }
 221   }
 222 #endif
 223 
 224   if (max_task->comp_level() == CompLevel_full_profile && TieredStopAtLevel > CompLevel_full_profile
 225       && is_method_profiled(max_method)) {
 226     max_task->set_comp_level(CompLevel_limited_profile);
 227     if (PrintTieredEvents) {
 228       print_event(UPDATE_IN_QUEUE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
 229     }
 230   }
 231 
 232   return max_task;
 233 }
 234 
 235 double AdvancedThresholdPolicy::threshold_scale(CompLevel level, int feedback_k) {
 236   double queue_size = CompileBroker::queue_size(level);
 237   int comp_count = compiler_count(level);
 238   double k = queue_size / (feedback_k * comp_count) + 1;