tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 2cf89694835ff74c2efacb1950b271d31d27f297
parent bacf29978d812f7178c3dfa9e5021d1c95c7c5eb
Author: Ryan Hunt <rhunt@eqrion.net>
Date:   Thu, 18 Dec 2025 16:45:25 +0000

Bug 2002625 - wasm: Remove onSuspendableStack flag. r=yury

We can just use `activeSuspender` for this and reduce the
amount of state we need to update.

Differential Revision: https://phabricator.services.mozilla.com/D274185

Diffstat:
Mjs/src/wasm/WasmContext.cpp | 9+--------
Mjs/src/wasm/WasmContext.h | 17++++++++---------
Mjs/src/wasm/WasmFrameIter.cpp | 9++++-----
Mjs/src/wasm/WasmPI.cpp | 2+-
4 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/js/src/wasm/WasmContext.cpp b/js/src/wasm/WasmContext.cpp @@ -33,7 +33,6 @@ Context::Context() #ifdef ENABLE_WASM_JSPI , activeSuspender_(nullptr), - onSuspendableStack(0), suspendableStacksCount(0), suspendedStacks_() #endif @@ -54,8 +53,6 @@ void Context::initStackLimit(JSContext* cx) { } #ifdef ENABLE_WASM_JSPI -SuspenderObject* Context::activeSuspender() { return activeSuspender_; } - void Context::trace(JSTracer* trc) { if (activeSuspender_) { TraceEdge(trc, &activeSuspender_, "suspender"); @@ -78,23 +75,19 @@ void Context::traceRoots(JSTracer* trc) { void Context::enterSuspendableStack(SuspenderObject* suspender, JS::NativeStackLimit newStackLimit) { - MOZ_ASSERT(onSuspendableStack == 0); MOZ_ASSERT(!activeSuspender_); activeSuspender_ = suspender; - onSuspendableStack = 1; stackLimit = newStackLimit; } void Context::leaveSuspendableStack(JSContext* cx) { - MOZ_ASSERT(onSuspendableStack != 0); MOZ_ASSERT(activeSuspender_); activeSuspender_ = nullptr; - onSuspendableStack = 0; initStackLimit(cx); } bool js::IsSuspendableStackActive(JSContext* cx) { - return cx->wasm().onSuspendableStack != 0; + return cx->wasm().onSuspendableStack(); } JS::NativeStackLimit js::GetSuspendableStackLimit(JSContext* cx) { diff --git a/js/src/wasm/WasmContext.h b/js/src/wasm/WasmContext.h @@ -45,16 +45,16 @@ class Context { static constexpr size_t offsetOfStackLimit() { return offsetof(Context, stackLimit); } -#ifdef ENABLE_WASM_JSPI - static constexpr size_t offsetOfOnSuspendableStack() { - return offsetof(Context, onSuspendableStack); - } -#endif void initStackLimit(JSContext* cx); #ifdef ENABLE_WASM_JSPI - SuspenderObject* activeSuspender(); + static constexpr size_t offsetOfActiveSuspender() { + return offsetof(Context, activeSuspender_); + } + + SuspenderObject* activeSuspender() { return activeSuspender_; } + bool onSuspendableStack() const { return activeSuspender_ != nullptr; } void enterSuspendableStack(SuspenderObject* suspender, JS::NativeStackLimit newStackLimit); @@ -75,10 +75,9 @@ class Context { JS::NativeStackLimit stackLimit; #ifdef ENABLE_WASM_JSPI + // The currently active suspender object. Null if we're executing on the + // system stack, otherwise we're on a wasm suspendable stack. HeapPtr<SuspenderObject*> activeSuspender_; - // Boolean value set to true when the top wasm frame is currently executed on - // a suspendable stack. Aligned to int32_t to be used on JIT code. - int32_t onSuspendableStack; mozilla::Atomic<uint32_t> suspendableStacksCount; // Using double-linked list to avoid allocation in the JIT code. mozilla::DoublyLinkedList<SuspenderObjectData> suspendedStacks_; diff --git a/js/src/wasm/WasmFrameIter.cpp b/js/src/wasm/WasmFrameIter.cpp @@ -1008,11 +1008,10 @@ void wasm::GenerateJitExitPrologue(MacroAssembler& masm, const Register scratch = ABINonArgReg0; masm.loadPtr(Address(InstanceReg, Instance::offsetOfCx()), scratch); - masm.load32( - Address(scratch, JSContext::offsetOfWasm() + - wasm::Context::offsetOfOnSuspendableStack()), - scratch); - masm.branchTest32(Assembler::NonZero, scratch, scratch, &fallback); + masm.loadPtr(Address(scratch, JSContext::offsetOfWasm() + + wasm::Context::offsetOfActiveSuspender()), + scratch); + masm.branchTestPtr(Assembler::NonZero, scratch, scratch, &fallback); } uint32_t entryOffset; diff --git a/js/src/wasm/WasmPI.cpp b/js/src/wasm/WasmPI.cpp @@ -443,7 +443,7 @@ void SuspenderObject::leave(JSContext* cx) { break; } case SuspenderState::Suspended: { - MOZ_ASSERT(cx->wasm().onSuspendableStack == 0); + MOZ_ASSERT(!cx->wasm().onSuspendableStack()); break; } case SuspenderState::Initial: