174 if (PrintTieredEvents) {
175 print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level());
176 }
177 CompileTaskWrapper ctw(task); // Frees the task
178 compile_queue->remove(task);
179 method->clear_queued_for_compilation();
180 task = next_task;
181 continue;
182 }
183
184 // Select a method with a higher rate
185 if (compare_methods(method, max_method)) {
186 max_task = task;
187 max_method = method;
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 }
380 }
381 break;
382 case CompLevel_full_profile:
383 {
384 MethodData* mdo = method->method_data();
385 if (mdo != NULL) {
386 if (mdo->would_profile()) {
387 int mdo_i = mdo->invocation_count_delta();
388 int mdo_b = mdo->backedge_count_delta();
389 if ((this->*p)(mdo_i, mdo_b, cur_level)) {
390 next_level = CompLevel_full_optimization;
391 }
392 } else {
393 next_level = CompLevel_full_optimization;
394 }
395 }
396 }
397 break;
398 }
399 }
400 return MIN2(next_level, (CompLevel)TieredStopAtLevel);
401 }
402
403 // Determine if a method should be compiled with a normal entry point at a different level.
404 CompLevel AdvancedThresholdPolicy::call_event(Method* method, CompLevel cur_level) {
405 CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
406 common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true));
407 CompLevel next_level = common(&AdvancedThresholdPolicy::call_predicate, method, cur_level);
408
409 // If OSR method level is greater than the regular method level, the levels should be
410 // equalized by raising the regular method level in order to avoid OSRs during each
411 // invocation of the method.
412 if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
413 MethodData* mdo = method->method_data();
414 guarantee(mdo != NULL, "MDO should not be NULL");
415 if (mdo->invocation_count() >= 1) {
416 next_level = CompLevel_full_optimization;
417 }
418 } else {
419 next_level = MAX2(osr_level, next_level);
420 }
|
174 if (PrintTieredEvents) {
175 print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level());
176 }
177 CompileTaskWrapper ctw(task); // Frees the task
178 compile_queue->remove(task);
179 method->clear_queued_for_compilation();
180 task = next_task;
181 continue;
182 }
183
184 // Select a method with a higher rate
185 if (compare_methods(method, max_method)) {
186 max_task = task;
187 max_method = method;
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) && !CodeCache::is_full(btMethodProfile)) {
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(CodeCache::get_code_blob_type(level));
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 }
380 }
381 break;
382 case CompLevel_full_profile:
383 {
384 MethodData* mdo = method->method_data();
385 if (mdo != NULL) {
386 if (mdo->would_profile()) {
387 int mdo_i = mdo->invocation_count_delta();
388 int mdo_b = mdo->backedge_count_delta();
389 if ((this->*p)(mdo_i, mdo_b, cur_level)) {
390 next_level = CompLevel_full_optimization;
391 }
392 } else {
393 next_level = CompLevel_full_optimization;
394 }
395 }
396 }
397 break;
398 }
399 }
400
401 next_level = MIN2(next_level, (CompLevel)TieredStopAtLevel);
402
403 if (CodeCache::is_full(CodeCache::get_code_blob_type(next_level))) {
404 // The CodeHeap for next_level is full, stay at current level
405 return cur_level;
406 }
407 return next_level;
408 }
409
410 // Determine if a method should be compiled with a normal entry point at a different level.
411 CompLevel AdvancedThresholdPolicy::call_event(Method* method, CompLevel cur_level) {
412 CompLevel osr_level = MIN2((CompLevel) method->highest_osr_comp_level(),
413 common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true));
414 CompLevel next_level = common(&AdvancedThresholdPolicy::call_predicate, method, cur_level);
415
416 // If OSR method level is greater than the regular method level, the levels should be
417 // equalized by raising the regular method level in order to avoid OSRs during each
418 // invocation of the method.
419 if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
420 MethodData* mdo = method->method_data();
421 guarantee(mdo != NULL, "MDO should not be NULL");
422 if (mdo->invocation_count() >= 1) {
423 next_level = CompLevel_full_optimization;
424 }
425 } else {
426 next_level = MAX2(osr_level, next_level);
427 }
|