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);
{
......
This diff is collapsed.
......@@ -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