From 8d39059edb1a3086f57499e4328cd7a9fa1059d7 Mon Sep 17 00:00:00 2001 From: Ryan Hunt Date: Wed, 14 May 2025 16:44:57 +0000 Subject: [PATCH] Bug 1965518 - wasm: Rename wasm_verbose to wasm_trace_api and support MOZ_LOG. r=bvisness Add a MOZ_LOG=wasmApi logging module that re-uses our existing wasm::Log infrastructure. This lets us see wasm JS-API usage in the profiler through markers, and also in the normal browser log stream. Rename wasm_verbose to wasmTraceApi to match the log module. Use the JS::Pref system instead of context options. Differential Revision: https://phabricator.services.mozilla.com/D248641 --- js/public/ContextOptions.h | 8 ------ js/src/shell/js.cpp | 3 --- js/src/shell/jsshell.h | 1 - js/src/vm/Logging.h | 1 + js/src/wasm/WasmLog.cpp | 33 ++++++++++++++++++------ js/xpconnect/src/XPCJSContext.cpp | 1 - modules/libpref/init/StaticPrefList.yaml | 6 +++++ 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/js/public/ContextOptions.h b/js/public/ContextOptions.h index 86d14e17cc8d..c619e6760b7f 100644 --- a/js/public/ContextOptions.h +++ b/js/public/ContextOptions.h @@ -24,7 +24,6 @@ class JS_PUBLIC_API ContextOptions { ContextOptions() : wasm_(true), wasmForTrustedPrinciples_(true), - wasmVerbose_(false), wasmBaseline_(true), wasmIon_(true), testWasmAwaitTier2_(false), @@ -67,12 +66,6 @@ class JS_PUBLIC_API ContextOptions { return *this; } - bool wasmVerbose() const { return wasmVerbose_; } - ContextOptions& setWasmVerbose(bool flag) { - wasmVerbose_ = flag; - return *this; - } - bool wasmBaseline() const { return wasmBaseline_; } ContextOptions& setWasmBaseline(bool flag) { wasmBaseline_ = flag; @@ -179,7 +172,6 @@ class JS_PUBLIC_API ContextOptions { // WASM options. bool wasm_ : 1; bool wasmForTrustedPrinciples_ : 1; - bool wasmVerbose_ : 1; bool wasmBaseline_ : 1; bool wasmIon_ : 1; bool testWasmAwaitTier2_ : 1; diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index c9d06989f15c..044cff7a369e 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -839,7 +839,6 @@ bool shell::enableWasm = false; bool shell::enableSharedMemory = SHARED_MEMORY_DEFAULT; bool shell::enableWasmBaseline = false; bool shell::enableWasmOptimizing = false; -bool shell::enableWasmVerbose = false; bool shell::enableTestWasmAwaitTier2 = false; bool shell::enableSourcePragmas = true; bool shell::enableAsyncStacks = false; @@ -11832,7 +11831,6 @@ static void SetWorkerContextOptions(JSContext* cx) { .setWasmBaseline(enableWasmBaseline) .setWasmIon(enableWasmOptimizing) - .setWasmVerbose(enableWasmVerbose) .setTestWasmAwaitTier2(enableTestWasmAwaitTier2) .setSourcePragmas(enableSourcePragmas); @@ -13358,7 +13356,6 @@ bool SetContextWasmOptions(JSContext* cx, const OptionParser& op) { } } - enableWasmVerbose = op.getBoolOption("wasm-verbose"); enableTestWasmAwaitTier2 = op.getBoolOption("test-wasm-await-tier2"); JS::ContextOptionsRef(cx) diff --git a/js/src/shell/jsshell.h b/js/src/shell/jsshell.h index cc48850356fb..7d48f1299593 100644 --- a/js/src/shell/jsshell.h +++ b/js/src/shell/jsshell.h @@ -113,7 +113,6 @@ extern bool enableWasm; extern bool enableSharedMemory; extern bool enableWasmBaseline; extern bool enableWasmOptimizing; -extern bool enableWasmVerbose; extern bool enableTestWasmAwaitTier2; extern bool enableSourcePragmas; extern bool enableAsyncStacks; diff --git a/js/src/vm/Logging.h b/js/src/vm/Logging.h index 7f09579d4e85..a325144e78ac 100644 --- a/js/src/vm/Logging.h +++ b/js/src/vm/Logging.h @@ -87,6 +87,7 @@ class LogModule { #define FOR_EACH_JS_LOG_MODULE(_) \ _(debug) /* A predefined log module for casual debugging */ \ _(wasmPerf) /* Wasm performance statistics */ \ + _(wasmApi) /* Wasm JS-API tracing */ \ _(fuseInvalidation) /* Invalidation triggered by a fuse */ \ _(thenable) /* Thenable on standard proto*/ \ _(startup) /* engine startup logging */ \ diff --git a/js/src/wasm/WasmLog.cpp b/js/src/wasm/WasmLog.cpp index 791e97fb2676..084dafa1acd9 100644 --- a/js/src/wasm/WasmLog.cpp +++ b/js/src/wasm/WasmLog.cpp @@ -24,6 +24,7 @@ #include "js/Printf.h" #include "js/Utility.h" #include "vm/JSContext.h" +#include "vm/Logging.h" #include "vm/Warnings.h" using namespace js; @@ -32,7 +33,10 @@ using namespace js::wasm; void wasm::Log(JSContext* cx, const char* fmt, ...) { MOZ_ASSERT(!cx->isExceptionPending() || cx->isThrowingOutOfMemory()); - if (!cx->options().wasmVerbose() || cx->isThrowingOutOfMemory()) { + bool shouldWarn = JS::Prefs::wasm_trace_api(); + bool shouldLog = wasmApiModule.shouldLog(LogLevel::Info); + + if (cx->isThrowingOutOfMemory() || (!shouldWarn && !shouldLog)) { return; } @@ -40,9 +44,15 @@ void wasm::Log(JSContext* cx, const char* fmt, ...) { va_start(args, fmt); if (UniqueChars chars = JS_vsmprintf(fmt, args)) { - WarnNumberASCII(cx, JSMSG_WASM_VERBOSE, chars.get()); - if (cx->isExceptionPending()) { - cx->clearPendingException(); + if (shouldWarn) { + WarnNumberASCII(cx, JSMSG_WASM_VERBOSE, chars.get()); + if (cx->isExceptionPending()) { + cx->clearPendingException(); + } + } + if (shouldLog) { + wasmApiModule.interface.logPrint(wasmApiModule.logger, LogLevel::Info, + "%s", chars.get()); } } @@ -50,10 +60,17 @@ void wasm::Log(JSContext* cx, const char* fmt, ...) { } void wasm::LogOffThread(const char* fmt, ...) { - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); + if (!wasmApiModule.shouldLog(LogLevel::Info)) { + return; + } + + va_list args; + va_start(args, fmt); + if (UniqueChars chars = JS_vsmprintf(fmt, args)) { + wasmApiModule.interface.logPrint(wasmApiModule.logger, LogLevel::Info, + "%s", chars.get()); + } + va_end(args); } #ifdef WASM_CODEGEN_DEBUG diff --git a/js/xpconnect/src/XPCJSContext.cpp b/js/xpconnect/src/XPCJSContext.cpp index a2553646d2d3..dba59cb8bd6d 100644 --- a/js/xpconnect/src/XPCJSContext.cpp +++ b/js/xpconnect/src/XPCJSContext.cpp @@ -810,7 +810,6 @@ void xpc::SetPrefableContextOptions(JS::ContextOptions& options) { .setWasmIon(Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_optimizingjit")) .setWasmBaseline( Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_baselinejit")) - .setWasmVerbose(Preferences::GetBool(JS_OPTIONS_DOT_STR "wasm_verbose")) .setAsyncStack(Preferences::GetBool(JS_OPTIONS_DOT_STR "asyncstack")) .setAsyncStackCaptureDebuggeeOnly(Preferences::GetBool( JS_OPTIONS_DOT_STR "asyncstack_capture_debuggee_only")); diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index c4ec578c2228..616fee2e553a 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -8805,6 +8805,12 @@ #endif mirror: always +- name: javascript.options.wasm_trace_api + type: bool + value: false + mirror: always + set_spidermonkey_pref: always + - name: javascript.options.wasm_disable_huge_memory type: bool value: false