Merge MicrotaskQueue::RunMicrotasks and Isolate::RunMicrotasks

This retires Isolate::RunMicrotasks in favor of using
MicrotaskQueue::RunMicrotasks.

Bug: v8:8124
Change-Id: I717dabce7c4127d7e4524bdb639f46c3d55df49b
Reviewed-on: https://chromium-review.googlesource.com/c/1385969
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58866}
This commit is contained in:
tzik 2019-01-16 18:22:12 +09:00 committed by Commit Bot
parent 943b5d029d
commit ba363c755b
7 changed files with 47 additions and 40 deletions

View File

@ -8521,7 +8521,8 @@ void Isolate::SetPromiseRejectCallback(PromiseRejectCallback callback) {
void Isolate::RunMicrotasks() {
DCHECK_NE(MicrotasksPolicy::kScoped, GetMicrotasksPolicy());
reinterpret_cast<i::Isolate*>(this)->RunMicrotasks();
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->default_microtask_queue()->RunMicrotasks(isolate);
}
void Isolate::EnqueueMicrotask(Local<Function> function) {
@ -8900,7 +8901,7 @@ void MicrotasksScope::PerformCheckpoint(Isolate* v8Isolate) {
auto* microtask_queue = isolate->default_microtask_queue();
if (!microtask_queue->GetMicrotasksScopeDepth() &&
!microtask_queue->HasMicrotasksSuppressions()) {
isolate->RunMicrotasks();
microtask_queue->RunMicrotasks(isolate);
}
}

View File

@ -4028,7 +4028,7 @@ void Isolate::FireCallCompletedCallback() {
v8::MicrotasksPolicy::kAuto;
if (run_microtasks) {
RunMicrotasks();
default_microtask_queue()->RunMicrotasks(this);
} else {
// TODO(marja): (spec) The discussion about when to clear the KeepDuringJob
// set is still open (whether to clear it after every microtask or once
@ -4276,33 +4276,6 @@ void Isolate::ReportPromiseReject(Handle<JSPromise> promise,
v8::Utils::StackTraceToLocal(stack_trace)));
}
void Isolate::RunMicrotasks() {
// Increase call depth to prevent recursive callbacks.
v8::Isolate::SuppressMicrotaskExecutionScope suppress(
reinterpret_cast<v8::Isolate*>(this));
MicrotaskQueue* microtask_queue = default_microtask_queue();
if (microtask_queue->size()) {
TRACE_EVENT0("v8.execute", "RunMicrotasks");
TRACE_EVENT_CALL_STATS_SCOPED(this, "v8", "V8.RunMicrotasks");
HandleScopeImplementer::EnteredContextRewindScope scope(
handle_scope_implementer());
// If execution is terminating, bail out, clean up, and propagate to
// TryCatch scope.
if (microtask_queue->RunMicrotasks(this) < 0) {
SetTerminationOnExternalTryCatch();
}
DCHECK_EQ(0, microtask_queue->size());
}
// TODO(marja): (spec) The discussion about when to clear the KeepDuringJob
// set is still open (whether to clear it after every microtask or once
// during a microtask checkpoint). See also
// https://github.com/tc39/proposal-weakrefs/issues/39 .
heap()->ClearKeepDuringJobSet();
microtask_queue->FireMicrotasksCompletedCallback(this);
}
void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) {
DCHECK(!use_counter_callback_);
use_counter_callback_ = callback;

View File

@ -1407,7 +1407,7 @@ class Isolate final : private HiddenFactory {
void ReportPromiseReject(Handle<JSPromise> promise, Handle<Object> value,
v8::PromiseRejectEvent event);
void RunMicrotasks();
void SetTerminationOnExternalTryCatch();
Handle<Symbol> SymbolFor(RootIndex dictionary_index, Handle<String> name,
bool private_symbol);
@ -1669,8 +1669,6 @@ class Isolate final : private HiddenFactory {
// then return true.
bool PropagatePendingExceptionToExternalTryCatch();
void SetTerminationOnExternalTryCatch();
void RunPromiseHookForAsyncEventDelegate(PromiseHookType type,
Handle<JSPromise> promise);

View File

@ -7,11 +7,13 @@
#include <stddef.h>
#include <algorithm>
#include "src/api.h"
#include "src/base/logging.h"
#include "src/handles-inl.h"
#include "src/isolate.h"
#include "src/objects/microtask-inl.h"
#include "src/roots-inl.h"
#include "src/tracing/trace-event.h"
#include "src/visitors.h"
namespace v8 {
@ -107,22 +109,40 @@ class SetIsRunningMicrotasks {
} // namespace
int MicrotaskQueue::RunMicrotasks(Isolate* isolate) {
if (!size()) {
OnCompleted(isolate);
return 0;
}
HandleScope handle_scope(isolate);
MaybeHandle<Object> maybe_exception;
SetIsRunningMicrotasks scope(&is_running_microtasks_);
MaybeHandle<Object> maybe_result =
Execution::TryRunMicrotasks(isolate, this, &maybe_exception);
MaybeHandle<Object> maybe_result;
// If execution is terminating, clean up and propagate that to the caller.
{
SetIsRunningMicrotasks scope(&is_running_microtasks_);
v8::Isolate::SuppressMicrotaskExecutionScope suppress(
reinterpret_cast<v8::Isolate*>(isolate));
HandleScopeImplementer::EnteredContextRewindScope rewind_scope(
isolate->handle_scope_implementer());
TRACE_EVENT0("v8.execute", "RunMicrotasks");
TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.RunMicrotasks");
maybe_result = Execution::TryRunMicrotasks(isolate, this, &maybe_exception);
}
// If execution is terminating, clean up and propagate that to TryCatch scope.
if (maybe_result.is_null() && maybe_exception.is_null()) {
delete[] ring_buffer_;
ring_buffer_ = nullptr;
capacity_ = 0;
size_ = 0;
start_ = 0;
isolate->SetTerminationOnExternalTryCatch();
OnCompleted(isolate);
return -1;
}
DCHECK_EQ(0, size());
OnCompleted(isolate);
// TODO(tzik): Return the number of microtasks run in this round.
return 0;
@ -179,6 +199,16 @@ void MicrotaskQueue::FireMicrotasksCompletedCallback(Isolate* isolate) const {
}
}
void MicrotaskQueue::OnCompleted(Isolate* isolate) {
// TODO(marja): (spec) The discussion about when to clear the KeepDuringJob
// set is still open (whether to clear it after every microtask or once
// during a microtask checkpoint). See also
// https://github.com/tc39/proposal-weakrefs/issues/39 .
isolate->heap()->ClearKeepDuringJobSet();
FireMicrotasksCompletedCallback(isolate);
}
void MicrotaskQueue::ResizeBuffer(intptr_t new_capacity) {
DCHECK_LE(size_, new_capacity);
Address* new_ring_buffer = new Address[new_capacity];

View File

@ -90,6 +90,8 @@ class V8_EXPORT_PRIVATE MicrotaskQueue {
static const intptr_t kMinimumCapacity;
private:
void OnCompleted(Isolate* isolate);
MicrotaskQueue();
void ResizeBuffer(intptr_t new_capacity);

View File

@ -5,6 +5,7 @@
#include "src/handles-inl.h"
#include "src/heap/factory-inl.h"
#include "src/isolate.h"
#include "src/microtask-queue.h"
#include "src/objects/js-objects.h"
#include "src/objects/js-weak-refs-inl.h"
#include "test/cctest/cctest.h"
@ -427,7 +428,7 @@ TEST(TestJSWeakRefKeepDuringJob) {
CHECK(!weak_ref->target()->IsUndefined(isolate));
// Clears the KeepDuringJob set.
isolate->RunMicrotasks();
isolate->default_microtask_queue()->RunMicrotasks(isolate);
CcTest::CollectAllGarbage();
CHECK(weak_ref->target()->IsUndefined(isolate));
@ -465,7 +466,7 @@ TEST(TestJSWeakRefKeepDuringJobIncrementalMarking) {
CHECK(!weak_ref->target()->IsUndefined(isolate));
// Clears the KeepDuringJob set.
isolate->RunMicrotasks();
isolate->default_microtask_queue()->RunMicrotasks(isolate);
heap::SimulateIncrementalMarking(heap, true);
CcTest::CollectAllGarbage();

View File

@ -4,6 +4,7 @@
#include <memory>
#include "src/microtask-queue.h"
#include "src/objects-inl.h"
#include "src/wasm/function-compiler.h"
#include "src/wasm/wasm-engine.h"
@ -180,7 +181,8 @@ void PumpMessageLoop(SharedEngineIsolate& isolate) {
v8::platform::PumpMessageLoop(i::V8::GetCurrentPlatform(),
isolate.v8_isolate(),
platform::MessageLoopBehavior::kWaitForWork);
isolate.isolate()->RunMicrotasks();
isolate.isolate()->default_microtask_queue()->RunMicrotasks(
isolate.isolate());
}
Handle<WasmInstanceObject> CompileAndInstantiateAsync(