@@ -2125,10 +2125,16 @@ Tagged<Object> Isolate::UnwindAndFindHandler() {
21252125 // We reached the base of the wasm stack. Follow the chain of
21262126 // continuations to find the parent stack and reset the iterator.
21272127 DCHECK (!continuation.is_null ());
2128- continuation = Cast<WasmContinuationObject>(continuation->parent ());
21292128 wasm::StackMemory* stack =
21302129 reinterpret_cast <wasm::StackMemory*>(continuation->stack ());
2131- iter.Reset (thread_local_top (), stack);
2130+ RetireWasmStack (stack);
2131+ continuation = Cast<WasmContinuationObject>(continuation->parent ());
2132+ wasm::StackMemory* parent =
2133+ reinterpret_cast <wasm::StackMemory*>(continuation->stack ());
2134+ parent->jmpbuf ()->state = wasm::JumpBuffer::Active;
2135+ roots_table ().slot (RootIndex::kActiveContinuation ).store (continuation);
2136+ SyncStackLimit ();
2137+ iter.Reset (thread_local_top (), parent);
21322138 }
21332139 }
21342140#endif
@@ -3642,6 +3648,25 @@ void Isolate::UpdateCentralStackInfo() {
36423648 }
36433649}
36443650
3651+ void Isolate::RetireWasmStack (wasm::StackMemory* stack) {
3652+ stack->jmpbuf ()->state = wasm::JumpBuffer::Retired;
3653+ size_t index = stack->index ();
3654+ // We can only return from a stack that was still in the global list.
3655+ DCHECK_LT (index, wasm_stacks ().size ());
3656+ std::unique_ptr<wasm::StackMemory> stack_ptr =
3657+ std::move (wasm_stacks ()[index]);
3658+ DCHECK_EQ (stack_ptr.get (), stack);
3659+ if (index != wasm_stacks ().size () - 1 ) {
3660+ wasm_stacks ()[index] = std::move (wasm_stacks ().back ());
3661+ wasm_stacks ()[index]->set_index (index);
3662+ }
3663+ wasm_stacks ().pop_back ();
3664+ for (size_t i = 0 ; i < wasm_stacks ().size (); ++i) {
3665+ SLOW_DCHECK (wasm_stacks ()[i]->index () == i);
3666+ }
3667+ stack_pool ().Add (std::move (stack_ptr));
3668+ }
3669+
36453670wasm::WasmOrphanedGlobalHandle* Isolate::NewWasmOrphanedGlobalHandle () {
36463671 return wasm::WasmEngine::NewOrphanedGlobalHandle (&wasm_orphaned_handle_);
36473672}
0 commit comments