Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Unified Diff: src/compiler-dispatcher/compiler-dispatcher.cc

Issue 2611313002: [complier] Enable parallel eager inner function compilation with compiler dispatcher. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/compiler-dispatcher/compiler-dispatcher.cc
diff --git a/src/compiler-dispatcher/compiler-dispatcher.cc b/src/compiler-dispatcher/compiler-dispatcher.cc
index 4070e8b8b0e43b678ab95bb2a923d8969b67f0ed..09601b5e90020a4be23cd6c54594a0da0958d98a 100644
--- a/src/compiler-dispatcher/compiler-dispatcher.cc
+++ b/src/compiler-dispatcher/compiler-dispatcher.cc
@@ -8,6 +8,7 @@
#include "include/v8.h"
#include "src/base/platform/time.h"
#include "src/cancelable-task.h"
+#include "src/compilation-info.h"
#include "src/compiler-dispatcher/compiler-dispatcher-job.h"
#include "src/compiler-dispatcher/compiler-dispatcher-tracer.h"
#include "src/flags.h"
@@ -226,7 +227,7 @@ CompilerDispatcher::~CompilerDispatcher() {
task_manager_->CancelAndWait();
}
-bool CompilerDispatcher::Enqueue(Handle<SharedFunctionInfo> function) {
+bool CompilerDispatcher::CanEnqueueJobs() {
if (!IsEnabled()) return false;
if (memory_pressure_level_.Value() != MemoryPressureLevel::kNone) {
@@ -235,8 +236,12 @@ bool CompilerDispatcher::Enqueue(Handle<SharedFunctionInfo> function) {
{
base::LockGuard<base::Mutex> lock(&mutex_);
- if (abort_) return false;
+ return !abort_;
}
+}
+
+bool CompilerDispatcher::Enqueue(Handle<SharedFunctionInfo> function) {
+ if (!CanEnqueueJobs()) return false;
// We only handle functions (no eval / top-level code / wasm) that are
// attached to a script.
@@ -250,7 +255,7 @@ bool CompilerDispatcher::Enqueue(Handle<SharedFunctionInfo> function) {
if (trace_compiler_dispatcher_) {
PrintF("CompilerDispatcher: enqueuing ");
function->ShortPrint();
- PrintF("\n");
+ PrintF(" for parse and compile\n");
}
std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
@@ -262,6 +267,33 @@ bool CompilerDispatcher::Enqueue(Handle<SharedFunctionInfo> function) {
return true;
}
+bool CompilerDispatcher::Enqueue(Zone* zone, ParseInfo* parse_info,
+ CompilationInfo* compile_info,
+ CompilationJob* compilation_job) {
+ if (!CanEnqueueJobs()) return false;
+
+ DCHECK(compile_info->has_shared_info());
+ Handle<SharedFunctionInfo> function = compile_info->shared_info();
+
+ if (IsEnqueued(function)) return true;
+
+ if (trace_compiler_dispatcher_) {
+ PrintF("CompilerDispatcher: enqueuing");
+ function->ShortPrint();
+ PrintF(" for compile\n");
+ }
+
+ CompilerDispatcherJob* job(new CompilerDispatcherJob(
+ isolate_, tracer_.get(), zone, parse_info, compile_info, compilation_job,
+ max_stack_size_));
+ std::pair<int, int> key(Script::cast(function->script())->id(),
+ function->function_literal_id());
+ jobs_.insert(std::make_pair(key, job));
+ ConsiderJobForBackgroundProcessing(job);
+ ScheduleIdleTaskIfNeeded();
+ return true;
+}
+
bool CompilerDispatcher::IsEnabled() const {
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_);
return FLAG_compiler_dispatcher && platform_->IdleTasksEnabled(v8_isolate);
@@ -287,6 +319,16 @@ void CompilerDispatcher::WaitForJobIfRunningOnBackground(
DCHECK(running_background_jobs_.find(job) == running_background_jobs_.end());
}
+bool CompilerDispatcher::FinishNow(CompilerDispatcherJob* job) {
+ WaitForJobIfRunningOnBackground(job);
+ while (!IsFinished(job)) {
+ DoNextStepOnMainThread(isolate_, job, ExceptionHandling::kThrow);
+ }
+ bool result = job->status() != CompileJobStatus::kFailed;
+ job->ResetOnMainThread();
+ return result;
+}
+
bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) {
JobMap::const_iterator job = GetJobFor(function);
CHECK(job != jobs_.end());
@@ -297,12 +339,7 @@ bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) {
PrintF(" now\n");
}
- WaitForJobIfRunningOnBackground(job->second.get());
- while (!IsFinished(job->second.get())) {
- DoNextStepOnMainThread(isolate_, job->second.get(),
- ExceptionHandling::kThrow);
- }
- bool result = job->second->status() != CompileJobStatus::kFailed;
+ bool result = FinishNow(job->second.get());
if (trace_compiler_dispatcher_) {
PrintF("CompilerDispatcher: finished working on ");
@@ -311,7 +348,6 @@ bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) {
tracer_->DumpStatistics();
}
- job->second->ResetOnMainThread();
jobs_.erase(job);
if (jobs_.empty()) {
base::LockGuard<base::Mutex> lock(&mutex_);
@@ -320,6 +356,28 @@ bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) {
return result;
}
+void CompilerDispatcher::FinishAllNow() {
+ if (trace_compiler_dispatcher_) {
+ PrintF("CompilerDispatcher: finishing all jobs now\n");
+ }
+
+ for (auto& it : jobs_) {
+ FinishNow(it.second.get());
+ }
+
+ if (trace_compiler_dispatcher_) {
+ PrintF("CompilerDispatcher: finished all jobs\n");
+ }
+
+ jobs_.clear();
+ {
+ base::LockGuard<base::Mutex> lock(&mutex_);
+ DCHECK(pending_background_jobs_.empty());
+ DCHECK(running_background_jobs_.empty());
+ abort_ = false;
+ }
+}
+
void CompilerDispatcher::AbortAll(BlockingBehavior blocking) {
bool background_tasks_running =
task_manager_->TryAbortAll() == CancelableTaskManager::kTaskRunning;
@@ -340,7 +398,6 @@ void CompilerDispatcher::AbortAll(BlockingBehavior blocking) {
DCHECK(running_background_jobs_.empty());
abort_ = false;
}
- return;
marja 2017/01/10 09:58:54 Why?
rmcilroy 2017/01/12 12:31:55 Opps not sure how that happened - that explains th
}
{

Powered by Google App Engine
This is Rietveld 408576698