2016-12-12 15:35:41 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/compiler-dispatcher/compiler-dispatcher.h"
|
2016-12-16 14:40:32 +00:00
|
|
|
|
2017-04-04 15:44:44 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2016-12-16 14:40:32 +00:00
|
|
|
#include "include/v8-platform.h"
|
2017-02-10 16:01:38 +00:00
|
|
|
#include "src/api.h"
|
2017-07-25 10:42:08 +00:00
|
|
|
#include "src/ast/ast-value-factory.h"
|
2017-01-03 17:00:56 +00:00
|
|
|
#include "src/base/platform/semaphore.h"
|
2016-12-16 14:40:32 +00:00
|
|
|
#include "src/compiler-dispatcher/compiler-dispatcher-job.h"
|
2017-01-03 17:00:56 +00:00
|
|
|
#include "src/compiler-dispatcher/compiler-dispatcher-tracer.h"
|
2017-08-18 20:34:14 +00:00
|
|
|
#include "src/compiler-dispatcher/unoptimized-compile-job.h"
|
2017-01-25 22:41:57 +00:00
|
|
|
#include "src/compiler.h"
|
2016-12-12 15:35:41 +00:00
|
|
|
#include "src/flags.h"
|
|
|
|
#include "src/handles.h"
|
|
|
|
#include "src/objects-inl.h"
|
2017-01-25 22:41:57 +00:00
|
|
|
#include "src/parsing/parse-info.h"
|
2017-02-10 15:01:29 +00:00
|
|
|
#include "src/parsing/parsing.h"
|
2017-01-03 17:00:56 +00:00
|
|
|
#include "src/v8.h"
|
2017-04-18 14:01:12 +00:00
|
|
|
#include "test/unittests/test-helpers.h"
|
2016-12-12 15:35:41 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
// V8 is smart enough to know something was already compiled and return compiled
|
|
|
|
// code straight away. We need a unique name for each test function so that V8
|
|
|
|
// returns an empty SharedFunctionInfo.
|
|
|
|
#define _STR(x) #x
|
|
|
|
#define STR(x) _STR(x)
|
|
|
|
#define _SCRIPT(fn, a, b, c) a fn b fn c
|
|
|
|
#define SCRIPT(a, b, c) _SCRIPT("f" STR(__LINE__), a, b, c)
|
2017-11-16 12:58:16 +00:00
|
|
|
#define TEST_SCRIPT() \
|
|
|
|
"function f" STR(__LINE__) "(x, y) { return x * y }; f" STR(__LINE__) ";"
|
2017-03-28 16:56:25 +00:00
|
|
|
|
2016-12-12 15:35:41 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2017-02-10 16:01:38 +00:00
|
|
|
class CompilerDispatcherTestFlags {
|
|
|
|
public:
|
|
|
|
static void SetFlagsForTest() {
|
2017-03-14 13:33:13 +00:00
|
|
|
CHECK_NULL(save_flags_);
|
|
|
|
save_flags_ = new SaveFlags();
|
|
|
|
FLAG_single_threaded = true;
|
|
|
|
FlagList::EnforceFlagImplications();
|
|
|
|
FLAG_compiler_dispatcher = true;
|
2017-02-10 16:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void RestoreFlags() {
|
2017-03-14 13:33:13 +00:00
|
|
|
CHECK_NOT_NULL(save_flags_);
|
|
|
|
delete save_flags_;
|
|
|
|
save_flags_ = nullptr;
|
2017-02-10 16:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-03-14 13:33:13 +00:00
|
|
|
static SaveFlags* save_flags_;
|
2017-02-10 16:01:38 +00:00
|
|
|
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(CompilerDispatcherTestFlags);
|
|
|
|
};
|
|
|
|
|
2017-03-14 13:33:13 +00:00
|
|
|
SaveFlags* CompilerDispatcherTestFlags::save_flags_ = nullptr;
|
2017-02-10 16:01:38 +00:00
|
|
|
|
2017-11-13 12:04:57 +00:00
|
|
|
class CompilerDispatcherTest : public TestWithNativeContext {
|
2017-01-02 12:59:07 +00:00
|
|
|
public:
|
|
|
|
CompilerDispatcherTest() = default;
|
|
|
|
~CompilerDispatcherTest() override = default;
|
|
|
|
|
|
|
|
static void SetUpTestCase() {
|
2017-02-10 16:01:38 +00:00
|
|
|
CompilerDispatcherTestFlags::SetFlagsForTest();
|
2017-11-13 12:04:57 +00:00
|
|
|
TestWithNativeContext ::SetUpTestCase();
|
2017-01-02 12:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TearDownTestCase() {
|
2017-11-13 12:04:57 +00:00
|
|
|
TestWithNativeContext ::TearDownTestCase();
|
2017-02-10 16:01:38 +00:00
|
|
|
CompilerDispatcherTestFlags::RestoreFlags();
|
2017-01-02 12:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherTest);
|
|
|
|
};
|
|
|
|
|
2016-12-16 14:40:32 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class MockPlatform : public v8::Platform {
|
|
|
|
public:
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform()
|
2017-07-03 08:23:26 +00:00
|
|
|
: time_(0.0),
|
|
|
|
time_step_(0.0),
|
|
|
|
idle_task_(nullptr),
|
|
|
|
sem_(0),
|
2017-08-01 14:16:30 +00:00
|
|
|
tracing_controller_(V8::GetCurrentPlatform()->GetTracingController()) {}
|
2017-01-03 17:00:56 +00:00
|
|
|
~MockPlatform() override {
|
2017-01-04 13:45:56 +00:00
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
EXPECT_TRUE(foreground_tasks_.empty());
|
|
|
|
EXPECT_TRUE(background_tasks_.empty());
|
2017-01-03 17:00:56 +00:00
|
|
|
EXPECT_TRUE(idle_task_ == nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t NumberOfAvailableBackgroundThreads() override { return 1; }
|
2016-12-16 14:40:32 +00:00
|
|
|
|
2017-11-15 14:26:16 +00:00
|
|
|
std::shared_ptr<TaskRunner> GetForegroundTaskRunner(
|
|
|
|
v8::Isolate* isolate) override {
|
|
|
|
constexpr bool is_foreground_task_runner = true;
|
|
|
|
return std::make_shared<MockTaskRunner>(this, is_foreground_task_runner);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<TaskRunner> GetBackgroundTaskRunner(
|
|
|
|
v8::Isolate* isolate) override {
|
|
|
|
constexpr bool is_foreground_task_runner = false;
|
|
|
|
return std::make_shared<MockTaskRunner>(this, is_foreground_task_runner);
|
|
|
|
}
|
|
|
|
|
2016-12-16 14:40:32 +00:00
|
|
|
void CallOnBackgroundThread(Task* task,
|
|
|
|
ExpectedRuntime expected_runtime) override {
|
2017-01-04 13:45:56 +00:00
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
background_tasks_.push_back(task);
|
2016-12-16 14:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override {
|
2017-01-04 13:45:56 +00:00
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
foreground_tasks_.push_back(task);
|
2016-12-16 14:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CallDelayedOnForegroundThread(v8::Isolate* isolate, Task* task,
|
|
|
|
double delay_in_seconds) override {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CallIdleOnForegroundThread(v8::Isolate* isolate,
|
|
|
|
IdleTask* task) override {
|
2017-01-04 13:45:56 +00:00
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
2017-01-03 17:00:56 +00:00
|
|
|
ASSERT_TRUE(idle_task_ == nullptr);
|
|
|
|
idle_task_ = task;
|
2016-12-16 14:40:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IdleTasksEnabled(v8::Isolate* isolate) override { return true; }
|
|
|
|
|
|
|
|
double MonotonicallyIncreasingTime() override {
|
|
|
|
time_ += time_step_;
|
|
|
|
return time_;
|
|
|
|
}
|
|
|
|
|
2017-08-25 07:12:51 +00:00
|
|
|
double CurrentClockTimeMillis() override {
|
|
|
|
return time_ * base::Time::kMillisecondsPerSecond;
|
|
|
|
}
|
|
|
|
|
2017-07-03 08:23:26 +00:00
|
|
|
v8::TracingController* GetTracingController() override {
|
|
|
|
return tracing_controller_;
|
|
|
|
}
|
|
|
|
|
2016-12-16 14:40:32 +00:00
|
|
|
void RunIdleTask(double deadline_in_seconds, double time_step) {
|
|
|
|
time_step_ = time_step;
|
2017-01-04 13:45:56 +00:00
|
|
|
IdleTask* task;
|
|
|
|
{
|
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
task = idle_task_;
|
|
|
|
ASSERT_TRUE(idle_task_ != nullptr);
|
|
|
|
idle_task_ = nullptr;
|
|
|
|
}
|
2016-12-16 14:40:32 +00:00
|
|
|
task->Run(deadline_in_seconds);
|
|
|
|
delete task;
|
|
|
|
}
|
|
|
|
|
2017-01-04 13:45:56 +00:00
|
|
|
bool IdleTaskPending() {
|
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
return idle_task_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BackgroundTasksPending() {
|
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
return !background_tasks_.empty();
|
|
|
|
}
|
2017-01-03 17:00:56 +00:00
|
|
|
|
2017-01-04 13:45:56 +00:00
|
|
|
bool ForegroundTasksPending() {
|
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
return !foreground_tasks_.empty();
|
|
|
|
}
|
2017-01-03 17:00:56 +00:00
|
|
|
|
|
|
|
void RunBackgroundTasksAndBlock(Platform* platform) {
|
|
|
|
std::vector<Task*> tasks;
|
2017-01-04 13:45:56 +00:00
|
|
|
{
|
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
tasks.swap(background_tasks_);
|
|
|
|
}
|
2017-01-03 17:00:56 +00:00
|
|
|
platform->CallOnBackgroundThread(new TaskWrapper(this, tasks, true),
|
|
|
|
kShortRunningTask);
|
|
|
|
sem_.Wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunBackgroundTasks(Platform* platform) {
|
|
|
|
std::vector<Task*> tasks;
|
2017-01-04 13:45:56 +00:00
|
|
|
{
|
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
tasks.swap(background_tasks_);
|
|
|
|
}
|
2017-01-03 17:00:56 +00:00
|
|
|
platform->CallOnBackgroundThread(new TaskWrapper(this, tasks, false),
|
|
|
|
kShortRunningTask);
|
|
|
|
}
|
|
|
|
|
2017-01-04 13:45:56 +00:00
|
|
|
void RunForegroundTasks() {
|
|
|
|
std::vector<Task*> tasks;
|
|
|
|
{
|
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
tasks.swap(foreground_tasks_);
|
|
|
|
}
|
|
|
|
for (auto& task : tasks) {
|
|
|
|
task->Run();
|
|
|
|
delete task;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-03 17:00:56 +00:00
|
|
|
void ClearBackgroundTasks() {
|
|
|
|
std::vector<Task*> tasks;
|
2017-01-04 13:45:56 +00:00
|
|
|
{
|
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
tasks.swap(background_tasks_);
|
|
|
|
}
|
|
|
|
for (auto& task : tasks) {
|
|
|
|
delete task;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearForegroundTasks() {
|
|
|
|
std::vector<Task*> tasks;
|
|
|
|
{
|
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
|
|
|
tasks.swap(foreground_tasks_);
|
|
|
|
}
|
2017-01-03 17:00:56 +00:00
|
|
|
for (auto& task : tasks) {
|
|
|
|
delete task;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearIdleTask() {
|
2017-01-04 13:45:56 +00:00
|
|
|
base::LockGuard<base::Mutex> lock(&mutex_);
|
2017-01-03 17:00:56 +00:00
|
|
|
ASSERT_TRUE(idle_task_ != nullptr);
|
|
|
|
delete idle_task_;
|
|
|
|
idle_task_ = nullptr;
|
|
|
|
}
|
2016-12-16 14:40:32 +00:00
|
|
|
|
|
|
|
private:
|
2017-01-03 17:00:56 +00:00
|
|
|
class TaskWrapper : public Task {
|
|
|
|
public:
|
|
|
|
TaskWrapper(MockPlatform* platform, const std::vector<Task*>& tasks,
|
|
|
|
bool signal)
|
|
|
|
: platform_(platform), tasks_(tasks), signal_(signal) {}
|
|
|
|
~TaskWrapper() = default;
|
|
|
|
|
|
|
|
void Run() override {
|
|
|
|
for (auto& task : tasks_) {
|
|
|
|
task->Run();
|
|
|
|
delete task;
|
|
|
|
}
|
|
|
|
if (signal_) platform_->sem_.Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MockPlatform* platform_;
|
|
|
|
std::vector<Task*> tasks_;
|
|
|
|
bool signal_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TaskWrapper);
|
|
|
|
};
|
|
|
|
|
2017-11-15 14:26:16 +00:00
|
|
|
class MockTaskRunner final : public TaskRunner {
|
|
|
|
public:
|
|
|
|
MockTaskRunner(MockPlatform* platform, bool is_foreground_task_runner)
|
|
|
|
: platform_(platform),
|
|
|
|
is_foreground_task_runner_(is_foreground_task_runner) {}
|
|
|
|
|
|
|
|
void PostTask(std::unique_ptr<v8::Task> task) override {
|
|
|
|
base::LockGuard<base::Mutex> lock(&platform_->mutex_);
|
|
|
|
if (is_foreground_task_runner_) {
|
|
|
|
platform_->foreground_tasks_.push_back(task.release());
|
|
|
|
} else {
|
|
|
|
platform_->background_tasks_.push_back(task.release());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PostDelayedTask(std::unique_ptr<Task> task,
|
|
|
|
double delay_in_seconds) override {
|
|
|
|
UNREACHABLE();
|
|
|
|
};
|
|
|
|
|
|
|
|
void PostIdleTask(std::unique_ptr<IdleTask> task) override {
|
|
|
|
DCHECK(IdleTasksEnabled());
|
|
|
|
base::LockGuard<base::Mutex> lock(&platform_->mutex_);
|
|
|
|
ASSERT_TRUE(platform_->idle_task_ == nullptr);
|
|
|
|
platform_->idle_task_ = task.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IdleTasksEnabled() override {
|
|
|
|
// Idle tasks are enabled only in the foreground task runner.
|
|
|
|
return is_foreground_task_runner_;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
MockPlatform* platform_;
|
|
|
|
bool is_foreground_task_runner_;
|
|
|
|
};
|
|
|
|
|
2016-12-16 14:40:32 +00:00
|
|
|
double time_;
|
|
|
|
double time_step_;
|
|
|
|
|
2017-01-04 13:45:56 +00:00
|
|
|
// Protects all *_tasks_.
|
|
|
|
base::Mutex mutex_;
|
|
|
|
|
|
|
|
IdleTask* idle_task_;
|
|
|
|
std::vector<Task*> background_tasks_;
|
|
|
|
std::vector<Task*> foreground_tasks_;
|
|
|
|
|
2017-01-03 17:00:56 +00:00
|
|
|
base::Semaphore sem_;
|
|
|
|
|
2017-07-03 08:23:26 +00:00
|
|
|
v8::TracingController* tracing_controller_;
|
|
|
|
|
2016-12-16 14:40:32 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(MockPlatform);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-12-12 15:35:41 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, Construct) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2016-12-16 14:40:32 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
2016-12-12 15:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CompilerDispatcherTest, IsEnqueued) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2016-12-16 14:40:32 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
2016-12-12 15:35:41 +00:00
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
|
|
|
|
2016-12-12 15:35:41 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
2016-12-16 14:40:32 +00:00
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
2017-01-03 17:00:56 +00:00
|
|
|
dispatcher.AbortAll(CompilerDispatcher::BlockingBehavior::kBlock);
|
2016-12-16 14:40:32 +00:00
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
2017-01-03 17:00:56 +00:00
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
platform.ClearIdleTask();
|
2016-12-12 15:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CompilerDispatcherTest, FinishNow) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2016-12-16 14:40:32 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
2016-12-12 15:35:41 +00:00
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2016-12-12 15:35:41 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
2016-12-19 15:41:04 +00:00
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
2016-12-16 14:40:32 +00:00
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
ASSERT_TRUE(dispatcher.FinishNow(shared));
|
2016-12-12 15:35:41 +00:00
|
|
|
// Finishing removes the SFI from the queue.
|
2016-12-16 14:40:32 +00:00
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
2016-12-19 15:41:04 +00:00
|
|
|
ASSERT_TRUE(shared->is_compiled());
|
2017-01-03 17:00:56 +00:00
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
platform.ClearIdleTask();
|
2016-12-16 14:40:32 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 15:44:44 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, FinishAllNow) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-04-04 15:44:44 +00:00
|
|
|
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();
|
2017-11-16 12:58:16 +00:00
|
|
|
std::string script("function f" + func_name + "(x, y) { return x * y }; f" +
|
|
|
|
func_name + ";");
|
2017-11-13 12:04:57 +00:00
|
|
|
f[i] = RunJS<JSFunction>(script.c_str());
|
2017-04-04 15:44:44 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2016-12-16 14:40:32 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, IdleTask) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2016-12-16 14:40:32 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2016-12-16 14:40:32 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
|
|
|
// Since time doesn't progress on the MockPlatform, this is enough idle time
|
|
|
|
// to finish compiling the function.
|
|
|
|
platform.RunIdleTask(1000.0, 0.0);
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
2016-12-19 15:41:04 +00:00
|
|
|
ASSERT_TRUE(shared->is_compiled());
|
2016-12-12 15:35:41 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 14:40:32 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, IdleTaskSmallIdleTime) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2016-12-16 14:40:32 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2016-12-16 14:40:32 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
|
|
|
// The job should be scheduled for the main thread.
|
2017-02-22 13:46:14 +00:00
|
|
|
ASSERT_EQ(dispatcher.jobs_.size(), 1u);
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kInitial,
|
2017-11-16 16:50:27 +00:00
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2016-12-16 14:40:32 +00:00
|
|
|
|
|
|
|
// Only grant a little idle time and have time advance beyond it in one step.
|
|
|
|
platform.RunIdleTask(2.0, 1.0);
|
|
|
|
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
2016-12-19 15:41:04 +00:00
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
2016-12-16 14:40:32 +00:00
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
|
|
|
// The job should be still scheduled for the main thread, but ready for
|
|
|
|
// parsing.
|
2017-02-22 13:46:14 +00:00
|
|
|
ASSERT_EQ(dispatcher.jobs_.size(), 1u);
|
2017-11-16 16:50:27 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2016-12-16 14:40:32 +00:00
|
|
|
|
2017-01-03 17:00:56 +00:00
|
|
|
// Now grant a lot of idle time and freeze time.
|
2016-12-16 14:40:32 +00:00
|
|
|
platform.RunIdleTask(1000.0, 0.0);
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
2016-12-19 15:41:04 +00:00
|
|
|
ASSERT_TRUE(shared->is_compiled());
|
2016-12-16 14:40:32 +00:00
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CompilerDispatcherTest, IdleTaskException) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2016-12-16 14:40:32 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, 50);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
std::string func_name("f" STR(__LINE__));
|
2017-11-16 12:58:16 +00:00
|
|
|
std::string script("function " + func_name + "(x) { var a = ");
|
2017-10-25 10:47:24 +00:00
|
|
|
for (int i = 0; i < 500; i++) {
|
|
|
|
// Alternate + and - to avoid n-ary operation nodes.
|
|
|
|
script += "'x' + 'x' - ";
|
2016-12-16 14:40:32 +00:00
|
|
|
}
|
2017-11-16 12:58:16 +00:00
|
|
|
script += " 'x'; }; " + func_name + ";";
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script.c_str());
|
2016-12-16 14:40:32 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
|
|
|
// Since time doesn't progress on the MockPlatform, this is enough idle time
|
|
|
|
// to finish compiling the function.
|
|
|
|
platform.RunIdleTask(1000.0, 0.0);
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
2016-12-19 15:41:04 +00:00
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
2017-01-04 10:07:59 +00:00
|
|
|
ASSERT_FALSE(i_isolate()->has_pending_exception());
|
2016-12-16 14:40:32 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 10:49:16 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, CompileOnBackgroundThread) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-01-03 17:00:56 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2017-01-03 17:00:56 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
2017-02-22 13:46:14 +00:00
|
|
|
ASSERT_EQ(dispatcher.jobs_.size(), 1u);
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kInitial,
|
2017-11-16 16:50:27 +00:00
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-03 17:00:56 +00:00
|
|
|
|
|
|
|
// Make compiling super expensive, and advance job as much as possible on the
|
|
|
|
// foreground thread.
|
2017-11-16 12:58:16 +00:00
|
|
|
dispatcher.tracer_->RecordCompile(50000.0, 1);
|
2017-01-03 17:00:56 +00:00
|
|
|
platform.RunIdleTask(10.0, 0.0);
|
2017-11-16 16:50:27 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-03 17:00:56 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(platform.BackgroundTasksPending());
|
|
|
|
|
|
|
|
platform.RunBackgroundTasksAndBlock(V8::GetCurrentPlatform());
|
|
|
|
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
ASSERT_FALSE(platform.BackgroundTasksPending());
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kCompiled,
|
2017-11-16 16:50:27 +00:00
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-03 17:00:56 +00:00
|
|
|
|
|
|
|
// Now grant a lot of idle time and freeze time.
|
|
|
|
platform.RunIdleTask(1000.0, 0.0);
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_TRUE(shared->is_compiled());
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
}
|
|
|
|
|
2017-01-16 10:49:16 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, FinishNowWithBackgroundTask) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-01-03 17:00:56 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2017-01-03 17:00:56 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
2017-02-22 13:46:14 +00:00
|
|
|
ASSERT_EQ(dispatcher.jobs_.size(), 1u);
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kInitial,
|
2017-11-16 16:50:27 +00:00
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-03 17:00:56 +00:00
|
|
|
|
|
|
|
// Make compiling super expensive, and advance job as much as possible on the
|
|
|
|
// foreground thread.
|
2017-11-16 12:58:16 +00:00
|
|
|
dispatcher.tracer_->RecordCompile(50000.0, 1);
|
2017-01-03 17:00:56 +00:00
|
|
|
platform.RunIdleTask(10.0, 0.0);
|
2017-11-16 16:50:27 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-03 17:00:56 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(platform.BackgroundTasksPending());
|
|
|
|
|
|
|
|
// This does not block, but races with the FinishNow() call below.
|
|
|
|
platform.RunBackgroundTasks(V8::GetCurrentPlatform());
|
|
|
|
|
|
|
|
ASSERT_TRUE(dispatcher.FinishNow(shared));
|
|
|
|
// Finishing removes the SFI from the queue.
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_TRUE(shared->is_compiled());
|
|
|
|
if (platform.IdleTaskPending()) platform.ClearIdleTask();
|
|
|
|
ASSERT_FALSE(platform.BackgroundTasksPending());
|
|
|
|
}
|
|
|
|
|
2017-01-04 10:07:59 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, IdleTaskMultipleJobs) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-01-04 10:07:59 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script1[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f1 = RunJS<JSFunction>(script1);
|
2017-01-04 10:07:59 +00:00
|
|
|
Handle<SharedFunctionInfo> shared1(f1->shared(), i_isolate());
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script2[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f2 = RunJS<JSFunction>(script2);
|
2017-01-04 10:07:59 +00:00
|
|
|
Handle<SharedFunctionInfo> shared2(f2->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared1));
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared2));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
|
|
|
// Since time doesn't progress on the MockPlatform, this is enough idle time
|
|
|
|
// to finish compiling the function.
|
|
|
|
platform.RunIdleTask(1000.0, 0.0);
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared1));
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared2));
|
|
|
|
ASSERT_TRUE(shared1->is_compiled());
|
|
|
|
ASSERT_TRUE(shared2->is_compiled());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CompilerDispatcherTest, FinishNowException) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-01-04 10:07:59 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, 50);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
std::string func_name("f" STR(__LINE__));
|
2017-11-16 12:58:16 +00:00
|
|
|
std::string script("function " + func_name + "(x) { var a = ");
|
2017-10-25 10:47:24 +00:00
|
|
|
for (int i = 0; i < 500; i++) {
|
|
|
|
// Alternate + and - to avoid n-ary operation nodes.
|
|
|
|
script += "'x' + 'x' - ";
|
2017-01-04 10:07:59 +00:00
|
|
|
}
|
2017-11-16 12:58:16 +00:00
|
|
|
script += " 'x'; }; " + func_name + ";";
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script.c_str());
|
2017-01-04 10:07:59 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.FinishNow(shared));
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
|
|
|
ASSERT_TRUE(i_isolate()->has_pending_exception());
|
|
|
|
|
|
|
|
i_isolate()->clear_pending_exception();
|
|
|
|
platform.ClearIdleTask();
|
|
|
|
}
|
|
|
|
|
2017-01-16 10:49:16 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, AsyncAbortAllPendingBackgroundTask) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-01-04 13:45:56 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2017-01-04 13:45:56 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
2017-02-22 13:46:14 +00:00
|
|
|
ASSERT_EQ(dispatcher.jobs_.size(), 1u);
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kInitial,
|
2017-11-16 16:50:27 +00:00
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-04 13:45:56 +00:00
|
|
|
|
|
|
|
// Make compiling super expensive, and advance job as much as possible on the
|
|
|
|
// foreground thread.
|
2017-11-16 12:58:16 +00:00
|
|
|
dispatcher.tracer_->RecordCompile(50000.0, 1);
|
2017-01-04 13:45:56 +00:00
|
|
|
platform.RunIdleTask(10.0, 0.0);
|
2017-11-16 16:50:27 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-04 13:45:56 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(platform.BackgroundTasksPending());
|
|
|
|
|
|
|
|
// The background task hasn't yet started, so we can just cancel it.
|
|
|
|
dispatcher.AbortAll(CompilerDispatcher::BlockingBehavior::kDontBlock);
|
|
|
|
ASSERT_FALSE(platform.ForegroundTasksPending());
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
|
|
|
|
|
|
|
platform.RunBackgroundTasksAndBlock(V8::GetCurrentPlatform());
|
|
|
|
|
|
|
|
if (platform.IdleTaskPending()) platform.ClearIdleTask();
|
|
|
|
ASSERT_FALSE(platform.BackgroundTasksPending());
|
|
|
|
ASSERT_FALSE(platform.ForegroundTasksPending());
|
|
|
|
}
|
|
|
|
|
2017-01-16 10:49:16 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, AsyncAbortAllRunningBackgroundTask) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-01-04 13:45:56 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script1[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f1 = RunJS<JSFunction>(script1);
|
2017-01-04 13:45:56 +00:00
|
|
|
Handle<SharedFunctionInfo> shared1(f1->shared(), i_isolate());
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script2[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f2 = RunJS<JSFunction>(script2);
|
2017-01-04 13:45:56 +00:00
|
|
|
Handle<SharedFunctionInfo> shared2(f2->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared1));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
2017-02-22 13:46:14 +00:00
|
|
|
ASSERT_EQ(dispatcher.jobs_.size(), 1u);
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kInitial,
|
2017-11-16 16:50:27 +00:00
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-04 13:45:56 +00:00
|
|
|
|
|
|
|
// Make compiling super expensive, and advance job as much as possible on the
|
|
|
|
// foreground thread.
|
2017-11-16 12:58:16 +00:00
|
|
|
dispatcher.tracer_->RecordCompile(50000.0, 1);
|
2017-01-04 13:45:56 +00:00
|
|
|
platform.RunIdleTask(10.0, 0.0);
|
2017-11-16 16:50:27 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-04 13:45:56 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared1));
|
|
|
|
ASSERT_FALSE(shared1->is_compiled());
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(platform.BackgroundTasksPending());
|
|
|
|
|
|
|
|
// Kick off background tasks and freeze them.
|
|
|
|
dispatcher.block_for_testing_.SetValue(true);
|
|
|
|
platform.RunBackgroundTasks(V8::GetCurrentPlatform());
|
|
|
|
|
|
|
|
// Busy loop until the background task started running.
|
|
|
|
while (dispatcher.block_for_testing_.Value()) {
|
|
|
|
}
|
|
|
|
dispatcher.AbortAll(CompilerDispatcher::BlockingBehavior::kDontBlock);
|
|
|
|
ASSERT_TRUE(platform.ForegroundTasksPending());
|
|
|
|
|
|
|
|
// We can't schedule new tasks while we're aborting.
|
|
|
|
ASSERT_FALSE(dispatcher.Enqueue(shared2));
|
|
|
|
|
|
|
|
// Run the first AbortTask. Since the background job is still pending, it
|
|
|
|
// can't do anything.
|
|
|
|
platform.RunForegroundTasks();
|
|
|
|
{
|
|
|
|
base::LockGuard<base::Mutex> lock(&dispatcher.mutex_);
|
|
|
|
ASSERT_TRUE(dispatcher.abort_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release background task.
|
|
|
|
dispatcher.semaphore_for_testing_.Signal();
|
|
|
|
|
|
|
|
// Busy loop until the background task scheduled another AbortTask task.
|
|
|
|
while (!platform.ForegroundTasksPending()) {
|
|
|
|
}
|
|
|
|
|
|
|
|
platform.RunForegroundTasks();
|
|
|
|
ASSERT_TRUE(dispatcher.jobs_.empty());
|
|
|
|
{
|
|
|
|
base::LockGuard<base::Mutex> lock(&dispatcher.mutex_);
|
|
|
|
ASSERT_FALSE(dispatcher.abort_);
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
platform.RunIdleTask(5.0, 1.0);
|
|
|
|
ASSERT_FALSE(platform.BackgroundTasksPending());
|
|
|
|
ASSERT_FALSE(platform.ForegroundTasksPending());
|
|
|
|
|
|
|
|
// Now it's possible to enqueue new functions again.
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared2));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
ASSERT_FALSE(platform.BackgroundTasksPending());
|
|
|
|
ASSERT_FALSE(platform.ForegroundTasksPending());
|
|
|
|
platform.ClearIdleTask();
|
|
|
|
}
|
|
|
|
|
2017-01-16 10:49:16 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, FinishNowDuringAbortAll) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-01-04 13:45:56 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2017-01-04 13:45:56 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
2017-02-22 13:46:14 +00:00
|
|
|
ASSERT_EQ(dispatcher.jobs_.size(), 1u);
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kInitial,
|
2017-11-16 16:50:27 +00:00
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-04 13:45:56 +00:00
|
|
|
|
|
|
|
// Make compiling super expensive, and advance job as much as possible on the
|
|
|
|
// foreground thread.
|
2017-11-16 12:58:16 +00:00
|
|
|
dispatcher.tracer_->RecordCompile(50000.0, 1);
|
2017-01-04 13:45:56 +00:00
|
|
|
platform.RunIdleTask(10.0, 0.0);
|
2017-11-16 16:50:27 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-04 13:45:56 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(platform.BackgroundTasksPending());
|
|
|
|
|
|
|
|
// Kick off background tasks and freeze them.
|
|
|
|
dispatcher.block_for_testing_.SetValue(true);
|
|
|
|
platform.RunBackgroundTasks(V8::GetCurrentPlatform());
|
|
|
|
|
|
|
|
// Busy loop until the background task started running.
|
|
|
|
while (dispatcher.block_for_testing_.Value()) {
|
|
|
|
}
|
|
|
|
dispatcher.AbortAll(CompilerDispatcher::BlockingBehavior::kDontBlock);
|
|
|
|
ASSERT_TRUE(platform.ForegroundTasksPending());
|
|
|
|
|
|
|
|
// Run the first AbortTask. Since the background job is still pending, it
|
|
|
|
// can't do anything.
|
|
|
|
platform.RunForegroundTasks();
|
|
|
|
{
|
|
|
|
base::LockGuard<base::Mutex> lock(&dispatcher.mutex_);
|
|
|
|
ASSERT_TRUE(dispatcher.abort_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// While the background thread holds on to a job, it is still enqueud.
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
|
|
|
|
|
|
|
// Release background task.
|
|
|
|
dispatcher.semaphore_for_testing_.Signal();
|
|
|
|
|
|
|
|
// Force the compilation to finish, even while aborting.
|
|
|
|
ASSERT_TRUE(dispatcher.FinishNow(shared));
|
|
|
|
ASSERT_TRUE(dispatcher.jobs_.empty());
|
2017-03-20 07:10:45 +00:00
|
|
|
|
|
|
|
// Busy wait for the background task to finish.
|
2017-03-17 14:23:28 +00:00
|
|
|
for (;;) {
|
2017-01-04 13:45:56 +00:00
|
|
|
base::LockGuard<base::Mutex> lock(&dispatcher.mutex_);
|
2017-03-17 14:23:28 +00:00
|
|
|
if (dispatcher.num_background_tasks_ == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2017-01-04 13:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_TRUE(platform.ForegroundTasksPending());
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
ASSERT_FALSE(platform.BackgroundTasksPending());
|
2017-03-20 07:10:45 +00:00
|
|
|
|
|
|
|
platform.RunForegroundTasks();
|
|
|
|
{
|
|
|
|
base::LockGuard<base::Mutex> lock(&dispatcher.mutex_);
|
|
|
|
ASSERT_FALSE(dispatcher.abort_);
|
|
|
|
}
|
|
|
|
|
2017-01-04 13:45:56 +00:00
|
|
|
platform.ClearForegroundTasks();
|
|
|
|
platform.ClearIdleTask();
|
|
|
|
}
|
|
|
|
|
2017-01-05 09:22:34 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, MemoryPressure) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-01-05 09:22:34 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2017-01-05 09:22:34 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
// Can't enqueue tasks under memory pressure.
|
|
|
|
dispatcher.MemoryPressureNotification(v8::MemoryPressureLevel::kCritical,
|
|
|
|
true);
|
|
|
|
ASSERT_FALSE(dispatcher.Enqueue(shared));
|
|
|
|
|
|
|
|
dispatcher.MemoryPressureNotification(v8::MemoryPressureLevel::kNone, true);
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
|
|
|
|
// Memory pressure cancels current jobs.
|
|
|
|
dispatcher.MemoryPressureNotification(v8::MemoryPressureLevel::kCritical,
|
|
|
|
true);
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
|
|
|
platform.ClearIdleTask();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class PressureNotificationTask : public CancelableTask {
|
|
|
|
public:
|
|
|
|
PressureNotificationTask(Isolate* isolate, CompilerDispatcher* dispatcher,
|
|
|
|
base::Semaphore* sem)
|
|
|
|
: CancelableTask(isolate), dispatcher_(dispatcher), sem_(sem) {}
|
|
|
|
~PressureNotificationTask() override {}
|
|
|
|
|
|
|
|
void RunInternal() override {
|
|
|
|
dispatcher_->MemoryPressureNotification(v8::MemoryPressureLevel::kCritical,
|
|
|
|
false);
|
|
|
|
sem_->Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CompilerDispatcher* dispatcher_;
|
|
|
|
base::Semaphore* sem_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(PressureNotificationTask);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST_F(CompilerDispatcherTest, MemoryPressureFromBackground) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-01-05 09:22:34 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2017-01-05 09:22:34 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared));
|
|
|
|
base::Semaphore sem(0);
|
|
|
|
V8::GetCurrentPlatform()->CallOnBackgroundThread(
|
|
|
|
new PressureNotificationTask(i_isolate(), &dispatcher, &sem),
|
|
|
|
v8::Platform::kShortRunningTask);
|
|
|
|
|
|
|
|
sem.Wait();
|
|
|
|
|
|
|
|
// A memory pressure task is pending, and running it will cancel the job.
|
|
|
|
ASSERT_TRUE(platform.ForegroundTasksPending());
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
|
|
|
platform.RunForegroundTasks();
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
|
|
|
|
|
|
|
// Since the AbortAll() call is made from a task, AbortAll thinks that there
|
|
|
|
// is at least one task running, and fires of an AbortTask to be safe.
|
|
|
|
ASSERT_TRUE(platform.ForegroundTasksPending());
|
|
|
|
platform.RunForegroundTasks();
|
|
|
|
ASSERT_FALSE(platform.ForegroundTasksPending());
|
|
|
|
|
|
|
|
platform.ClearIdleTask();
|
|
|
|
}
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, EnqueueJob) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-03-28 16:56:25 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2017-03-28 16:56:25 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
std::unique_ptr<CompilerDispatcherJob> job(
|
2017-07-27 13:33:53 +00:00
|
|
|
new UnoptimizedCompileJob(i_isolate(), dispatcher.tracer_.get(), shared,
|
2017-03-28 16:56:25 +00:00
|
|
|
dispatcher.max_stack_size_));
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
|
|
|
dispatcher.Enqueue(std::move(job));
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
|
|
|
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
platform.ClearIdleTask();
|
|
|
|
ASSERT_FALSE(platform.BackgroundTasksPending());
|
|
|
|
}
|
|
|
|
|
2017-01-09 08:52:04 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, EnqueueAndStep) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-01-09 08:52:04 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2017-01-09 08:52:04 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
|
|
|
ASSERT_TRUE(dispatcher.EnqueueAndStep(shared));
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
|
|
|
|
2017-11-16 16:50:27 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-01-09 08:52:04 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
platform.ClearIdleTask();
|
2017-01-16 10:49:16 +00:00
|
|
|
ASSERT_TRUE(platform.BackgroundTasksPending());
|
|
|
|
platform.ClearBackgroundTasks();
|
2017-01-09 08:52:04 +00:00
|
|
|
}
|
|
|
|
|
2017-02-10 18:46:31 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, CompileLazyFinishesDispatcherJob) {
|
|
|
|
// Use the real dispatcher so that CompileLazy checks the same one for
|
|
|
|
// enqueued functions.
|
|
|
|
CompilerDispatcher* dispatcher = i_isolate()->compiler_dispatcher();
|
|
|
|
|
2017-11-16 12:58:16 +00:00
|
|
|
const char script[] = "function lazy() { return 42; }; lazy;";
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2017-02-10 18:46:31 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(shared->is_compiled());
|
|
|
|
ASSERT_FALSE(dispatcher->IsEnqueued(shared));
|
|
|
|
ASSERT_TRUE(dispatcher->Enqueue(shared));
|
|
|
|
ASSERT_TRUE(dispatcher->IsEnqueued(shared));
|
|
|
|
|
|
|
|
// Now force the function to run and ensure CompileLazy finished and dequeues
|
|
|
|
// it from the dispatcher.
|
2017-11-16 12:58:16 +00:00
|
|
|
RunJS("lazy();");
|
2017-02-10 18:46:31 +00:00
|
|
|
ASSERT_TRUE(shared->is_compiled());
|
|
|
|
ASSERT_FALSE(dispatcher->IsEnqueued(shared));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CompilerDispatcherTest, CompileLazy2FinishesDispatcherJob) {
|
|
|
|
// Use the real dispatcher so that CompileLazy checks the same one for
|
|
|
|
// enqueued functions.
|
|
|
|
CompilerDispatcher* dispatcher = i_isolate()->compiler_dispatcher();
|
|
|
|
|
|
|
|
const char source2[] = "function lazy2() { return 42; }; lazy2;";
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> lazy2 = RunJS<JSFunction>(source2);
|
2017-02-10 18:46:31 +00:00
|
|
|
Handle<SharedFunctionInfo> shared2(lazy2->shared(), i_isolate());
|
|
|
|
ASSERT_FALSE(shared2->is_compiled());
|
|
|
|
|
|
|
|
const char source1[] = "function lazy1() { return lazy2(); }; lazy1;";
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> lazy1 = RunJS<JSFunction>(source1);
|
2017-02-10 18:46:31 +00:00
|
|
|
Handle<SharedFunctionInfo> shared1(lazy1->shared(), i_isolate());
|
|
|
|
ASSERT_FALSE(shared1->is_compiled());
|
|
|
|
|
|
|
|
ASSERT_TRUE(dispatcher->Enqueue(shared1));
|
|
|
|
ASSERT_TRUE(dispatcher->Enqueue(shared2));
|
|
|
|
|
2017-11-13 12:04:57 +00:00
|
|
|
RunJS("lazy1();");
|
2017-02-10 18:46:31 +00:00
|
|
|
ASSERT_TRUE(shared1->is_compiled());
|
|
|
|
ASSERT_TRUE(shared2->is_compiled());
|
|
|
|
ASSERT_FALSE(dispatcher->IsEnqueued(shared1));
|
|
|
|
ASSERT_FALSE(dispatcher->IsEnqueued(shared2));
|
|
|
|
}
|
|
|
|
|
2017-02-10 22:12:39 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, EnqueueAndStepTwice) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-02-10 22:12:39 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-07-27 16:19:17 +00:00
|
|
|
const char script[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f = RunJS<JSFunction>(script);
|
2017-02-10 22:12:39 +00:00
|
|
|
Handle<SharedFunctionInfo> shared(f->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared));
|
2017-07-27 16:19:17 +00:00
|
|
|
ASSERT_TRUE(dispatcher.EnqueueAndStep(shared));
|
2017-02-10 22:12:39 +00:00
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared));
|
2017-11-16 16:50:27 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-02-10 22:12:39 +00:00
|
|
|
|
2017-07-27 16:19:17 +00:00
|
|
|
// EnqueueAndStep of the same function again (shouldn't step the job.
|
2017-02-10 22:12:39 +00:00
|
|
|
ASSERT_TRUE(dispatcher.EnqueueAndStep(shared));
|
2017-11-16 16:50:27 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-02-10 22:12:39 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(platform.BackgroundTasksPending());
|
|
|
|
platform.ClearIdleTask();
|
|
|
|
platform.ClearBackgroundTasks();
|
|
|
|
}
|
|
|
|
|
2017-03-03 17:00:22 +00:00
|
|
|
TEST_F(CompilerDispatcherTest, CompileMultipleOnBackgroundThread) {
|
2017-08-01 14:16:30 +00:00
|
|
|
MockPlatform platform;
|
2017-03-03 17:00:22 +00:00
|
|
|
CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size);
|
|
|
|
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script1[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f1 = RunJS<JSFunction>(script1);
|
2017-03-03 17:00:22 +00:00
|
|
|
Handle<SharedFunctionInfo> shared1(f1->shared(), i_isolate());
|
2017-03-28 16:56:25 +00:00
|
|
|
const char script2[] = TEST_SCRIPT();
|
2017-11-13 12:04:57 +00:00
|
|
|
Handle<JSFunction> f2 = RunJS<JSFunction>(script2);
|
2017-03-03 17:00:22 +00:00
|
|
|
Handle<SharedFunctionInfo> shared2(f2->shared(), i_isolate());
|
|
|
|
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared1));
|
|
|
|
ASSERT_TRUE(dispatcher.Enqueue(shared2));
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
|
|
|
|
ASSERT_EQ(dispatcher.jobs_.size(), 2u);
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kInitial,
|
2017-11-16 16:50:27 +00:00
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kInitial,
|
2017-11-16 16:50:27 +00:00
|
|
|
(++dispatcher.jobs_.begin())->second->status());
|
2017-03-03 17:00:22 +00:00
|
|
|
|
|
|
|
// Make compiling super expensive, and advance job as much as possible on the
|
|
|
|
// foreground thread.
|
2017-11-16 12:58:16 +00:00
|
|
|
dispatcher.tracer_->RecordCompile(50000.0, 1);
|
2017-03-03 17:00:22 +00:00
|
|
|
platform.RunIdleTask(10.0, 0.0);
|
|
|
|
ASSERT_EQ(dispatcher.jobs_.size(), 2u);
|
2017-11-16 16:50:27 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
dispatcher.jobs_.begin()->second->status());
|
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kPrepared,
|
|
|
|
(++dispatcher.jobs_.begin())->second->status());
|
2017-03-03 17:00:22 +00:00
|
|
|
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared1));
|
|
|
|
ASSERT_TRUE(dispatcher.IsEnqueued(shared2));
|
|
|
|
ASSERT_FALSE(shared1->is_compiled());
|
|
|
|
ASSERT_FALSE(shared2->is_compiled());
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
ASSERT_TRUE(platform.BackgroundTasksPending());
|
|
|
|
|
|
|
|
platform.RunBackgroundTasksAndBlock(V8::GetCurrentPlatform());
|
|
|
|
|
|
|
|
ASSERT_TRUE(platform.IdleTaskPending());
|
|
|
|
ASSERT_FALSE(platform.BackgroundTasksPending());
|
|
|
|
ASSERT_EQ(dispatcher.jobs_.size(), 2u);
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kCompiled,
|
2017-11-16 16:50:27 +00:00
|
|
|
dispatcher.jobs_.begin()->second->status());
|
2017-07-27 13:33:53 +00:00
|
|
|
ASSERT_EQ(UnoptimizedCompileJob::Status::kCompiled,
|
2017-11-16 16:50:27 +00:00
|
|
|
(++dispatcher.jobs_.begin())->second->status());
|
2017-03-03 17:00:22 +00:00
|
|
|
|
|
|
|
// Now grant a lot of idle time and freeze time.
|
|
|
|
platform.RunIdleTask(1000.0, 0.0);
|
|
|
|
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared1));
|
|
|
|
ASSERT_FALSE(dispatcher.IsEnqueued(shared2));
|
|
|
|
ASSERT_TRUE(shared1->is_compiled());
|
|
|
|
ASSERT_TRUE(shared2->is_compiled());
|
|
|
|
ASSERT_FALSE(platform.IdleTaskPending());
|
|
|
|
}
|
|
|
|
|
2017-11-16 12:58:16 +00:00
|
|
|
#undef _STR
|
|
|
|
#undef STR
|
|
|
|
#undef _SCRIPT
|
|
|
|
#undef SCRIPT
|
|
|
|
#undef TEST_SCRIPT
|
|
|
|
|
2016-12-12 15:35:41 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|