Commit 9c546d8f authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

[wasm-simd] Add use counter for SIMD opcodes

This CL adds use counters, as well as the callbacks needed to
register usage during the SIMD origin trial.

Change-Id: I35b7f48277b519b72136f86cf03508adbaa069b8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2189334
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67690}
parent d6c4901a
......@@ -7483,6 +7483,9 @@ typedef bool (*WasmThreadsEnabledCallback)(Local<Context> context);
typedef Local<String> (*WasmLoadSourceMapCallback)(Isolate* isolate,
const char* name);
// --- Callback for checking if WebAssembly Simd is enabled ---
typedef bool (*WasmSimdEnabledCallback)(Local<Context> context);
// --- Garbage Collection Callbacks ---
/**
......@@ -8445,6 +8448,7 @@ class V8_EXPORT Isolate {
kInvalidatedStringIteratorLookupChainProtector = 103,
kInvalidatedStringLengthOverflowLookupChainProtector = 104,
kInvalidatedTypedArraySpeciesLookupChainProtector = 105,
kWasmSimdOpcodes = 106,
// If you add new values here, you'll also need to update Chromium's:
// web_feature.mojom, use_counter_callback.cc, and enums.xml. V8 changes to
......@@ -9347,6 +9351,8 @@ class V8_EXPORT Isolate {
void SetWasmLoadSourceMapCallback(WasmLoadSourceMapCallback callback);
void SetWasmSimdEnabledCallback(WasmSimdEnabledCallback callback);
/**
* Check if V8 is dead and therefore unusable. This is the case after
* fatal errors such as out-of-memory situations.
......
......@@ -8908,6 +8908,9 @@ CALLBACK_SETTER(WasmThreadsEnabledCallback, WasmThreadsEnabledCallback,
CALLBACK_SETTER(WasmLoadSourceMapCallback, WasmLoadSourceMapCallback,
wasm_load_source_map_callback)
CALLBACK_SETTER(WasmSimdEnabledCallback, WasmSimdEnabledCallback,
wasm_simd_enabled_callback)
void Isolate::AddNearHeapLimitCallback(v8::NearHeapLimitCallback callback,
void* data) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
......
......@@ -2504,6 +2504,14 @@ bool Isolate::AreWasmThreadsEnabled(Handle<Context> context) {
return FLAG_experimental_wasm_threads;
}
bool Isolate::IsWasmSimdEnabled(Handle<Context> context) {
if (wasm_simd_enabled_callback()) {
v8::Local<v8::Context> api_context = v8::Utils::ToLocal(context);
return wasm_simd_enabled_callback()(api_context);
}
return FLAG_experimental_wasm_simd;
}
Handle<Context> Isolate::GetIncumbentContext() {
JavaScriptFrameIterator it(this);
......
......@@ -408,6 +408,7 @@ using DebugObjectCache = std::vector<Handle<HeapObject>>;
V(WasmStreamingCallback, wasm_streaming_callback, nullptr) \
V(WasmThreadsEnabledCallback, wasm_threads_enabled_callback, nullptr) \
V(WasmLoadSourceMapCallback, wasm_load_source_map_callback, nullptr) \
V(WasmSimdEnabledCallback, wasm_simd_enabled_callback, nullptr) \
/* State for Relocatable. */ \
V(Relocatable*, relocatable_top, nullptr) \
V(DebugObjectCache*, string_stream_debug_object_cache, nullptr) \
......@@ -621,6 +622,7 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
inline void clear_pending_exception();
bool AreWasmThreadsEnabled(Handle<Context> context);
bool IsWasmSimdEnabled(Handle<Context> context);
THREAD_LOCAL_TOP_ADDRESS(Object, pending_exception)
......
......@@ -637,6 +637,9 @@ void UpdateFeatureUseCounts(Isolate* isolate, const WasmFeatures& detected) {
if (detected.has_threads()) {
isolate->CountUsage(v8::Isolate::UseCounterFeature::kWasmThreadOpcodes);
}
if (detected.has_simd()) {
isolate->CountUsage(v8::Isolate::UseCounterFeature::kWasmSimdOpcodes);
}
}
} // namespace
......
......@@ -27,6 +27,9 @@ WasmFeatures WasmFeatures::FromIsolate(Isolate* isolate) {
if (isolate->AreWasmThreadsEnabled(handle(isolate->context(), isolate))) {
features.Add(kFeature_threads);
}
if (isolate->IsWasmSimdEnabled(handle(isolate->context(), isolate))) {
features.Add(kFeature_simd);
}
return features;
}
......
......@@ -130,11 +130,16 @@ TEST(WasmStreamingAbortWithoutReject) {
namespace {
bool wasm_threads_enabled_value = false;
bool wasm_simd_enabled_value = false;
bool MockWasmThreadsEnabledCallback(v8::Local<v8::Context>) {
return wasm_threads_enabled_value;
}
bool MockWasmSimdEnabledCallback(v8::Local<v8::Context>) {
return wasm_simd_enabled_value;
}
} // namespace
TEST(TestSetWasmThreadsEnabledCallback) {
......@@ -165,3 +170,32 @@ TEST(TestSetWasmThreadsEnabledCallback) {
i::FLAG_experimental_wasm_threads = false;
CHECK(i_isolate->AreWasmThreadsEnabled(i_context));
}
TEST(TestSetWasmSimdEnabledCallback) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
v8::HandleScope scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
i::Handle<i::Context> i_context = v8::Utils::OpenHandle(*context);
// {Isolate::IsWasmSimdEnabled} calls the callback set by the embedder if
// such a callback exists. Otherwise it returns
// {FLAG_experimental_wasm_simd}. 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_simd = false;
CHECK(!i_isolate->IsWasmSimdEnabled(i_context));
i::FLAG_experimental_wasm_simd = true;
CHECK(i_isolate->IsWasmSimdEnabled(i_context));
isolate->SetWasmSimdEnabledCallback(MockWasmSimdEnabledCallback);
wasm_simd_enabled_value = false;
CHECK(!i_isolate->IsWasmSimdEnabled(i_context));
wasm_simd_enabled_value = true;
i::FLAG_experimental_wasm_simd = false;
CHECK(i_isolate->IsWasmSimdEnabled(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