Commit 1d7da9c6 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[compiler] Move JSFunction post-instantiation tasks.

This moves the post-instantiation work performed on newly allocated
JSFunction objects into the Compiler class. The aim is to eventually
have all decisions how to compile functions be centralized within the
compiler pipeline.

R=mvstanton@chromium.org

Review URL: https://codereview.chromium.org/1764023003

Cr-Commit-Position: refs/heads/master@{#34550}
parent cf43d2a7
......@@ -1516,8 +1516,6 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
compilation_cache->PutEval(source, outer_info, context, shared_info,
line_offset);
}
} else if (shared_info->ic_age() != isolate->heap()->global_ic_age()) {
shared_info->ResetForNewContext(isolate->heap()->global_ic_age());
}
Handle<JSFunction> result =
......@@ -1908,6 +1906,41 @@ MaybeHandle<Code> Compiler::GetConcurrentlyOptimizedCode(
return MaybeHandle<Code>();
}
void Compiler::PostInstantiation(Handle<JSFunction> function,
PretenureFlag pretenure) {
Handle<SharedFunctionInfo> shared(function->shared());
if (FLAG_always_opt && shared->allows_lazy_compilation()) {
function->MarkForOptimization();
}
CodeAndLiterals cached = shared->SearchOptimizedCodeMap(
function->context()->native_context(), BailoutId::None());
if (cached.code != nullptr) {
// Caching of optimized code enabled and optimized code found.
DCHECK(!cached.code->marked_for_deoptimization());
DCHECK(function->shared()->is_compiled());
function->ReplaceCode(cached.code);
}
if (cached.literals != nullptr) {
function->set_literals(cached.literals);
} else {
Isolate* isolate = function->GetIsolate();
int number_of_literals = shared->num_literals();
Handle<LiteralsArray> literals =
LiteralsArray::New(isolate, handle(shared->feedback_vector()),
number_of_literals, pretenure);
function->set_literals(*literals);
// Cache context-specific literals.
MaybeHandle<Code> code;
if (cached.code != nullptr) code = handle(cached.code);
Handle<Context> native_context(function->context()->native_context());
SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code,
literals, BailoutId::None());
}
}
#if DEBUG
void CompilationInfo::PrintAstForTesting() {
......
......@@ -598,6 +598,11 @@ class Compiler : public AllStatic {
static bool CompileDebugCode(Handle<SharedFunctionInfo> shared);
static void CompileForLiveEdit(Handle<Script> script);
// Give the compiler a chance to perform low-latency initialization tasks of
// the given {function} on its instantiation. Note that only the runtime will
// offer this chance, optimized closure instantiation will not call this.
static void PostInstantiation(Handle<JSFunction> function, PretenureFlag);
// Parser::Parse, then Compiler::Analyze.
static bool ParseAndAnalyze(ParseInfo* info);
// Rewrite, analyze scopes, and renumber.
......
......@@ -1350,35 +1350,8 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
info->ResetForNewContext(isolate()->heap()->global_ic_age());
}
if (FLAG_always_opt && info->allows_lazy_compilation()) {
result->MarkForOptimization();
}
CodeAndLiterals cached = info->SearchOptimizedCodeMap(
context->native_context(), BailoutId::None());
if (cached.code != nullptr) {
// Caching of optimized code enabled and optimized code found.
DCHECK(!cached.code->marked_for_deoptimization());
DCHECK(result->shared()->is_compiled());
result->ReplaceCode(cached.code);
}
if (cached.literals != nullptr) {
result->set_literals(cached.literals);
} else {
int number_of_literals = info->num_literals();
Handle<LiteralsArray> literals =
LiteralsArray::New(isolate(), handle(info->feedback_vector()),
number_of_literals, pretenure);
result->set_literals(*literals);
// Cache context-specific literals.
MaybeHandle<Code> code;
if (cached.code != nullptr) code = handle(cached.code);
Handle<Context> native_context(context->native_context());
SharedFunctionInfo::AddToOptimizedCodeMap(info, native_context, code,
literals, BailoutId::None());
}
// Give compiler a chance to pre-initialize.
Compiler::PostInstantiation(result, pretenure);
return result;
}
......
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