Skip to content

Commit 5453cd9

Browse files
targosjuanarbol
authored andcommitted
deps: V8: cherry-pick bf0bd4868dde
Original commit message: [fastcall] Disable fast calls with stack args on M1 Bug: v8:13171 Change-Id: I549d942d8ae24e2de0aa3202d7400b587254fb75 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3963995 Commit-Queue: Camillo Bruni <cbruni@chromium.org> Auto-Submit: Maya Lekova <mslekova@chromium.org> Reviewed-by: Camillo Bruni <cbruni@chromium.org> Commit-Queue: Maya Lekova <mslekova@chromium.org> Cr-Commit-Position: refs/heads/main@{#83886} Refs: v8/v8@bf0bd48 PR-URL: #45908 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 8adaa13 commit 5453cd9

File tree

5 files changed

+127
-7
lines changed

5 files changed

+127
-7
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.23',
39+
'v8_embedder_string': '-node.24',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/src/compiler/fast-api-calls.cc

+7
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ OverloadsResolutionResult ResolveOverloads(
8383
bool CanOptimizeFastSignature(const CFunctionInfo* c_signature) {
8484
USE(c_signature);
8585

86+
#if defined(V8_OS_MACOS) && defined(V8_TARGET_ARCH_ARM64)
87+
// On MacArm64 hardware we don't support passing of arguments on the stack.
88+
if (c_signature->ArgumentCount() > 8) {
89+
return false;
90+
}
91+
#endif // defined(V8_OS_MACOS) && defined(V8_TARGET_ARCH_ARM64)
92+
8693
#ifndef V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
8794
if (c_signature->ReturnInfo().GetType() == CTypeInfo::Type::kFloat32 ||
8895
c_signature->ReturnInfo().GetType() == CTypeInfo::Type::kFloat64) {

deps/v8/src/d8/d8-test.cc

+61-6
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,19 @@ class FastCApiObject {
456456
}
457457

458458
#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
459+
static AnyCType AddAll32BitIntFastCallback_8ArgsPatch(
460+
AnyCType receiver, AnyCType should_fallback, AnyCType arg1_i32,
461+
AnyCType arg2_i32, AnyCType arg3_i32, AnyCType arg4_u32,
462+
AnyCType arg5_u32, AnyCType arg6_u32, AnyCType arg7_u32,
463+
AnyCType arg8_u32, AnyCType options) {
464+
AnyCType ret;
465+
ret.int32_value = AddAll32BitIntFastCallback_8Args(
466+
receiver.object_value, should_fallback.bool_value, arg1_i32.int32_value,
467+
arg2_i32.int32_value, arg3_i32.int32_value, arg4_u32.uint32_value,
468+
arg5_u32.uint32_value, arg6_u32.uint32_value, arg7_u32.uint32_value,
469+
arg8_u32.uint32_value, *options.options_value);
470+
return ret;
471+
}
459472
static AnyCType AddAll32BitIntFastCallback_6ArgsPatch(
460473
AnyCType receiver, AnyCType should_fallback, AnyCType arg1_i32,
461474
AnyCType arg2_i32, AnyCType arg3_i32, AnyCType arg4_u32,
@@ -479,6 +492,26 @@ class FastCApiObject {
479492
}
480493
#endif // V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
481494

495+
static int AddAll32BitIntFastCallback_8Args(
496+
Local<Object> receiver, bool should_fallback, int32_t arg1_i32,
497+
int32_t arg2_i32, int32_t arg3_i32, uint32_t arg4_u32, uint32_t arg5_u32,
498+
uint32_t arg6_u32, uint32_t arg7_u32, uint32_t arg8_u32,
499+
FastApiCallbackOptions& options) {
500+
FastCApiObject* self = UnwrapObject(receiver);
501+
CHECK_SELF_OR_FALLBACK(0);
502+
self->fast_call_count_++;
503+
504+
if (should_fallback) {
505+
options.fallback = true;
506+
return 0;
507+
}
508+
509+
int64_t result = static_cast<int64_t>(arg1_i32) + arg2_i32 + arg3_i32 +
510+
arg4_u32 + arg5_u32 + arg6_u32 + arg7_u32 + arg8_u32;
511+
if (result > INT_MAX) return INT_MAX;
512+
if (result < INT_MIN) return INT_MIN;
513+
return static_cast<int>(result);
514+
}
482515
static int AddAll32BitIntFastCallback_6Args(
483516
Local<Object> receiver, bool should_fallback, int32_t arg1_i32,
484517
int32_t arg2_i32, int32_t arg3_i32, uint32_t arg4_u32, uint32_t arg5_u32,
@@ -516,24 +549,29 @@ class FastCApiObject {
516549

517550
HandleScope handle_scope(isolate);
518551

552+
Local<Context> context = isolate->GetCurrentContext();
519553
double sum = 0;
520554
if (args.Length() > 1 && args[1]->IsNumber()) {
521-
sum += args[1]->Int32Value(isolate->GetCurrentContext()).FromJust();
555+
sum += args[1]->Int32Value(context).FromJust();
522556
}
523557
if (args.Length() > 2 && args[2]->IsNumber()) {
524-
sum += args[2]->Int32Value(isolate->GetCurrentContext()).FromJust();
558+
sum += args[2]->Int32Value(context).FromJust();
525559
}
526560
if (args.Length() > 3 && args[3]->IsNumber()) {
527-
sum += args[3]->Int32Value(isolate->GetCurrentContext()).FromJust();
561+
sum += args[3]->Int32Value(context).FromJust();
528562
}
529563
if (args.Length() > 4 && args[4]->IsNumber()) {
530-
sum += args[4]->Uint32Value(isolate->GetCurrentContext()).FromJust();
564+
sum += args[4]->Uint32Value(context).FromJust();
531565
}
532566
if (args.Length() > 5 && args[5]->IsNumber()) {
533-
sum += args[5]->Uint32Value(isolate->GetCurrentContext()).FromJust();
567+
sum += args[5]->Uint32Value(context).FromJust();
534568
}
535569
if (args.Length() > 6 && args[6]->IsNumber()) {
536-
sum += args[6]->Uint32Value(isolate->GetCurrentContext()).FromJust();
570+
sum += args[6]->Uint32Value(context).FromJust();
571+
}
572+
if (args.Length() > 7 && args[7]->IsNumber() && args[8]->IsNumber()) {
573+
sum += args[7]->Uint32Value(context).FromJust();
574+
sum += args[8]->Uint32Value(context).FromJust();
537575
}
538576

539577
args.GetReturnValue().Set(Number::New(isolate, sum));
@@ -804,6 +842,9 @@ Local<FunctionTemplate> Shell::CreateTestFastCApiTemplate(Isolate* isolate) {
804842
signature, 1, ConstructorBehavior::kThrow,
805843
SideEffectType::kHasSideEffect, {add_all_invalid_overloads, 2}));
806844

845+
CFunction add_all_32bit_int_8args_c_func = CFunction::Make(
846+
FastCApiObject::AddAll32BitIntFastCallback_8Args V8_IF_USE_SIMULATOR(
847+
FastCApiObject::AddAll32BitIntFastCallback_8ArgsPatch));
807848
CFunction add_all_32bit_int_6args_c_func = CFunction::Make(
808849
FastCApiObject::AddAll32BitIntFastCallback_6Args V8_IF_USE_SIMULATOR(
809850
FastCApiObject::AddAll32BitIntFastCallback_6ArgsPatch));
@@ -820,6 +861,20 @@ Local<FunctionTemplate> Shell::CreateTestFastCApiTemplate(Isolate* isolate) {
820861
signature, 1, ConstructorBehavior::kThrow,
821862
SideEffectType::kHasSideEffect, {c_function_overloads, 2}));
822863

864+
api_obj_ctor->PrototypeTemplate()->Set(
865+
isolate, "overloaded_add_all_8args",
866+
FunctionTemplate::New(
867+
isolate, FastCApiObject::AddAll32BitIntSlowCallback, Local<Value>(),
868+
signature, 1, ConstructorBehavior::kThrow,
869+
SideEffectType::kHasSideEffect, &add_all_32bit_int_8args_c_func));
870+
871+
api_obj_ctor->PrototypeTemplate()->Set(
872+
isolate, "overloaded_add_all_32bit_int_no_sig",
873+
FunctionTemplate::NewWithCFunctionOverloads(
874+
isolate, FastCApiObject::AddAll32BitIntSlowCallback, Local<Value>(),
875+
Local<Signature>(), 1, ConstructorBehavior::kThrow,
876+
SideEffectType::kHasSideEffect, {c_function_overloads, 2}));
877+
823878
CFunction add_all_no_options_c_func = CFunction::Make(
824879
FastCApiObject::AddAllFastCallbackNoOptions V8_IF_USE_SIMULATOR(
825880
FastCApiObject::AddAllFastCallbackNoOptionsPatch));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2021 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// This file tests fast callbacks with more than 8 arguments. It should
6+
// fail on arm64 + OSX configuration, because of stack alignment issue,
7+
// see crbug.com/v8/13171.
8+
9+
// Flags: --turbo-fast-api-calls --expose-fast-api --allow-natives-syntax --turbofan
10+
// --always-turbofan is disabled because we rely on particular feedback for
11+
// optimizing to the fastest path.
12+
// Flags: --no-always-turbofan
13+
// The test relies on optimizing/deoptimizing at predictable moments, so
14+
// it's not suitable for deoptimization fuzzing.
15+
// Flags: --deopt-every-n-times=0
16+
17+
const add_all_32bit_int_arg1 = -42;
18+
const add_all_32bit_int_arg2 = 45;
19+
const add_all_32bit_int_arg3 = -12345678;
20+
const add_all_32bit_int_arg4 = 0x1fffffff;
21+
const add_all_32bit_int_arg5 = 1e6;
22+
const add_all_32bit_int_arg6 = 1e8;
23+
const add_all_32bit_int_arg7 = 31;
24+
const add_all_32bit_int_arg8 = 63;
25+
const add_all_32bit_int_result_8args = add_all_32bit_int_arg1 +
26+
add_all_32bit_int_arg2 + add_all_32bit_int_arg3 + add_all_32bit_int_arg4 +
27+
add_all_32bit_int_arg5 + add_all_32bit_int_arg6 + add_all_32bit_int_arg7 + add_all_32bit_int_arg8;
28+
29+
const fast_c_api = new d8.test.FastCAPI();
30+
31+
(function () {
32+
function overloaded_add_all(should_fallback = false) {
33+
return fast_c_api.overloaded_add_all_8args(should_fallback,
34+
add_all_32bit_int_arg1, add_all_32bit_int_arg2, add_all_32bit_int_arg3,
35+
add_all_32bit_int_arg4, add_all_32bit_int_arg5, add_all_32bit_int_arg6,
36+
add_all_32bit_int_arg7, add_all_32bit_int_arg8);
37+
}
38+
39+
%PrepareFunctionForOptimization(overloaded_add_all);
40+
let result = overloaded_add_all();
41+
assertEquals(add_all_32bit_int_result_8args, result);
42+
43+
fast_c_api.reset_counts();
44+
%OptimizeFunctionOnNextCall(overloaded_add_all);
45+
result = overloaded_add_all();
46+
assertOptimized(overloaded_add_all);
47+
48+
assertEquals(1, fast_c_api.fast_call_count());
49+
assertEquals(0, fast_c_api.slow_call_count());
50+
})();

deps/v8/test/mjsunit/mjsunit.status

+8
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,14 @@
966966
'wasm/compare-exchange64-stress': [SKIP],
967967
}], # 'system == macos'
968968

969+
##############################################################################
970+
['system == macos and arch == arm64', {
971+
# BUG(v8:13171): The following tests a function that shouldn't be optimized
972+
# on M1 hardware, unless a proper fix for the stack corruption is
973+
# implemented (see linked issue).
974+
'compiler/fast-api-calls-8args': [FAIL],
975+
}], # 'system == macos and arch == arm64'
976+
969977
##############################################################################
970978
['system == windows', {
971979
# Too slow with turbo fan.

0 commit comments

Comments
 (0)