Commit dab18fb0 authored by ulan's avatar ulan Committed by Commit bot

Make idle tasks optional in the default platform.

BUG=v8:6056

Review-Url: https://codereview.chromium.org/2737743002
Cr-Commit-Position: refs/heads/master@{#43640}
parent 698c2f3b
......@@ -12,6 +12,8 @@
namespace v8 {
namespace platform {
enum class IdleTaskSupport { kDisabled, kEnabled };
/**
* Returns a new instance of the default v8::Platform implementation.
*
......@@ -19,9 +21,13 @@ namespace platform {
* is the number of worker threads to allocate for background jobs. If a value
* of zero is passed, a suitable default based on the current number of
* processors online will be chosen.
* If |idle_task_support| is enabled then the platform will accept idle
* tasks (IdleTasksEnabled will return true) and will rely on the embedder
* calling v8::platform::RunIdleTasks to process the idle tasks.
*/
V8_PLATFORM_EXPORT v8::Platform* CreateDefaultPlatform(
int thread_pool_size = 0);
int thread_pool_size = 0,
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled);
/**
* Pumps the message loop for the given isolate.
......
......@@ -2892,7 +2892,8 @@ int Shell::Main(int argc, char* argv[]) {
v8::V8::InitializeICUDefaultLocation(argv[0], options.icu_data_file);
g_platform = i::FLAG_verify_predictable
? new PredictablePlatform()
: v8::platform::CreateDefaultPlatform();
: v8::platform::CreateDefaultPlatform(
0, v8::platform::IdleTaskSupport::kEnabled);
platform::tracing::TracingController* tracing_controller;
if (options.trace_enabled) {
......
......@@ -17,9 +17,9 @@
namespace v8 {
namespace platform {
v8::Platform* CreateDefaultPlatform(int thread_pool_size) {
DefaultPlatform* platform = new DefaultPlatform();
v8::Platform* CreateDefaultPlatform(int thread_pool_size,
IdleTaskSupport idle_task_support) {
DefaultPlatform* platform = new DefaultPlatform(idle_task_support);
platform->SetThreadPoolSize(thread_pool_size);
platform->EnsureInitialized();
return platform;
......@@ -45,8 +45,10 @@ void SetTracingController(
const int DefaultPlatform::kMaxThreadPoolSize = 8;
DefaultPlatform::DefaultPlatform()
: initialized_(false), thread_pool_size_(0) {}
DefaultPlatform::DefaultPlatform(IdleTaskSupport idle_task_support)
: initialized_(false),
thread_pool_size_(0),
idle_task_support_(idle_task_support) {}
DefaultPlatform::~DefaultPlatform() {
if (tracing_controller_) {
......@@ -165,6 +167,7 @@ bool DefaultPlatform::PumpMessageLoop(v8::Isolate* isolate) {
void DefaultPlatform::RunIdleTasks(v8::Isolate* isolate,
double idle_time_in_seconds) {
DCHECK(IdleTaskSupport::kEnabled == idle_task_support_);
double deadline_in_seconds =
MonotonicallyIncreasingTime() + idle_time_in_seconds;
while (deadline_in_seconds > MonotonicallyIncreasingTime()) {
......@@ -208,7 +211,9 @@ void DefaultPlatform::CallIdleOnForegroundThread(Isolate* isolate,
main_thread_idle_queue_[isolate].push(task);
}
bool DefaultPlatform::IdleTasksEnabled(Isolate* isolate) { return true; }
bool DefaultPlatform::IdleTasksEnabled(Isolate* isolate) {
return idle_task_support_ == IdleTaskSupport::kEnabled;
}
double DefaultPlatform::MonotonicallyIncreasingTime() {
return base::TimeTicks::HighResolutionNow().ToInternalValue() /
......
......@@ -12,6 +12,7 @@
#include <vector>
#include "include/libplatform/libplatform-export.h"
#include "include/libplatform/libplatform.h"
#include "include/libplatform/v8-tracing.h"
#include "include/v8-platform.h"
#include "src/base/compiler-specific.h"
......@@ -32,7 +33,8 @@ class TracingController;
class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
public:
DefaultPlatform();
explicit DefaultPlatform(
IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled);
virtual ~DefaultPlatform();
void SetThreadPoolSize(int thread_pool_size);
......@@ -81,6 +83,7 @@ class V8_PLATFORM_EXPORT DefaultPlatform : public NON_EXPORTED_BASE(Platform) {
base::Mutex lock_;
bool initialized_;
int thread_pool_size_;
IdleTaskSupport idle_task_support_;
std::vector<WorkerThread*> thread_pool_;
TaskQueue queue_;
std::map<v8::Isolate*, std::queue<Task*>> main_thread_queue_;
......
......@@ -27,7 +27,8 @@ struct MockIdleTask : public IdleTask {
class DefaultPlatformWithMockTime : public DefaultPlatform {
public:
DefaultPlatformWithMockTime() : time_(0) {}
DefaultPlatformWithMockTime()
: DefaultPlatform(IdleTaskSupport::kEnabled), time_(0) {}
double MonotonicallyIncreasingTime() override { return time_; }
void IncreaseTime(double seconds) { time_ += seconds; }
......
......@@ -15,7 +15,8 @@ class DefaultPlatformEnvironment final : public ::testing::Environment {
void SetUp() override {
EXPECT_EQ(NULL, platform_);
platform_ = v8::platform::CreateDefaultPlatform();
platform_ = v8::platform::CreateDefaultPlatform(
0, v8::platform::IdleTaskSupport::kEnabled);
ASSERT_TRUE(platform_ != NULL);
v8::V8::InitializePlatform(platform_);
ASSERT_TRUE(v8::V8::Initialize());
......
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