Skip to content

Commit 906e41b

Browse files
thibaudmichaudV8 LUCI CQ
authored andcommitted
[wasm][jspi] Fix JSPI + lazy deopt
With JSPI, the stack frame iterator stops at the end of the current stack segment. Follow the chain of stacks to find all frames marked for deoptimization. [email protected] Fixed: 365376497 Change-Id: Iff1112dbd2a86a014c8de6d844f585fd568ad552 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5850428 Commit-Queue: Thibaud Michaud <[email protected]> Reviewed-by: Matthias Liedtke <[email protected]> Cr-Commit-Position: refs/heads/main@{#96028}
1 parent d23c608 commit 906e41b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/deoptimizer/deoptimizer.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,21 @@ class ActivationsFinder : public ThreadVisitor {
341341
// for the trampoline to the deoptimizer call respective to each code, and use
342342
// it to replace the current pc on the stack.
343343
void VisitThread(Isolate* isolate, ThreadLocalTop* top) override {
344+
#if V8_ENABLE_WEBASSEMBLY
345+
// Also visit the ancestors of the active stack for wasm stack switching.
346+
// We don't need to visit suspended stacks at the moment, because 1) they
347+
// only contain wasm frames and 2) wasm does not do lazy deopt. Revisit this
348+
// if one of these assumptions changes.
349+
Tagged<WasmContinuationObject> continuation;
350+
if (top == isolate->thread_local_top()) {
351+
Tagged<Object> maybe_continuation =
352+
isolate->root(RootIndex::kActiveContinuation);
353+
if (!IsUndefined(maybe_continuation)) {
354+
continuation = Cast<WasmContinuationObject>(maybe_continuation);
355+
}
356+
}
357+
#endif
358+
344359
for (StackFrameIterator it(isolate, top); !it.done(); it.Advance()) {
345360
if (it.frame()->is_optimized()) {
346361
Tagged<GcSafeCode> code = it.frame()->GcSafeLookupCode();
@@ -379,6 +394,19 @@ class ActivationsFinder : public ThreadVisitor {
379394
}
380395
}
381396
}
397+
398+
#if V8_ENABLE_WEBASSEMBLY
399+
// We reached the base of the wasm stack. Follow the chain of
400+
// continuations to find the parent stack and reset the iterator.
401+
if (it.frame()->type() == StackFrame::STACK_SWITCH) {
402+
CHECK_EQ(top, isolate->thread_local_top());
403+
DCHECK(!continuation.is_null());
404+
continuation = Cast<WasmContinuationObject>(continuation->parent());
405+
wasm::StackMemory* parent =
406+
reinterpret_cast<wasm::StackMemory*>(continuation->stack());
407+
it.Reset(top, parent);
408+
}
409+
#endif
382410
}
383411
}
384412

0 commit comments

Comments
 (0)