@@ -2292,28 +2292,56 @@ DEFINE_RUNTIME_ENTRY(TraceICCall, 2) {
22922292 ic_data.NumberOfChecks (), function.ToFullyQualifiedCString ());
22932293}
22942294
2295+ // This is called from interpreter when function usage counter reached
2296+ // compilation threshold and function needs to be compiled.
2297+ DEFINE_RUNTIME_ENTRY (CompileInterpretedFunction, 1 ) {
2298+ #if !defined(DART_PRECOMPILED_RUNTIME)
2299+ const Function& function = Function::CheckedHandle (zone, arguments.ArgAt (0 ));
2300+ ASSERT (!function.IsNull ());
2301+ ASSERT (FLAG_enable_interpreter);
2302+
2303+ #if !defined(PRODUCT)
2304+ if (Debugger::IsDebugging (thread, function)) {
2305+ return ;
2306+ }
2307+ #endif // !defined(PRODUCT)
2308+
2309+ if (FLAG_background_compilation) {
2310+ if (!BackgroundCompiler::IsDisabled (isolate,
2311+ /* optimizing_compilation = */ false ) &&
2312+ function.is_background_optimizable ()) {
2313+ // Ensure background compiler is running, if not start it.
2314+ BackgroundCompiler::Start (isolate);
2315+ // Reduce the chance of triggering a compilation while the function is
2316+ // being compiled in the background. INT_MIN should ensure that it
2317+ // takes long time to trigger a compilation.
2318+ // Note that the background compilation queue rejects duplicate entries.
2319+ function.SetUsageCounter (INT_MIN);
2320+ isolate->background_compiler ()->Compile (function);
2321+ return ;
2322+ }
2323+ }
2324+
2325+ // Reset usage counter for future optimization.
2326+ function.SetUsageCounter (0 );
2327+ Object& result =
2328+ Object::Handle (zone, Compiler::CompileFunction (thread, function));
2329+ ThrowIfError (result);
2330+ #else
2331+ UNREACHABLE ();
2332+ #endif // !DART_PRECOMPILED_RUNTIME
2333+ }
2334+
22952335// This is called from function that needs to be optimized.
22962336// The requesting function can be already optimized (reoptimization).
22972337// Returns the Code object where to continue execution.
22982338DEFINE_RUNTIME_ENTRY (OptimizeInvokedFunction, 1 ) {
22992339#if !defined(DART_PRECOMPILED_RUNTIME)
23002340 const Function& function = Function::CheckedHandle (zone, arguments.ArgAt (0 ));
23012341 ASSERT (!function.IsNull ());
2342+ ASSERT (function.HasCode ());
23022343
2303- // If running with interpreter, do the unoptimized compilation first.
2304- const bool optimizing_compilation = function.ShouldCompilerOptimize ();
2305- ASSERT (FLAG_enable_interpreter || optimizing_compilation);
2306- ASSERT ((!optimizing_compilation) || function.HasCode () ||
2307- function.ForceOptimize ());
2308-
2309- #if defined(PRODUCT)
2310- if (!optimizing_compilation ||
2311- Compiler::CanOptimizeFunction (thread, function)) {
2312- #else
2313- if ((!optimizing_compilation && !Debugger::IsDebugging (thread, function)) ||
2314- (optimizing_compilation &&
2315- Compiler::CanOptimizeFunction (thread, function))) {
2316- #endif // defined(PRODUCT)
2344+ if (Compiler::CanOptimizeFunction (thread, function)) {
23172345 if (FLAG_background_compilation) {
23182346 if (FLAG_enable_inlining_annotations) {
23192347 FATAL (" Cannot enable inlining annotations and background compilation" );
@@ -2328,7 +2356,8 @@ DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) {
23282356 // Get next field.
23292357 field = isolate->GetDeoptimizingBoxedField ();
23302358 }
2331- if (!BackgroundCompiler::IsDisabled (isolate, optimizing_compilation) &&
2359+ if (!BackgroundCompiler::IsDisabled (isolate,
2360+ /* optimizing_compiler = */ true ) &&
23322361 function.is_background_optimizable ()) {
23332362 // Ensure background compiler is running, if not start it.
23342363 BackgroundCompiler::Start (isolate);
@@ -2337,12 +2366,7 @@ DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) {
23372366 // takes long time to trigger a compilation.
23382367 // Note that the background compilation queue rejects duplicate entries.
23392368 function.SetUsageCounter (INT_MIN);
2340- if (optimizing_compilation) {
2341- isolate->optimizing_background_compiler ()->Compile (function);
2342- } else {
2343- ASSERT (FLAG_enable_interpreter);
2344- isolate->background_compiler ()->Compile (function);
2345- }
2369+ isolate->optimizing_background_compiler ()->Compile (function);
23462370 // Continue in the same code.
23472371 arguments.SetReturn (function);
23482372 return ;
@@ -2358,12 +2382,8 @@ DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) {
23582382 function.ToFullyQualifiedCString ());
23592383 }
23602384 }
2361- Object& result = Object::Handle (zone);
2362- if (optimizing_compilation) {
2363- result = Compiler::CompileOptimizedFunction (thread, function);
2364- } else {
2365- result = Compiler::CompileFunction (thread, function);
2366- }
2385+ Object& result = Object::Handle (
2386+ zone, Compiler::CompileOptimizedFunction (thread, function));
23672387 ThrowIfError (result);
23682388 }
23692389 arguments.SetReturn (function);
0 commit comments