--- old/src/share/vm/runtime/advancedThresholdPolicy.cpp 2016-03-01 14:59:45.550117874 +0100 +++ new/src/share/vm/runtime/advancedThresholdPolicy.cpp 2016-03-01 14:59:45.446117870 +0100 @@ -24,6 +24,8 @@ #include "precompiled.hpp" #include "code/codeCache.hpp" +#include "compiler/compilerDirectives.hpp" +#include "compiler/compilerOracle.hpp" #include "compiler/compileTask.hpp" #include "runtime/advancedThresholdPolicy.hpp" #include "runtime/simpleThresholdPolicy.inline.hpp" @@ -179,10 +181,24 @@ max_task = task; max_method = method; } else { + // Prefer 'blocking' compilations to minimize waits on them. + // This also helps to prevent blocking compiles from getting stale. + CompLevel level = (CompLevel)task->comp_level(); + bool backgroundCompilation; + DirectiveSet* directive = + DirectivesStack::getMatchingDirective(methodHandle(method), + CompileBroker::compiler(level)); + backgroundCompilation = directive->BackgroundCompilationOption; + DirectivesStack::release(directive); + if (backgroundCompilation == false) { + max_task = task; + max_method = method; + break; + } // If a method has been stale for some time, remove it from the queue. if (is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) { if (PrintTieredEvents) { - print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), (CompLevel)task->comp_level()); + print_event(REMOVE_FROM_QUEUE, method, method, task->osr_bci(), level); } task->log_task_dequeued("stale"); compile_queue->remove_and_mark_stale(task);