Commit 8ab9080d authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[compiler] Mark shared functions which have an optimization job (reland)

Marking shared functions for tier-up was optimizing the functions
non-concurrently, to avoid the case where the same shared function is
optimized concurrently by multiple JS functions. This was particularly a
problem for small functions, which (if called in a loop) could get
marked for optimisation quite quickly.

In this CL, the shared function is instead marked as having an active
optimization job running, and these do not spawn a compilation job.

BUG=chromium:693590
BUG=chromium:700863
BUG=chromium:701665

Change-Id: I2b1c5af8e7aa8d779f86814c22c65c78bee0630f
Reviewed-on: https://chromium-review.googlesource.com/455779Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43833}
parent 3db32e06
......@@ -759,6 +759,16 @@ bool GetOptimizedCodeLater(CompilationJob* job) {
CompilationInfo* info = job->info();
Isolate* isolate = info->isolate();
if (FLAG_mark_optimizing_shared_functions &&
info->closure()->shared()->has_concurrent_optimization_job()) {
if (FLAG_trace_concurrent_recompilation) {
PrintF(" ** Compilation job already running for ");
info->shared_info()->ShortPrint();
PrintF(".\n");
}
return false;
}
if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) {
if (FLAG_trace_concurrent_recompilation) {
PrintF(" ** Compilation queue full, will retry optimizing ");
......@@ -793,6 +803,7 @@ bool GetOptimizedCodeLater(CompilationJob* job) {
if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false;
isolate->optimizing_compile_dispatcher()->QueueForOptimization(job);
info->closure()->shared()->set_has_concurrent_optimization_job(true);
if (FLAG_trace_concurrent_recompilation) {
PrintF(" ** Queued ");
......@@ -813,9 +824,6 @@ MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
DCHECK_IMPLIES(ignition_osr, !osr_ast_id.IsNone());
DCHECK_IMPLIES(ignition_osr, FLAG_ignition_osr);
// Shared function no longer needs to be tiered up
shared->set_marked_for_tier_up(false);
Handle<Code> cached_code;
// TODO(4764): When compiling for OSR from bytecode, BailoutId might derive
// from bytecode offset and overlap with actual BailoutId. No lookup!
......@@ -928,6 +936,13 @@ MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
return MaybeHandle<Code>();
}
MaybeHandle<Code> GetOptimizedCodeMaybeLater(Handle<JSFunction> function) {
Isolate* isolate = function->GetIsolate();
return GetOptimizedCode(function, isolate->concurrent_recompilation_enabled()
? Compiler::CONCURRENT
: Compiler::NOT_CONCURRENT);
}
CompilationJob::Status FinalizeOptimizedCompilationJob(CompilationJob* job) {
CompilationInfo* info = job->info();
Isolate* isolate = info->isolate();
......@@ -947,6 +962,11 @@ CompilationJob::Status FinalizeOptimizedCompilationJob(CompilationJob* job) {
shared->set_profiler_ticks(0);
}
shared->set_has_concurrent_optimization_job(false);
// Shared function no longer needs to be tiered up.
shared->set_marked_for_tier_up(false);
DCHECK(!shared->HasDebugInfo());
// 1) Optimization on the concurrent thread may have failed.
......@@ -1094,9 +1114,7 @@ MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) {
}
Handle<Code> code;
// TODO(leszeks): Look into performing this compilation concurrently.
if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT)
.ToHandle(&code)) {
if (GetOptimizedCodeMaybeLater(function).ToHandle(&code)) {
return code;
}
break;
......
......@@ -277,6 +277,8 @@ DEFINE_BOOL(allocation_site_pretenuring, true,
"pretenure with allocation sites")
DEFINE_BOOL(mark_shared_functions_for_tier_up, true,
"mark shared functions for tier up")
DEFINE_BOOL(mark_optimizing_shared_functions, true,
"mark shared functions if they are concurrently optimizing")
DEFINE_BOOL(page_promotion, true, "promote pages based on utilization")
DEFINE_INT(page_promotion_threshold, 70,
"min percentage of live bytes on a page to enable fast evacuation")
......
......@@ -5971,6 +5971,8 @@ BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_declaration,
kIsDeclaration)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, marked_for_tier_up,
kMarkedForTierUp)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints,
has_concurrent_optimization_job, kHasConcurrentOptimizationJob)
BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, needs_home_object,
kNeedsHomeObject)
......
......@@ -7259,6 +7259,9 @@ class SharedFunctionInfo: public HeapObject {
// Whether this function was marked to be tiered up.
DECL_BOOLEAN_ACCESSORS(marked_for_tier_up)
// Whether this function has a concurrent compilation job running.
DECL_BOOLEAN_ACCESSORS(has_concurrent_optimization_job)
// Indicates that asm->wasm conversion failed and should not be re-attempted.
DECL_BOOLEAN_ACCESSORS(is_asm_wasm_broken)
......@@ -7541,9 +7544,9 @@ class SharedFunctionInfo: public HeapObject {
kDontFlush,
kIsDeclaration,
kIsAsmWasmBroken,
kHasConcurrentOptimizationJob,
kUnused1, // Unused fields.
kUnused2,
// byte 2
kFunctionKind,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment