@@ -759,6 +759,16 @@ bool GetOptimizedCodeLater(CompilationJob* job) {
759759 CompilationInfo* info = job->info ();
760760 Isolate* isolate = info->isolate ();
761761
762+ if (FLAG_mark_optimizing_shared_functions &&
763+ info->closure ()->shared ()->has_concurrent_optimization_job ()) {
764+ if (FLAG_trace_concurrent_recompilation) {
765+ PrintF (" ** Compilation job already running for " );
766+ info->shared_info ()->ShortPrint ();
767+ PrintF (" .\n " );
768+ }
769+ return false ;
770+ }
771+
762772 if (!isolate->optimizing_compile_dispatcher ()->IsQueueAvailable ()) {
763773 if (FLAG_trace_concurrent_recompilation) {
764774 PrintF (" ** Compilation queue full, will retry optimizing " );
@@ -793,6 +803,7 @@ bool GetOptimizedCodeLater(CompilationJob* job) {
793803
794804 if (job->PrepareJob () != CompilationJob::SUCCEEDED) return false ;
795805 isolate->optimizing_compile_dispatcher ()->QueueForOptimization (job);
806+ info->closure ()->shared ()->set_has_concurrent_optimization_job (true );
796807
797808 if (FLAG_trace_concurrent_recompilation) {
798809 PrintF (" ** Queued " );
@@ -813,9 +824,6 @@ MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
813824 DCHECK_IMPLIES (ignition_osr, !osr_ast_id.IsNone ());
814825 DCHECK_IMPLIES (ignition_osr, FLAG_ignition_osr);
815826
816- // Shared function no longer needs to be tiered up
817- shared->set_marked_for_tier_up (false );
818-
819827 Handle<Code> cached_code;
820828 // TODO(4764): When compiling for OSR from bytecode, BailoutId might derive
821829 // from bytecode offset and overlap with actual BailoutId. No lookup!
@@ -928,6 +936,13 @@ MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
928936 return MaybeHandle<Code>();
929937}
930938
939+ MaybeHandle<Code> GetOptimizedCodeMaybeLater (Handle<JSFunction> function) {
940+ Isolate* isolate = function->GetIsolate ();
941+ return GetOptimizedCode (function, isolate->concurrent_recompilation_enabled ()
942+ ? Compiler::CONCURRENT
943+ : Compiler::NOT_CONCURRENT);
944+ }
945+
931946CompilationJob::Status FinalizeOptimizedCompilationJob (CompilationJob* job) {
932947 CompilationInfo* info = job->info ();
933948 Isolate* isolate = info->isolate ();
@@ -947,6 +962,11 @@ CompilationJob::Status FinalizeOptimizedCompilationJob(CompilationJob* job) {
947962 shared->set_profiler_ticks (0 );
948963 }
949964
965+ shared->set_has_concurrent_optimization_job (false );
966+
967+ // Shared function no longer needs to be tiered up.
968+ shared->set_marked_for_tier_up (false );
969+
950970 DCHECK (!shared->HasDebugInfo ());
951971
952972 // 1) Optimization on the concurrent thread may have failed.
@@ -1094,9 +1114,7 @@ MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) {
10941114 }
10951115
10961116 Handle<Code> code;
1097- // TODO(leszeks): Look into performing this compilation concurrently.
1098- if (GetOptimizedCode (function, Compiler::NOT_CONCURRENT)
1099- .ToHandle (&code)) {
1117+ if (GetOptimizedCodeMaybeLater (function).ToHandle (&code)) {
11001118 return code;
11011119 }
11021120 break ;
0 commit comments