From 85870e8698780ba836422b23f18e0d4b3d77133a Mon Sep 17 00:00:00 2001 From: mstarzinger Date: Wed, 20 Apr 2016 01:50:24 -0700 Subject: [PATCH] [compiler] Extract scope info installation into helper. This moves the installation of the scope info object on the shared function info into a separate helper to share common code. This is preparatory work in order to reuse existing scope info objects. R=bmeurer@chromium.org Review URL: https://codereview.chromium.org/1894023004 Cr-Commit-Position: refs/heads/master@{#35647} --- src/compiler.cc | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/compiler.cc b/src/compiler.cc index 1ff4a46e20..7912953ebc 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -558,14 +558,19 @@ bool CompileBaselineCode(CompilationInfo* info) { return true; } -void InstallBaselineCompilationResult(CompilationInfo* info, - Handle shared, - Handle scope_info) { +void InstallSharedScopeInfo(CompilationInfo* info, + Handle shared) { + Handle scope_info = + ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); + shared->set_scope_info(*scope_info); +} + +void InstallSharedCompilationResult(CompilationInfo* info, + Handle shared) { // Assert that we are not overwriting (possibly patched) debug code. DCHECK(!shared->HasDebugCode()); DCHECK(!info->code().is_null()); shared->ReplaceCode(*info->code()); - shared->set_scope_info(*scope_info); if (info->has_bytecode_array()) { DCHECK(!shared->HasBytecodeArray()); // Only compiled once. shared->set_bytecode_array(*info->bytecode_array()); @@ -585,13 +590,11 @@ MUST_USE_RESULT MaybeHandle GetUnoptimizedCode(CompilationInfo* info) { if (!CompileBaselineCode(info)) return MaybeHandle(); RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, shared); - // Update the shared function info with the scope info. Allocating the - // ScopeInfo object may cause a GC. - Handle scope_info = - ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); + // Update the shared function info with the scope info. + InstallSharedScopeInfo(info, shared); // Install compilation result on the shared function info - InstallBaselineCompilationResult(info, shared, scope_info); + InstallSharedCompilationResult(info, shared); return info->code(); } @@ -1014,10 +1017,11 @@ Handle CompileToplevel(CompilationInfo* info) { return Handle::null(); } + // Update the shared function info with the scope info. + InstallSharedScopeInfo(info, result); + // Install compilation result on the shared function info - Handle scope_info = - ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); - InstallBaselineCompilationResult(info, result, scope_info); + InstallSharedCompilationResult(info, result); Handle script_name = script->name()->IsString() @@ -1212,9 +1216,7 @@ bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { // The scope info might not have been set if a lazily compiled // function is inlined before being called for the first time. if (shared->scope_info() == ScopeInfo::Empty(info->isolate())) { - Handle target_scope_info = - ScopeInfo::Create(info->isolate(), info->zone(), info->scope()); - shared->set_scope_info(*target_scope_info); + InstallSharedScopeInfo(info, shared); } // The existing unoptimized code was replaced with the new one. @@ -1533,14 +1535,14 @@ Handle Compiler::GetSharedFunctionInfo( // Code generation will ensure that the feedback vector is present and // appropriately sized. DCHECK(!info.code().is_null()); - Handle scope_info = - ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); if (literal->should_eager_compile() && literal->should_be_used_once_hint()) { info.code()->MarkToBeExecutedOnce(isolate); } + // Update the shared function info with the scope info. + InstallSharedScopeInfo(&info, result); // Install compilation result on the shared function info. - InstallBaselineCompilationResult(&info, result, scope_info); + InstallSharedCompilationResult(&info, result); } else { return Handle::null(); }