@@ -2125,10 +2125,16 @@ Tagged<Object> Isolate::UnwindAndFindHandler() {
2125
2125
// We reached the base of the wasm stack. Follow the chain of
2126
2126
// continuations to find the parent stack and reset the iterator.
2127
2127
DCHECK (!continuation.is_null ());
2128
- continuation = Cast<WasmContinuationObject>(continuation->parent ());
2129
2128
wasm::StackMemory* stack =
2130
2129
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);
2132
2138
}
2133
2139
}
2134
2140
#endif
@@ -3642,6 +3648,25 @@ void Isolate::UpdateCentralStackInfo() {
3642
3648
}
3643
3649
}
3644
3650
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
+
3645
3670
wasm::WasmOrphanedGlobalHandle* Isolate::NewWasmOrphanedGlobalHandle () {
3646
3671
return wasm::WasmEngine::NewOrphanedGlobalHandle (&wasm_orphaned_handle_);
3647
3672
}
0 commit comments