Commit c6be438f authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[d8] Implement Platform::PostJob on all platforms

PostJob is used for wasm compilation since https://crrev.com/c/2301933,
so all platforms need to implement it.

R=ulan@chromium.org

Bug: v8:10745, chromium:1101340
Change-Id: Idf88a1305ab3f33ce3980ca7f82d4fc02b0e2443
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2315980
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69020}
parent ab7e89f1
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
namespace v8 { namespace v8 {
class PredictablePlatform : public Platform { class PredictablePlatform final : public Platform {
public: public:
explicit PredictablePlatform(std::unique_ptr<Platform> platform) explicit PredictablePlatform(std::unique_ptr<Platform> platform)
: platform_(std::move(platform)) { : platform_(std::move(platform)) {
...@@ -63,6 +63,11 @@ class PredictablePlatform : public Platform { ...@@ -63,6 +63,11 @@ class PredictablePlatform : public Platform {
bool IdleTasksEnabled(Isolate* isolate) override { return false; } bool IdleTasksEnabled(Isolate* isolate) override { return false; }
std::unique_ptr<JobHandle> PostJob(
TaskPriority priority, std::unique_ptr<JobTask> job_task) override {
return platform_->PostJob(priority, std::move(job_task));
}
double MonotonicallyIncreasingTime() override { double MonotonicallyIncreasingTime() override {
return synthetic_time_in_sec_ += 0.00001; return synthetic_time_in_sec_ += 0.00001;
} }
...@@ -89,7 +94,7 @@ std::unique_ptr<Platform> MakePredictablePlatform( ...@@ -89,7 +94,7 @@ std::unique_ptr<Platform> MakePredictablePlatform(
return std::make_unique<PredictablePlatform>(std::move(platform)); return std::make_unique<PredictablePlatform>(std::move(platform));
} }
class DelayedTasksPlatform : public Platform { class DelayedTasksPlatform final : public Platform {
public: public:
explicit DelayedTasksPlatform(std::unique_ptr<Platform> platform) explicit DelayedTasksPlatform(std::unique_ptr<Platform> platform)
: platform_(std::move(platform)) { : platform_(std::move(platform)) {
...@@ -159,6 +164,11 @@ class DelayedTasksPlatform : public Platform { ...@@ -159,6 +164,11 @@ class DelayedTasksPlatform : public Platform {
return platform_->IdleTasksEnabled(isolate); return platform_->IdleTasksEnabled(isolate);
} }
std::unique_ptr<JobHandle> PostJob(
TaskPriority priority, std::unique_ptr<JobTask> job_task) override {
return platform_->PostJob(priority, MakeDelayedJob(std::move(job_task)));
}
double MonotonicallyIncreasingTime() override { double MonotonicallyIncreasingTime() override {
return platform_->MonotonicallyIncreasingTime(); return platform_->MonotonicallyIncreasingTime();
} }
...@@ -222,11 +232,12 @@ class DelayedTasksPlatform : public Platform { ...@@ -222,11 +232,12 @@ class DelayedTasksPlatform : public Platform {
} }
}; };
class DelayedTask : public Task { class DelayedTask final : public Task {
public: public:
DelayedTask(std::unique_ptr<Task> task, int32_t delay_ms) DelayedTask(std::unique_ptr<Task> task, int32_t delay_ms)
: task_(std::move(task)), delay_ms_(delay_ms) {} : task_(std::move(task)), delay_ms_(delay_ms) {}
void Run() final {
void Run() override {
base::OS::Sleep(base::TimeDelta::FromMicroseconds(delay_ms_)); base::OS::Sleep(base::TimeDelta::FromMicroseconds(delay_ms_));
task_->Run(); task_->Run();
} }
...@@ -236,11 +247,12 @@ class DelayedTasksPlatform : public Platform { ...@@ -236,11 +247,12 @@ class DelayedTasksPlatform : public Platform {
int32_t delay_ms_; int32_t delay_ms_;
}; };
class DelayedIdleTask : public IdleTask { class DelayedIdleTask final : public IdleTask {
public: public:
DelayedIdleTask(std::unique_ptr<IdleTask> task, int32_t delay_ms) DelayedIdleTask(std::unique_ptr<IdleTask> task, int32_t delay_ms)
: task_(std::move(task)), delay_ms_(delay_ms) {} : task_(std::move(task)), delay_ms_(delay_ms) {}
void Run(double deadline_in_seconds) final {
void Run(double deadline_in_seconds) override {
base::OS::Sleep(base::TimeDelta::FromMicroseconds(delay_ms_)); base::OS::Sleep(base::TimeDelta::FromMicroseconds(delay_ms_));
task_->Run(deadline_in_seconds); task_->Run(deadline_in_seconds);
} }
...@@ -250,6 +262,29 @@ class DelayedTasksPlatform : public Platform { ...@@ -250,6 +262,29 @@ class DelayedTasksPlatform : public Platform {
int32_t delay_ms_; int32_t delay_ms_;
}; };
class DelayedJob final : public JobTask {
public:
DelayedJob(std::unique_ptr<JobTask> job_task, int32_t delay_ms)
: job_task_(std::move(job_task)), delay_ms_(delay_ms) {}
void Run(JobDelegate* delegate) override {
// If this job is being executed via worker tasks (as e.g. the
// {DefaultJobHandle} implementation does it), the worker task would
// already include a delay. In order to not depend on that, we add our own
// delay here anyway.
base::OS::Sleep(base::TimeDelta::FromMicroseconds(delay_ms_));
job_task_->Run(delegate);
}
size_t GetMaxConcurrency() const override {
return job_task_->GetMaxConcurrency();
}
private:
std::unique_ptr<JobTask> job_task_;
int32_t delay_ms_;
};
std::unique_ptr<Platform> platform_; std::unique_ptr<Platform> platform_;
// The Mutex protects the RNG, which is used by foreground and background // The Mutex protects the RNG, which is used by foreground and background
...@@ -279,6 +314,11 @@ class DelayedTasksPlatform : public Platform { ...@@ -279,6 +314,11 @@ class DelayedTasksPlatform : public Platform {
GetRandomDelayInMilliseconds()); GetRandomDelayInMilliseconds());
} }
std::unique_ptr<JobTask> MakeDelayedJob(std::unique_ptr<JobTask> task) {
return std::make_unique<DelayedJob>(std::move(task),
GetRandomDelayInMilliseconds());
}
DISALLOW_COPY_AND_ASSIGN(DelayedTasksPlatform); DISALLOW_COPY_AND_ASSIGN(DelayedTasksPlatform);
}; };
......
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