Index: runtime/vm/code_generator.cc |
diff --git a/runtime/vm/code_generator.cc b/runtime/vm/code_generator.cc |
index 41175a72f4e4da6ec19ea601d977ff216b75549a..4ab89ca6e7260fe4025b94ac6fff64b7ad9b8468 100644 |
--- a/runtime/vm/code_generator.cc |
+++ b/runtime/vm/code_generator.cc |
@@ -1448,10 +1448,12 @@ DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { |
ASSERT(function.HasCode()); |
if (CanOptimizeFunction(function, isolate)) { |
- // Reset usage counter for reoptimization before calling optimizer to |
- // prevent recursive triggering of function optimization. |
- function.set_usage_counter(0); |
if (FLAG_background_compilation) { |
+ // Reduce the chance of triggering optimization while the function is |
+ // being optimized in the background. INT_MIN should ensure that it takes |
+ // long time to trigger optimization. |
+ // Note that the background compilation queue rejects duplicate entries. |
+ function.set_usage_counter(INT_MIN); |
BackgroundCompiler::EnsureInit(thread); |
ASSERT(isolate->background_compiler() != NULL); |
isolate->background_compiler()->CompileOptimized(function); |
@@ -1459,6 +1461,10 @@ DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { |
arguments.SetReturn(Code::Handle(zone, function.CurrentCode())); |
return; |
} |
+ |
+ // Reset usage counter for reoptimization before calling optimizer to |
+ // prevent recursive triggering of function optimization. |
+ function.set_usage_counter(0); |
if (FLAG_trace_compiler) { |
if (function.HasOptimizedCode()) { |
THR_Print("ReCompiling function: '%s' \n", |