Commit 08b68464 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[offthread] Support block coverage in off-thread finalization

Move CoverageInfo installation to the main-thread part of finalization.
Since this is debug-only, it won't affect non-debug compiles.

This allows us to use off-thread finalization when block coverage is
enabled, removing the last non-flag reason for disabling off-thread
finalization. This means we can remove the per-task "finalize
off-thread" flag on BackgroundCompileTask, and make off-thread
finalization always on when the flag is on.

Bug: chromium:1011762
Change-Id: Ib733d501c4043b493ded9a1951cceb5cfc524eb4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2497177
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70758}
parent a9f376aa
......@@ -517,19 +517,6 @@ void InstallInterpreterTrampolineCopy(Isolate* isolate,
script_name, line_num, column_num));
}
void InstallCoverageInfo(Isolate* isolate, Handle<SharedFunctionInfo> shared,
Handle<CoverageInfo> coverage_info) {
DCHECK(isolate->is_block_code_coverage());
isolate->debug()->InstallCoverageInfo(shared, coverage_info);
}
void InstallCoverageInfo(LocalIsolate* isolate,
Handle<SharedFunctionInfo> shared,
Handle<CoverageInfo> coverage_info) {
// We should only have coverage info when finalizing on the main thread.
UNREACHABLE();
}
template <typename LocalIsolate>
void InstallUnoptimizedCode(UnoptimizedCompilationInfo* compilation_info,
Handle<SharedFunctionInfo> shared_info,
......@@ -558,12 +545,6 @@ void InstallUnoptimizedCode(UnoptimizedCompilationInfo* compilation_info,
shared_info->set_feedback_metadata(
ReadOnlyRoots(isolate).empty_feedback_metadata());
}
if (compilation_info->has_coverage_info() &&
!shared_info->HasCoverageInfo()) {
InstallCoverageInfo(isolate, shared_info,
compilation_info->coverage_info());
}
}
void LogUnoptimizedCompilation(Isolate* isolate,
......@@ -634,8 +615,15 @@ CompilationJob::Status FinalizeSingleUnoptimizedCompilationJob(
CompilationJob::Status status = job->FinalizeJob(shared_info, isolate);
if (status == CompilationJob::SUCCEEDED) {
InstallUnoptimizedCode(compilation_info, shared_info, isolate);
MaybeHandle<CoverageInfo> coverage_info;
if (compilation_info->has_coverage_info() &&
!shared_info->HasCoverageInfo()) {
coverage_info = compilation_info->coverage_info();
}
finalize_unoptimized_compilation_data_list->emplace_back(
isolate, shared_info, job->time_taken_to_execute(),
isolate, shared_info, coverage_info, job->time_taken_to_execute(),
job->time_taken_to_finalize());
}
DCHECK_IMPLIES(status == CompilationJob::RETRY_ON_MAIN_THREAD,
......@@ -1220,6 +1208,10 @@ void FinalizeUnoptimizedCompilation(
if (FLAG_interpreted_frames_native_stack) {
InstallInterpreterTrampolineCopy(isolate, shared_info);
}
Handle<CoverageInfo> coverage_info;
if (finalize_data.coverage_info().ToHandle(&coverage_info)) {
isolate->debug()->InstallCoverageInfo(shared_info, coverage_info);
}
LogUnoptimizedCompilation(isolate, shared_info, flags,
finalize_data.time_taken_to_execute(),
......@@ -1412,11 +1404,14 @@ CompilationHandleScope::~CompilationHandleScope() {
FinalizeUnoptimizedCompilationData::FinalizeUnoptimizedCompilationData(
LocalIsolate* isolate, Handle<SharedFunctionInfo> function_handle,
MaybeHandle<CoverageInfo> coverage_info,
base::TimeDelta time_taken_to_execute,
base::TimeDelta time_taken_to_finalize)
: time_taken_to_execute_(time_taken_to_execute),
time_taken_to_finalize_(time_taken_to_finalize),
function_handle_(isolate->heap()->NewPersistentHandle(function_handle)) {}
function_handle_(isolate->heap()->NewPersistentHandle(function_handle)),
coverage_info_(isolate->heap()->NewPersistentMaybeHandle(coverage_info)) {
}
DeferredFinalizationJobData::DeferredFinalizationJobData(
LocalIsolate* isolate, Handle<SharedFunctionInfo> function_handle,
......@@ -1431,7 +1426,7 @@ BackgroundCompileTask::BackgroundCompileTask(ScriptStreamingData* streamed_data,
REPLMode::kNo)),
compile_state_(isolate),
info_(std::make_unique<ParseInfo>(isolate, flags_, &compile_state_)),
isolate_for_local_isolate_(nullptr),
isolate_for_local_isolate_(isolate),
start_position_(0),
end_position_(0),
function_literal_id_(kFunctionLiteralIdTopLevel),
......@@ -1451,13 +1446,6 @@ BackgroundCompileTask::BackgroundCompileTask(ScriptStreamingData* streamed_data,
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(
streamed_data->source_stream.get(), streamed_data->encoding));
info_->set_character_stream(std::move(stream));
// TODO(leszeks): Add block coverage support to off-thread finalization.
finalize_on_background_thread_ =
FLAG_finalize_streaming_on_background && !flags_.block_coverage_enabled();
if (finalize_on_background_thread()) {
isolate_for_local_isolate_ = isolate;
}
}
BackgroundCompileTask::BackgroundCompileTask(
......@@ -1477,8 +1465,7 @@ BackgroundCompileTask::BackgroundCompileTask(
stack_size_(max_stack_size),
worker_thread_runtime_call_stats_(worker_thread_runtime_stats),
timer_(timer),
language_mode_(info_->language_mode()),
finalize_on_background_thread_(false) {
language_mode_(info_->language_mode()) {
DCHECK_EQ(outer_parse_info->parameters_end_pos(), kNoSourcePosition);
DCHECK_NULL(outer_parse_info->extension());
......@@ -1562,7 +1549,7 @@ void BackgroundCompileTask::Run() {
// Save the language mode.
language_mode_ = info_->language_mode();
if (!finalize_on_background_thread_) {
if (!FLAG_finalize_streaming_on_background) {
if (info_->literal() != nullptr) {
CompileOnBackgroundThread(info_.get(), compile_state_.allocator(),
&compilation_jobs_);
......@@ -1857,7 +1844,7 @@ bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag,
bool Compiler::FinalizeBackgroundCompileTask(
BackgroundCompileTask* task, Handle<SharedFunctionInfo> shared_info,
Isolate* isolate, ClearExceptionFlag flag) {
DCHECK(!task->finalize_on_background_thread());
DCHECK(!FLAG_finalize_streaming_on_background);
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
"V8.FinalizeBackgroundCompileTask");
......@@ -2838,7 +2825,7 @@ Compiler::GetSharedFunctionInfoForStreamedScript(
// the isolate cache.
Handle<Script> script;
if (task->finalize_on_background_thread()) {
if (FLAG_finalize_streaming_on_background) {
RuntimeCallTimerScope runtimeTimerScope(
isolate, RuntimeCallCounterId::kCompilePublishBackgroundFinalization);
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
......
......@@ -16,6 +16,7 @@
#include "src/handles/persistent-handles.h"
#include "src/logging/code-events.h"
#include "src/objects/contexts.h"
#include "src/objects/debug-objects.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/pending-compilation-error-handler.h"
#include "src/utils/allocation.h"
......@@ -374,14 +375,17 @@ class FinalizeUnoptimizedCompilationData {
public:
FinalizeUnoptimizedCompilationData(Isolate* isolate,
Handle<SharedFunctionInfo> function_handle,
MaybeHandle<CoverageInfo> coverage_info,
base::TimeDelta time_taken_to_execute,
base::TimeDelta time_taken_to_finalize)
: time_taken_to_execute_(time_taken_to_execute),
time_taken_to_finalize_(time_taken_to_finalize),
function_handle_(function_handle) {}
function_handle_(function_handle),
coverage_info_(coverage_info) {}
FinalizeUnoptimizedCompilationData(LocalIsolate* isolate,
Handle<SharedFunctionInfo> function_handle,
MaybeHandle<CoverageInfo> coverage_info,
base::TimeDelta time_taken_to_execute,
base::TimeDelta time_taken_to_finalize);
......@@ -389,6 +393,8 @@ class FinalizeUnoptimizedCompilationData {
return function_handle_;
}
MaybeHandle<CoverageInfo> coverage_info() const { return coverage_info_; }
base::TimeDelta time_taken_to_execute() const {
return time_taken_to_execute_;
}
......@@ -400,6 +406,7 @@ class FinalizeUnoptimizedCompilationData {
base::TimeDelta time_taken_to_execute_;
base::TimeDelta time_taken_to_finalize_;
Handle<SharedFunctionInfo> function_handle_;
MaybeHandle<CoverageInfo> coverage_info_;
};
using FinalizeUnoptimizedCompilationDataList =
......@@ -476,9 +483,6 @@ class V8_EXPORT_PRIVATE BackgroundCompileTask {
UnoptimizedCompileFlags flags() const { return flags_; }
UnoptimizedCompileState* compile_state() { return &compile_state_; }
LanguageMode language_mode() { return language_mode_; }
bool finalize_on_background_thread() {
return finalize_on_background_thread_;
}
FinalizeUnoptimizedCompilationDataList*
finalize_unoptimized_compilation_data() {
return &finalize_unoptimized_compilation_data_;
......@@ -529,13 +533,6 @@ class V8_EXPORT_PRIVATE BackgroundCompileTask {
TimedHistogram* timer_;
LanguageMode language_mode_;
// True if the background compilation should be finalized on the background
// thread. When this is true, the ParseInfo, Parser and compilation jobs are
// freed on the background thread, the outer_function_sfi holds the top-level
// function, and the off_thread_isolate has to be merged into the main-thread
// Isolate.
bool finalize_on_background_thread_;
DISALLOW_COPY_AND_ASSIGN(BackgroundCompileTask);
};
......
......@@ -435,7 +435,7 @@ Handle<CoverageInfo> FactoryBase<Impl>::NewCoverageInfo(
int size = CoverageInfo::SizeFor(slot_count);
Map map = read_only_roots().coverage_info_map();
HeapObject result =
AllocateRawWithImmortalMap(size, AllocationType::kYoung, map);
AllocateRawWithImmortalMap(size, AllocationType::kOld, map);
Handle<CoverageInfo> info(CoverageInfo::cast(result), isolate());
info->set_slot_count(slot_count);
......
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