@@ -2232,10 +2232,16 @@ Tagged<Object> Isolate::UnwindAndFindHandler() {
22322232 // We reached the base of the wasm stack. Follow the chain of
22332233 // continuations to find the parent stack and reset the iterator.
22342234 DCHECK (!continuation.is_null ());
2235- continuation = Cast<WasmContinuationObject>(continuation->parent ());
22362235 wasm::StackMemory* stack =
22372236 reinterpret_cast <wasm::StackMemory*>(continuation->stack ());
2238- iter.Reset (thread_local_top (), stack);
2237+ RetireWasmStack (stack);
2238+ continuation = Cast<WasmContinuationObject>(continuation->parent ());
2239+ wasm::StackMemory* parent =
2240+ reinterpret_cast <wasm::StackMemory*>(continuation->stack ());
2241+ parent->jmpbuf ()->state = wasm::JumpBuffer::Active;
2242+ roots_table ().slot (RootIndex::kActiveContinuation ).store (continuation);
2243+ SyncStackLimit ();
2244+ iter.Reset (thread_local_top (), parent);
22392245 }
22402246 }
22412247#endif
@@ -3753,6 +3759,25 @@ void Isolate::UpdateCentralStackInfo() {
37533759 }
37543760}
37553761
3762+ void Isolate::RetireWasmStack (wasm::StackMemory* stack) {
3763+ stack->jmpbuf ()->state = wasm::JumpBuffer::Retired;
3764+ size_t index = stack->index ();
3765+ // We can only return from a stack that was still in the global list.
3766+ DCHECK_LT (index, wasm_stacks ().size ());
3767+ std::unique_ptr<wasm::StackMemory> stack_ptr =
3768+ std::move (wasm_stacks ()[index]);
3769+ DCHECK_EQ (stack_ptr.get (), stack);
3770+ if (index != wasm_stacks ().size () - 1 ) {
3771+ wasm_stacks ()[index] = std::move (wasm_stacks ().back ());
3772+ wasm_stacks ()[index]->set_index (index);
3773+ }
3774+ wasm_stacks ().pop_back ();
3775+ for (size_t i = 0 ; i < wasm_stacks ().size (); ++i) {
3776+ SLOW_DCHECK (wasm_stacks ()[i]->index () == i);
3777+ }
3778+ stack_pool ().Add (std::move (stack_ptr));
3779+ }
3780+
37563781wasm::WasmOrphanedGlobalHandle* Isolate::NewWasmOrphanedGlobalHandle () {
37573782 return wasm::WasmEngine::NewOrphanedGlobalHandle (&wasm_orphaned_handle_);
37583783}
0 commit comments