Skip to content

Commit 9f46bde

Browse files
Matt LoringMylesBorins
Matt Loring
authored andcommitted
deps: backport d727680 from V8 upstream
Original commit message: [d8] Bring PredictablePlatform in line with default platform This removes a lot of special handling for the predictable platform. Instead of executing spawned foreground and background tasks immediately (i.e. inside the scope that spawns the tasks), just add both to the foreground task queue. This avoids existing special handling for predictable mode in wasm async compilation, and should fix current failures on the predictable bot. BUG=v8:6427 Change-Id: Idbaa764a3dc8c230c29f3937d885e12174691ac4 Reviewed-on: https://chromium-review.googlesource.com/509694 Reviewed-by: Jochen Eisinger <[email protected]> Commit-Queue: Clemens Hammacher <[email protected]> Cr-Commit-Position: refs/heads/master@{#45538} PR-URL: #14947 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Nikolai Vavilov <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent a6344d5 commit 9f46bde

File tree

4 files changed

+95
-123
lines changed

4 files changed

+95
-123
lines changed

deps/v8/src/d8.cc

+81-98
Original file line numberDiff line numberDiff line change
@@ -191,76 +191,65 @@ class MockArrayBufferAllocator : public ArrayBufferAllocatorBase {
191191
}
192192
};
193193

194-
195-
// Predictable v8::Platform implementation. All background and foreground
196-
// tasks are run immediately, delayed tasks are not executed at all.
194+
// Predictable v8::Platform implementation. Background tasks and idle tasks are
195+
// disallowed, and the time reported by {MonotonicallyIncreasingTime} is
196+
// deterministic.
197197
class PredictablePlatform : public Platform {
198-
public:
199-
PredictablePlatform() {}
200-
201-
void CallOnBackgroundThread(Task* task,
202-
ExpectedRuntime expected_runtime) override {
203-
task->Run();
204-
delete task;
205-
}
206-
207-
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override {
208-
task->Run();
209-
delete task;
210-
}
211-
212-
void CallDelayedOnForegroundThread(v8::Isolate* isolate, Task* task,
213-
double delay_in_seconds) override {
214-
delete task;
215-
}
216-
217-
void CallIdleOnForegroundThread(v8::Isolate* isolate,
218-
IdleTask* task) override {
219-
UNREACHABLE();
220-
}
221-
222-
bool IdleTasksEnabled(v8::Isolate* isolate) override { return false; }
223-
224-
double MonotonicallyIncreasingTime() override {
225-
return synthetic_time_in_sec_ += 0.00001;
226-
}
227-
228-
v8::TracingController* GetTracingController() override {
229-
return platform_->GetTracingController();
230-
}
231-
232-
using Platform::AddTraceEvent;
233-
uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag,
234-
const char* name, const char* scope, uint64_t id,
235-
uint64_t bind_id, int numArgs, const char** argNames,
236-
const uint8_t* argTypes, const uint64_t* argValues,
237-
unsigned int flags) override {
238-
return 0;
239-
}
240-
241-
void UpdateTraceEventDuration(const uint8_t* categoryEnabledFlag,
242-
const char* name, uint64_t handle) override {}
243-
244-
const uint8_t* GetCategoryGroupEnabled(const char* name) override {
245-
static uint8_t no = 0;
246-
return &no;
247-
}
248-
249-
const char* GetCategoryGroupName(
250-
const uint8_t* categoryEnabledFlag) override {
251-
static const char* dummy = "dummy";
252-
return dummy;
253-
}
254-
255-
private:
256-
double synthetic_time_in_sec_ = 0.0;
257-
258-
DISALLOW_COPY_AND_ASSIGN(PredictablePlatform);
198+
public:
199+
explicit PredictablePlatform(std::unique_ptr<Platform> platform)
200+
: platform_(std::move(platform)) {
201+
DCHECK_NOT_NULL(platform_);
202+
}
203+
204+
void CallOnBackgroundThread(Task* task,
205+
ExpectedRuntime expected_runtime) override {
206+
// It's not defined when background tasks are being executed, so we can just
207+
// execute them right away.
208+
task->Run();
209+
delete task;
210+
}
211+
212+
void CallOnForegroundThread(v8::Isolate* isolate, Task* task) override {
213+
platform_->CallOnForegroundThread(isolate, task);
214+
}
215+
216+
void CallDelayedOnForegroundThread(v8::Isolate* isolate, Task* task,
217+
double delay_in_seconds) override {
218+
platform_->CallDelayedOnForegroundThread(isolate, task, delay_in_seconds);
219+
}
220+
221+
void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) override {
222+
UNREACHABLE();
223+
}
224+
225+
bool IdleTasksEnabled(Isolate* isolate) override { return false; }
226+
227+
double MonotonicallyIncreasingTime() override {
228+
return synthetic_time_in_sec_ += 0.00001;
229+
}
230+
231+
v8::TracingController* GetTracingController() override {
232+
return platform_->GetTracingController();
233+
}
234+
235+
Platform* platform() const { return platform_.get(); }
236+
237+
private:
238+
double synthetic_time_in_sec_ = 0.0;
239+
std::unique_ptr<Platform> platform_;
240+
241+
DISALLOW_COPY_AND_ASSIGN(PredictablePlatform);
259242
};
260243

