Commit b0118171 authored by Simon Zünd's avatar Simon Zünd Committed by V8 LUCI CQ

[builtins] Add 'RestartFrameTrampoline'

Doc: https://bit.ly/revive-restart-frame
Context: https://crrev.com/c/3582395 (jumbo CL with the whole feature)

This CL adds a new builtin called "RestartFrameTrampoline". This
trampoline is relatively simple: It leaves the current frame and
re-invokes the function. This essentially restarts the function and
is one of the key components required to bring back the "Restart
frame" DevTools debugging feature.

The builtin is closely related to the "FrameDropperTrampoline"
removed in the CL https://crrev.com/c/2854750. The key difference
is that the "FrameDropperTrampoline" dropped to an "arbitrary"
frame pointer before restarting the function (arbitrary in the
sense that it was provided as an argument). This caused issues
as the feature was implemented in a way that the frame pointer
wasn't necessarily valid anymore.

In comparison, the "RestartFrameTrampoline" relies on the V8
unwinder to drop it in the correct frame first and is then
invoked via either the CEntry stub or the deoptimizer
(see design doc for details).

Bug: chromium:1303521
Change-Id: I7bd46620808f8694c2c776b8bcd267e525d5b581
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3585944
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80254}
parent 231dfdef
......@@ -3745,6 +3745,22 @@ void Builtins::Generate_InterpreterOnStackReplacement_ToBaseline(
Generate_BaselineOrInterpreterEntry(masm, false, true);
}
void Builtins::Generate_RestartFrameTrampoline(MacroAssembler* masm) {
// Frame is being dropped:
// - Look up current function on the frame.
// - Leave the frame.
// - Restart the frame by calling the function.
__ ldr(r1, MemOperand(fp, StandardFrameConstants::kFunctionOffset));
__ ldr(r0, MemOperand(fp, StandardFrameConstants::kArgCOffset));
__ LeaveFrame(StackFrame::INTERNAL);
// The arguments are already in the stack (including any necessary padding),
// we should not try to massage the arguments again.
__ mov(r2, Operand(kDontAdaptArgumentsSentinel));
__ InvokeFunction(r1, r2, r0, InvokeType::kJump);
}
#undef __
} // namespace internal
......
......@@ -4247,6 +4247,23 @@ void Builtins::Generate_InterpreterOnStackReplacement_ToBaseline(
Generate_BaselineOrInterpreterEntry(masm, false, true);
}
void Builtins::Generate_RestartFrameTrampoline(MacroAssembler* masm) {
// Frame is being dropped:
// - Look up current function on the frame.
// - Leave the frame.
// - Restart the frame by calling the function.
__ Ldr(x1, MemOperand(fp, StandardFrameConstants::kFunctionOffset));
__ ldr(x0, MemOperand(fp, StandardFrameConstants::kArgCOffset));
__ LeaveFrame(StackFrame::INTERPRETED);
// The arguments are already in the stack (including any necessary padding),
// we should not try to massage the arguments again.
__ Mov(x2, kDontAdaptArgumentsSentinel);
__ InvokeFunction(x1, x2, x0, InvokeType::kJump);
}
#undef __
} // namespace internal
......
......@@ -249,6 +249,7 @@ namespace internal {
\
/* Debugger */ \
TFJ(DebugBreakTrampoline, kDontAdaptArgumentsSentinel) \
ASM(RestartFrameTrampoline, RestartFrameTrampoline) \
\
/* Type conversions */ \
TFC(ToNumber, TypeConversion) \
......
......@@ -4369,6 +4369,24 @@ void Builtins::Generate_InterpreterOnStackReplacement_ToBaseline(
Generate_BaselineOrInterpreterEntry(masm, false, true);
}
void Builtins::Generate_RestartFrameTrampoline(MacroAssembler* masm) {
// Frame is being dropped:
// - Look up current function on the frame.
// - Leave the frame.
// - Restart the frame by calling the function.
__ mov(edi, Operand(ebp, StandardFrameConstants::kFunctionOffset));
__ mov(eax, Operand(ebp, StandardFrameConstants::kArgCOffset));
__ LeaveFrame(StackFrame::INTERPRETED);
// The arguments are already in the stack (including any necessary padding),
// we should not try to massage the arguments again.
__ mov(ecx, Immediate(kDontAdaptArgumentsSentinel));
__ mov(esi, FieldOperand(edi, JSFunction::kContextOffset));
__ InvokeFunctionCode(edi, no_reg, ecx, eax, InvokeType::kJump);
}
#undef __
} // namespace internal
......
......@@ -3756,6 +3756,22 @@ void Builtins::Generate_InterpreterOnStackReplacement_ToBaseline(
Generate_BaselineOrInterpreterEntry(masm, false, true);
}
void Builtins::Generate_RestartFrameTrampoline(MacroAssembler* masm) {
// Restart the current frame:
// - Look up current function on the frame.
// - Leave the frame.
// - Restart the frame by calling the function.
__ Ld_d(a1, MemOperand(fp, StandardFrameConstants::kFunctionOffset));
__ Ld_d(a0, MemOperand(fp, StandardFrameConstants::kArgCOffset));
__ LeaveFrame(StackFrame::INTERPRETED);
// The arguments are already in the stack (including any necessary padding),
// we should not try to massage the arguments again.
__ li(a2, Operand(kDontAdaptArgumentsSentinel));
__ InvokeFunction(a1, a2, a0, InvokeType::kJump);
}
#undef __
} // namespace internal
......
......@@ -4204,6 +4204,23 @@ void Builtins::Generate_InterpreterOnStackReplacement_ToBaseline(
Generate_BaselineOrInterpreterEntry(masm, false, true);
}
void Builtins::Generate_RestartFrameTrampoline(MacroAssembler* masm) {
// Frame is being dropped:
// - Look up current function on the frame.
// - Leave the frame.
// - Restart the frame by calling the function.
__ lw(a1, MemOperand(fp, StandardFrameConstants::kFunctionOffset));
__ lw(a0, MemOperand(fp, StandardFrameConstants::kArgCOffset));
// Pop return address and frame.
__ LeaveFrame(StackFrame::INTERPRETED);
__ li(a2, Operand(kDontAdaptArgumentsSentinel));
__ InvokeFunction(a1, a2, a0, InvokeType::kJump);
}
#undef __
} // namespace internal
......
......@@ -3781,6 +3781,23 @@ void Builtins::Generate_InterpreterOnStackReplacement_ToBaseline(
Generate_BaselineOrInterpreterEntry(masm, false, true);
}
void Builtins::Generate_RestartFrameTrampoline(MacroAssembler* masm) {
// Frame is being dropped:
// - Look up current function on the frame.
// - Leave the frame.
// - Restart the frame by calling the function.
__ Ld(a1, MemOperand(fp, StandardFrameConstants::kFunctionOffset));
__ Ld(a0, MemOperand(fp, StandardFrameConstants::kArgCOffset));
// Pop return address and frame.
__ LeaveFrame(StackFrame::INTERPRETED);
__ li(a2, Operand(kDontAdaptArgumentsSentinel));
__ InvokeFunction(a1, a2, a0, InvokeType::kJump);
}
#undef __
} // namespace internal
......
......@@ -3881,6 +3881,22 @@ void Builtins::Generate_InterpreterOnStackReplacement_ToBaseline(
Generate_BaselineOrInterpreterEntry(masm, false, true);
}
void Builtins::Generate_RestartFrameTrampoline(MacroAssembler* masm) {
// Frame is being dropped:
// - Look up current function on the frame.
// - Leave the frame.
// - Restart the frame by calling the function.
__ LoadP(r4, MemOperand(fp, StandardFrameConstants::kFunctionOffset));
__ LoadP(r3, MemOperand(fp, StandardFrameConstants::kArgCOffset));
__ LeaveFrame(StackFrame::INTERPRETED);
// The arguments are already in the stack (including any necessary padding),
// we should not try to massage the arguments again.
__ mov(r5, Operand(kDontAdaptArgumentsSentinel));
__ InvokeFunction(r4, r5, r3, InvokeType::kJump);
}
#undef __
} // namespace internal
} // namespace v8
......
......@@ -3866,6 +3866,23 @@ void Builtins::Generate_InterpreterOnStackReplacement_ToBaseline(
Generate_BaselineOrInterpreterEntry(masm, false, true);
}
void Builtins::Generate_RestartFrameTrampoline(MacroAssembler* masm) {
// Frame is being dropped:
// - Look up current function on the frame.
// - Leave the frame.
// - Restart the frame by calling the function.
__ Ld(a1, MemOperand(fp, StandardFrameConstants::kFunctionOffset));
__ Ld(a0, MemOperand(fp, StandardFrameConstants::kArgCOffset));
// Pop return address and frame.
__ LeaveFrame(StackFrame::INTERPRETED);
__ li(a2, Operand(kDontAdaptArgumentsSentinel));
__ InvokeFunction(a1, a2, a0, InvokeType::kJump);
}
#undef __
} // namespace internal
......
......@@ -3885,6 +3885,22 @@ void Builtins::Generate_InterpreterOnStackReplacement_ToBaseline(
Generate_BaselineOrInterpreterEntry(masm, false, true);
}
void Builtins::Generate_RestartFrameTrampoline(MacroAssembler* masm) {
// Frame is being dropped:
// - Look up current function on the frame.
// - Leave the frame.
// - Restart the frame by calling the function.
__ LoadU64(r3, MemOperand(fp, StandardFrameConstants::kFunctionOffset));
__ LoadU64(r2, MemOperand(fp, StandardFrameConstants::kArgCOffset));
__ LeaveFrame(StackFrame::INTERPRETED);
// The arguments are already in the stack (including any necessary padding),
// we should not try to massage the arguments again.
__ mov(r4, Operand(kDontAdaptArgumentsSentinel));
__ InvokeFunction(r3, r4, r2, InvokeType::kJump);
}
#undef __
} // namespace internal
......
......@@ -5186,6 +5186,23 @@ void Builtins::Generate_InterpreterOnStackReplacement_ToBaseline(
Generate_BaselineOrInterpreterEntry(masm, false, true);
}
void Builtins::Generate_RestartFrameTrampoline(MacroAssembler* masm) {
// Restart the current frame:
// - Look up current function on the frame.
// - Leave the frame.
// - Restart the frame by calling the function.
__ movq(rdi, Operand(rbp, StandardFrameConstants::kFunctionOffset));
__ movq(rax, Operand(rbp, StandardFrameConstants::kArgCOffset));
__ LeaveFrame(StackFrame::INTERPRETED);
// The arguments are already in the stack (including any necessary padding),
// we should not try to massage the arguments again.
__ movq(rbx, Immediate(kDontAdaptArgumentsSentinel));
__ InvokeFunction(rdi, no_reg, rbx, rax, InvokeType::kJump);
}
#undef __
} // namespace internal
......
......@@ -104,6 +104,7 @@ namespace internal {
V(LookupBaseline) \
V(NewHeapNumber) \
V(NoContext) \
V(RestartFrameTrampoline) \
V(ResumeGenerator) \
V(ResumeGeneratorBaseline) \
V(RunMicrotasks) \
......@@ -1868,6 +1869,13 @@ class SuspendGeneratorBaselineDescriptor final
DECLARE_DESCRIPTOR(SuspendGeneratorBaselineDescriptor)
};
class RestartFrameTrampolineDescriptor final
: public StaticCallInterfaceDescriptor<RestartFrameTrampolineDescriptor> {
public:
DEFINE_PARAMETERS()
DECLARE_DESCRIPTOR(RestartFrameTrampolineDescriptor)
};
class RunMicrotasksEntryDescriptor final
: public StaticCallInterfaceDescriptor<RunMicrotasksEntryDescriptor> {
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment