174 }
175 return false;
176 }
177
178 // Called with the queue locked and with at least one element
179 CompileTask* AdvancedThresholdPolicy::select_task(CompileQueue* compile_queue) {
180 CompileTask *max_blocking_task = NULL;
181 CompileTask *max_task = NULL;
182 Method* max_method = NULL;
183 jlong t = os::javaTimeMillis();
184 // Iterate through the queue and find a method with a maximum rate.
185 for (CompileTask* task = compile_queue->first(); task != NULL;) {
186 CompileTask* next_task = task->next();
187 Method* method = task->method();
188 update_rate(t, method);
189 if (max_task == NULL) {
190 max_task = task;
191 max_method = method;
192 } else {
193 // If a method has been stale for some time, remove it from the queue.
194 // Blocking tasks don't become stale
195 if (!task->is_blocking() && is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) {
196 if (PrintTieredEvents) {
197 print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level());
198 }
199 task->log_task_dequeued("stale");
200 compile_queue->remove_and_mark_stale(task);
201 method->clear_queued_for_compilation();
202 task = next_task;
203 continue;
204 }
205
206 // Select a method with a higher rate
207 if (compare_methods(method, max_method)) {
208 max_task = task;
209 max_method = method;
210 }
211 }
212
213 if (task->is_blocking()) {
214 if (max_blocking_task == NULL || compare_methods(method, max_blocking_task->method())) {
215 max_blocking_task = task;
474 }
475
476 // Determine if we should do an OSR compilation of a given method.
477 CompLevel AdvancedThresholdPolicy::loop_event(Method* method, CompLevel cur_level) {
478 CompLevel next_level = common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true);
479 if (cur_level == CompLevel_none) {
480 // If there is a live OSR method that means that we deopted to the interpreter
481 // for the transition.
482 CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
483 if (osr_level > CompLevel_none) {
484 return osr_level;
485 }
486 }
487 return next_level;
488 }
489
490 // Update the rate and submit compile
491 void AdvancedThresholdPolicy::submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread) {
492 int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
493 update_rate(os::javaTimeMillis(), mh());
494 CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", thread);
495 }
496
497 // Handle the invocation event.
498 void AdvancedThresholdPolicy::method_invocation_event(const methodHandle& mh, const methodHandle& imh,
499 CompLevel level, nmethod* nm, JavaThread* thread) {
500 if (should_create_mdo(mh(), level)) {
501 create_mdo(mh, thread);
502 }
503 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
504 CompLevel next_level = call_event(mh(), level);
505 if (next_level != level) {
506 compile(mh, InvocationEntryBci, next_level, thread);
507 }
508 }
509 }
510
511 // Handle the back branch event. Notice that we can compile the method
512 // with a regular entry from here.
513 void AdvancedThresholdPolicy::method_back_branch_event(const methodHandle& mh, const methodHandle& imh,
514 int bci, CompLevel level, nmethod* nm, JavaThread* thread) {
|
174 }
175 return false;
176 }
177
178 // Called with the queue locked and with at least one element
179 CompileTask* AdvancedThresholdPolicy::select_task(CompileQueue* compile_queue) {
180 CompileTask *max_blocking_task = NULL;
181 CompileTask *max_task = NULL;
182 Method* max_method = NULL;
183 jlong t = os::javaTimeMillis();
184 // Iterate through the queue and find a method with a maximum rate.
185 for (CompileTask* task = compile_queue->first(); task != NULL;) {
186 CompileTask* next_task = task->next();
187 Method* method = task->method();
188 update_rate(t, method);
189 if (max_task == NULL) {
190 max_task = task;
191 max_method = method;
192 } else {
193 // If a method has been stale for some time, remove it from the queue.
194 // Blocking tasks and tasks submitted from whitebox API don't become stale
195 if (task->can_become_stale() && is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) {
196 if (PrintTieredEvents) {
197 print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level());
198 }
199 task->log_task_dequeued("stale");
200 compile_queue->remove_and_mark_stale(task);
201 method->clear_queued_for_compilation();
202 task = next_task;
203 continue;
204 }
205
206 // Select a method with a higher rate
207 if (compare_methods(method, max_method)) {
208 max_task = task;
209 max_method = method;
210 }
211 }
212
213 if (task->is_blocking()) {
214 if (max_blocking_task == NULL || compare_methods(method, max_blocking_task->method())) {
215 max_blocking_task = task;
474 }
475
476 // Determine if we should do an OSR compilation of a given method.
477 CompLevel AdvancedThresholdPolicy::loop_event(Method* method, CompLevel cur_level) {
478 CompLevel next_level = common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level, true);
479 if (cur_level == CompLevel_none) {
480 // If there is a live OSR method that means that we deopted to the interpreter
481 // for the transition.
482 CompLevel osr_level = MIN2((CompLevel)method->highest_osr_comp_level(), next_level);
483 if (osr_level > CompLevel_none) {
484 return osr_level;
485 }
486 }
487 return next_level;
488 }
489
490 // Update the rate and submit compile
491 void AdvancedThresholdPolicy::submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread) {
492 int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
493 update_rate(os::javaTimeMillis(), mh());
494 CompileBroker::compile_method(mh, bci, level, mh, hot_count, CompileTask::Reason_Tiered, thread);
495 }
496
497 // Handle the invocation event.
498 void AdvancedThresholdPolicy::method_invocation_event(const methodHandle& mh, const methodHandle& imh,
499 CompLevel level, nmethod* nm, JavaThread* thread) {
500 if (should_create_mdo(mh(), level)) {
501 create_mdo(mh, thread);
502 }
503 if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh)) {
504 CompLevel next_level = call_event(mh(), level);
505 if (next_level != level) {
506 compile(mh, InvocationEntryBci, next_level, thread);
507 }
508 }
509 }
510
511 // Handle the back branch event. Notice that we can compile the method
512 // with a regular entry from here.
513 void AdvancedThresholdPolicy::method_back_branch_event(const methodHandle& mh, const methodHandle& imh,
514 int bci, CompLevel level, nmethod* nm, JavaThread* thread) {
|