Commit e91b9692 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Compiler] Move construction of CompilationInfo into GenerateUnoptimizedCode

Moves the construction of CompilationInfo for unoptimized code into
GenerateUnoptimizedCode in preparation for making it owned by the
unoptimized compilation jobs (to be done in a followup CL).

This CL also adds a new constructor for creation of unoptimized
CompilationInfos with fields correctly initialized and updates the existing
constructor to he exclusively for optimized compilation. Finally, also moves
the call to RecordFunctionCompilation with LAZY_COMPILE_TAG recording into
FinalizeUnoptimizedCompilationJob where it is called for other unoptimized
compiles.

BUG=v8:5203,v8:6659

Change-Id: Icfd7f56588073f2fc547e002db9fa99843ed2e8b
Reviewed-on: https://chromium-review.googlesource.com/598908
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47160}
parent 15ef03cb
......@@ -10,22 +10,21 @@
#include "src/debug/debug.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/parsing/parse-info.h"
#include "src/source-position.h"
namespace v8 {
namespace internal {
CompilationInfo::CompilationInfo(Zone* zone, Isolate* isolate,
Handle<Script> script,
Handle<SharedFunctionInfo> shared,
Handle<JSFunction> closure)
: CompilationInfo(script, {}, Code::ComputeFlags(Code::FUNCTION), BASE,
isolate, zone) {
ParseInfo* parse_info,
Handle<SharedFunctionInfo> shared)
: CompilationInfo(parse_info->script(), {},
Code::ComputeFlags(Code::FUNCTION), BASE, isolate, zone) {
DCHECK_NOT_NULL(parse_info->literal());
literal_ = parse_info->literal();
source_range_map_ = parse_info->source_range_map();
shared_info_ = shared;
closure_ = closure;
if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing();
if (FLAG_turbo_splitting) MarkAsSplittingEnabled();
// Collect source positions for optimized code when profiling or if debugger
// is active, to be able to get more precise source positions at the price of
......@@ -39,14 +38,37 @@ CompilationInfo::CompilationInfo(Zone* zone, Isolate* isolate,
MarkAsBlockCoverageEnabled();
}
if (script_->type() == Script::TYPE_NATIVE) {
MarkAsNative();
}
if (parse_info->is_debug()) MarkAsDebug();
if (parse_info->is_eval()) MarkAsEval();
if (parse_info->is_native()) MarkAsNative();
if (parse_info->will_serialize()) MarkAsSerializing();
if (script_->type() == Script::TYPE_NATIVE) MarkAsNative();
if (script_->compilation_type() == Script::COMPILATION_TYPE_EVAL) {
MarkAsEval();
}
}
CompilationInfo::CompilationInfo(Zone* zone, Isolate* isolate,
Handle<Script> script,
Handle<SharedFunctionInfo> shared,
Handle<JSFunction> closure)
: CompilationInfo(script, {}, Code::ComputeFlags(Code::OPTIMIZED_FUNCTION),
OPTIMIZE, isolate, zone) {
shared_info_ = shared;
closure_ = closure;
optimization_id_ = isolate->NextOptimizationId();
if (FLAG_function_context_specialization) MarkAsFunctionContextSpecializing();
if (FLAG_turbo_splitting) MarkAsSplittingEnabled();
// Collect source positions for optimized code when profiling or if debugger
// is active, to be able to get more precise source positions at the price of
// more memory consumption.
if (isolate_->NeedsSourcePositionsForProfiling()) {
MarkAsSourcePositionsEnabled();
}
}
CompilationInfo::CompilationInfo(Vector<const char> debug_name,
Isolate* isolate, Zone* zone,
Code::Flags code_flags)
......@@ -204,13 +226,6 @@ JSGlobalObject* CompilationInfo::global_object() const {
return has_global_object() ? native_context()->global_object() : nullptr;
}
void CompilationInfo::SetOptimizing() {
DCHECK(has_shared_info());
SetMode(OPTIMIZE);
optimization_id_ = isolate()->NextOptimizationId();
code_flags_ = Code::KindField::update(code_flags_, Code::OPTIMIZED_FUNCTION);
}
int CompilationInfo::AddInlinedFunction(
Handle<SharedFunctionInfo> inlined_function, SourcePosition pos) {
int id = static_cast<int>(inlined_functions_.size());
......
......@@ -25,6 +25,7 @@ class DeferredHandles;
class FunctionLiteral;
class Isolate;
class JavaScriptFrame;
class ParseInfo;
class SourceRangeMap;
class Zone;
......@@ -54,9 +55,14 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
kLoopPeelingEnabled = 1 << 16,
};
// Construct a compilation info for unoptimized compilation.
CompilationInfo(Zone* zone, Isolate* isolate, ParseInfo* parse_info,
Handle<SharedFunctionInfo> shared);
// Construct a compilation info for optimized compilation.
CompilationInfo(Zone* zone, Isolate* isolate, Handle<Script> script,
Handle<SharedFunctionInfo> shared,
Handle<JSFunction> closure);
// Construct a compilation info for stub compilation (or testing).
CompilationInfo(Vector<const char> debug_name, Isolate* isolate, Zone* zone,
Code::Flags code_flags);
~CompilationInfo();
......@@ -212,9 +218,8 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
bool IsOptimizing() const { return mode_ == OPTIMIZE; }
bool IsStub() const { return mode_ == STUB; }
bool IsWasm() const { return output_code_kind() == Code::WASM_FUNCTION; }
void SetOptimizing();
void SetOptimizingForOsr(BailoutId osr_ast_id, JavaScriptFrame* osr_frame) {
SetOptimizing();
DCHECK(IsOptimizing());
osr_ast_id_ = osr_ast_id;
osr_frame_ = osr_frame;
}
......@@ -259,7 +264,10 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
CompilationDependencies* dependencies() { return &dependencies_; }
int optimization_id() const { return optimization_id_; }
int optimization_id() const {
DCHECK(IsOptimizing());
return optimization_id_;
}
int osr_expr_stack_height() {
DCHECK_GE(osr_expr_stack_height_, 0);
......
......@@ -400,10 +400,9 @@ void UnoptimizedCompileJob::AnalyzeOnMainThread(Isolate* isolate) {
}
compile_zone_.reset(new Zone(isolate->allocator(), ZONE_NAME));
compilation_info_.reset(new CompilationInfo(
compile_zone_.get(), isolate, parse_info_->script(),
Handle<SharedFunctionInfo>::null(), Handle<JSFunction>::null()));
compilation_info_->set_literal(parse_info_->literal());
compilation_info_.reset(
new CompilationInfo(compile_zone_.get(), isolate, parse_info_.get(),
Handle<SharedFunctionInfo>::null()));
DeferredHandleScope scope(isolate);
{
......
......@@ -414,12 +414,15 @@ CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job) {
CompilationJob::Status status = job->FinalizeJob();
if (status == CompilationJob::SUCCEEDED) {
InstallUnoptimizedCode(compilation_info);
CodeEventListener::LogEventsAndTags log_tags =
parse_info->is_toplevel() ? compilation_info->is_eval()
? CodeEventListener::EVAL_TAG
: CodeEventListener::SCRIPT_TAG
: CodeEventListener::FUNCTION_TAG;
RecordFunctionCompilation(log_tags, compilation_info);
CodeEventListener::LogEventsAndTags log_tag;
if (parse_info->is_toplevel()) {
log_tag = compilation_info->is_eval() ? CodeEventListener::EVAL_TAG
: CodeEventListener::SCRIPT_TAG;
} else {
log_tag = parse_info->lazy_compile() ? CodeEventListener::LAZY_COMPILE_TAG
: CodeEventListener::FUNCTION_TAG;
}
RecordFunctionCompilation(log_tag, compilation_info);
job->RecordUnoptimizedCompilationStats();
}
return status;
......@@ -440,60 +443,60 @@ bool RunUnoptimizedCompilationJob(CompilationJob* job) {
return FinalizeUnoptimizedCompilationJob(job) == CompilationJob::SUCCEEDED;
}
bool GenerateUnoptimizedCode(ParseInfo* parse_info,
CompilationInfo* compilation_info) {
if (UseAsmWasm(compilation_info->scope(), compilation_info->shared_info(),
compilation_info->is_debug())) {
Handle<SharedFunctionInfo> GenerateUnoptimizedCode(
ParseInfo* parse_info, Handle<SharedFunctionInfo> shared_info,
Isolate* isolate) {
// TODO(rmcilroy): Move the compilation info to be owned by the compilation
// job.
Zone compile_zone(isolate->allocator(), ZONE_NAME);
CompilationInfo compilation_info(&compile_zone, isolate, parse_info,
shared_info);
if (UseAsmWasm(parse_info->scope(), shared_info, parse_info->is_debug())) {
std::unique_ptr<CompilationJob> job(
AsmJs::NewCompilationJob(parse_info, compilation_info));
if (RunUnoptimizedCompilationJob(job.get())) return true;
AsmJs::NewCompilationJob(parse_info, &compilation_info));
if (RunUnoptimizedCompilationJob(job.get())) {
return compilation_info.shared_info();
}
// asm.js validation failed, fall through to standard unoptimized compile.
}
std::unique_ptr<CompilationJob> job(
GetUnoptimizedCompilationJob(parse_info, compilation_info));
return RunUnoptimizedCompilationJob(job.get());
GetUnoptimizedCompilationJob(parse_info, &compilation_info));
if (RunUnoptimizedCompilationJob(job.get())) {
return compilation_info.shared_info();
}
return Handle<SharedFunctionInfo>::null(); // Compilation failed.
}
bool CompileUnoptimizedInnerFunctions(
Compiler::EagerInnerFunctionLiterals* literals, ParseInfo* outer_parse_info,
CompilationInfo* outer_compilation_info) {
Compiler::EagerInnerFunctionLiterals* literals, Handle<Script> script,
ParseInfo* outer_parse_info, Isolate* isolate) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
"V8.CompileUnoptimizedInnerFunctions");
Isolate* isolate = outer_compilation_info->isolate();
Handle<Script> script = outer_compilation_info->script();
bool is_debug = outer_compilation_info->is_debug();
bool will_serialize = outer_compilation_info->will_serialize();
bool is_debug = outer_parse_info->is_debug();
bool will_serialize = outer_parse_info->will_serialize();
RuntimeCallTimerScope runtimeTimer(isolate,
&RuntimeCallStats::CompileInnerFunction);
for (auto it : *literals) {
FunctionLiteral* literal = it->value();
Handle<SharedFunctionInfo> shared = Compiler::GetSharedFunctionInfo(
literal, script, outer_compilation_info);
Handle<SharedFunctionInfo> shared =
Compiler::GetSharedFunctionInfo(literal, script, isolate);
if (shared->is_compiled()) continue;
// Generate unoptimized code now.
ParseInfo parse_info(script);
CompilationInfo info(parse_info.zone(), isolate, script, shared,
Handle<JSFunction>::null());
parse_info.set_toplevel(false);
parse_info.set_literal(literal);
parse_info.set_function_literal_id(shared->function_literal_id());
parse_info.set_language_mode(literal->scope()->language_mode());
parse_info.ShareAstValueFactory(outer_parse_info);
parse_info.set_source_range_map(outer_parse_info->source_range_map());
info.set_source_range_map(outer_compilation_info->source_range_map());
info.set_literal(literal);
if (will_serialize) {
parse_info.set_will_serialize();
info.MarkAsSerializing();
}
if (is_debug) {
parse_info.set_is_debug();
info.MarkAsDebug();
}
if (will_serialize) parse_info.set_will_serialize();
if (is_debug) parse_info.set_is_debug();
if (!GenerateUnoptimizedCode(&parse_info, &info)) {
if (GenerateUnoptimizedCode(&parse_info, shared, isolate).is_null()) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return false;
}
......@@ -510,22 +513,22 @@ bool InnerFunctionShouldUseFullCodegen(
return false;
}
bool CompileUnoptimizedCode(ParseInfo* parse_info,
CompilationInfo* compilation_info) {
Isolate* isolate = compilation_info->isolate();
Handle<SharedFunctionInfo> CompileUnoptimizedCode(
ParseInfo* parse_info, Handle<SharedFunctionInfo> shared_info,
Isolate* isolate) {
DCHECK(AllowCompilation::IsAllowed(isolate));
Compiler::EagerInnerFunctionLiterals inner_literals;
if (!Compiler::Analyze(parse_info, isolate, &inner_literals)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return false;
return Handle<SharedFunctionInfo>::null();
}
if (ShouldUseFullCodegen(compilation_info->literal()) ||
if (ShouldUseFullCodegen(parse_info->literal()) ||
InnerFunctionShouldUseFullCodegen(&inner_literals)) {
// If we might compile with full-codegen internalize now, otherwise
// we internalize when finalizing compilation.
parse_info->ast_value_factory()->Internalize(compilation_info->isolate());
parse_info->ast_value_factory()->Internalize(isolate);
// Full-codegen needs to access ScopeInfos when compiling, so allocate now.
DeclarationScope::AllocateScopeInfos(parse_info, isolate,
......@@ -538,23 +541,22 @@ bool CompileUnoptimizedCode(ParseInfo* parse_info,
}
}
if (!GenerateUnoptimizedCode(parse_info, compilation_info) ||
!CompileUnoptimizedInnerFunctions(&inner_literals, parse_info,
compilation_info)) {
Handle<SharedFunctionInfo> result =
GenerateUnoptimizedCode(parse_info, shared_info, isolate);
if (result.is_null() ||
!CompileUnoptimizedInnerFunctions(&inner_literals, parse_info->script(),
parse_info, isolate)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return false;
return Handle<SharedFunctionInfo>::null();
}
return true;
return result;
}
MUST_USE_RESULT MaybeHandle<Code> CompileUnoptimizedFunction(
ParseInfo* parse_info, CompilationInfo* compilation_info,
ParseInfo* parse_info, Isolate* isolate,
Handle<SharedFunctionInfo> shared_info) {
RuntimeCallTimerScope runtimeTimer(
compilation_info->isolate(),
&RuntimeCallStats::CompileUnoptimizedFunction);
Isolate* isolate = compilation_info->isolate();
isolate, &RuntimeCallStats::CompileUnoptimizedFunction);
VMState<COMPILER> state(isolate);
PostponeInterruptsScope postpone(isolate);
......@@ -563,21 +565,15 @@ MUST_USE_RESULT MaybeHandle<Code> CompileUnoptimizedFunction(
return MaybeHandle<Code>();
}
// TODO(rmcilroy): Construct compile info at this point passing literal and
// source_range_map to the constructor.
compilation_info->set_literal(parse_info->literal());
compilation_info->set_source_range_map(parse_info->source_range_map());
// Compile either unoptimized code or bytecode for the interpreter.
if (!CompileUnoptimizedCode(parse_info, compilation_info)) {
Handle<SharedFunctionInfo> result =
CompileUnoptimizedCode(parse_info, shared_info, isolate);
if (result.is_null()) {
return MaybeHandle<Code>();
}
DCHECK(shared_info.is_identical_to(result));
// Record the function compilation event.
RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG,
compilation_info);
return compilation_info->code();
return handle(result->code(), isolate);
}
MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeCache(
......@@ -953,9 +949,7 @@ MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) {
Handle<SharedFunctionInfo> shared(function->shared());
ParseInfo parse_info(shared);
Zone compile_zone(isolate->allocator(), ZONE_NAME);
CompilationInfo compilation_info(&compile_zone, isolate,
parse_info.script(), shared, function);
parse_info.set_lazy_compile();
if (FLAG_experimental_preparser_scope_analysis) {
if (shared->HasPreParsedScopeData()) {
Handle<PreParsedScopeData> data(
......@@ -969,10 +963,9 @@ MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) {
Handle<Code> result;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, result,
CompileUnoptimizedFunction(&parse_info, &compilation_info, shared),
Code);
CompileUnoptimizedFunction(&parse_info, isolate, shared), Code);
if (FLAG_always_opt && !compilation_info.shared_info()->HasAsmWasmData()) {
if (FLAG_always_opt && !shared->HasAsmWasmData()) {
if (FLAG_trace_opt) {
PrintF("[optimizing ");
function->ShortPrint();
......@@ -992,9 +985,9 @@ MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) {
}
}
Handle<SharedFunctionInfo> CompileToplevel(ParseInfo* parse_info,
CompilationInfo* compilation_info) {
Isolate* isolate = compilation_info->isolate();
Handle<SharedFunctionInfo> CompileToplevel(
ParseInfo* parse_info, Isolate* isolate,
Handle<SharedFunctionInfo> shared_info) {
TimerEventScope<TimerEventCompileCode> timer(isolate);
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode");
PostponeInterruptsScope postpone(isolate);
......@@ -1004,7 +997,6 @@ Handle<SharedFunctionInfo> CompileToplevel(ParseInfo* parse_info,
: &RuntimeCallStats::CompileScript);
Handle<Script> script = parse_info->script();
Handle<SharedFunctionInfo> result;
{
......@@ -1013,33 +1005,29 @@ Handle<SharedFunctionInfo> CompileToplevel(ParseInfo* parse_info,
!parsing::ParseProgram(parse_info, isolate)) {
return Handle<SharedFunctionInfo>::null();
}
// TODO(rmcilroy): Construct compile info at this point passing literal and
// source_range_map to the constructor.
compilation_info->set_literal(parse_info->literal());
compilation_info->set_source_range_map(parse_info->source_range_map());
// Measure how long it takes to do the compilation; only take the
// rest of the function into account to avoid overlap with the
// parsing statistics.
HistogramTimer* rate =
parse_info->is_eval()
? compilation_info->isolate()->counters()->compile_eval()
: compilation_info->isolate()->counters()->compile();
HistogramTimer* rate = parse_info->is_eval()
? isolate->counters()->compile_eval()
: isolate->counters()->compile();
HistogramTimerScope timer(rate);
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
parse_info->is_eval() ? "V8.CompileEval" : "V8.Compile");
// Compile the code.
if (!CompileUnoptimizedCode(parse_info, compilation_info)) {
result = CompileUnoptimizedCode(parse_info, shared_info, isolate);
if (result.is_null()) {
return Handle<SharedFunctionInfo>::null();
}
DCHECK_IMPLIES(!shared_info.is_null(), shared_info.is_identical_to(result));
if (!script.is_null()) {
script->set_compilation_state(Script::COMPILATION_STATE_COMPILED);
}
}
return compilation_info->shared_info();
return result;
}
} // namespace
......@@ -1142,19 +1130,14 @@ bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) {
// Start a compilation.
ParseInfo parse_info(shared);
CompilationInfo compilation_info(parse_info.zone(), isolate,
parse_info.script(), shared,
Handle<JSFunction>::null());
parse_info.set_is_debug();
compilation_info.MarkAsDebug();
if (parse_info.is_toplevel()) {
if (CompileToplevel(&parse_info, &compilation_info).is_null()) {
if (CompileToplevel(&parse_info, isolate, shared).is_null()) {
isolate->clear_pending_exception();
return false;
}
} else {
if (CompileUnoptimizedFunction(&parse_info, &compilation_info, shared)
.is_null()) {
if (CompileUnoptimizedFunction(&parse_info, isolate, shared).is_null()) {
isolate->clear_pending_exception();
return false;
}
......@@ -1180,18 +1163,12 @@ MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) {
// Start a compilation.
ParseInfo parse_info(script);
Zone compile_zone(isolate->allocator(), ZONE_NAME);
CompilationInfo compilation_info(&compile_zone, isolate, script,
Handle<SharedFunctionInfo>::null(),
Handle<JSFunction>::null());
parse_info.set_is_debug();
compilation_info.MarkAsDebug();
// TODO(635): support extensions.
const bool compilation_succeeded =
!CompileToplevel(&parse_info, &compilation_info).is_null();
Handle<JSArray> infos;
if (compilation_succeeded) {
if (!CompileToplevel(&parse_info, isolate, Handle<SharedFunctionInfo>::null())
.is_null()) {
// Check postconditions on success.
DCHECK(!isolate->has_pending_exception());
infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script,
......@@ -1206,17 +1183,14 @@ MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) {
return infos;
}
bool Compiler::EnsureBytecode(ParseInfo* parse_info,
CompilationInfo* compilation_info) {
Handle<SharedFunctionInfo> shared_info = compilation_info->shared_info();
bool Compiler::EnsureBytecode(ParseInfo* parse_info, Isolate* isolate,
Handle<SharedFunctionInfo> shared_info) {
if (!shared_info->is_compiled()) {
DCHECK(!parse_info->is_toplevel());
CompilerDispatcher* dispatcher =
compilation_info->isolate()->compiler_dispatcher();
CompilerDispatcher* dispatcher = isolate->compiler_dispatcher();
if (dispatcher->IsEnqueued(shared_info)) {
if (!dispatcher->FinishNow(compilation_info->shared_info())) return false;
} else if (CompileUnoptimizedFunction(parse_info, compilation_info,
shared_info)
if (!dispatcher->FinishNow(shared_info)) return false;
} else if (CompileUnoptimizedFunction(parse_info, isolate, shared_info)
.is_null()) {
return false;
}
......@@ -1283,11 +1257,6 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
Script::SetEvalOrigin(script, outer_info, eval_position);
ParseInfo parse_info(script);
Zone compile_zone(isolate->allocator(), ZONE_NAME);
CompilationInfo compilation_info(&compile_zone, isolate, script,
Handle<SharedFunctionInfo>::null(),
Handle<JSFunction>::null());
compilation_info.MarkAsEval();
parse_info.set_eval();
parse_info.set_language_mode(language_mode);
parse_info.set_parse_restriction(restriction);
......@@ -1296,7 +1265,8 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
parse_info.set_outer_scope_info(handle(context->scope_info()));
}
shared_info = CompileToplevel(&parse_info, &compilation_info);
shared_info = CompileToplevel(&parse_info, isolate,
Handle<SharedFunctionInfo>::null());
if (shared_info.is_null()) {
return MaybeHandle<JSFunction>();
}
......@@ -1499,9 +1469,6 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
// Compile the function and add it to the cache.
ParseInfo parse_info(script);
Zone compile_zone(isolate->allocator(), ZONE_NAME);
CompilationInfo compilation_info(&compile_zone, isolate, script,
Handle<SharedFunctionInfo>::null(),
Handle<JSFunction>::null());
if (resource_options.IsModule()) parse_info.set_module();
if (compile_options != ScriptCompiler::kNoCompileOptions) {
parse_info.set_cached_data(cached_data);
......@@ -1514,12 +1481,12 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
if (FLAG_serialize_toplevel &&
compile_options == ScriptCompiler::kProduceCodeCache) {
parse_info.set_will_serialize();
compilation_info.MarkAsSerializing();
}
parse_info.set_language_mode(
static_cast<LanguageMode>(parse_info.language_mode() | language_mode));
result = CompileToplevel(&parse_info, &compilation_info);
result = CompileToplevel(&parse_info, isolate,
Handle<SharedFunctionInfo>::null());
if (extension == NULL && !result.is_null()) {
// We need a feedback vector.
DCHECK(result->is_compiled());
......@@ -1567,25 +1534,18 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForStreamedScript(
parse_info->set_language_mode(
static_cast<LanguageMode>(parse_info->language_mode() | language_mode));
Zone compile_zone(isolate->allocator(), ZONE_NAME);
CompilationInfo compilation_info(&compile_zone, isolate, script,
Handle<SharedFunctionInfo>::null(),
Handle<JSFunction>::null());
// The source was parsed lazily, so compiling for debugging is not possible.
DCHECK(!compilation_info.is_debug());
DCHECK(!parse_info->is_debug());
Handle<SharedFunctionInfo> result =
CompileToplevel(parse_info, &compilation_info);
CompileToplevel(parse_info, isolate, Handle<SharedFunctionInfo>::null());
if (!result.is_null()) isolate->debug()->OnAfterCompile(script);
return result;
}
Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfo(
FunctionLiteral* literal, Handle<Script> script,
CompilationInfo* outer_info) {
FunctionLiteral* literal, Handle<Script> script, Isolate* isolate) {
// Precondition: code has been parsed and scopes have been analyzed.
Isolate* isolate = outer_info->isolate();
MaybeHandle<SharedFunctionInfo> maybe_existing;
// Find any previously allocated shared function info for the given literal.
......
......@@ -76,8 +76,8 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
static bool Analyze(ParseInfo* parse_info, Isolate* isolate,
EagerInnerFunctionLiterals* eager_literals = nullptr);
// Ensures that bytecode is generated, calls ParseAndAnalyze internally.
static bool EnsureBytecode(ParseInfo* parse_info,
CompilationInfo* compilation_info);
static bool EnsureBytecode(ParseInfo* parse_info, Isolate* isolate,
Handle<SharedFunctionInfo> shared_info);
// ===========================================================================
// The following family of methods instantiates new functions for scripts or
......@@ -123,8 +123,9 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
Handle<Script> script, ParseInfo* info, int source_length);
// Create a shared function info object (the code may be lazily compiled).
static Handle<SharedFunctionInfo> GetSharedFunctionInfo(
FunctionLiteral* node, Handle<Script> script, CompilationInfo* outer);
static Handle<SharedFunctionInfo> GetSharedFunctionInfo(FunctionLiteral* node,
Handle<Script> script,
Isolate* isolate);
// Create a shared function info object for a native function literal.
static Handle<SharedFunctionInfo> GetSharedFunctionInfoForNative(
......
......@@ -808,7 +808,7 @@ void AstGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) {
switch (variable->location()) {
case VariableLocation::UNALLOCATED: {
Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo(
decl->fun(), info()->script(), info());
decl->fun(), info()->script(), info()->isolate());
// Check for stack-overflow exception.
if (function.is_null()) return SetStackOverflow();
globals()->push_back(variable->name());
......@@ -1048,8 +1048,8 @@ void AstGraphBuilder::VisitDebuggerStatement(DebuggerStatement* stmt) {
void AstGraphBuilder::VisitFunctionLiteral(FunctionLiteral* expr) {
// Find or build a shared function info.
Handle<SharedFunctionInfo> shared_info =
Compiler::GetSharedFunctionInfo(expr, info()->script(), info());
Handle<SharedFunctionInfo> shared_info = Compiler::GetSharedFunctionInfo(
expr, info()->script(), info()->isolate());
CHECK(!shared_info.is_null()); // TODO(mstarzinger): Set stack overflow?
// Create node to instantiate a new closure.
......
......@@ -507,13 +507,7 @@ Reduction JSInliner::ReduceJSCall(Node* node) {
}
ParseInfo parse_info(shared_info);
CompilationInfo info(parse_info.zone(), shared_info->GetIsolate(),
parse_info.script(), shared_info,
Handle<JSFunction>::null());
if (info_->is_deoptimization_enabled()) info.MarkAsDeoptimizationEnabled();
info.MarkAsOptimizeFromBytecode();
if (!Compiler::EnsureBytecode(&parse_info, &info)) {
if (!Compiler::EnsureBytecode(&parse_info, info_->isolate(), shared_info)) {
TRACE("Not inlining %s into %s because bytecode generation failed\n",
shared_info->DebugName()->ToCString().get(),
info_->shared_info()->DebugName()->ToCString().get());
......@@ -607,7 +601,7 @@ Reduction JSInliner::ReduceJSCall(Node* node) {
Node* frame_state_inside = CreateArtificialFrameState(
node, frame_state, call.formal_arguments(),
BailoutId::ConstructStubCreate(), FrameStateType::kConstructStub,
info.shared_info());
shared_info);
Node* create =
graph()->NewNode(javascript()->Create(), call.target(), new_target,
context, frame_state_inside, effect, control);
......@@ -703,10 +697,10 @@ Reduction JSInliner::ReduceJSCall(Node* node) {
node->ReplaceInput(1, receiver);
// Insert a construct stub frame into the chain of frame states. This will
// reconstruct the proper frame when deoptimizing within the constructor.
frame_state = CreateArtificialFrameState(
node, frame_state, call.formal_arguments(),
BailoutId::ConstructStubInvoke(), FrameStateType::kConstructStub,
info.shared_info());
frame_state =
CreateArtificialFrameState(node, frame_state, call.formal_arguments(),
BailoutId::ConstructStubInvoke(),
FrameStateType::kConstructStub, shared_info);
}
// Insert a JSConvertReceiver node for sloppy callees. Note that the context
......
......@@ -769,8 +769,8 @@ void FullCodeGenerator::VisitFunctionDeclaration(
DCHECK(!slot.IsInvalid());
globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone());
Handle<SharedFunctionInfo> function =
Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_);
Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo(
declaration->fun(), script(), isolate());
// Check for stack-overflow exception.
if (function.is_null()) return SetStackOverflow();
globals_->Add(function, zone());
......
......@@ -757,8 +757,8 @@ void FullCodeGenerator::VisitFunctionDeclaration(
DCHECK(!slot.IsInvalid());
globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone());
Handle<SharedFunctionInfo> function =
Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_);
Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo(
declaration->fun(), script(), isolate());
// Check for stack overflow exception.
if (function.is_null()) return SetStackOverflow();
globals_->Add(function, zone());
......
......@@ -1196,7 +1196,7 @@ void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
// Build the function boilerplate and instantiate it.
Handle<SharedFunctionInfo> function_info =
Compiler::GetSharedFunctionInfo(expr, script(), info_);
Compiler::GetSharedFunctionInfo(expr, script(), info_->isolate());
if (function_info.is_null()) {
SetStackOverflow();
return;
......
......@@ -699,8 +699,8 @@ void FullCodeGenerator::VisitFunctionDeclaration(
DCHECK(!slot.IsInvalid());
globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone());
Handle<SharedFunctionInfo> function =
Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_);
Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo(
declaration->fun(), script(), isolate());
// Check for stack-overflow exception.
if (function.is_null()) return SetStackOverflow();
globals_->Add(function, zone());
......
......@@ -756,8 +756,8 @@ void FullCodeGenerator::VisitFunctionDeclaration(
DCHECK(!slot.IsInvalid());
globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone());
Handle<SharedFunctionInfo> function =
Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_);
Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo(
declaration->fun(), script(), isolate());
// Check for stack-overflow exception.
if (function.is_null()) return SetStackOverflow();
globals_->Add(function, zone());
......
......@@ -756,8 +756,8 @@ void FullCodeGenerator::VisitFunctionDeclaration(
DCHECK(!slot.IsInvalid());
globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone());
Handle<SharedFunctionInfo> function =
Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_);
Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo(
declaration->fun(), script(), isolate());
// Check for stack-overflow exception.
if (function.is_null()) return SetStackOverflow();
globals_->Add(function, zone());
......
......@@ -730,8 +730,8 @@ void FullCodeGenerator::VisitFunctionDeclaration(
DCHECK(!slot.IsInvalid());
globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone());
Handle<SharedFunctionInfo> function =
Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_);
Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo(
declaration->fun(), script(), isolate());
// Check for stack-overflow exception.
if (function.is_null()) return SetStackOverflow();
globals_->Add(function, zone());
......
......@@ -704,8 +704,8 @@ void FullCodeGenerator::VisitFunctionDeclaration(
DCHECK(!slot.IsInvalid());
globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone());
Handle<SharedFunctionInfo> function =
Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_);
Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo(
declaration->fun(), script(), isolate());
// Check for stack-overflow exception.
if (function.is_null()) return SetStackOverflow();
globals_->Add(function, zone());
......
......@@ -712,8 +712,8 @@ void FullCodeGenerator::VisitFunctionDeclaration(
DCHECK(!slot.IsInvalid());
globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone());
Handle<SharedFunctionInfo> function =
Compiler::GetSharedFunctionInfo(declaration->fun(), script(), info_);
Handle<SharedFunctionInfo> function = Compiler::GetSharedFunctionInfo(
declaration->fun(), script(), isolate());
// Check for stack-overflow exception.
if (function.is_null()) return SetStackOverflow();
globals_->Add(function, zone());
......
......@@ -666,8 +666,8 @@ class BytecodeGenerator::GlobalDeclarationsBuilder final : public ZoneObject {
if (func == nullptr) {
initial_value = info->isolate()->factory()->undefined_value();
} else {
initial_value =
Compiler::GetSharedFunctionInfo(func, info->script(), info);
initial_value = Compiler::GetSharedFunctionInfo(func, info->script(),
info->isolate());
}
// Return a null handle if any initial values can't be created. Caller
......@@ -810,7 +810,7 @@ void BytecodeGenerator::AllocateDeferredConstants(Isolate* isolate) {
for (std::pair<FunctionLiteral*, size_t> literal : function_literals_) {
FunctionLiteral* expr = literal.first;
Handle<SharedFunctionInfo> shared_info =
Compiler::GetSharedFunctionInfo(expr, info()->script(), info());
Compiler::GetSharedFunctionInfo(expr, info()->script(), isolate);
if (shared_info.is_null()) return SetStackOverflow();
builder()->SetDeferredConstantPoolEntry(literal.second, shared_info);
}
......
......@@ -75,6 +75,7 @@ class V8_EXPORT_PRIVATE ParseInfo : public UnoptimizedCompileJobFinishCallback {
set_is_named_expression)
FLAG_ACCESSOR(kDebug, is_debug, set_is_debug)
FLAG_ACCESSOR(kSerializing, will_serialize, set_will_serialize)
FLAG_ACCESSOR(kLazyCompile, lazy_compile, set_lazy_compile)
FLAG_ACCESSOR(kCollectTypeProfile, collect_type_profile,
set_collect_type_profile)
#undef FLAG_ACCESSOR
......@@ -269,6 +270,7 @@ class V8_EXPORT_PRIVATE ParseInfo : public UnoptimizedCompileJobFinishCallback {
kIsNamedExpression = 1 << 8,
kDebug = 1 << 9,
kSerializing = 1 << 10,
kLazyCompile = 1 << 11,
kCollectTypeProfile = 1 << 12,
};
......
......@@ -144,7 +144,6 @@ Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) {
CompilationInfo info(parse_info.zone(), function->GetIsolate(),
parse_info.script(), shared, function);
info.SetOptimizing();
if (flags_ & CompilationInfo::kInliningEnabled) {
info.MarkAsInliningEnabled();
}
......@@ -177,7 +176,6 @@ Handle<JSFunction> FunctionTester::CompileGraph(Graph* graph) {
CHECK(
parsing::ParseFunction(&parse_info, info.shared_info(), info.isolate()));
info.SetOptimizing();
Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph);
CHECK(!code.is_null());
......
......@@ -123,7 +123,6 @@ class BytecodeGraphTester {
Handle<Script> script(Script::cast(shared->script()));
CompilationInfo compilation_info(&zone, function->GetIsolate(), script,
shared, function);
compilation_info.SetOptimizing();
compilation_info.MarkAsDeoptimizationEnabled();
compilation_info.MarkAsOptimizeFromBytecode();
Handle<Code> code = Pipeline::GenerateCodeForTesting(&compilation_info);
......
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