From 28385dc9c08f99b4b4af09a0667c02a69cb83532 Mon Sep 17 00:00:00 2001 From: "mstarzinger@chromium.org" Date: Mon, 22 Sep 2014 12:32:47 +0000 Subject: [PATCH] Fix profiler for TurboFan by reducing duplication. R=titzer@chromium.org Review URL: https://codereview.chromium.org/592703002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24115 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compiler.cc | 249 ++++++++++++++++++++++++++------------------------------ 1 file changed, 115 insertions(+), 134 deletions(-) diff --git a/src/compiler.cc b/src/compiler.cc index 685009e..c605f66 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -325,10 +325,6 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() { DCHECK(info()->IsOptimizing()); DCHECK(!info()->IsCompilingForDebugging()); - // We should never arrive here if there is no code object on the - // shared function object. - DCHECK(info()->shared_info()->code()->kind() == Code::FUNCTION); - // We should never arrive here if optimization has been disabled on the // shared function info. DCHECK(!info()->shared_info()->optimization_disabled()); @@ -396,7 +392,8 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() { DCHECK(info()->shared_info()->has_deoptimization_support()); // Check the whitelist for TurboFan. - if (info()->closure()->PassesFilter(FLAG_turbo_filter)) { + if ((FLAG_turbo_asm && info()->shared_info()->asm_function()) || + info()->closure()->PassesFilter(FLAG_turbo_filter)) { compiler::Pipeline pipeline(info()); pipeline.GenerateCode(); if (!info()->code().is_null()) { @@ -704,6 +701,117 @@ MUST_USE_RESULT static MaybeHandle GetUnoptimizedCodeCommon( } +MUST_USE_RESULT static MaybeHandle GetCodeFromOptimizedCodeMap( + Handle function, BailoutId osr_ast_id) { + if (FLAG_cache_optimized_code) { + Handle shared(function->shared()); + // Bound functions are not cached. + if (shared->bound()) return MaybeHandle(); + DisallowHeapAllocation no_gc; + int index = shared->SearchOptimizedCodeMap( + function->context()->native_context(), osr_ast_id); + if (index > 0) { + if (FLAG_trace_opt) { + PrintF("[found optimized code for "); + function->ShortPrint(); + if (!osr_ast_id.IsNone()) { + PrintF(" at OSR AST id %d", osr_ast_id.ToInt()); + } + PrintF("]\n"); + } + FixedArray* literals = shared->GetLiteralsFromOptimizedCodeMap(index); + if (literals != NULL) function->set_literals(literals); + return Handle(shared->GetCodeFromOptimizedCodeMap(index)); + } + } + return MaybeHandle(); +} + + +static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { + Handle code = info->code(); + if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. + + // Context specialization folds-in the context, so no sharing can occur. + if (code->is_turbofanned() && info->is_context_specializing()) return; + + // Cache optimized code. + if (FLAG_cache_optimized_code) { + Handle function = info->closure(); + Handle shared(function->shared()); + // Do not cache bound functions. + if (shared->bound()) return; + Handle literals(function->literals()); + Handle native_context(function->context()->native_context()); + SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, + literals, info->osr_ast_id()); + } +} + + +static bool CompileOptimizedPrologue(CompilationInfo* info) { + if (!Parser::Parse(info)) return false; + if (!Rewriter::Rewrite(info)) return false; + if (!Scope::Analyze(info)) return false; + DCHECK(info->scope() != NULL); + return true; +} + + +static bool GetOptimizedCodeNow(CompilationInfo* info) { + if (!CompileOptimizedPrologue(info)) return false; + + TimerEventScope timer(info->isolate()); + + OptimizedCompileJob job(info); + if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED) return false; + if (job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED) return false; + if (job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) return false; + + // Success! + DCHECK(!info->isolate()->has_pending_exception()); + InsertCodeIntoOptimizedCodeMap(info); + RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, + info->shared_info()); + return true; +} + + +static bool GetOptimizedCodeLater(CompilationInfo* info) { + Isolate* isolate = info->isolate(); + if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { + if (FLAG_trace_concurrent_recompilation) { + PrintF(" ** Compilation queue full, will retry optimizing "); + info->closure()->PrintName(); + PrintF(" later.\n"); + } + return false; + } + + CompilationHandleScope handle_scope(info); + if (!CompileOptimizedPrologue(info)) return false; + info->SaveHandles(); // Copy handles to the compilation handle scope. + + TimerEventScope timer(info->isolate()); + + OptimizedCompileJob* job = new (info->zone()) OptimizedCompileJob(info); + OptimizedCompileJob::Status status = job->CreateGraph(); + if (status != OptimizedCompileJob::SUCCEEDED) return false; + isolate->optimizing_compiler_thread()->QueueForOptimization(job); + + if (FLAG_trace_concurrent_recompilation) { + PrintF(" ** Queued "); + info->closure()->PrintName(); + if (info->is_osr()) { + PrintF(" for concurrent OSR at %d.\n", info->osr_ast_id().ToInt()); + } else { + PrintF(" for concurrent optimization.\n"); + } + } + return true; +} + + MaybeHandle Compiler::GetUnoptimizedCode(Handle function) { DCHECK(!function->GetIsolate()->has_pending_exception()); DCHECK(!function->is_compiled()); @@ -730,29 +838,14 @@ MaybeHandle Compiler::GetLazyCode(Handle function) { VMState state(info.isolate()); PostponeInterruptsScope postpone(info.isolate()); - if (FLAG_trace_opt) { - // TODO(titzer): record and report full stats here. - PrintF("[optimizing asm "); - function->ShortPrint(); - PrintF("]\n"); - } - - if (!Parser::Parse(&info)) return MaybeHandle(); - if (!Rewriter::Rewrite(&info)) return MaybeHandle(); - if (!Scope::Analyze(&info)) return MaybeHandle(); - if (FLAG_turbo_deoptimization && !EnsureDeoptimizationSupport(&info)) { - return MaybeHandle(); - } - info.SetOptimizing(BailoutId::None(), Handle(function->shared()->code())); info.MarkAsContextSpecializing(); info.MarkAsTypingEnabled(); info.MarkAsInliningDisabled(); - compiler::Pipeline pipeline(&info); - pipeline.GenerateCode(); - if (!info.code().is_null()) return info.code(); + + if (GetOptimizedCodeNow(&info)) return info.code(); } if (function->shared()->is_compiled()) { @@ -1209,118 +1302,6 @@ Handle Compiler::BuildFunctionInfo( } -MUST_USE_RESULT static MaybeHandle GetCodeFromOptimizedCodeMap( - Handle function, - BailoutId osr_ast_id) { - if (FLAG_cache_optimized_code) { - Handle shared(function->shared()); - // Bound functions are not cached. - if (shared->bound()) return MaybeHandle(); - DisallowHeapAllocation no_gc; - int index = shared->SearchOptimizedCodeMap( - function->context()->native_context(), osr_ast_id); - if (index > 0) { - if (FLAG_trace_opt) { - PrintF("[found optimized code for "); - function->ShortPrint(); - if (!osr_ast_id.IsNone()) { - PrintF(" at OSR AST id %d", osr_ast_id.ToInt()); - } - PrintF("]\n"); - } - FixedArray* literals = shared->GetLiteralsFromOptimizedCodeMap(index); - if (literals != NULL) function->set_literals(literals); - return Handle(shared->GetCodeFromOptimizedCodeMap(index)); - } - } - return MaybeHandle(); -} - - -static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { - Handle code = info->code(); - if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. - - // Context specialization folds-in the context, so no sharing can occur. - if (code->is_turbofanned() && info->is_context_specializing()) return; - - // Cache optimized code. - if (FLAG_cache_optimized_code) { - Handle function = info->closure(); - Handle shared(function->shared()); - // Do not cache bound functions. - if (shared->bound()) return; - Handle literals(function->literals()); - Handle native_context(function->context()->native_context()); - SharedFunctionInfo::AddToOptimizedCodeMap( - shared, native_context, code, literals, info->osr_ast_id()); - } -} - - -static bool CompileOptimizedPrologue(CompilationInfo* info) { - if (!Parser::Parse(info)) return false; - if (!Rewriter::Rewrite(info)) return false; - if (!Scope::Analyze(info)) return false; - DCHECK(info->scope() != NULL); - return true; -} - - -static bool GetOptimizedCodeNow(CompilationInfo* info) { - if (!CompileOptimizedPrologue(info)) return false; - - TimerEventScope timer(info->isolate()); - - OptimizedCompileJob job(info); - if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED) return false; - if (job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED) return false; - if (job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) return false; - - // Success! - DCHECK(!info->isolate()->has_pending_exception()); - InsertCodeIntoOptimizedCodeMap(info); - RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, - info->shared_info()); - return true; -} - - -static bool GetOptimizedCodeLater(CompilationInfo* info) { - Isolate* isolate = info->isolate(); - if (!isolate->optimizing_compiler_thread()->IsQueueAvailable()) { - if (FLAG_trace_concurrent_recompilation) { - PrintF(" ** Compilation queue full, will retry optimizing "); - info->closure()->PrintName(); - PrintF(" later.\n"); - } - return false; - } - - CompilationHandleScope handle_scope(info); - if (!CompileOptimizedPrologue(info)) return false; - info->SaveHandles(); // Copy handles to the compilation handle scope. - - TimerEventScope timer(info->isolate()); - - OptimizedCompileJob* job = new(info->zone()) OptimizedCompileJob(info); - OptimizedCompileJob::Status status = job->CreateGraph(); - if (status != OptimizedCompileJob::SUCCEEDED) return false; - isolate->optimizing_compiler_thread()->QueueForOptimization(job); - - if (FLAG_trace_concurrent_recompilation) { - PrintF(" ** Queued "); - info->closure()->PrintName(); - if (info->is_osr()) { - PrintF(" for concurrent OSR at %d.\n", info->osr_ast_id().ToInt()); - } else { - PrintF(" for concurrent optimization.\n"); - } - } - return true; -} - - MaybeHandle Compiler::GetOptimizedCode(Handle function, Handle current_code, ConcurrencyMode mode, -- 2.7.4