Commit c3927608 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[api] Add API function Isolate::HasPendingBackgroundTasks

This CL adds an API function that tells the embedder if there is ongoing
background work that will eventually post foreground tasks.

Design doc: https://docs.google.com/document/d/18vaABH1mR35PQr8XPHZySuQYgSjJbWFyAW63LW2m8-w

R=adamk@chromium.org

Bug: v8:10787
Change-Id: I9060c5cdc9dbafeb7ea7c5c26d09c2dc744800bd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2342847Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69312}
parent 2fe94069
......@@ -9028,6 +9028,13 @@ class V8_EXPORT Isolate {
*/
void RequestInterrupt(InterruptCallback callback, void* data);
/**
* Returns true if there is ongoing background work within V8 that will
* eventually post a foreground task, like asynchronous WebAssembly
* compilation.
*/
bool HasPendingBackgroundTasks();
/**
* Request garbage collection in this Isolate. It is only valid to call this
* function if --expose_gc was specified.
......
......@@ -8235,6 +8235,11 @@ void Isolate::RequestInterrupt(InterruptCallback callback, void* data) {
isolate->RequestInterrupt(callback, data);
}
bool Isolate::HasPendingBackgroundTasks() {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
return isolate->wasm_engine()->HasRunningCompileJob(isolate);
}
void Isolate::RequestGarbageCollectionForTesting(GarbageCollectionType type) {
CHECK(i::FLAG_expose_gc);
if (type == kMinorGarbageCollection) {
......
......@@ -3286,10 +3286,10 @@ bool Shell::SetOptions(int argc, char* argv[]) {
} else if (strcmp(argv[i], "--omit-quit") == 0) {
options.omit_quit = true;
argv[i] = nullptr;
} else if (strcmp(argv[i], "--no-wait-for-wasm") == 0) {
} else if (strcmp(argv[i], "--no-wait-for-background-tasks") == 0) {
// TODO(herhut) Remove this flag once wasm compilation is fully
// isolate-independent.
options.wait_for_wasm = false;
options.wait_for_background_tasks = false;
argv[i] = nullptr;
} else if (strcmp(argv[i], "-f") == 0) {
// Ignore any -f flags for compatibility with other stand-alone
......@@ -3601,10 +3601,8 @@ bool Shell::CompleteMessageLoop(Isolate* isolate) {
auto get_waiting_behaviour = [isolate]() {
base::MutexGuard guard(isolate_status_lock_.Pointer());
DCHECK_GT(isolate_status_.count(isolate), 0);
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::wasm::WasmEngine* wasm_engine = i_isolate->wasm_engine();
bool should_wait = (options.wait_for_wasm &&
wasm_engine->HasRunningCompileJob(i_isolate)) ||
bool should_wait = (options.wait_for_background_tasks &&
isolate->HasPendingBackgroundTasks()) ||
isolate_status_[isolate] ||
isolate_running_streaming_tasks_[isolate] > 0;
return should_wait ? platform::MessageLoopBehavior::kWaitForWork
......
......@@ -297,7 +297,7 @@ class ShellOptions {
bool send_idle_notification = false;
bool invoke_weak_callbacks = false;
bool omit_quit = false;
bool wait_for_wasm = true;
bool wait_for_background_tasks = true;
bool stress_opt = false;
int stress_runs = 1;
bool stress_snapshot = false;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-wasm --no-wait-for-wasm
// Flags: --expose-wasm --no-wait-for-background-tasks
load("test/mjsunit/wasm/wasm-module-builder.js");
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --no-wait-for-wasm --wasm-tier-up
// Flags: --no-wait-for-background-tasks --wasm-tier-up
load("test/mjsunit/wasm/wasm-module-builder.js");
......
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