Commit 06d91dac authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Compiler] Split CompileUnoptimizedCode into main and non-main thread phases

Splits CompileUnoptimizedCode into a non-main thread GenerateUnoptimizedCode and
a main thread FinalizeUnoptimizedCode phase. Adds Disallow<HeapAccess> scopes in
CompileUnoptimizedCode to ensure no access to the heap during this phase.

Also cleans up a few heap accesses in CompilationInfo's constructor to avoid
violating the disallowed heap access.

Currently we reallow heap access during asm.js compilation as a temporary
measure until the script streamer uses an off-heap script buffer.

BUG=v8:5203
TBR=titzer@chromium.org

Change-Id: I7f6140f19938a10a85f1cd89501812dd59dbf6d4
Reviewed-on: https://chromium-review.googlesource.com/605949
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47337}
parent 19ae2fc1
...@@ -213,6 +213,14 @@ class AsmJsCompilationJob final : public CompilationJob { ...@@ -213,6 +213,14 @@ class AsmJsCompilationJob final : public CompilationJob {
}; };
CompilationJob::Status AsmJsCompilationJob::PrepareJobImpl() { CompilationJob::Status AsmJsCompilationJob::PrepareJobImpl() {
// TODO(rmcilroy): Temporarily allow heap access here until we use a
// off-heap ScannerStream.
DCHECK(
ThreadId::Current().Equals(compilation_info()->isolate()->thread_id()));
AllowHeapAllocation allow_allocation;
AllowHandleAllocation allow_handles;
AllowHandleDereference allow_deref;
// 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(
compilation_info()->isolate()->counters()->asm_wasm_translation_time()); compilation_info()->isolate()->counters()->asm_wasm_translation_time());
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "src/accessors.h" #include "src/accessors.h"
#include "src/ast/ast.h" #include "src/ast/ast.h"
#include "src/base/optional.h"
#include "src/bootstrapper.h" #include "src/bootstrapper.h"
#include "src/counters.h" #include "src/counters.h"
#include "src/messages.h" #include "src/messages.h"
...@@ -651,6 +652,12 @@ void DeclarationScope::Analyze(ParseInfo* info) { ...@@ -651,6 +652,12 @@ void DeclarationScope::Analyze(ParseInfo* info) {
DCHECK(info->literal() != NULL); DCHECK(info->literal() != NULL);
DeclarationScope* scope = info->literal()->scope(); DeclarationScope* scope = info->literal()->scope();
base::Optional<AllowHandleDereference> allow_deref;
if (!info->maybe_outer_scope_info().is_null()) {
// Allow dereferences to the scope info if there is one.
allow_deref.emplace();
}
if (scope->is_eval_scope() && is_sloppy(scope->language_mode())) { if (scope->is_eval_scope() && is_sloppy(scope->language_mode())) {
AstNodeFactory factory(info->ast_value_factory(), info->zone()); AstNodeFactory factory(info->ast_value_factory(), info->zone());
scope->HoistSloppyBlockFunctions(&factory); scope->HoistSloppyBlockFunctions(&factory);
...@@ -678,8 +685,7 @@ void DeclarationScope::Analyze(ParseInfo* info) { ...@@ -678,8 +685,7 @@ void DeclarationScope::Analyze(ParseInfo* info) {
scope->AllocateVariables(info); scope->AllocateVariables(info);
#ifdef DEBUG #ifdef DEBUG
if (info->script_is_native() ? FLAG_print_builtin_scopes if (info->is_native() ? FLAG_print_builtin_scopes : FLAG_print_scopes) {
: FLAG_print_scopes) {
PrintF("Global scope:\n"); PrintF("Global scope:\n");
scope->Print(); scope->Print();
} }
...@@ -1978,7 +1984,7 @@ void UpdateNeedsHoleCheck(Variable* var, VariableProxy* proxy, Scope* scope) { ...@@ -1978,7 +1984,7 @@ void UpdateNeedsHoleCheck(Variable* var, VariableProxy* proxy, Scope* scope) {
void Scope::ResolveTo(ParseInfo* info, VariableProxy* proxy, Variable* var) { void Scope::ResolveTo(ParseInfo* info, VariableProxy* proxy, Variable* var) {
#ifdef DEBUG #ifdef DEBUG
if (info->script_is_native()) { if (info->is_native()) {
// To avoid polluting the global object in native scripts // To avoid polluting the global object in native scripts
// - Variables must not be allocated to the global scope. // - Variables must not be allocated to the global scope.
CHECK_NOT_NULL(outer_scope()); CHECK_NOT_NULL(outer_scope());
......
...@@ -43,6 +43,9 @@ BackgroundParsingTask::BackgroundParsingTask( ...@@ -43,6 +43,9 @@ BackgroundParsingTask::BackgroundParsingTask(
if (V8_UNLIKELY(FLAG_runtime_stats)) { if (V8_UNLIKELY(FLAG_runtime_stats)) {
info->set_runtime_call_stats(new (info->zone()) RuntimeCallStats()); info->set_runtime_call_stats(new (info->zone()) RuntimeCallStats());
} }
if (V8_UNLIKELY(info->block_coverage_enabled())) {
info->AllocateSourceRangeMap();
}
source_->info->set_cached_data(&script_data_); source_->info->set_cached_data(&script_data_);
// Parser needs to stay alive for finalizing the parsing on the main // Parser needs to stay alive for finalizing the parsing on the main
......
...@@ -99,9 +99,13 @@ void CodeGenerator::MakeCodePrologue(ParseInfo* parse_info, ...@@ -99,9 +99,13 @@ void CodeGenerator::MakeCodePrologue(ParseInfo* parse_info,
if (!FLAG_trace_codegen && !print_ast) return; if (!FLAG_trace_codegen && !print_ast) return;
// Requires internalizing the AST, so make sure we are on the main thread. // Requires internalizing the AST, so make sure we are on the main thread and
// allow handle dereference and allocations.
// TODO(rmcilroy): Make ast-printer print ast raw strings instead of
// internalized strings to avoid internalizing here.
DCHECK(ThreadId::Current().Equals(info->isolate()->thread_id())); DCHECK(ThreadId::Current().Equals(info->isolate()->thread_id()));
AllowDeferredHandleDereference allow_deref; AllowHandleDereference allow_deref;
AllowHandleAllocation allow_handles;
AllowHeapAllocation allow_gc; AllowHeapAllocation allow_gc;
parse_info->ast_value_factory()->Internalize(info->isolate()); parse_info->ast_value_factory()->Internalize(info->isolate());
......
...@@ -30,26 +30,10 @@ CompilationInfo::CompilationInfo(Zone* zone, Isolate* isolate, ...@@ -30,26 +30,10 @@ CompilationInfo::CompilationInfo(Zone* zone, Isolate* isolate,
literal_ = literal; literal_ = literal;
source_range_map_ = parse_info->source_range_map(); source_range_map_ = parse_info->source_range_map();
// 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();
}
if (FLAG_block_coverage && isolate->is_block_code_coverage() &&
script_->IsUserJavaScript()) {
MarkAsBlockCoverageEnabled();
}
if (parse_info->is_debug()) MarkAsDebug(); if (parse_info->is_debug()) MarkAsDebug();
if (parse_info->is_eval()) MarkAsEval(); if (parse_info->is_eval()) MarkAsEval();
if (parse_info->is_native()) MarkAsNative(); if (parse_info->is_native()) MarkAsNative();
if (parse_info->will_serialize()) MarkAsSerializing(); 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, CompilationInfo::CompilationInfo(Zone* zone, Isolate* isolate,
......
...@@ -40,15 +40,14 @@ class V8_EXPORT_PRIVATE CompilationInfo final { ...@@ -40,15 +40,14 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
kIsEval = 1 << 1, kIsEval = 1 << 1,
kIsNative = 1 << 2, kIsNative = 1 << 2,
kSerializing = 1 << 3, kSerializing = 1 << 3,
kBlockCoverageEnabled = 1 << 4, kAccessorInliningEnabled = 1 << 4,
kAccessorInliningEnabled = 1 << 5, kFunctionContextSpecializing = 1 << 5,
kFunctionContextSpecializing = 1 << 6, kInliningEnabled = 1 << 6,
kInliningEnabled = 1 << 7, kDisableFutureOptimization = 1 << 7,
kDisableFutureOptimization = 1 << 8, kSplittingEnabled = 1 << 8,
kSplittingEnabled = 1 << 9, kSourcePositionsEnabled = 1 << 9,
kSourcePositionsEnabled = 1 << 10, kBailoutOnUninitialized = 1 << 10,
kBailoutOnUninitialized = 1 << 11, kLoopPeelingEnabled = 1 << 11,
kLoopPeelingEnabled = 1 << 12,
}; };
// Construct a compilation info for unoptimized compilation. // Construct a compilation info for unoptimized compilation.
...@@ -71,6 +70,7 @@ class V8_EXPORT_PRIVATE CompilationInfo final { ...@@ -71,6 +70,7 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
literal_ = literal; literal_ = literal;
} }
bool has_source_range_map() const { return source_range_map_ != nullptr; }
SourceRangeMap* source_range_map() const { return source_range_map_; } SourceRangeMap* source_range_map() const { return source_range_map_; }
void set_source_range_map(SourceRangeMap* source_range_map) { void set_source_range_map(SourceRangeMap* source_range_map) {
source_range_map_ = source_range_map; source_range_map_ = source_range_map;
...@@ -122,11 +122,6 @@ class V8_EXPORT_PRIVATE CompilationInfo final { ...@@ -122,11 +122,6 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
void MarkAsNative() { SetFlag(kIsNative); } void MarkAsNative() { SetFlag(kIsNative); }
bool is_native() const { return GetFlag(kIsNative); } bool is_native() const { return GetFlag(kIsNative); }
void MarkAsBlockCoverageEnabled() { SetFlag(kBlockCoverageEnabled); }
bool is_block_coverage_enabled() const {
return GetFlag(kBlockCoverageEnabled);
}
// Flags used by optimized compilation. // Flags used by optimized compilation.
void MarkAsFunctionContextSpecializing() { void MarkAsFunctionContextSpecializing() {
......
...@@ -255,14 +255,13 @@ void EnsureFeedbackMetadata(CompilationInfo* compilation_info) { ...@@ -255,14 +255,13 @@ void EnsureFeedbackMetadata(CompilationInfo* compilation_info) {
compilation_info->literal()->feedback_vector_spec())); compilation_info->literal()->feedback_vector_spec()));
} }
bool UseAsmWasm(FunctionLiteral* literal, bool UseAsmWasm(FunctionLiteral* literal, bool asm_wasm_broken, bool is_debug) {
Handle<SharedFunctionInfo> shared_info, bool is_debug) {
// Check whether asm.js validation is enabled. // Check whether asm.js validation is enabled.
if (!FLAG_validate_asm) return false; if (!FLAG_validate_asm) return false;
// Modules that have validated successfully, but were subsequently broken by // Modules that have validated successfully, but were subsequently broken by
// invalid module instantiation attempts are off limit forever. // invalid module instantiation attempts are off limit forever.
if (!shared_info.is_null() && shared_info->is_asm_wasm_broken()) return false; if (asm_wasm_broken) return false;
// Compiling for debugging is not supported, fall back. // Compiling for debugging is not supported, fall back.
if (is_debug) return false; if (is_debug) return false;
...@@ -316,7 +315,8 @@ void InstallUnoptimizedCode(CompilationInfo* compilation_info) { ...@@ -316,7 +315,8 @@ void InstallUnoptimizedCode(CompilationInfo* compilation_info) {
// Install coverage info on the shared function info. // Install coverage info on the shared function info.
if (compilation_info->has_coverage_info()) { if (compilation_info->has_coverage_info()) {
DCHECK(compilation_info->is_block_coverage_enabled()); DCHECK(FLAG_block_coverage &&
compilation_info->isolate()->is_block_code_coverage());
compilation_info->isolate()->debug()->InstallCoverageInfo( compilation_info->isolate()->debug()->InstallCoverageInfo(
compilation_info->shared_info(), compilation_info->coverage_info()); compilation_info->shared_info(), compilation_info->coverage_info());
} }
...@@ -384,9 +384,9 @@ bool Renumber(ParseInfo* parse_info, ...@@ -384,9 +384,9 @@ bool Renumber(ParseInfo* parse_info,
} }
std::unique_ptr<CompilationJob> PrepareAndExecuteUnoptimizedCompileJob( std::unique_ptr<CompilationJob> PrepareAndExecuteUnoptimizedCompileJob(
ParseInfo* parse_info, FunctionLiteral* literal, ParseInfo* parse_info, FunctionLiteral* literal, Isolate* isolate) {
Handle<SharedFunctionInfo> shared_info, Isolate* isolate) { if (UseAsmWasm(literal, parse_info->is_asm_wasm_broken(),
if (UseAsmWasm(literal, shared_info, parse_info->is_debug())) { parse_info->is_debug())) {
std::unique_ptr<CompilationJob> asm_job( std::unique_ptr<CompilationJob> asm_job(
AsmJs::NewCompilationJob(parse_info, literal, isolate)); AsmJs::NewCompilationJob(parse_info, literal, isolate));
if (asm_job->PrepareJob() == CompilationJob::SUCCEEDED && if (asm_job->PrepareJob() == CompilationJob::SUCCEEDED &&
...@@ -409,41 +409,45 @@ std::unique_ptr<CompilationJob> PrepareAndExecuteUnoptimizedCompileJob( ...@@ -409,41 +409,45 @@ std::unique_ptr<CompilationJob> PrepareAndExecuteUnoptimizedCompileJob(
return std::unique_ptr<CompilationJob>(); // Compilation failed, return null. return std::unique_ptr<CompilationJob>(); // Compilation failed, return null.
} }
Handle<SharedFunctionInfo> CompileUnoptimizedCode( // TODO(rmcilroy): Remove |isolate| once CompilationJob doesn't need it.
ParseInfo* parse_info, Handle<SharedFunctionInfo> shared_info, std::unique_ptr<CompilationJob> GenerateUnoptimizedCode(
Isolate* isolate) { ParseInfo* parse_info, Isolate* isolate,
DCHECK(AllowCompilation::IsAllowed(isolate)); std::forward_list<std::unique_ptr<CompilationJob>>* inner_function_jobs) {
DisallowHeapAllocation no_allocation;
DisallowHandleAllocation no_handles;
DisallowHandleDereference no_deref;
DCHECK(inner_function_jobs->empty());
Compiler::EagerInnerFunctionLiterals inner_literals; Compiler::EagerInnerFunctionLiterals inner_literals;
if (!Compiler::Analyze(parse_info, &inner_literals)) { if (!Compiler::Analyze(parse_info, &inner_literals)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow(); return std::unique_ptr<CompilationJob>();
return Handle<SharedFunctionInfo>::null();
} }
// Prepare and execute compilation of the outer-most function. // Prepare and execute compilation of the outer-most function.
std::unique_ptr<CompilationJob> outer_job( std::unique_ptr<CompilationJob> outer_function_job(
PrepareAndExecuteUnoptimizedCompileJob(parse_info, parse_info->literal(), PrepareAndExecuteUnoptimizedCompileJob(parse_info, parse_info->literal(),
shared_info, isolate)); isolate));
if (!outer_job) { if (!outer_function_job) return std::unique_ptr<CompilationJob>();
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return Handle<SharedFunctionInfo>::null();
}
// Prepare and execute compilation jobs for eager inner functions. // Prepare and execute compilation jobs for eager inner functions.
std::forward_list<std::unique_ptr<CompilationJob>> inner_jobs;
for (auto it : inner_literals) { for (auto it : inner_literals) {
FunctionLiteral* inner_literal = it->value(); FunctionLiteral* inner_literal = it->value();
std::unique_ptr<CompilationJob> inner_job( std::unique_ptr<CompilationJob> inner_job(
PrepareAndExecuteUnoptimizedCompileJob( PrepareAndExecuteUnoptimizedCompileJob(parse_info, inner_literal,
parse_info, inner_literal, Handle<SharedFunctionInfo>::null(), isolate));
isolate)); if (!inner_job) return std::unique_ptr<CompilationJob>();
if (!inner_job) { inner_function_jobs->emplace_front(std::move(inner_job));
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return Handle<SharedFunctionInfo>::null();
}
inner_jobs.emplace_front(std::move(inner_job));
} }
return outer_function_job;
}
bool FinalizeUnoptimizedCode(
ParseInfo* parse_info, Isolate* isolate,
Handle<SharedFunctionInfo> shared_info, CompilationJob* outer_function_job,
std::forward_list<std::unique_ptr<CompilationJob>>* inner_function_jobs) {
DCHECK(AllowCompilation::IsAllowed(isolate));
// Internalize ast values onto the heap. // Internalize ast values onto the heap.
parse_info->ast_value_factory()->Internalize(isolate); parse_info->ast_value_factory()->Internalize(isolate);
...@@ -465,15 +469,14 @@ Handle<SharedFunctionInfo> CompileUnoptimizedCode( ...@@ -465,15 +469,14 @@ Handle<SharedFunctionInfo> CompileUnoptimizedCode(
} }
// Finalize the outer-most function's compilation job. // Finalize the outer-most function's compilation job.
outer_job->compilation_info()->set_shared_info(shared_info); outer_function_job->compilation_info()->set_shared_info(shared_info);
if (FinalizeUnoptimizedCompilationJob(outer_job.get()) != if (FinalizeUnoptimizedCompilationJob(outer_function_job) !=
CompilationJob::SUCCEEDED) { CompilationJob::SUCCEEDED) {
if (!isolate->has_pending_exception()) isolate->StackOverflow(); return false;
return Handle<SharedFunctionInfo>::null();
} }
// Finalize the inner functions' compilation jobs. // Finalize the inner functions' compilation jobs.
for (auto&& inner_job : inner_jobs) { for (auto&& inner_job : *inner_function_jobs) {
Handle<SharedFunctionInfo> inner_shared_info = Handle<SharedFunctionInfo> inner_shared_info =
Compiler::GetSharedFunctionInfo( Compiler::GetSharedFunctionInfo(
inner_job->compilation_info()->literal(), parse_info->script(), inner_job->compilation_info()->literal(), parse_info->script(),
...@@ -484,13 +487,10 @@ Handle<SharedFunctionInfo> CompileUnoptimizedCode( ...@@ -484,13 +487,10 @@ Handle<SharedFunctionInfo> CompileUnoptimizedCode(
inner_job->compilation_info()->set_shared_info(inner_shared_info); inner_job->compilation_info()->set_shared_info(inner_shared_info);
if (FinalizeUnoptimizedCompilationJob(inner_job.get()) != if (FinalizeUnoptimizedCompilationJob(inner_job.get()) !=
CompilationJob::SUCCEEDED) { CompilationJob::SUCCEEDED) {
if (!isolate->has_pending_exception()) isolate->StackOverflow(); return false;
return Handle<SharedFunctionInfo>::null();
} }
} }
return true;
// Compilation succeeded, return result.
return shared_info;
} }
MUST_USE_RESULT MaybeHandle<Code> CompileUnoptimizedFunction( MUST_USE_RESULT MaybeHandle<Code> CompileUnoptimizedFunction(
...@@ -506,15 +506,24 @@ MUST_USE_RESULT MaybeHandle<Code> CompileUnoptimizedFunction( ...@@ -506,15 +506,24 @@ MUST_USE_RESULT MaybeHandle<Code> CompileUnoptimizedFunction(
return MaybeHandle<Code>(); return MaybeHandle<Code>();
} }
// Compile either unoptimized code or bytecode for the interpreter. // Generate the unoptimized bytecode or asm-js data.
Handle<SharedFunctionInfo> result = std::forward_list<std::unique_ptr<CompilationJob>> inner_function_jobs;
CompileUnoptimizedCode(parse_info, shared_info, isolate); std::unique_ptr<CompilationJob> outer_function_job(
if (result.is_null()) { GenerateUnoptimizedCode(parse_info, isolate, &inner_function_jobs));
if (!outer_function_job) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return MaybeHandle<Code>();
}
// Finalize compilation of the unoptimized bytecode or asm-js data.
if (!FinalizeUnoptimizedCode(parse_info, isolate, shared_info,
outer_function_job.get(),
&inner_function_jobs)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return MaybeHandle<Code>(); return MaybeHandle<Code>();
} }
DCHECK(shared_info.is_identical_to(result));
return handle(result->code(), isolate); return handle(shared_info->code(), isolate);
} }
MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeCache( MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeCache(
...@@ -906,11 +915,23 @@ Handle<SharedFunctionInfo> CompileToplevel( ...@@ -906,11 +915,23 @@ Handle<SharedFunctionInfo> CompileToplevel(
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
parse_info->is_eval() ? "V8.CompileEval" : "V8.Compile"); parse_info->is_eval() ? "V8.CompileEval" : "V8.Compile");
// Compile the code. // Generate the unoptimized bytecode or asm-js data.
result = CompileUnoptimizedCode(parse_info, shared_info, isolate); std::forward_list<std::unique_ptr<CompilationJob>> inner_function_jobs;
if (result.is_null()) { std::unique_ptr<CompilationJob> outer_function_job(
GenerateUnoptimizedCode(parse_info, isolate, &inner_function_jobs));
if (!outer_function_job) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return Handle<SharedFunctionInfo>::null();
}
// Finalize compilation of the unoptimized bytecode or asm-js data.
if (!FinalizeUnoptimizedCode(parse_info, isolate, shared_info,
outer_function_job.get(),
&inner_function_jobs)) {
if (!isolate->has_pending_exception()) isolate->StackOverflow();
return Handle<SharedFunctionInfo>::null(); return Handle<SharedFunctionInfo>::null();
} }
result = outer_function_job->compilation_info()->shared_info();
DCHECK_IMPLIES(!shared_info.is_null(), shared_info.is_identical_to(result)); DCHECK_IMPLIES(!shared_info.is_null(), shared_info.is_identical_to(result));
if (!script.is_null()) { if (!script.is_null()) {
......
...@@ -772,7 +772,7 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info) ...@@ -772,7 +772,7 @@ BytecodeGenerator::BytecodeGenerator(CompilationInfo* info)
loop_depth_(0), loop_depth_(0),
catch_prediction_(HandlerTable::UNCAUGHT) { catch_prediction_(HandlerTable::UNCAUGHT) {
DCHECK_EQ(closure_scope(), closure_scope()->GetClosureScope()); DCHECK_EQ(closure_scope(), closure_scope()->GetClosureScope());
if (info->is_block_coverage_enabled()) { if (info->has_source_range_map()) {
DCHECK(FLAG_block_coverage); DCHECK(FLAG_block_coverage);
block_coverage_builder_ = new (zone()) block_coverage_builder_ = new (zone())
BlockCoverageBuilder(zone(), builder(), info->source_range_map()); BlockCoverageBuilder(zone(), builder(), info->source_range_map());
...@@ -784,7 +784,7 @@ Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) { ...@@ -784,7 +784,7 @@ Handle<BytecodeArray> BytecodeGenerator::FinalizeBytecode(Isolate* isolate) {
AllocateDeferredConstants(isolate); AllocateDeferredConstants(isolate);
if (info()->is_block_coverage_enabled()) { if (block_coverage_builder_) {
info()->set_coverage_info( info()->set_coverage_info(
isolate->factory()->NewCoverageInfo(block_coverage_builder_->slots())); isolate->factory()->NewCoverageInfo(block_coverage_builder_->slots()));
if (FLAG_trace_block_coverage) { if (FLAG_trace_block_coverage) {
......
...@@ -57,6 +57,7 @@ ParseInfo::ParseInfo(Handle<SharedFunctionInfo> shared) ...@@ -57,6 +57,7 @@ ParseInfo::ParseInfo(Handle<SharedFunctionInfo> shared)
function_literal_id_ = shared->function_literal_id(); function_literal_id_ = shared->function_literal_id();
set_language_mode(shared->language_mode()); set_language_mode(shared->language_mode());
set_module(shared->kind() == FunctionKind::kModule); set_module(shared->kind() == FunctionKind::kModule);
set_asm_wasm_broken(shared->is_asm_wasm_broken());
Handle<Script> script(Script::cast(shared->script())); Handle<Script> script(Script::cast(shared->script()));
set_script(script); set_script(script);
...@@ -76,6 +77,9 @@ ParseInfo::ParseInfo(Handle<SharedFunctionInfo> shared) ...@@ -76,6 +77,9 @@ ParseInfo::ParseInfo(Handle<SharedFunctionInfo> shared)
shared->feedback_metadata()->length() == 0 shared->feedback_metadata()->length() == 0
? FLAG_type_profile && script->IsUserJavaScript() ? FLAG_type_profile && script->IsUserJavaScript()
: shared->feedback_metadata()->HasTypeProfileSlot()); : shared->feedback_metadata()->HasTypeProfileSlot());
if (block_coverage_enabled() && script->IsUserJavaScript()) {
AllocateSourceRangeMap();
}
} }
ParseInfo::ParseInfo(Handle<Script> script) ParseInfo::ParseInfo(Handle<Script> script)
...@@ -90,6 +94,9 @@ ParseInfo::ParseInfo(Handle<Script> script) ...@@ -90,6 +94,9 @@ ParseInfo::ParseInfo(Handle<Script> script)
set_eval(script->compilation_type() == Script::COMPILATION_TYPE_EVAL); set_eval(script->compilation_type() == Script::COMPILATION_TYPE_EVAL);
set_collect_type_profile(FLAG_type_profile && script->IsUserJavaScript()); set_collect_type_profile(FLAG_type_profile && script->IsUserJavaScript());
if (block_coverage_enabled() && script->IsUserJavaScript()) {
AllocateSourceRangeMap();
}
} }
// static // static
...@@ -145,7 +152,7 @@ void ParseInfo::InitFromIsolate(Isolate* isolate) { ...@@ -145,7 +152,7 @@ void ParseInfo::InitFromIsolate(Isolate* isolate) {
set_runtime_call_stats(isolate->counters()->runtime_call_stats()); set_runtime_call_stats(isolate->counters()->runtime_call_stats());
set_ast_string_constants(isolate->ast_string_constants()); set_ast_string_constants(isolate->ast_string_constants());
if (FLAG_block_coverage && isolate->is_block_code_coverage()) { if (FLAG_block_coverage && isolate->is_block_code_coverage()) {
set_source_range_map(new (zone()) SourceRangeMap(zone())); set_block_coverage_enabled();
} }
} }
...@@ -199,11 +206,10 @@ void ParseInfo::ShareAstValueFactory(ParseInfo* other) { ...@@ -199,11 +206,10 @@ void ParseInfo::ShareAstValueFactory(ParseInfo* other) {
ast_value_factory_ = other->ast_value_factory_; ast_value_factory_ = other->ast_value_factory_;
} }
#ifdef DEBUG void ParseInfo::AllocateSourceRangeMap() {
bool ParseInfo::script_is_native() const { DCHECK(block_coverage_enabled());
return script_->type() == Script::TYPE_NATIVE; set_source_range_map(new (zone()) SourceRangeMap(zone()));
} }
#endif // DEBUG
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -78,6 +78,9 @@ class V8_EXPORT_PRIVATE ParseInfo : public UnoptimizedCompileJobFinishCallback { ...@@ -78,6 +78,9 @@ class V8_EXPORT_PRIVATE ParseInfo : public UnoptimizedCompileJobFinishCallback {
FLAG_ACCESSOR(kLazyCompile, lazy_compile, set_lazy_compile) FLAG_ACCESSOR(kLazyCompile, lazy_compile, set_lazy_compile)
FLAG_ACCESSOR(kCollectTypeProfile, collect_type_profile, FLAG_ACCESSOR(kCollectTypeProfile, collect_type_profile,
set_collect_type_profile) set_collect_type_profile)
FLAG_ACCESSOR(kIsAsmWasmBroken, is_asm_wasm_broken, set_asm_wasm_broken)
FLAG_ACCESSOR(kBlockCoverageEnabled, block_coverage_enabled,
set_block_coverage_enabled)
#undef FLAG_ACCESSOR #undef FLAG_ACCESSOR
void set_parse_restriction(ParseRestriction restriction) { void set_parse_restriction(ParseRestriction restriction) {
...@@ -203,6 +206,7 @@ class V8_EXPORT_PRIVATE ParseInfo : public UnoptimizedCompileJobFinishCallback { ...@@ -203,6 +206,7 @@ class V8_EXPORT_PRIVATE ParseInfo : public UnoptimizedCompileJobFinishCallback {
runtime_call_stats_ = runtime_call_stats; runtime_call_stats_ = runtime_call_stats;
} }
void AllocateSourceRangeMap();
SourceRangeMap* source_range_map() const { return source_range_map_; } SourceRangeMap* source_range_map() const { return source_range_map_; }
void set_source_range_map(SourceRangeMap* source_range_map) { void set_source_range_map(SourceRangeMap* source_range_map) {
source_range_map_ = source_range_map; source_range_map_ = source_range_map;
...@@ -251,10 +255,6 @@ class V8_EXPORT_PRIVATE ParseInfo : public UnoptimizedCompileJobFinishCallback { ...@@ -251,10 +255,6 @@ class V8_EXPORT_PRIVATE ParseInfo : public UnoptimizedCompileJobFinishCallback {
void ParseFinished(std::unique_ptr<ParseInfo> info) override; void ParseFinished(std::unique_ptr<ParseInfo> info) override;
#ifdef DEBUG
bool script_is_native() const;
#endif // DEBUG
private: private:
// Various configuration flags for parsing. // Various configuration flags for parsing.
enum Flag { enum Flag {
...@@ -272,6 +272,8 @@ class V8_EXPORT_PRIVATE ParseInfo : public UnoptimizedCompileJobFinishCallback { ...@@ -272,6 +272,8 @@ class V8_EXPORT_PRIVATE ParseInfo : public UnoptimizedCompileJobFinishCallback {
kSerializing = 1 << 10, kSerializing = 1 << 10,
kLazyCompile = 1 << 11, kLazyCompile = 1 << 11,
kCollectTypeProfile = 1 << 12, kCollectTypeProfile = 1 << 12,
kBlockCoverageEnabled = 1 << 13,
kIsAsmWasmBroken = 1 << 14,
}; };
//------------- Inputs to parsing and scope analysis ----------------------- //------------- Inputs to parsing and scope analysis -----------------------
......
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