[Compiler] Decouple CompilationInfo and ParseInfo.

Don't hold a pointer to parse_info in compilation_info, and instead explicitly
add the fields needed in compiation_info. The intention is to make ParseInfo
only actually needed for parsing, and eventually make it possible to compile
with only a CompileInfo.

BUG=v8:5203

Change-Id: Iecd39245e44c218874401c3991eeaf3ceef2816f
Reviewed-on: https://chromium-review.googlesource.com/595738
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47119}
This commit is contained in:
Ross McIlroy 2017-08-03 12:00:57 +01:00 committed by Commit Bot
parent e44c2af0c0
commit b4e55e9443
25 changed files with 572 additions and 499 deletions

View File

@ -184,8 +184,8 @@ void ReportInstantiationFailure(Handle<Script> script, int position,
// code. // code.
class AsmJsCompilationJob final : public CompilationJob { class AsmJsCompilationJob final : public CompilationJob {
public: public:
explicit AsmJsCompilationJob(CompilationInfo* info) explicit AsmJsCompilationJob(ParseInfo* parse_info, CompilationInfo* info)
: CompilationJob(info->isolate(), info, "AsmJs"), : CompilationJob(info->isolate(), parse_info, info, "AsmJs"),
module_(nullptr), module_(nullptr),
asm_offsets_(nullptr), asm_offsets_(nullptr),
translate_time_(0), translate_time_(0),
@ -210,23 +210,25 @@ class AsmJsCompilationJob final : public CompilationJob {
CompilationJob::Status AsmJsCompilationJob::PrepareJobImpl() { CompilationJob::Status AsmJsCompilationJob::PrepareJobImpl() {
// Step 1: Translate asm.js module to WebAssembly module. // Step 1: Translate asm.js module to WebAssembly module.
HistogramTimerScope translate_time_scope( HistogramTimerScope translate_time_scope(
info()->isolate()->counters()->asm_wasm_translation_time()); compilation_info()->isolate()->counters()->asm_wasm_translation_time());
size_t compile_zone_start = info()->zone()->allocation_size(); size_t compile_zone_start = compilation_info()->zone()->allocation_size();
base::ElapsedTimer translate_timer; base::ElapsedTimer translate_timer;
translate_timer.Start(); translate_timer.Start();
Zone* compile_zone = info()->zone(); Zone* compile_zone = compilation_info()->zone();
Zone translate_zone(info()->isolate()->allocator(), ZONE_NAME); Zone translate_zone(compilation_info()->isolate()->allocator(), ZONE_NAME);
// TODO(mstarzinger): In order to move translation to the non-main thread // TODO(mstarzinger): In order to move translation to the non-main thread
// ExecuteJob phase, the scanner stream needs to be off-heap. // ExecuteJob phase, the scanner stream needs to be off-heap.
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For( std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(
handle(String::cast(info()->script()->source())), handle(String::cast(compilation_info()->script()->source())),
info()->literal()->start_position(), info()->literal()->end_position())); compilation_info()->literal()->start_position(),
compilation_info()->literal()->end_position()));
wasm::AsmJsParser parser(&translate_zone, stack_limit(), std::move(stream)); wasm::AsmJsParser parser(&translate_zone, stack_limit(), std::move(stream));
if (!parser.Run()) { if (!parser.Run()) {
DCHECK(!info()->isolate()->has_pending_exception()); DCHECK(!compilation_info()->isolate()->has_pending_exception());
ReportCompilationFailure(info()->script(), parser.failure_location(), ReportCompilationFailure(compilation_info()->script(),
parser.failure_location(),
parser.failure_message()); parser.failure_message());
return FAILED; return FAILED;
} }
@ -237,9 +239,9 @@ CompilationJob::Status AsmJsCompilationJob::PrepareJobImpl() {
stdlib_uses_ = *parser.stdlib_uses(); stdlib_uses_ = *parser.stdlib_uses();
size_t compile_zone_size = size_t compile_zone_size =
info()->zone()->allocation_size() - compile_zone_start; compilation_info()->zone()->allocation_size() - compile_zone_start;
size_t translate_zone_size = translate_zone.allocation_size(); size_t translate_zone_size = translate_zone.allocation_size();
info() compilation_info()
->isolate() ->isolate()
->counters() ->counters()
->asm_wasm_translation_peak_memory_bytes() ->asm_wasm_translation_peak_memory_bytes()
@ -266,15 +268,15 @@ CompilationJob::Status AsmJsCompilationJob::FinalizeJobImpl() {
compile_timer.Start(); compile_timer.Start();
Handle<HeapNumber> uses_bitset = Handle<HeapNumber> uses_bitset =
info()->isolate()->factory()->NewHeapNumberFromBits( compilation_info()->isolate()->factory()->NewHeapNumberFromBits(
stdlib_uses_.ToIntegral()); stdlib_uses_.ToIntegral());
wasm::ErrorThrower thrower(info()->isolate(), "AsmJs::Compile"); wasm::ErrorThrower thrower(compilation_info()->isolate(), "AsmJs::Compile");
Handle<WasmModuleObject> compiled = Handle<WasmModuleObject> compiled =
SyncCompileTranslatedAsmJs( SyncCompileTranslatedAsmJs(
info()->isolate(), &thrower, compilation_info()->isolate(), &thrower,
wasm::ModuleWireBytes(module_->begin(), module_->end()), wasm::ModuleWireBytes(module_->begin(), module_->end()),
info()->script(), compilation_info()->script(),
Vector<const byte>(asm_offsets_->begin(), asm_offsets_->size())) Vector<const byte>(asm_offsets_->begin(), asm_offsets_->size()))
.ToHandleChecked(); .ToHandleChecked();
DCHECK(!thrower.error()); DCHECK(!thrower.error());
@ -282,19 +284,23 @@ CompilationJob::Status AsmJsCompilationJob::FinalizeJobImpl() {
// The result is a compiled module and serialized standard library uses. // The result is a compiled module and serialized standard library uses.
Handle<FixedArray> result = Handle<FixedArray> result =
info()->isolate()->factory()->NewFixedArray(kWasmDataEntryCount); compilation_info()->isolate()->factory()->NewFixedArray(
kWasmDataEntryCount);
result->set(kWasmDataCompiledModule, *compiled); result->set(kWasmDataCompiledModule, *compiled);
result->set(kWasmDataUsesBitSet, *uses_bitset); result->set(kWasmDataUsesBitSet, *uses_bitset);
info()->SetAsmWasmData(result); compilation_info()->SetAsmWasmData(result);
info()->SetCode(BUILTIN_CODE(info()->isolate(), InstantiateAsmJs)); compilation_info()->SetCode(
BUILTIN_CODE(compilation_info()->isolate(), InstantiateAsmJs));
ReportCompilationSuccess(info()->script(), info()->literal()->position(), ReportCompilationSuccess(compilation_info()->script(),
compilation_info()->literal()->position(),
translate_time_, compile_time_, module_->size()); translate_time_, compile_time_, module_->size());
return SUCCEEDED; return SUCCEEDED;
} }
CompilationJob* AsmJs::NewCompilationJob(CompilationInfo* info) { CompilationJob* AsmJs::NewCompilationJob(ParseInfo* parse_info,
return new AsmJsCompilationJob(info); CompilationInfo* compilation_info) {
return new AsmJsCompilationJob(parse_info, compilation_info);
} }
MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate, MaybeHandle<Object> AsmJs::InstantiateAsmWasm(Isolate* isolate,

View File

@ -15,12 +15,14 @@ namespace internal {
class CompilationInfo; class CompilationInfo;
class CompilationJob; class CompilationJob;
class JSArrayBuffer; class JSArrayBuffer;
class ParseInfo;
class SharedFunctionInfo; class SharedFunctionInfo;
// Interface to compile and instantiate for asm.js modules. // Interface to compile and instantiate for asm.js modules.
class AsmJs { class AsmJs {
public: public:
static CompilationJob* NewCompilationJob(CompilationInfo* info); static CompilationJob* NewCompilationJob(ParseInfo* parse_info,
CompilationInfo* compilation_info);
static MaybeHandle<Object> InstantiateAsmWasm(Isolate* isolate, static MaybeHandle<Object> InstantiateAsmWasm(Isolate* isolate,
Handle<SharedFunctionInfo>, Handle<SharedFunctionInfo>,
Handle<FixedArray> wasm_data, Handle<FixedArray> wasm_data,

View File

@ -84,8 +84,8 @@ Comment::~Comment() {
#endif // DEBUG #endif // DEBUG
void CodeGenerator::MakeCodePrologue(ParseInfo* parse_info,
void CodeGenerator::MakeCodePrologue(CompilationInfo* info, const char* kind) { CompilationInfo* info, const char* kind) {
bool print_ast = false; bool print_ast = false;
const char* ftype; const char* ftype;
@ -103,7 +103,7 @@ void CodeGenerator::MakeCodePrologue(CompilationInfo* info, const char* kind) {
DCHECK(ThreadId::Current().Equals(info->isolate()->thread_id())); DCHECK(ThreadId::Current().Equals(info->isolate()->thread_id()));
AllowDeferredHandleDereference allow_deref; AllowDeferredHandleDereference allow_deref;
AllowHeapAllocation allow_gc; AllowHeapAllocation allow_gc;
info->parse_info()->ast_value_factory()->Internalize(info->isolate()); parse_info->ast_value_factory()->Internalize(info->isolate());
if (FLAG_trace_codegen || print_ast) { if (FLAG_trace_codegen || print_ast) {
std::unique_ptr<char[]> name = info->GetDebugName(); std::unique_ptr<char[]> name = info->GetDebugName();
@ -112,7 +112,7 @@ void CodeGenerator::MakeCodePrologue(CompilationInfo* info, const char* kind) {
} }
#ifdef DEBUG #ifdef DEBUG
if (info->parse_info() && print_ast) { if (!info->IsStub() && print_ast) {
PrintF("--- AST ---\n%s\n", PrintF("--- AST ---\n%s\n",
AstPrinter(info->isolate()).PrintProgram(info->literal())); AstPrinter(info->isolate()).PrintProgram(info->literal()));
} }
@ -252,8 +252,7 @@ void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
OFStream os(tracing_scope.file()); OFStream os(tracing_scope.file());
// Print the source code if available. // Print the source code if available.
bool print_source = bool print_source = code->kind() == Code::OPTIMIZED_FUNCTION;
info->parse_info() && (code->kind() == Code::OPTIMIZED_FUNCTION);
if (print_source) { if (print_source) {
Handle<SharedFunctionInfo> shared = info->shared_info(); Handle<SharedFunctionInfo> shared = info->shared_info();
Handle<Script> script = info->script(); Handle<Script> script = info->script();
@ -274,7 +273,7 @@ void CodeGenerator::PrintCode(Handle<Code> code, CompilationInfo* info) {
} }
} }
if (info->IsOptimizing()) { if (info->IsOptimizing()) {
if (FLAG_print_unopt_code && info->parse_info()) { if (FLAG_print_unopt_code) {
os << "--- Unoptimized code ---\n"; os << "--- Unoptimized code ---\n";
info->closure()->shared()->code()->Disassemble(debug_name.get(), os); info->closure()->shared()->code()->Disassemble(debug_name.get(), os);
} }

View File

@ -69,11 +69,13 @@ namespace internal {
class CompilationInfo; class CompilationInfo;
class EhFrameWriter; class EhFrameWriter;
class ParseInfo;
class CodeGenerator { class CodeGenerator {
public: public:
// Printing of AST, etc. as requested by flags. // Printing of AST, etc. as requested by flags.
static void MakeCodePrologue(CompilationInfo* info, const char* kind); static void MakeCodePrologue(ParseInfo* parse_info, CompilationInfo* info,
const char* kind);
// Allocate and install the code. // Allocate and install the code.
static Handle<Code> MakeCodeEpilogue(TurboAssembler* tasm, static Handle<Code> MakeCodeEpilogue(TurboAssembler* tasm,

View File

@ -10,49 +10,16 @@
#include "src/debug/debug.h" #include "src/debug/debug.h"
#include "src/isolate.h" #include "src/isolate.h"
#include "src/objects-inl.h" #include "src/objects-inl.h"
#include "src/parsing/parse-info.h"
#include "src/source-position.h" #include "src/source-position.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
#define PARSE_INFO_GETTER(type, name) \ CompilationInfo::CompilationInfo(Zone* zone, Isolate* isolate,
type CompilationInfo::name() const { \ Handle<Script> script,
CHECK(parse_info()); \
return parse_info()->name(); \
}
#define PARSE_INFO_GETTER_WITH_DEFAULT(type, name, def) \
type CompilationInfo::name() const { \
return parse_info() ? parse_info()->name() : def; \
}
PARSE_INFO_GETTER(Handle<Script>, script)
PARSE_INFO_GETTER(FunctionLiteral*, literal)
PARSE_INFO_GETTER_WITH_DEFAULT(DeclarationScope*, scope, nullptr)
#undef PARSE_INFO_GETTER
#undef PARSE_INFO_GETTER_WITH_DEFAULT
bool CompilationInfo::is_debug() const {
return parse_info() ? parse_info()->is_debug() : false;
}
void CompilationInfo::set_is_debug() {
CHECK(parse_info());
parse_info()->set_is_debug();
}
void CompilationInfo::PrepareForSerializing() {
if (parse_info()) parse_info()->set_will_serialize();
SetFlag(kSerializing);
}
CompilationInfo::CompilationInfo(Zone* zone, ParseInfo* parse_info,
Isolate* isolate,
Handle<SharedFunctionInfo> shared, Handle<SharedFunctionInfo> shared,
Handle<JSFunction> closure) Handle<JSFunction> closure)
: CompilationInfo(parse_info, {}, Code::ComputeFlags(Code::FUNCTION), BASE, : CompilationInfo(script, {}, Code::ComputeFlags(Code::FUNCTION), BASE,
isolate, zone) { isolate, zone) {
shared_info_ = shared; shared_info_ = shared;
closure_ = closure; closure_ = closure;
@ -68,22 +35,31 @@ CompilationInfo::CompilationInfo(Zone* zone, ParseInfo* parse_info,
} }
if (FLAG_block_coverage && isolate->is_block_code_coverage() && if (FLAG_block_coverage && isolate->is_block_code_coverage() &&
parse_info->script()->IsUserJavaScript()) { script_->IsUserJavaScript()) {
MarkAsBlockCoverageEnabled(); MarkAsBlockCoverageEnabled();
} }
if (script_->type() == Script::TYPE_NATIVE) {
MarkAsNative();
}
if (script_->compilation_type() == Script::COMPILATION_TYPE_EVAL) {
MarkAsEval();
}
} }
CompilationInfo::CompilationInfo(Vector<const char> debug_name, CompilationInfo::CompilationInfo(Vector<const char> debug_name,
Isolate* isolate, Zone* zone, Isolate* isolate, Zone* zone,
Code::Flags code_flags) Code::Flags code_flags)
: CompilationInfo(nullptr, debug_name, code_flags, STUB, isolate, zone) {} : CompilationInfo(Handle<Script>::null(), debug_name, code_flags, STUB,
isolate, zone) {}
CompilationInfo::CompilationInfo(ParseInfo* parse_info, CompilationInfo::CompilationInfo(Handle<Script> script,
Vector<const char> debug_name, Vector<const char> debug_name,
Code::Flags code_flags, Mode mode, Code::Flags code_flags, Mode mode,
Isolate* isolate, Zone* zone) Isolate* isolate, Zone* zone)
: parse_info_(parse_info), : isolate_(isolate),
isolate_(isolate), script_(script),
literal_(nullptr),
flags_(0), flags_(0),
code_flags_(code_flags), code_flags_(code_flags),
mode_(mode), mode_(mode),
@ -105,6 +81,11 @@ CompilationInfo::~CompilationInfo() {
dependencies()->Rollback(); dependencies()->Rollback();
} }
DeclarationScope* CompilationInfo::scope() const {
DCHECK_NOT_NULL(literal_);
return literal_->scope();
}
int CompilationInfo::num_parameters() const { int CompilationInfo::num_parameters() const {
return !IsStub() ? scope()->num_parameters() : parameter_count_; return !IsStub() ? scope()->num_parameters() : parameter_count_;
} }
@ -137,6 +118,9 @@ void CompilationInfo::set_deferred_handles(DeferredHandles* deferred_handles) {
} }
void CompilationInfo::ReopenHandlesInNewHandleScope() { void CompilationInfo::ReopenHandlesInNewHandleScope() {
if (!script_.is_null()) {
script_ = Handle<Script>(*script_);
}
if (!shared_info_.is_null()) { if (!shared_info_.is_null()) {
shared_info_ = Handle<SharedFunctionInfo>(*shared_info_); shared_info_ = Handle<SharedFunctionInfo>(*shared_info_);
} }
@ -150,9 +134,9 @@ bool CompilationInfo::has_simple_parameters() {
} }
std::unique_ptr<char[]> CompilationInfo::GetDebugName() const { std::unique_ptr<char[]> CompilationInfo::GetDebugName() const {
if (parse_info() && parse_info()->literal()) { if (literal()) {
AllowHandleDereference allow_deref; AllowHandleDereference allow_deref;
return parse_info()->literal()->debug_name()->ToCString(); return literal()->debug_name()->ToCString();
} }
if (!shared_info().is_null()) { if (!shared_info().is_null()) {
return shared_info()->DebugName()->ToCString(); return shared_info()->DebugName()->ToCString();
@ -190,15 +174,14 @@ StackFrame::Type CompilationInfo::GetOutputStackFrameType() const {
} }
int CompilationInfo::GetDeclareGlobalsFlags() const { int CompilationInfo::GetDeclareGlobalsFlags() const {
return DeclareGlobalsEvalFlag::encode(parse_info()->is_eval()) | return DeclareGlobalsEvalFlag::encode(is_eval()) |
DeclareGlobalsNativeFlag::encode(parse_info()->is_native()); DeclareGlobalsNativeFlag::encode(is_native());
} }
SourcePositionTableBuilder::RecordingMode SourcePositionTableBuilder::RecordingMode
CompilationInfo::SourcePositionRecordingMode() const { CompilationInfo::SourcePositionRecordingMode() const {
return parse_info() && parse_info()->is_native() return is_native() ? SourcePositionTableBuilder::OMIT_SOURCE_POSITIONS
? SourcePositionTableBuilder::OMIT_SOURCE_POSITIONS : SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS;
: SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS;
} }
bool CompilationInfo::has_context() const { return !closure().is_null(); } bool CompilationInfo::has_context() const { return !closure().is_null(); }

View File

@ -23,9 +23,9 @@ class CoverageInfo;
class DeclarationScope; class DeclarationScope;
class DeferredHandles; class DeferredHandles;
class FunctionLiteral; class FunctionLiteral;
class JavaScriptFrame;
class ParseInfo;
class Isolate; class Isolate;
class JavaScriptFrame;
class SourceRangeMap;
class Zone; class Zone;
// CompilationInfo encapsulates some information known at compile time. It // CompilationInfo encapsulates some information known at compile time. It
@ -52,24 +52,32 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
kOptimizeFromBytecode = 1 << 14, kOptimizeFromBytecode = 1 << 14,
kLoopPeelingEnabled = 1 << 15, kLoopPeelingEnabled = 1 << 15,
kBlockCoverageEnabled = 1 << 16, kBlockCoverageEnabled = 1 << 16,
kIsDebug = 1 << 17,
kIsEval = 1 << 18,
kIsNative = 1 << 19,
}; };
CompilationInfo(Zone* zone, ParseInfo* parse_info, Isolate* isolate, CompilationInfo(Zone* zone, Isolate* isolate, Handle<Script> script,
Handle<SharedFunctionInfo> shared, Handle<SharedFunctionInfo> shared,
Handle<JSFunction> closure); Handle<JSFunction> closure);
CompilationInfo(Vector<const char> debug_name, Isolate* isolate, Zone* zone, CompilationInfo(Vector<const char> debug_name, Isolate* isolate, Zone* zone,
Code::Flags code_flags); Code::Flags code_flags);
~CompilationInfo(); ~CompilationInfo();
ParseInfo* parse_info() const { return parse_info_; } Handle<Script> script() const { return script_; }
FunctionLiteral* literal() const { return literal_; }
void set_literal(FunctionLiteral* literal) {
DCHECK_NOT_NULL(literal);
literal_ = literal;
}
SourceRangeMap* source_range_map() const { return source_range_map_; }
void set_source_range_map(SourceRangeMap* source_range_map) {
source_range_map_ = source_range_map;
}
// -----------------------------------------------------------
// TODO(titzer): inline and delete accessors of ParseInfo
// -----------------------------------------------------------
Handle<Script> script() const;
FunctionLiteral* literal() const;
DeclarationScope* scope() const; DeclarationScope* scope() const;
// -----------------------------------------------------------
Isolate* isolate() const { return isolate_; } Isolate* isolate() const { return isolate_; }
Zone* zone() { return zone_; } Zone* zone() { return zone_; }
@ -121,13 +129,11 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
// Compiles marked as debug produce unoptimized code with debug break slots. // Compiles marked as debug produce unoptimized code with debug break slots.
// Inner functions that cannot be compiled w/o context are compiled eagerly. // Inner functions that cannot be compiled w/o context are compiled eagerly.
void MarkAsDebug() { void MarkAsDebug() { SetFlag(kIsDebug); }
set_is_debug();
}
bool is_debug() const; bool is_debug() const { return GetFlag(kIsDebug); }
void PrepareForSerializing(); void MarkAsSerializing() { SetFlag(kSerializing); }
bool will_serialize() const { return GetFlag(kSerializing); } bool will_serialize() const { return GetFlag(kSerializing); }
@ -191,6 +197,14 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
return GetFlag(kBlockCoverageEnabled); return GetFlag(kBlockCoverageEnabled);
} }
void MarkAsEval() { SetFlag(kIsEval); }
bool is_eval() const { return GetFlag(kIsEval); }
void MarkAsNative() { SetFlag(kIsNative); }
bool is_native() const { return GetFlag(kIsNative); }
bool GeneratePreagedPrologue() const { bool GeneratePreagedPrologue() const {
// Generate a pre-aged prologue if we are optimizing for size, which // Generate a pre-aged prologue if we are optimizing for size, which
// will make code old more aggressive. Only apply to Code::FUNCTION, // will make code old more aggressive. Only apply to Code::FUNCTION,
@ -335,13 +349,10 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
// OPTIMIZE is optimized code generated by the Hydrogen-based backend. // OPTIMIZE is optimized code generated by the Hydrogen-based backend.
enum Mode { BASE, OPTIMIZE, STUB }; enum Mode { BASE, OPTIMIZE, STUB };
CompilationInfo(ParseInfo* parse_info, Vector<const char> debug_name, CompilationInfo(Handle<Script> script, Vector<const char> debug_name,
Code::Flags code_flags, Mode mode, Isolate* isolate, Code::Flags code_flags, Mode mode, Isolate* isolate,
Zone* zone); Zone* zone);
ParseInfo* parse_info_;
Isolate* isolate_;
void SetMode(Mode mode) { mode_ = mode; } void SetMode(Mode mode) { mode_ = mode; }
void SetFlag(Flag flag) { flags_ |= flag; } void SetFlag(Flag flag) { flags_ |= flag; }
@ -352,7 +363,10 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; } bool GetFlag(Flag flag) const { return (flags_ & flag) != 0; }
void set_is_debug(); Isolate* isolate_;
Handle<Script> script_;
FunctionLiteral* literal_;
SourceRangeMap* source_range_map_; // Used when block coverage is enabled.
unsigned flags_; unsigned flags_;

View File

@ -20,7 +20,7 @@ namespace {
void DisposeCompilationJob(CompilationJob* job, bool restore_function_code) { void DisposeCompilationJob(CompilationJob* job, bool restore_function_code) {
if (restore_function_code) { if (restore_function_code) {
Handle<JSFunction> function = job->info()->closure(); Handle<JSFunction> function = job->compilation_info()->closure();
function->ReplaceCode(function->shared()->code()); function->ReplaceCode(function->shared()->code());
if (function->IsInOptimizationQueue()) { if (function->IsInOptimizationQueue()) {
function->ClearOptimizationMarker(); function->ClearOptimizationMarker();
@ -197,7 +197,7 @@ void OptimizingCompileDispatcher::InstallOptimizedFunctions() {
job = output_queue_.front(); job = output_queue_.front();
output_queue_.pop(); output_queue_.pop();
} }
CompilationInfo* info = job->info(); CompilationInfo* info = job->compilation_info();
Handle<JSFunction> function(*info->closure()); Handle<JSFunction> function(*info->closure());
if (function->HasOptimizedCode()) { if (function->HasOptimizedCode()) {
if (FLAG_trace_concurrent_recompilation) { if (FLAG_trace_concurrent_recompilation) {

View File

@ -400,20 +400,21 @@ void UnoptimizedCompileJob::AnalyzeOnMainThread(Isolate* isolate) {
} }
compile_zone_.reset(new Zone(isolate->allocator(), ZONE_NAME)); compile_zone_.reset(new Zone(isolate->allocator(), ZONE_NAME));
compile_info_.reset(new CompilationInfo( compilation_info_.reset(new CompilationInfo(
compile_zone_.get(), parse_info_.get(), isolate, compile_zone_.get(), isolate, parse_info_->script(),
Handle<SharedFunctionInfo>::null(), Handle<JSFunction>::null())); Handle<SharedFunctionInfo>::null(), Handle<JSFunction>::null()));
compilation_info_->set_literal(parse_info_->literal());
DeferredHandleScope scope(isolate); DeferredHandleScope scope(isolate);
{ {
if (Compiler::Analyze(compile_info_.get())) { if (Compiler::Analyze(parse_info_.get(), isolate)) {
status_ = Status::kAnalyzed; status_ = Status::kAnalyzed;
} else { } else {
status_ = Status::kFailed; status_ = Status::kFailed;
if (!isolate->has_pending_exception()) isolate->StackOverflow(); if (!isolate->has_pending_exception()) isolate->StackOverflow();
} }
} }
compile_info_->set_deferred_handles(scope.Detach()); compilation_info_->set_deferred_handles(scope.Detach());
} }
void UnoptimizedCompileJob::PrepareToCompileOnMainThread(Isolate* isolate) { void UnoptimizedCompileJob::PrepareToCompileOnMainThread(Isolate* isolate) {
@ -422,15 +423,15 @@ void UnoptimizedCompileJob::PrepareToCompileOnMainThread(Isolate* isolate) {
DCHECK(status() == Status::kAnalyzed); DCHECK(status() == Status::kAnalyzed);
COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kPrepareToCompile); COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kPrepareToCompile);
compile_job_.reset( compilation_job_.reset(Compiler::PrepareUnoptimizedCompilationJob(
Compiler::PrepareUnoptimizedCompilationJob(compile_info_.get())); parse_info_.get(), compilation_info_.get()));
if (!compile_job_.get()) { if (!compilation_job_.get()) {
if (!isolate->has_pending_exception()) isolate->StackOverflow(); if (!isolate->has_pending_exception()) isolate->StackOverflow();
status_ = Status::kFailed; status_ = Status::kFailed;
return; return;
} }
CHECK(compile_job_->can_execute_on_background_thread()); CHECK(compilation_job_->can_execute_on_background_thread());
status_ = Status::kReadyToCompile; status_ = Status::kReadyToCompile;
} }
@ -445,9 +446,9 @@ void UnoptimizedCompileJob::Compile() {
// CompilationJob::ExecuteJob. // CompilationJob::ExecuteJob.
uintptr_t stack_limit = GetCurrentStackPosition() - max_stack_size_ * KB; uintptr_t stack_limit = GetCurrentStackPosition() - max_stack_size_ * KB;
compile_job_->set_stack_limit(stack_limit); compilation_job_->set_stack_limit(stack_limit);
CompilationJob::Status status = compile_job_->ExecuteJob(); CompilationJob::Status status = compilation_job_->ExecuteJob();
USE(status); USE(status);
// Always transition to kCompiled - errors will be reported by // Always transition to kCompiled - errors will be reported by
@ -467,17 +468,17 @@ void UnoptimizedCompileJob::FinalizeCompilingOnMainThread(Isolate* isolate) {
{ {
HandleScope scope(isolate); HandleScope scope(isolate);
compile_info_->set_shared_info(shared_); compilation_info_->set_shared_info(shared_);
if (compile_job_->state() == CompilationJob::State::kFailed || if (compilation_job_->state() == CompilationJob::State::kFailed ||
!Compiler::FinalizeCompilationJob(compile_job_.release())) { !Compiler::FinalizeCompilationJob(compilation_job_.release())) {
if (!isolate->has_pending_exception()) isolate->StackOverflow(); if (!isolate->has_pending_exception()) isolate->StackOverflow();
status_ = Status::kFailed; status_ = Status::kFailed;
return; return;
} }
} }
compile_job_.reset(); compilation_job_.reset();
compile_info_.reset(); compilation_info_.reset();
compile_zone_.reset(); compile_zone_.reset();
parse_info_.reset(); parse_info_.reset();
@ -489,8 +490,8 @@ void UnoptimizedCompileJob::ResetOnMainThread(Isolate* isolate) {
PrintF("UnoptimizedCompileJob[%p]: Resetting\n", static_cast<void*>(this)); PrintF("UnoptimizedCompileJob[%p]: Resetting\n", static_cast<void*>(this));
} }
compile_job_.reset(); compilation_job_.reset();
compile_info_.reset(); compilation_info_.reset();
compile_zone_.reset(); compile_zone_.reset();
parser_.reset(); parser_.reset();
unicode_cache_.reset(); unicode_cache_.reset();

View File

@ -132,8 +132,8 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob {
// Members required for compiling. // Members required for compiling.
std::shared_ptr<Zone> compile_zone_; std::shared_ptr<Zone> compile_zone_;
std::unique_ptr<CompilationInfo> compile_info_; std::unique_ptr<CompilationInfo> compilation_info_;
std::unique_ptr<CompilationJob> compile_job_; std::unique_ptr<CompilationJob> compilation_job_;
bool trace_compiler_dispatcher_jobs_; bool trace_compiler_dispatcher_jobs_;

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,7 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
// Prepare a compilation job for unoptimized code. Requires ParseAndAnalyse. // Prepare a compilation job for unoptimized code. Requires ParseAndAnalyse.
static CompilationJob* PrepareUnoptimizedCompilationJob( static CompilationJob* PrepareUnoptimizedCompilationJob(
CompilationInfo* info); ParseInfo* parse_info, CompilationInfo* compilation_info);
// Generate and install code from previously queued compilation job. // Generate and install code from previously queued compilation job.
static bool FinalizeCompilationJob(CompilationJob* job); static bool FinalizeCompilationJob(CompilationJob* job);
@ -68,20 +68,16 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
EagerInnerFunctionLiterals; EagerInnerFunctionLiterals;
// Parser::Parse, then Compiler::Analyze. // Parser::Parse, then Compiler::Analyze.
static bool ParseAndAnalyze(ParseInfo* info, static bool ParseAndAnalyze(ParseInfo* parse_info,
Handle<SharedFunctionInfo> shared_info, Handle<SharedFunctionInfo> shared_info,
Isolate* isolate); Isolate* isolate);
// Convenience function.
static bool ParseAndAnalyze(CompilationInfo* info);
// Rewrite, analyze scopes, and renumber. If |eager_literals| is non-null, it // Rewrite, analyze scopes, and renumber. If |eager_literals| is non-null, it
// is appended with inner function literals which should be eagerly compiled. // is appended with inner function literals which should be eagerly compiled.
static bool Analyze(ParseInfo* info, Isolate* isolate, static bool Analyze(ParseInfo* parse_info, Isolate* isolate,
EagerInnerFunctionLiterals* eager_literals = nullptr);
// Convenience function
static bool Analyze(CompilationInfo* info,
EagerInnerFunctionLiterals* eager_literals = nullptr); EagerInnerFunctionLiterals* eager_literals = nullptr);
// Ensures that bytecode is generated, calls ParseAndAnalyze internally. // Ensures that bytecode is generated, calls ParseAndAnalyze internally.
static bool EnsureBytecode(CompilationInfo* info); static bool EnsureBytecode(ParseInfo* parse_info,
CompilationInfo* compilation_info);
// =========================================================================== // ===========================================================================
// The following family of methods instantiates new functions for scripts or // The following family of methods instantiates new functions for scripts or
@ -169,7 +165,7 @@ class V8_EXPORT_PRIVATE CompilationJob {
kFailed, kFailed,
}; };
CompilationJob(Isolate* isolate, CompilationInfo* info, CompilationJob(Isolate* isolate, ParseInfo* parse_info, CompilationInfo* info,
const char* compiler_name, const char* compiler_name,
State initial_state = State::kReadyToPrepare); State initial_state = State::kReadyToPrepare);
virtual ~CompilationJob() {} virtual ~CompilationJob() {}
@ -206,7 +202,8 @@ class V8_EXPORT_PRIVATE CompilationJob {
return executed_on_background_thread_; return executed_on_background_thread_;
} }
State state() const { return state_; } State state() const { return state_; }
CompilationInfo* info() const { return info_; } ParseInfo* parse_info() const { return parse_info_; }
CompilationInfo* compilation_info() const { return compilation_info_; }
Isolate* isolate() const; Isolate* isolate() const;
virtual size_t AllocatedMemory() const { return 0; } virtual size_t AllocatedMemory() const { return 0; }
@ -217,7 +214,9 @@ class V8_EXPORT_PRIVATE CompilationJob {
virtual Status FinalizeJobImpl() = 0; virtual Status FinalizeJobImpl() = 0;
private: private:
CompilationInfo* info_; // TODO(6409): Remove parse_info once Fullcode and AstGraphBuilder are gone.
ParseInfo* parse_info_;
CompilationInfo* compilation_info_;
ThreadId isolate_thread_id_; ThreadId isolate_thread_id_;
base::TimeDelta time_taken_to_prepare_; base::TimeDelta time_taken_to_prepare_;
base::TimeDelta time_taken_to_execute_; base::TimeDelta time_taken_to_execute_;

View File

@ -527,7 +527,7 @@ void CodeGenerator::AssembleSourcePosition(SourcePosition source_position) {
source_position, false); source_position, false);
if (FLAG_code_comments) { if (FLAG_code_comments) {
CompilationInfo* info = this->info(); CompilationInfo* info = this->info();
if (!info->parse_info()) return; if (info->IsStub()) return;
std::ostringstream buffer; std::ostringstream buffer;
buffer << "-- "; buffer << "-- ";
if (FLAG_trace_turbo || if (FLAG_trace_turbo ||

View File

@ -46,7 +46,7 @@ std::unique_ptr<char[]> GetVisualizerLogFileName(CompilationInfo* info,
} }
EmbeddedVector<char, 256> source_file(0); EmbeddedVector<char, 256> source_file(0);
bool source_available = false; bool source_available = false;
if (FLAG_trace_file_names && info->parse_info()) { if (FLAG_trace_file_names && !info->script().is_null()) {
Object* source_name = info->script()->name(); Object* source_name = info->script()->name();
if (source_name->IsString()) { if (source_name->IsString()) {
String* str = String::cast(source_name); String* str = String::cast(source_name);

View File

@ -507,13 +507,13 @@ Reduction JSInliner::ReduceJSCall(Node* node) {
} }
ParseInfo parse_info(shared_info); ParseInfo parse_info(shared_info);
CompilationInfo info(parse_info.zone(), &parse_info, CompilationInfo info(parse_info.zone(), shared_info->GetIsolate(),
shared_info->GetIsolate(), shared_info, parse_info.script(), shared_info,
Handle<JSFunction>::null()); Handle<JSFunction>::null());
if (info_->is_deoptimization_enabled()) info.MarkAsDeoptimizationEnabled(); if (info_->is_deoptimization_enabled()) info.MarkAsDeoptimizationEnabled();
info.MarkAsOptimizeFromBytecode(); info.MarkAsOptimizeFromBytecode();
if (!Compiler::EnsureBytecode(&info)) { if (!Compiler::EnsureBytecode(&parse_info, &info)) {
TRACE("Not inlining %s into %s because bytecode generation failed\n", TRACE("Not inlining %s into %s because bytecode generation failed\n",
shared_info->DebugName()->ToCString().get(), shared_info->DebugName()->ToCString().get(),
info_->shared_info()->DebugName()->ToCString().get()); info_->shared_info()->DebugName()->ToCString().get());

View File

@ -574,12 +574,11 @@ PipelineStatistics* CreatePipelineStatistics(CompilationInfo* info,
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
TurboJsonFile json_of(info, std::ios_base::trunc); TurboJsonFile json_of(info, std::ios_base::trunc);
std::unique_ptr<char[]> function_name = info->GetDebugName(); std::unique_ptr<char[]> function_name = info->GetDebugName();
int pos = info->parse_info() ? info->shared_info()->start_position() : 0; int pos = info->IsStub() ? 0 : info->shared_info()->start_position();
json_of << "{\"function\":\"" << function_name.get() json_of << "{\"function\":\"" << function_name.get()
<< "\", \"sourcePosition\":" << pos << ", \"source\":\""; << "\", \"sourcePosition\":" << pos << ", \"source\":\"";
Isolate* isolate = info->isolate(); Isolate* isolate = info->isolate();
Handle<Script> script = Handle<Script> script = info->script();
info->parse_info() ? info->script() : Handle<Script>::null();
if (!script.is_null() && !script->source()->IsUndefined(isolate)) { if (!script.is_null() && !script->source()->IsUndefined(isolate)) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
int start = info->shared_info()->start_position(); int start = info->shared_info()->start_position();
@ -604,13 +603,15 @@ class PipelineCompilationJob final : public CompilationJob {
Handle<JSFunction> function) Handle<JSFunction> function)
// Note that the CompilationInfo is not initialized at the time we pass it // Note that the CompilationInfo is not initialized at the time we pass it
// to the CompilationJob constructor, but it is not dereferenced there. // to the CompilationJob constructor, but it is not dereferenced there.
: CompilationJob(function->GetIsolate(), &info_, "TurboFan"), : CompilationJob(function->GetIsolate(), parse_info, &compilation_info_,
"TurboFan"),
parse_info_(parse_info), parse_info_(parse_info),
zone_stats_(function->GetIsolate()->allocator()), zone_stats_(function->GetIsolate()->allocator()),
info_(parse_info_.get()->zone(), parse_info_.get(), compilation_info_(parse_info_.get()->zone(), function->GetIsolate(),
function->GetIsolate(), shared_info, function), parse_info_->script(), shared_info, function),
pipeline_statistics_(CreatePipelineStatistics(info(), &zone_stats_)), pipeline_statistics_(
data_(&zone_stats_, info(), pipeline_statistics_.get()), CreatePipelineStatistics(compilation_info(), &zone_stats_)),
data_(&zone_stats_, compilation_info(), pipeline_statistics_.get()),
pipeline_(&data_), pipeline_(&data_),
linkage_(nullptr) {} linkage_(nullptr) {}
@ -625,7 +626,7 @@ class PipelineCompilationJob final : public CompilationJob {
private: private:
std::unique_ptr<ParseInfo> parse_info_; std::unique_ptr<ParseInfo> parse_info_;
ZoneStats zone_stats_; ZoneStats zone_stats_;
CompilationInfo info_; CompilationInfo compilation_info_;
std::unique_ptr<PipelineStatistics> pipeline_statistics_; std::unique_ptr<PipelineStatistics> pipeline_statistics_;
PipelineData data_; PipelineData data_;
PipelineImpl pipeline_; PipelineImpl pipeline_;
@ -635,45 +636,47 @@ class PipelineCompilationJob final : public CompilationJob {
}; };
PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl() { PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl() {
if (info()->shared_info()->asm_function()) { if (compilation_info()->shared_info()->asm_function()) {
if (info()->osr_frame() && !info()->is_optimizing_from_bytecode()) { if (compilation_info()->osr_frame() &&
info()->MarkAsFrameSpecializing(); !compilation_info()->is_optimizing_from_bytecode()) {
compilation_info()->MarkAsFrameSpecializing();
} }
info()->MarkAsFunctionContextSpecializing(); compilation_info()->MarkAsFunctionContextSpecializing();
} else { } else {
if (!FLAG_always_opt) { if (!FLAG_always_opt) {
info()->MarkAsBailoutOnUninitialized(); compilation_info()->MarkAsBailoutOnUninitialized();
} }
if (FLAG_turbo_loop_peeling) { if (FLAG_turbo_loop_peeling) {
info()->MarkAsLoopPeelingEnabled(); compilation_info()->MarkAsLoopPeelingEnabled();
} }
} }
if (info()->is_optimizing_from_bytecode()) { if (compilation_info()->is_optimizing_from_bytecode()) {
info()->MarkAsDeoptimizationEnabled(); compilation_info()->MarkAsDeoptimizationEnabled();
if (FLAG_turbo_inlining) { if (FLAG_turbo_inlining) {
info()->MarkAsInliningEnabled(); compilation_info()->MarkAsInliningEnabled();
} }
if (FLAG_inline_accessors) { if (FLAG_inline_accessors) {
info()->MarkAsAccessorInliningEnabled(); compilation_info()->MarkAsAccessorInliningEnabled();
} }
if (info()->closure()->feedback_vector_cell()->map() == if (compilation_info()->closure()->feedback_vector_cell()->map() ==
isolate()->heap()->one_closure_cell_map()) { isolate()->heap()->one_closure_cell_map()) {
info()->MarkAsFunctionContextSpecializing(); compilation_info()->MarkAsFunctionContextSpecializing();
} }
info()->MarkAsInliningEnabled(); compilation_info()->MarkAsInliningEnabled();
} }
data_.set_start_source_position(info()->shared_info()->start_position()); data_.set_start_source_position(
compilation_info()->shared_info()->start_position());
linkage_ = new (info()->zone()) linkage_ = new (compilation_info()->zone()) Linkage(
Linkage(Linkage::ComputeIncoming(info()->zone(), info())); Linkage::ComputeIncoming(compilation_info()->zone(), compilation_info()));
if (!pipeline_.CreateGraph()) { if (!pipeline_.CreateGraph()) {
if (isolate()->has_pending_exception()) return FAILED; // Stack overflowed. if (isolate()->has_pending_exception()) return FAILED; // Stack overflowed.
return AbortOptimization(kGraphBuildingFailed); return AbortOptimization(kGraphBuildingFailed);
} }
if (info()->is_osr()) data_.InitializeOsrHelper(); if (compilation_info()->is_osr()) data_.InitializeOsrHelper();
// Make sure that we have generated the maximal number of deopt entries. // Make sure that we have generated the maximal number of deopt entries.
// This is in order to avoid triggering the generation of deopt entries later // This is in order to avoid triggering the generation of deopt entries later
@ -692,15 +695,15 @@ PipelineCompilationJob::Status PipelineCompilationJob::ExecuteJobImpl() {
PipelineCompilationJob::Status PipelineCompilationJob::FinalizeJobImpl() { PipelineCompilationJob::Status PipelineCompilationJob::FinalizeJobImpl() {
Handle<Code> code = pipeline_.FinalizeCode(); Handle<Code> code = pipeline_.FinalizeCode();
if (code.is_null()) { if (code.is_null()) {
if (info()->bailout_reason() == kNoReason) { if (compilation_info()->bailout_reason() == kNoReason) {
return AbortOptimization(kCodeGenerationFailed); return AbortOptimization(kCodeGenerationFailed);
} }
return FAILED; return FAILED;
} }
info()->dependencies()->Commit(code); compilation_info()->dependencies()->Commit(code);
info()->SetCode(code); compilation_info()->SetCode(code);
if (info()->is_deoptimization_enabled()) { if (compilation_info()->is_deoptimization_enabled()) {
info()->context()->native_context()->AddOptimizedCode(*code); compilation_info()->context()->native_context()->AddOptimizedCode(*code);
RegisterWeakObjectsInOptimizedCode(code); RegisterWeakObjectsInOptimizedCode(code);
} }
return SUCCEEDED; return SUCCEEDED;
@ -765,7 +768,7 @@ class PipelineWasmCompilationJob final : public CompilationJob {
SourcePositionTable* source_positions, SourcePositionTable* source_positions,
ZoneVector<trap_handler::ProtectedInstructionData>* protected_insts, ZoneVector<trap_handler::ProtectedInstructionData>* protected_insts,
wasm::ModuleOrigin wasm_origin) wasm::ModuleOrigin wasm_origin)
: CompilationJob(info->isolate(), info, "TurboFan", : CompilationJob(info->isolate(), nullptr, info, "TurboFan",
State::kReadyToExecute), State::kReadyToExecute),
zone_stats_(info->isolate()->allocator()), zone_stats_(info->isolate()->allocator()),
pipeline_statistics_(CreatePipelineStatistics(info, &zone_stats_)), pipeline_statistics_(CreatePipelineStatistics(info, &zone_stats_)),
@ -806,8 +809,8 @@ PipelineWasmCompilationJob::PrepareJobImpl() {
PipelineWasmCompilationJob::Status PipelineWasmCompilationJob::Status
PipelineWasmCompilationJob::ExecuteJobImpl() { PipelineWasmCompilationJob::ExecuteJobImpl() {
if (FLAG_trace_turbo) { if (FLAG_trace_turbo) {
TurboJsonFile json_of(info(), std::ios_base::trunc); TurboJsonFile json_of(compilation_info(), std::ios_base::trunc);
json_of << "{\"function\":\"" << info()->GetDebugName().get() json_of << "{\"function\":\"" << compilation_info()->GetDebugName().get()
<< "\", \"source\":\"\",\n\"phases\":["; << "\", \"source\":\"\",\n\"phases\":[";
} }
@ -1873,7 +1876,7 @@ Handle<Code> Pipeline::GenerateCodeForCodeStub(Isolate* isolate,
Code::Flags flags, Code::Flags flags,
const char* debug_name) { const char* debug_name) {
CompilationInfo info(CStrVector(debug_name), isolate, graph->zone(), flags); CompilationInfo info(CStrVector(debug_name), isolate, graph->zone(), flags);
if (isolate->serializer_enabled()) info.PrepareForSerializing(); if (isolate->serializer_enabled()) info.MarkAsSerializing();
// Construct a pipeline for scheduling and code generation. // Construct a pipeline for scheduling and code generation.
ZoneStats zone_stats(isolate->allocator()); ZoneStats zone_stats(isolate->allocator());

View File

@ -29,8 +29,9 @@ namespace internal {
class FullCodegenCompilationJob final : public CompilationJob { class FullCodegenCompilationJob final : public CompilationJob {
public: public:
explicit FullCodegenCompilationJob(CompilationInfo* info) explicit FullCodegenCompilationJob(ParseInfo* parse_info,
: CompilationJob(info->isolate(), info, "Full-Codegen") {} CompilationInfo* info)
: CompilationJob(info->isolate(), parse_info, info, "Full-Codegen") {}
bool can_execute_on_background_thread() const override { return false; } bool can_execute_on_background_thread() const override { return false; }
@ -38,8 +39,10 @@ class FullCodegenCompilationJob final : public CompilationJob {
CompilationJob::Status ExecuteJobImpl() final { CompilationJob::Status ExecuteJobImpl() final {
DCHECK(ThreadId::Current().Equals(isolate()->thread_id())); DCHECK(ThreadId::Current().Equals(isolate()->thread_id()));
return FullCodeGenerator::MakeCode(info(), stack_limit()) ? SUCCEEDED return FullCodeGenerator::MakeCode(parse_info(), compilation_info(),
: FAILED; stack_limit())
? SUCCEEDED
: FAILED;
} }
CompilationJob::Status FinalizeJobImpl() final { return SUCCEEDED; } CompilationJob::Status FinalizeJobImpl() final { return SUCCEEDED; }
@ -70,17 +73,14 @@ FullCodeGenerator::FullCodeGenerator(MacroAssembler* masm,
} }
// static // static
CompilationJob* FullCodeGenerator::NewCompilationJob(CompilationInfo* info) { CompilationJob* FullCodeGenerator::NewCompilationJob(
return new FullCodegenCompilationJob(info); ParseInfo* parse_info, CompilationInfo* compilation_info) {
return new FullCodegenCompilationJob(parse_info, compilation_info);
} }
// static // static
bool FullCodeGenerator::MakeCode(CompilationInfo* info) { bool FullCodeGenerator::MakeCode(ParseInfo* parse_info, CompilationInfo* info,
return MakeCode(info, info->isolate()->stack_guard()->real_climit()); uintptr_t stack_limit) {
}
// static
bool FullCodeGenerator::MakeCode(CompilationInfo* info, uintptr_t stack_limit) {
Isolate* isolate = info->isolate(); Isolate* isolate = info->isolate();
DCHECK(!info->literal()->must_use_ignition()); DCHECK(!info->literal()->must_use_ignition());
@ -96,7 +96,7 @@ bool FullCodeGenerator::MakeCode(CompilationInfo* info, uintptr_t stack_limit) {
int len = String::cast(script->source())->length(); int len = String::cast(script->source())->length();
isolate->counters()->total_full_codegen_source_size()->Increment(len); isolate->counters()->total_full_codegen_source_size()->Increment(len);
} }
CodeGenerator::MakeCodePrologue(info, "full"); CodeGenerator::MakeCodePrologue(parse_info, info, "full");
const int kInitialBufferSize = 4 * KB; const int kInitialBufferSize = 4 * KB;
MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize, MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize,
CodeObjectRequired::kYes); CodeObjectRequired::kYes);

View File

@ -25,6 +25,7 @@ namespace internal {
class CompilationInfo; class CompilationInfo;
class CompilationJob; class CompilationJob;
class JumpPatchSite; class JumpPatchSite;
class ParseInfo;
class Scope; class Scope;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -37,10 +38,11 @@ class FullCodeGenerator final : public AstVisitor<FullCodeGenerator> {
void Initialize(uintptr_t stack_limit); void Initialize(uintptr_t stack_limit);
static CompilationJob* NewCompilationJob(CompilationInfo* info); static CompilationJob* NewCompilationJob(ParseInfo* parse_info,
CompilationInfo* compilation_info);
static bool MakeCode(CompilationInfo* info, uintptr_t stack_limit); static bool MakeCode(ParseInfo* parse_info, CompilationInfo* info,
static bool MakeCode(CompilationInfo* info); uintptr_t stack_limit);
static const int kMaxBackEdgeWeight = 127; static const int kMaxBackEdgeWeight = 127;

View File

@ -774,8 +774,8 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info)
DCHECK_EQ(closure_scope(), closure_scope()->GetClosureScope()); DCHECK_EQ(closure_scope(), closure_scope()->GetClosureScope());
if (info->is_block_coverage_enabled()) { if (info->is_block_coverage_enabled()) {
DCHECK(FLAG_block_coverage); DCHECK(FLAG_block_coverage);
block_coverage_builder_ = new (zone()) BlockCoverageBuilder( block_coverage_builder_ = new (zone())
zone(), builder(), info->parse_info()->source_range_map()); BlockCoverageBuilder(zone(), builder(), info->source_range_map());
} }
} }

View File

@ -24,7 +24,8 @@ namespace interpreter {
class InterpreterCompilationJob final : public CompilationJob { class InterpreterCompilationJob final : public CompilationJob {
public: public:
explicit InterpreterCompilationJob(CompilationInfo* info); InterpreterCompilationJob(ParseInfo* pare_info,
CompilationInfo* compilation_info);
protected: protected:
Status PrepareJobImpl() final; Status PrepareJobImpl() final;
@ -143,15 +144,19 @@ bool ShouldPrintBytecode(Handle<SharedFunctionInfo> shared) {
} // namespace } // namespace
InterpreterCompilationJob::InterpreterCompilationJob(CompilationInfo* info) InterpreterCompilationJob::InterpreterCompilationJob(
: CompilationJob(info->isolate(), info, "Ignition"), ParseInfo* parse_info, CompilationInfo* compilation_info)
generator_(info), : CompilationJob(compilation_info->isolate(), parse_info, compilation_info,
runtime_call_stats_(info->isolate()->counters()->runtime_call_stats()), "Ignition"),
generator_(compilation_info),
runtime_call_stats_(
compilation_info->isolate()->counters()->runtime_call_stats()),
background_execute_counter_("CompileBackgroundIgnition") {} background_execute_counter_("CompileBackgroundIgnition") {}
InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() { InterpreterCompilationJob::Status InterpreterCompilationJob::PrepareJobImpl() {
// TODO(5203): Move code out of codegen.cc once FCG goes away. // TODO(5203): Move code out of codegen.cc once FCG goes away.
CodeGenerator::MakeCodePrologue(info(), "interpreter"); CodeGenerator::MakeCodePrologue(parse_info(), compilation_info(),
"interpreter");
return SUCCEEDED; return SUCCEEDED;
} }
@ -186,22 +191,24 @@ InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl() {
return FAILED; return FAILED;
} }
if (ShouldPrintBytecode(info()->shared_info())) { if (ShouldPrintBytecode(compilation_info()->shared_info())) {
OFStream os(stdout); OFStream os(stdout);
std::unique_ptr<char[]> name = info()->GetDebugName(); std::unique_ptr<char[]> name = compilation_info()->GetDebugName();
os << "[generating bytecode for function: " << info()->GetDebugName().get() os << "[generating bytecode for function: "
<< "]" << std::endl; << compilation_info()->GetDebugName().get() << "]" << std::endl;
bytecodes->Disassemble(os); bytecodes->Disassemble(os);
os << std::flush; os << std::flush;
} }
info()->SetBytecodeArray(bytecodes); compilation_info()->SetBytecodeArray(bytecodes);
info()->SetCode(BUILTIN_CODE(info()->isolate(), InterpreterEntryTrampoline)); compilation_info()->SetCode(
BUILTIN_CODE(compilation_info()->isolate(), InterpreterEntryTrampoline));
return SUCCEEDED; return SUCCEEDED;
} }
CompilationJob* Interpreter::NewCompilationJob(CompilationInfo* info) { CompilationJob* Interpreter::NewCompilationJob(
return new InterpreterCompilationJob(info); ParseInfo* parse_info, CompilationInfo* compilation_info) {
return new InterpreterCompilationJob(parse_info, compilation_info);
} }
bool Interpreter::IsDispatchTableInitialized() { bool Interpreter::IsDispatchTableInitialized() {

View File

@ -23,6 +23,7 @@ class Isolate;
class Callable; class Callable;
class CompilationInfo; class CompilationInfo;
class CompilationJob; class CompilationJob;
class ParseInfo;
class SetupIsolateDelegate; class SetupIsolateDelegate;
class RootVisitor; class RootVisitor;
@ -38,8 +39,10 @@ class Interpreter {
// Returns the interrupt budget which should be used for the profiler counter. // Returns the interrupt budget which should be used for the profiler counter.
static int InterruptBudget(); static int InterruptBudget();
// Creates a compilation job which will generate bytecode for |info|. // Creates a compilation job which will generate bytecode for |parse_info| and
static CompilationJob* NewCompilationJob(CompilationInfo* info); // |compilation_info|.
static CompilationJob* NewCompilationJob(ParseInfo* parse_info,
CompilationInfo* compilation_info);
// Return bytecode handler for |bytecode|. // Return bytecode handler for |bytecode|.
Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale); Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale);

View File

@ -141,8 +141,8 @@ Handle<JSFunction> FunctionTester::ForMachineGraph(Graph* graph,
Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) { Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) {
Handle<SharedFunctionInfo> shared(function->shared()); Handle<SharedFunctionInfo> shared(function->shared());
ParseInfo parse_info(shared); ParseInfo parse_info(shared);
CompilationInfo info(parse_info.zone(), &parse_info, function->GetIsolate(), CompilationInfo info(parse_info.zone(), function->GetIsolate(),
shared, function); parse_info.script(), shared, function);
info.SetOptimizing(); info.SetOptimizing();
if (flags_ & CompilationInfo::kInliningEnabled) { if (flags_ & CompilationInfo::kInliningEnabled) {
@ -154,7 +154,7 @@ Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) {
info.MarkAsDeoptimizationEnabled(); info.MarkAsDeoptimizationEnabled();
info.MarkAsOptimizeFromBytecode(); info.MarkAsOptimizeFromBytecode();
} else { } else {
CHECK(Compiler::ParseAndAnalyze(&info)); CHECK(Compiler::ParseAndAnalyze(&parse_info, shared, info.isolate()));
parse_info.ast_value_factory()->Internalize(info.isolate()); parse_info.ast_value_factory()->Internalize(info.isolate());
} }
JSFunction::EnsureLiterals(function); JSFunction::EnsureLiterals(function);
@ -172,11 +172,11 @@ Handle<JSFunction> FunctionTester::Compile(Handle<JSFunction> function) {
Handle<JSFunction> FunctionTester::CompileGraph(Graph* graph) { Handle<JSFunction> FunctionTester::CompileGraph(Graph* graph) {
Handle<SharedFunctionInfo> shared(function->shared()); Handle<SharedFunctionInfo> shared(function->shared());
ParseInfo parse_info(shared); ParseInfo parse_info(shared);
CompilationInfo info(parse_info.zone(), &parse_info, function->GetIsolate(), CompilationInfo info(parse_info.zone(), function->GetIsolate(),
shared, function); parse_info.script(), shared, function);
CHECK(parsing::ParseFunction(info.parse_info(), info.shared_info(), CHECK(
info.isolate())); parsing::ParseFunction(&parse_info, info.shared_info(), info.isolate()));
info.SetOptimizing(); info.SetOptimizing();
Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph); Handle<Code> code = Pipeline::GenerateCodeForTesting(&info, graph);

View File

@ -46,8 +46,8 @@ TEST(TestLinkageCreate) {
HandleAndZoneScope handles; HandleAndZoneScope handles;
Handle<JSFunction> function = Compile("a + b"); Handle<JSFunction> function = Compile("a + b");
Handle<SharedFunctionInfo> shared(function->shared()); Handle<SharedFunctionInfo> shared(function->shared());
ParseInfo parse_info(shared); Handle<Script> script(Script::cast(shared->script()));
CompilationInfo info(parse_info.zone(), &parse_info, function->GetIsolate(), CompilationInfo info(handles.main_zone(), function->GetIsolate(), script,
shared, function); shared, function);
CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info); CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
CHECK(descriptor); CHECK(descriptor);
@ -64,8 +64,8 @@ TEST(TestLinkageJSFunctionIncoming) {
Handle<JSFunction>::cast(v8::Utils::OpenHandle( Handle<JSFunction>::cast(v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(CompileRun(sources[i])))); *v8::Local<v8::Function>::Cast(CompileRun(sources[i]))));
Handle<SharedFunctionInfo> shared(function->shared()); Handle<SharedFunctionInfo> shared(function->shared());
ParseInfo parse_info(shared); Handle<Script> script(Script::cast(shared->script()));
CompilationInfo info(parse_info.zone(), &parse_info, function->GetIsolate(), CompilationInfo info(handles.main_zone(), function->GetIsolate(), script,
shared, function); shared, function);
CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info); CallDescriptor* descriptor = Linkage::ComputeIncoming(info.zone(), &info);
CHECK(descriptor); CHECK(descriptor);
@ -82,8 +82,8 @@ TEST(TestLinkageJSCall) {
HandleAndZoneScope handles; HandleAndZoneScope handles;
Handle<JSFunction> function = Compile("a + c"); Handle<JSFunction> function = Compile("a + c");
Handle<SharedFunctionInfo> shared(function->shared()); Handle<SharedFunctionInfo> shared(function->shared());
ParseInfo parse_info(shared); Handle<Script> script(Script::cast(shared->script()));
CompilationInfo info(parse_info.zone(), &parse_info, function->GetIsolate(), CompilationInfo info(handles.main_zone(), function->GetIsolate(), script,
shared, function); shared, function);
for (int i = 0; i < 32; i++) { for (int i = 0; i < 32; i++) {

View File

@ -35,11 +35,12 @@ struct TestHelper : public HandleAndZoneScope {
// TODO(titzer): don't scope analyze every single time. // TODO(titzer): don't scope analyze every single time.
Handle<SharedFunctionInfo> shared(function->shared()); Handle<SharedFunctionInfo> shared(function->shared());
ParseInfo parse_info(shared); ParseInfo parse_info(shared);
CompilationInfo info(parse_info.zone(), &parse_info, function->GetIsolate(), CompilationInfo info(parse_info.zone(), function->GetIsolate(),
shared, function); parse_info.script(), shared, function);
CHECK(parsing::ParseFunction(&parse_info, info.shared_info(), CHECK(parsing::ParseFunction(&parse_info, info.shared_info(),
info.isolate())); info.isolate()));
info.set_literal(parse_info.literal());
CHECK(Rewriter::Rewrite(&parse_info)); CHECK(Rewriter::Rewrite(&parse_info));
DeclarationScope::Analyze(&parse_info, info.isolate()); DeclarationScope::Analyze(&parse_info, info.isolate());

View File

@ -118,13 +118,11 @@ class BytecodeGraphTester {
Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function)); Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function));
CHECK(function->shared()->HasBytecodeArray()); CHECK(function->shared()->HasBytecodeArray());
// TODO(mstarzinger): We should be able to prime CompilationInfo without Zone zone(function->GetIsolate()->allocator(), ZONE_NAME);
// having to instantiate a ParseInfo first. Fix this!
Handle<SharedFunctionInfo> shared(function->shared()); Handle<SharedFunctionInfo> shared(function->shared());
ParseInfo parse_info(shared); Handle<Script> script(Script::cast(shared->script()));
CompilationInfo compilation_info(&zone, function->GetIsolate(), script,
CompilationInfo compilation_info(parse_info.zone(), &parse_info, shared, function);
function->GetIsolate(), shared, function);
compilation_info.SetOptimizing(); compilation_info.SetOptimizing();
compilation_info.MarkAsDeoptimizationEnabled(); compilation_info.MarkAsDeoptimizationEnabled();
compilation_info.MarkAsOptimizeFromBytecode(); compilation_info.MarkAsOptimizeFromBytecode();

View File

@ -26,12 +26,12 @@ namespace {
class BlockingCompilationJob : public CompilationJob { class BlockingCompilationJob : public CompilationJob {
public: public:
BlockingCompilationJob(Isolate* isolate, Handle<JSFunction> function) BlockingCompilationJob(Isolate* isolate, Handle<JSFunction> function)
: CompilationJob(isolate, &info_, "BlockingCompilationJob", : CompilationJob(isolate, &parse_info_, &info_, "BlockingCompilationJob",
State::kReadyToExecute), State::kReadyToExecute),
shared_(function->shared()), shared_(function->shared()),
parse_info_(shared_), parse_info_(shared_),
info_(parse_info_.zone(), &parse_info_, function->GetIsolate(), shared_, info_(parse_info_.zone(), function->GetIsolate(), parse_info_.script(),
function), shared_, function),
blocking_(false), blocking_(false),
semaphore_(0) {} semaphore_(0) {}
~BlockingCompilationJob() override = default; ~BlockingCompilationJob() override = default;