Commit cc208b28 authored by Wiktor Garbacz's avatar Wiktor Garbacz Committed by Commit Bot

[compiler-dispatcher] FinishNow all remaining jobs.

This a step towards using CompilerDispatcher in parallel
parsing.

BUG=v8:6093

Change-Id: Idee84105e342950badb5694fa2a850e05430abaa
Reviewed-on: https://chromium-review.googlesource.com/473246
Commit-Queue: Wiktor Garbacz <wiktorg@google.com>
Reviewed-by: 's avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44573}
parent 30439676
......@@ -454,28 +454,39 @@ void CompilerDispatcher::WaitForJobIfRunningOnBackground(
DCHECK(running_background_jobs_.find(job) == running_background_jobs_.end());
}
bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
"V8.CompilerDispatcherFinishNow");
JobMap::const_iterator job = GetJobFor(function);
CHECK(job != jobs_.end());
bool CompilerDispatcher::FinishNow(CompilerDispatcherJob* job) {
if (trace_compiler_dispatcher_) {
PrintF("CompilerDispatcher: finishing ");
function->ShortPrint();
job->ShortPrint();
PrintF(" now\n");
}
WaitForJobIfRunningOnBackground(job);
while (!IsFinished(job)) {
DoNextStepOnMainThread(isolate_, job, ExceptionHandling::kThrow);
}
return job->status() != CompileJobStatus::kFailed;
}
WaitForJobIfRunningOnBackground(job->second.get());
while (!IsFinished(job->second.get())) {
DoNextStepOnMainThread(isolate_, job->second.get(),
ExceptionHandling::kThrow);
bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
"V8.CompilerDispatcherFinishNow");
JobMap::const_iterator job = GetJobFor(function);
CHECK(job != jobs_.end());
bool result = FinishNow(job->second.get());
if (!job->second->shared().is_null()) {
shared_to_job_id_.Delete(job->second->shared());
}
bool result = job->second->status() != CompileJobStatus::kFailed;
RemoveIfFinished(job);
return result;
}
void CompilerDispatcher::FinishAllNow() {
for (auto it = jobs_.cbegin(); it != jobs_.cend();
it = RemoveIfFinished(it)) {
FinishNow(it->second.get());
}
}
void CompilerDispatcher::AbortAll(BlockingBehavior blocking) {
bool background_tasks_running =
task_manager_->TryAbortAll() == CancelableTaskManager::kTaskRunning;
......
......@@ -118,6 +118,9 @@ class V8_EXPORT_PRIVATE CompilerDispatcher {
// possible). Returns true if the compile job was successful.
bool FinishNow(Handle<SharedFunctionInfo> function);
// Blocks until all jobs are finished.
void FinishAllNow();
// Aborts a given job. Blocks if requested.
void Abort(Handle<SharedFunctionInfo> function, BlockingBehavior blocking);
......@@ -168,6 +171,7 @@ class V8_EXPORT_PRIVATE CompilerDispatcher {
JobMap::const_iterator RemoveIfFinished(JobMap::const_iterator job);
// Returns iterator following the removed job.
JobMap::const_iterator RemoveJob(JobMap::const_iterator job);
bool FinishNow(CompilerDispatcherJob* job);
Isolate* isolate_;
Platform* platform_;
......
......@@ -4,6 +4,8 @@
#include "src/compiler-dispatcher/compiler-dispatcher.h"
#include <sstream>
#include "include/v8-platform.h"
#include "src/api.h"
#include "src/base/platform/semaphore.h"
......@@ -316,6 +318,36 @@ TEST_F(CompilerDispatcherTest, FinishNow) {
platform.ClearIdleTask();
}
TEST_F(CompilerDispatcherTest, FinishAllNow) {
MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
constexpr int num_funcs = 2;
Handle<JSFunction> f[num_funcs];
Handle<SharedFunctionInfo> shared[num_funcs];
for (int i = 0; i < num_funcs; ++i) {
std::stringstream ss;
ss << 'f' << STR(__LINE__) << '_' << i;
std::string func_name = ss.str();
std::string script("function g() { function " + func_name +
"(x) { var a = 'x'; }; return " + func_name +
"; } g();");
f[i] = Handle<JSFunction>::cast(test::RunJS(isolate(), script.c_str()));
shared[i] = Handle<SharedFunctionInfo>(f[i]->shared(), i_isolate());
ASSERT_FALSE(shared[i]->is_compiled());
ASSERT_TRUE(dispatcher.Enqueue(shared[i]));
}
dispatcher.FinishAllNow();
for (int i = 0; i < num_funcs; ++i) {
// Finishing removes the SFI from the queue.
ASSERT_FALSE(dispatcher.IsEnqueued(shared[i]));
ASSERT_TRUE(shared[i]->is_compiled());
}
platform.ClearIdleTask();
platform.ClearBackgroundTasks();
}
TEST_F(CompilerDispatcherTest, IdleTask) {
MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
......
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