Commit 5012e883 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[api] Add API callback setter for the wasm thread origin trial

With the callback we can check if the origin trial is turned on for a
given context.

I will not land the other CL which added a flag to the isolate. The
information if the origin trial is on is context-specific and not
isolate-specific, and it's hard on the embedder side to track all
creations of a context.

With the API proposed in this CL we will ask the embedder every time we
start compilation whether the origin trial is on or off.

R=yangguo@chromium.org

Bug:868844

Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I8822f40ab12582a5b0bd6640790a269107fc085a
Reviewed-on: https://chromium-review.googlesource.com/1163621
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55011}
parent 5b74a7ee
......@@ -6767,6 +6767,9 @@ typedef void (*ApiImplementationCallback)(const FunctionCallbackInfo<Value>&);
// --- Callback for WebAssembly.compileStreaming ---
typedef void (*WasmStreamingCallback)(const FunctionCallbackInfo<Value>&);
// --- Callback for checking if WebAssembly threads are enabled ---
typedef bool (*WasmThreadsEnabledCallback)(Local<Context> context);
// --- Garbage Collection Callbacks ---
/**
......@@ -8298,6 +8301,8 @@ class V8_EXPORT Isolate {
void SetWasmStreamingCallback(WasmStreamingCallback callback);
void SetWasmThreadsEnabledCallback(WasmThreadsEnabledCallback callback);
/**
* Check if V8 is dead and therefore unusable. This is the case after
* fatal errors such as out-of-memory situations.
......
......@@ -9119,6 +9119,9 @@ CALLBACK_SETTER(WasmCompileStreamingCallback, ApiImplementationCallback,
CALLBACK_SETTER(WasmStreamingCallback, WasmStreamingCallback,
wasm_streaming_callback)
CALLBACK_SETTER(WasmThreadsEnabledCallback, WasmThreadsEnabledCallback,
wasm_threads_enabled_callback)
void Isolate::AddNearHeapLimitCallback(v8::NearHeapLimitCallback callback,
void* data) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
......
......@@ -2216,6 +2216,14 @@ void Isolate::SetAbortOnUncaughtExceptionCallback(
abort_on_uncaught_exception_callback_ = callback;
}
bool Isolate::AreWasmThreadsEnabled(Handle<Context> context) {
if (wasm_threads_enabled_callback()) {
v8::Local<v8::Context> api_context = v8::Utils::ToLocal(context);
return wasm_threads_enabled_callback()(api_context);
}
return FLAG_experimental_wasm_threads;
}
Handle<Context> Isolate::GetCallingNativeContext() {
JavaScriptFrameIterator it(this);
if (it.done()) return Handle<Context>::null();
......
......@@ -490,7 +490,6 @@ class ThreadLocalTop BASE_EMBEDDED {
v8::TryCatch* try_catch_handler_ = nullptr;
};
#ifdef DEBUG
#define ISOLATE_INIT_DEBUG_ARRAY_LIST(V) \
......@@ -524,6 +523,7 @@ typedef std::vector<HeapObject*> DebugObjectCache;
V(ExtensionCallback, wasm_instance_callback, &NoExtension) \
V(ApiImplementationCallback, wasm_compile_streaming_callback, nullptr) \
V(WasmStreamingCallback, wasm_streaming_callback, nullptr) \
V(WasmThreadsEnabledCallback, wasm_threads_enabled_callback, nullptr) \
/* State for Relocatable. */ \
V(Relocatable*, relocatable_top, nullptr) \
V(DebugObjectCache*, string_stream_debug_object_cache, nullptr) \
......@@ -721,6 +721,8 @@ class Isolate : private HiddenFactory {
inline void set_wasm_caught_exception(Object* exception);
inline void clear_wasm_caught_exception();
bool AreWasmThreadsEnabled(Handle<Context> context);
THREAD_LOCAL_TOP_ADDRESS(Object*, pending_exception)
inline bool has_pending_exception();
......
......@@ -28620,3 +28620,42 @@ TEST(BigIntAPI) {
CHECK_EQ(word_count, 2);
}
}
namespace {
bool wasm_threads_enabled_value = false;
bool MockWasmThreadsEnabledCallback(Local<Context>) {
return wasm_threads_enabled_value;
}
} // namespace
TEST(TestSetWasmThreadsEnabledCallback) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
v8::HandleScope scope(isolate);
v8::Local<Context> context = Context::New(CcTest::isolate());
i::Handle<i::Context> i_context = v8::Utils::OpenHandle(*context);
// {Isolate::AreWasmThreadsEnabled} calls the callback set by the embedder if
// such a callback exists. Otherwise it returns
// {FLAG_experimental_wasm_threads}. First we test that the flag is returned
// correctly if no callback is set. Then we test that the flag is ignored if
// the callback is set.
i::FLAG_experimental_wasm_threads = false;
CHECK(!i_isolate->AreWasmThreadsEnabled(i_context));
i::FLAG_experimental_wasm_threads = true;
CHECK(i_isolate->AreWasmThreadsEnabled(i_context));
isolate->SetWasmThreadsEnabledCallback(MockWasmThreadsEnabledCallback);
wasm_threads_enabled_value = false;
CHECK(!i_isolate->AreWasmThreadsEnabled(i_context));
wasm_threads_enabled_value = true;
i::FLAG_experimental_wasm_threads = false;
CHECK(i_isolate->AreWasmThreadsEnabled(i_context));
}
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