261244

262245
v8::Platform* g_platform = NULL;
263246

247+
v8::Platform* GetDefaultPlatform() {
248+
return i::FLAG_verify_predictable
249+
? static_cast<PredictablePlatform*>(g_platform)->platform()
250+
: g_platform;
251+
}
252+
264253
static Local<Value> Throw(Isolate* isolate, const char* message) {
265254
return isolate->ThrowException(
266255
String::NewFromUtf8(isolate, message, NewStringType::kNormal)
@@ -1389,8 +1378,6 @@ void Shell::Quit(const v8::FunctionCallbackInfo<v8::Value>& args) {
13891378
const_cast<v8::FunctionCallbackInfo<v8::Value>*>(&args));
13901379
}
13911380

1392-
// Note that both WaitUntilDone and NotifyDone are no-op when
1393-
// --verify-predictable. See comment in Shell::EnsureEventLoopInitialized.
13941381
void Shell::WaitUntilDone(const v8::FunctionCallbackInfo<v8::Value>& args) {
13951382
SetWaitUntilDone(args.GetIsolate(), true);
13961383
}
@@ -2767,13 +2754,8 @@ void Shell::CollectGarbage(Isolate* isolate) {
27672754
}
27682755

27692756
void Shell::EnsureEventLoopInitialized(Isolate* isolate) {
2770-
// When using PredictablePlatform (i.e. FLAG_verify_predictable),
2771-
// we don't need event loop support, because tasks are completed
2772-
// immediately - both background and foreground ones.
2773-
if (!i::FLAG_verify_predictable) {
2774-
v8::platform::EnsureEventLoopInitialized(g_platform, isolate);
2775-
SetWaitUntilDone(isolate, false);
2776-
}
2757+
v8::platform::EnsureEventLoopInitialized(GetDefaultPlatform(), isolate);
2758+
SetWaitUntilDone(isolate, false);
27772759
}
27782760

27792761
void Shell::SetWaitUntilDone(Isolate* isolate, bool value) {
@@ -2792,29 +2774,32 @@ bool Shell::IsWaitUntilDone(Isolate* isolate) {
27922774
}
27932775

27942776
void Shell::CompleteMessageLoop(Isolate* isolate) {
2795-
// See comment in EnsureEventLoopInitialized.
2796-
if (i::FLAG_verify_predictable) return;
2777+
Platform* platform = GetDefaultPlatform();
27972778
while (v8::platform::PumpMessageLoop(
2798-
g_platform, isolate,
2779+
platform, isolate,
27992780
Shell::IsWaitUntilDone(isolate)
28002781
? platform::MessageLoopBehavior::kWaitForWork
28012782
: platform::MessageLoopBehavior::kDoNotWait)) {
28022783
isolate->RunMicrotasks();
28032784
}
2804-
v8::platform::RunIdleTasks(g_platform, isolate,
2805-
50.0 / base::Time::kMillisecondsPerSecond);
2785+
if (platform->IdleTasksEnabled(isolate)) {
2786+
v8::platform::RunIdleTasks(platform, isolate,
2787+
50.0 / base::Time::kMillisecondsPerSecond);
2788+
}
28062789
}
28072790

28082791
void Shell::EmptyMessageQueues(Isolate* isolate) {
2809-
if (i::FLAG_verify_predictable) return;
2792+
Platform* platform = GetDefaultPlatform();
28102793
// Pump the message loop until it is empty.
28112794
while (v8::platform::PumpMessageLoop(
2812-
g_platform, isolate, platform::MessageLoopBehavior::kDoNotWait)) {
2795+
platform, isolate, platform::MessageLoopBehavior::kDoNotWait)) {
28132796
isolate->RunMicrotasks();
28142797
}
28152798
// Run the idle tasks.
2816-
v8::platform::RunIdleTasks(g_platform, isolate,
2817-
50.0 / base::Time::kMillisecondsPerSecond);
2799+
if (platform->IdleTasksEnabled(isolate)) {
2800+
v8::platform::RunIdleTasks(platform, isolate,
2801+
50.0 / base::Time::kMillisecondsPerSecond);
2802+
}
28182803
}
28192804

28202805
class Serializer : public ValueSerializer::Delegate {
@@ -3067,29 +3052,29 @@ int Shell::Main(int argc, char* argv[]) {
30673052
if (!SetOptions(argc, argv)) return 1;
30683053
v8::V8::InitializeICUDefaultLocation(argv[0], options.icu_data_file);
30693054

3055+
v8::platform::InProcessStackDumping in_process_stack_dumping =
3056+
options.disable_in_process_stack_traces
3057+
? v8::platform::InProcessStackDumping::kDisabled
3058+
: v8::platform::InProcessStackDumping::kEnabled;
3059+
3060+
g_platform = v8::platform::CreateDefaultPlatform(
3061+
0, v8::platform::IdleTaskSupport::kEnabled, in_process_stack_dumping);
3062+
if (i::FLAG_verify_predictable) {
3063+
g_platform = new PredictablePlatform(std::unique_ptr<Platform>(g_platform));
3064+
}
3065+
30703066
platform::tracing::TracingController* tracing_controller = nullptr;
3071-
if (options.trace_enabled) {
3067+
if (options.trace_enabled && !i::FLAG_verify_predictable) {
30723068
trace_file.open("v8_trace.json");
30733069
tracing_controller = new platform::tracing::TracingController();
30743070
platform::tracing::TraceBuffer* trace_buffer =
30753071
platform::tracing::TraceBuffer::CreateTraceBufferRingBuffer(
30763072
platform::tracing::TraceBuffer::kRingBufferChunks,
30773073
platform::tracing::TraceWriter::CreateJSONTraceWriter(trace_file));
30783074
tracing_controller->Initialize(trace_buffer);
3075+
platform::SetTracingController(g_platform, tracing_controller);
30793076
}
30803077

3081-
v8::platform::InProcessStackDumping in_process_stack_dumping =
3082-
options.disable_in_process_stack_traces
3083-
? v8::platform::InProcessStackDumping::kDisabled
3084-
: v8::platform::InProcessStackDumping::kEnabled;
3085-
3086-
g_platform = i::FLAG_verify_predictable
3087-
? new PredictablePlatform()
3088-
: v8::platform::CreateDefaultPlatform(
3089-
0, v8::platform::IdleTaskSupport::kEnabled,
3090-
in_process_stack_dumping,
3091-
tracing_controller);
3092-
30933078
v8::V8::InitializePlatform(g_platform);
30943079
v8::V8::Initialize();
30953080
if (options.natives_blob || options.snapshot_blob) {
@@ -3136,6 +3121,7 @@ int Shell::Main(int argc, char* argv[]) {
31363121
}
31373122

31383123
Isolate* isolate = Isolate::New(create_params);
3124+
31393125
D8Console console(isolate);
31403126
{
31413127
Isolate::Scope scope(isolate);
@@ -3205,9 +3191,6 @@ int Shell::Main(int argc, char* argv[]) {
32053191
V8::Dispose();
32063192
V8::ShutdownPlatform();
32073193
delete g_platform;
3208-
if (i::FLAG_verify_predictable) {
3209-
delete tracing_controller;
3210-
}
32113194

32123195
return result;
32133196
}

deps/v8/src/heap/page-parallel-job.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class PageParallelJob {
6969
void Run(int num_tasks, Callback per_task_data_callback) {
7070
if (num_items_ == 0) return;
7171
DCHECK_GE(num_tasks, 1);
72-
uint32_t task_ids[kMaxNumberOfTasks];
72+
CancelableTaskManager::Id task_ids[kMaxNumberOfTasks];
7373
const int max_num_tasks = Min(
7474
kMaxNumberOfTasks,
7575
static_cast<int>(

deps/v8/src/libplatform/default-platform.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,25 @@ v8::Platform* CreateDefaultPlatform(int thread_pool_size,
4747

4848
bool PumpMessageLoop(v8::Platform* platform, v8::Isolate* isolate,
4949
MessageLoopBehavior behavior) {
50-
return reinterpret_cast<DefaultPlatform*>(platform)->PumpMessageLoop(
51-
isolate, behavior);
50+
return static_cast<DefaultPlatform*>(platform)->PumpMessageLoop(isolate,
51+
behavior);
5252
}
5353

5454
void EnsureEventLoopInitialized(v8::Platform* platform, v8::Isolate* isolate) {
55-
return reinterpret_cast<DefaultPlatform*>(platform)
56-
->EnsureEventLoopInitialized(isolate);
55+
return static_cast<DefaultPlatform*>(platform)->EnsureEventLoopInitialized(
56+
isolate);
5757
}
5858

5959
void RunIdleTasks(v8::Platform* platform, v8::Isolate* isolate,
6060
double idle_time_in_seconds) {
61-
reinterpret_cast<DefaultPlatform*>(platform)->RunIdleTasks(
62-
isolate, idle_time_in_seconds);
61+
static_cast<DefaultPlatform*>(platform)->RunIdleTasks(isolate,
62+
idle_time_in_seconds);
6363
}
6464

6565
void SetTracingController(
6666
v8::Platform* platform,
6767
v8::platform::tracing::TracingController* tracing_controller) {
68-
return reinterpret_cast<DefaultPlatform*>(platform)->SetTracingController(
68+
return static_cast<DefaultPlatform*>(platform)->SetTracingController(
6969
tracing_controller);
7070
}
7171

deps/v8/src/wasm/wasm-module.cc

+6-17
Original file line numberDiff line numberDiff line change
@@ -2695,10 +2695,6 @@ void wasm::AsyncInstantiate(Isolate* isolate, Handle<JSPromise> promise,
26952695
// foreground task. All other tasks (e.g. decoding and validating, the majority
26962696
// of the work of compilation) can be background tasks.
26972697
// TODO(wasm): factor out common parts of this with the synchronous pipeline.
2698-
//
2699-
// Note: In predictable mode, DoSync and DoAsync execute the referenced function
2700-
// immediately before returning. Thus we handle the predictable mode specially,
2701-
// e.g. when we synchronizing tasks or when we delete the AyncCompileJob.
27022698
class AsyncCompileJob {
27032699
// TODO(ahaas): Fix https://bugs.chromium.org/p/v8/issues/detail?id=6263 to
27042700
// make sure that d8 does not shut down before the AsyncCompileJob is
@@ -2761,14 +2757,14 @@ class AsyncCompileJob {
27612757
RejectPromise(isolate_, context_, thrower, module_promise_);
27622758
// The AsyncCompileJob is finished, we resolved the promise, we do not need
27632759
// the data anymore. We can delete the AsyncCompileJob object.
2764-
if (!FLAG_verify_predictable) delete this;
2760+
delete this;
27652761
}
27662762

27672763
void AsyncCompileSucceeded(Handle<Object> result) {
27682764
ResolvePromise(isolate_, context_, module_promise_, result);
27692765
// The AsyncCompileJob is finished, we resolved the promise, we do not need
27702766
// the data anymore. We can delete the AsyncCompileJob object.
2771-
if (!FLAG_verify_predictable) delete this;
2767+
delete this;
27722768
}
27732769

27742770
enum TaskType { SYNC, ASYNC };
@@ -2975,9 +2971,7 @@ class AsyncCompileJob {
29752971
// TODO(ahaas): Limit the number of outstanding compilation units to be
29762972
// finished to reduce memory overhead.
29772973
}
2978-
// Special handling for predictable mode, see above.
2979-
if (!FLAG_verify_predictable)
2980-
job_->helper_->module_->pending_tasks.get()->Signal();
2974+
job_->helper_->module_->pending_tasks.get()->Signal();
29812975
}
29822976
};
29832977

@@ -3026,12 +3020,9 @@ class AsyncCompileJob {
30263020
// Bump next_unit_, such that background tasks stop processing the queue.
30273021
job_->helper_->next_unit_.SetValue(
30283022
job_->helper_->compilation_units_.size());
3029-
// Special handling for predictable mode, see above.
3030-
if (!FLAG_verify_predictable) {
3031-
for (size_t i = 0; i < job_->num_background_tasks_; ++i) {
3032-
// We wait for it to finish.
3033-
job_->helper_->module_->pending_tasks.get()->Wait();
3034-
}
3023+
for (size_t i = 0; i < job_->num_background_tasks_; ++i) {
3024+
// We wait for it to finish.
3025+
job_->helper_->module_->pending_tasks.get()->Wait();
30353026
}
30363027
if (thrower_.error()) {
30373028
job_->DoSync<FailCompile>(std::move(thrower_));
@@ -3194,8 +3185,6 @@ void wasm::AsyncCompile(Isolate* isolate, Handle<JSPromise> promise,
31943185
auto job = new AsyncCompileJob(isolate, std::move(copy), bytes.length(),
31953186
handle(isolate->context()), promise);
31963187
job->Start();
3197-
// Special handling for predictable mode, see above.
3198-
if (FLAG_verify_predictable) delete job;
31993188
}
32003189

32013190
Handle<Code> wasm::CompileLazy(Isolate* isolate) {

0 commit comments

Comments
 (0)