Skip to content

Commit 32a6c8d

Browse files
gahaasV8 LUCI CQ
authored andcommitted
[fastcall] Return value after deopt after fast call is undefined
Even if the return type of an API function is `void`, there is still a return value in JavaScript, undefined. This CL hard-codes the return value in the assembly code of the `DeoptimizationEntry_LazyAfterFastCall` builtin. Ideally the return value is handled in a continuation builtin, as suggested in crbug.com/418936518, but that turned out to be more difficult than expected. [email protected] Bug: 422099361 Change-Id: I2d98deeff6a27b51cff9b312246816982ddd7dd1 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6623291 Reviewed-by: Leszek Swirski <[email protected]> Commit-Queue: Andreas Haas <[email protected]> Cr-Commit-Position: refs/heads/main@{#100706}
1 parent 88ee60c commit 32a6c8d

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed

src/builtins/arm/builtins-arm.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4840,6 +4840,12 @@ void Builtins::Generate_DeoptimizationEntry_LazyAfterFastCall(
48404840
__ PopAll(kCalleeSaveFPRegisters);
48414841
__ LeaveFrame(StackFrame::BUILTIN);
48424842
__ bind(&no_exception);
4843+
// Deoptimization expects that the return value of the API call is in the
4844+
// return register. As we only allow deoptimization if the return type is
4845+
// void, the return value is always `undefined`.
4846+
// TODO(crbug.com/418936518): Handle the return value in an actual
4847+
// deoptimization continuation.
4848+
__ LoadRoot(kReturnRegister0, RootIndex::kUndefinedValue);
48434849
__ TailCallBuiltin(Builtin::kDeoptimizationEntry_Lazy);
48444850
}
48454851

src/builtins/arm64/builtins-arm64.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5436,6 +5436,12 @@ void Builtins::Generate_DeoptimizationEntry_LazyAfterFastCall(
54365436
__ PopAll(kCalleeSaveFPRegisters);
54375437
__ LeaveFrame(StackFrame::INTERNAL);
54385438
__ bind(&no_exception);
5439+
// Deoptimization expects that the return value of the API call is in the
5440+
// return register. As we only allow deoptimization if the return type is
5441+
// void, the return value is always `undefined`.
5442+
// TODO(crbug.com/418936518): Handle the return value in an actual
5443+
// deoptimization continuation.
5444+
__ LoadRoot(kReturnRegister0, RootIndex::kUndefinedValue);
54395445
__ TailCallBuiltin(Builtin::kDeoptimizationEntry_Lazy);
54405446
}
54415447

src/builtins/ia32/builtins-ia32.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5330,6 +5330,12 @@ void Builtins::Generate_DeoptimizationEntry_LazyAfterFastCall(
53305330
__ LeaveFrame(StackFrame::INTERNAL);
53315331

53325332
__ bind(&no_exception);
5333+
// Deoptimization expects that the return value of the API call is in the
5334+
// return register. As we only allow deoptimization if the return type is
5335+
// void, the return value is always `undefined`.
5336+
// TODO(crbug.com/418936518): Handle the return value in an actual
5337+
// deoptimization continuation.
5338+
__ LoadRoot(kReturnRegister0, RootIndex::kUndefinedValue);
53335339
__ TailCallBuiltin(Builtin::kDeoptimizationEntry_Lazy);
53345340
}
53355341

src/builtins/x64/builtins-x64.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5125,6 +5125,14 @@ void Builtins::Generate_DeoptimizationEntry_LazyAfterFastCall(
51255125
__ LeaveFrame(StackFrame::INTERNAL);
51265126

51275127
__ bind(&no_exception);
5128+
// LINT.IfChange(DeoptAfterFastCallSetReturnValue)
5129+
// Deoptimization expects that the return value of the API call is in the
5130+
// return register. As we only allow deoptimization if the return type is
5131+
// void, the return value is always `undefined`.
5132+
// TODO(crbug.com/418936518): Handle the return value in an actual
5133+
// deoptimization continuation.
5134+
__ LoadRoot(kReturnRegister0, RootIndex::kUndefinedValue);
5135+
// LINT.ThenChange()
51285136
__ TailCallBuiltin(Builtin::kDeoptimizationEntry_Lazy);
51295137
}
51305138

src/compiler/js-call-reducer.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ class FastApiCallReducerAssembler : public JSCallReducerAssembler {
719719
static_cast<unsigned>(
720720
function_template_info_.c_functions(broker()).size()));
721721

722+
// LINT.IfChange
722723
// TODO(crbug.com/418936518): Support deopt for functions with return value.
723724
Node* error_message = jsgraph()->SmiConstant(
724725
static_cast<int>(AbortReason::kUnsupportedDeopt));
@@ -730,6 +731,11 @@ class FastApiCallReducerAssembler : public JSCallReducerAssembler {
730731
: CreateStubBuiltinContinuationFrameState(
731732
jsgraph(), Builtin::kAbort, ContextInput(), &error_message, 1,
732733
FrameStateInput(), ContinuationFrameStateMode::LAZY);
734+
// The `DeoptimizationEntry_LazyAfterFastCall` builtin currently sets the
735+
// return value unconditionally to `undefined`. If a continuation builtin is
736+
// set up here, then the entry builtin should not overwrite the return
737+
// value.
738+
// LINT.ThenChange(/src/builtins/x64/builtins-x64.cc:DeoptAfterFastCallSetReturnValue)
733739

734740
// Callback data value for fast Api calls. Unlike slow Api calls, the fast
735741
// variant passes callback data directly.

0 commit comments

Comments
 (0)