Commit 65537684 authored by jochen's avatar jochen Committed by Commit bot

Add ability to enqueue SharedFunctionInfos so they can run on bg threads

If this is possible at all, we need to at least do the first step
(prepare to parse).

BUG=v8:5215
R=vogelheim@chromium.org,marja@chromium.org

Review-Url: https://codereview.chromium.org/2610173004
Cr-Commit-Position: refs/heads/master@{#42124}
parent 5f418c8a
......@@ -262,6 +262,21 @@ bool CompilerDispatcher::Enqueue(Handle<SharedFunctionInfo> function) {
return true;
}
bool CompilerDispatcher::EnqueueAndStep(Handle<SharedFunctionInfo> function) {
if (!Enqueue(function)) return false;
if (trace_compiler_dispatcher_) {
PrintF("CompilerDispatcher: stepping ");
function->ShortPrint();
PrintF("\n");
}
JobMap::const_iterator job = GetJobFor(function);
DoNextStepOnMainThread(isolate_, job->second.get(),
ExceptionHandling::kSwallow);
ConsiderJobForBackgroundProcessing(job->second.get());
return true;
}
bool CompilerDispatcher::IsEnabled() const {
v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_);
return FLAG_compiler_dispatcher && platform_->IdleTasksEnabled(v8_isolate);
......
......@@ -71,6 +71,11 @@ class V8_EXPORT_PRIVATE CompilerDispatcher {
// Returns true if a job was enqueued.
bool Enqueue(Handle<SharedFunctionInfo> function);
// Like Enqueue, but also advances the job so that it can potentially
// continue running on a background thread (if at all possible). Returns
// true if the job was enqueued.
bool EnqueueAndStep(Handle<SharedFunctionInfo> function);
// Returns true if there is a pending job for the given function.
bool IsEnqueued(Handle<SharedFunctionInfo> function) const;
......@@ -89,6 +94,7 @@ class V8_EXPORT_PRIVATE CompilerDispatcher {
bool is_isolate_locked);
private:
FRIEND_TEST(CompilerDispatcherTest, EnqueueAndStep);
FRIEND_TEST(CompilerDispatcherTest, IdleTaskSmallIdleTime);
FRIEND_TEST(IgnitionCompilerDispatcherTest, CompileOnBackgroundThread);
FRIEND_TEST(IgnitionCompilerDispatcherTest, FinishNowWithBackgroundTask);
......
......@@ -797,5 +797,27 @@ TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) {
platform.ClearIdleTask();
}
TEST_F(CompilerDispatcherTest, EnqueueAndStep) {
MockPlatform platform;
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
const char script[] =
"function g() { var y = 1; function f16(x) { return x * y }; return f16; "
"} g();";
Handle<JSFunction> f = Handle<JSFunction>::cast(RunJS(isolate(), script));
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
ASSERT_TRUE(dispatcher.EnqueueAndStep(shared));
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
ASSERT_TRUE(dispatcher.jobs_.begin()->second->status() ==
CompileJobStatus::kReadyToParse);
ASSERT_TRUE(platform.IdleTaskPending());
platform.ClearIdleTask();
ASSERT_FALSE(platform.BackgroundTasksPending());
}
} // namespace internal
} // namespace v8
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