Skip to content

Commit e294410

Browse files
committed
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 ca65e41 commit e294410

File tree

5 files changed

+120
-7
lines changed

5 files changed

+120
-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.8',
39+
'v8_embedder_string': '-node.9',
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
@@ -84,6 +84,13 @@ OverloadsResolutionResult ResolveOverloads(
8484
bool CanOptimizeFastSignature(const CFunctionInfo* c_signature) {
8585
USE(c_signature);
8686

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

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

+54-6
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,19 @@ class FastCApiObject {
471471
}
472472

473473
#ifdef V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
474+
static AnyCType AddAll32BitIntFastCallback_8ArgsPatch(
475+
AnyCType receiver, AnyCType should_fallback, AnyCType arg1_i32,
476+
AnyCType arg2_i32, AnyCType arg3_i32, AnyCType arg4_u32,
477+
AnyCType arg5_u32, AnyCType arg6_u32, AnyCType arg7_u32,
478+
AnyCType arg8_u32, AnyCType options) {
479+
AnyCType ret;
480+
ret.int32_value = AddAll32BitIntFastCallback_8Args(
481+
receiver.object_value, should_fallback.bool_value, arg1_i32.int32_value,
482+
arg2_i32.int32_value, arg3_i32.int32_value, arg4_u32.uint32_value,
483+
arg5_u32.uint32_value, arg6_u32.uint32_value, arg7_u32.uint32_value,
484+
arg8_u32.uint32_value, *options.options_value);
485+
return ret;
486+
}
474487
static AnyCType AddAll32BitIntFastCallback_6ArgsPatch(
475488
AnyCType receiver, AnyCType should_fallback, AnyCType arg1_i32,
476489
AnyCType arg2_i32, AnyCType arg3_i32, AnyCType arg4_u32,
@@ -494,6 +507,26 @@ class FastCApiObject {
494507
}
495508
#endif // V8_USE_SIMULATOR_WITH_GENERIC_C_CALLS
496509

510+
static int AddAll32BitIntFastCallback_8Args(
511+
Local<Object> receiver, bool should_fallback, int32_t arg1_i32,
512+
int32_t arg2_i32, int32_t arg3_i32, uint32_t arg4_u32, uint32_t arg5_u32,
513+
uint32_t arg6_u32, uint32_t arg7_u32, uint32_t arg8_u32,
514+
FastApiCallbackOptions& options) {
515+
FastCApiObject* self = UnwrapObject(receiver);
516+
CHECK_SELF_OR_FALLBACK(0);
517+
self->fast_call_count_++;
518+
519+
if (should_fallback) {
520+
options.fallback = true;
521+
return 0;
522+
}
523+
524+
int64_t result = static_cast<int64_t>(arg1_i32) + arg2_i32 + arg3_i32 +
525+
arg4_u32 + arg5_u32 + arg6_u32 + arg7_u32 + arg8_u32;
526+
if (result > INT_MAX) return INT_MAX;
527+
if (result < INT_MIN) return INT_MIN;
528+
return static_cast<int>(result);
529+
}
497530
static int AddAll32BitIntFastCallback_6Args(
498531
Local<Object> receiver, bool should_fallback, int32_t arg1_i32,
499532
int32_t arg2_i32, int32_t arg3_i32, uint32_t arg4_u32, uint32_t arg5_u32,
@@ -531,24 +564,29 @@ class FastCApiObject {
531564

532565
HandleScope handle_scope(isolate);
533566

567+
Local<Context> context = isolate->GetCurrentContext();
534568
double sum = 0;
535569
if (args.Length() > 1 && args[1]->IsNumber()) {
536-
sum += args[1]->Int32Value(isolate->GetCurrentContext()).FromJust();
570+
sum += args[1]->Int32Value(context).FromJust();
537571
}
538572
if (args.Length() > 2 && args[2]->IsNumber()) {
539-
sum += args[2]->Int32Value(isolate->GetCurrentContext()).FromJust();
573+
sum += args[2]->Int32Value(context).FromJust();
540574
}
541575
if (args.Length() > 3 && args[3]->IsNumber()) {
542-
sum += args[3]->Int32Value(isolate->GetCurrentContext()).FromJust();
576+
sum += args[3]->Int32Value(context).FromJust();
543577
}
544578
if (args.Length() > 4 && args[4]->IsNumber()) {
545-
sum += args[4]->Uint32Value(isolate->GetCurrentContext()).FromJust();
579+
sum += args[4]->Uint32Value(context).FromJust();
546580
}
547581
if (args.Length() > 5 && args[5]->IsNumber()) {
548-
sum += args[5]->Uint32Value(isolate->GetCurrentContext()).FromJust();
582+
sum += args[5]->Uint32Value(context).FromJust();
549583
}
550584
if (args.Length() > 6 && args[6]->IsNumber()) {
551-
sum += args[6]->Uint32Value(isolate->GetCurrentContext()).FromJust();
585+
sum += args[6]->Uint32Value(context).FromJust();
586+
}
587+
if (args.Length() > 7 && args[7]->IsNumber() && args[8]->IsNumber()) {
588+
sum += args[7]->Uint32Value(context).FromJust();
589+
sum += args[8]->Uint32Value(context).FromJust();
552590
}
553591

554592
args.GetReturnValue().Set(Number::New(isolate, sum));
@@ -1160,6 +1198,9 @@ Local<FunctionTemplate> Shell::CreateTestFastCApiTemplate(Isolate* isolate) {
11601198
signature, 1, ConstructorBehavior::kThrow,
11611199
SideEffectType::kHasSideEffect, {add_all_invalid_overloads, 2}));
11621200

1201+
CFunction add_all_32bit_int_8args_c_func = CFunction::Make(
1202+
FastCApiObject::AddAll32BitIntFastCallback_8Args V8_IF_USE_SIMULATOR(
1203+
FastCApiObject::AddAll32BitIntFastCallback_8ArgsPatch));
11631204
CFunction add_all_32bit_int_6args_c_func = CFunction::Make(
11641205
FastCApiObject::AddAll32BitIntFastCallback_6Args V8_IF_USE_SIMULATOR(
11651206
FastCApiObject::AddAll32BitIntFastCallback_6ArgsPatch));
@@ -1176,6 +1217,13 @@ Local<FunctionTemplate> Shell::CreateTestFastCApiTemplate(Isolate* isolate) {
11761217
signature, 1, ConstructorBehavior::kThrow,
11771218
SideEffectType::kHasSideEffect, {c_function_overloads, 2}));
11781219

1220+
api_obj_ctor->PrototypeTemplate()->Set(
1221+
isolate, "overloaded_add_all_8args",
1222+
FunctionTemplate::New(
1223+
isolate, FastCApiObject::AddAll32BitIntSlowCallback, Local<Value>(),
1224+
signature, 1, ConstructorBehavior::kThrow,
1225+
SideEffectType::kHasSideEffect, &add_all_32bit_int_8args_c_func));
1226+
11791227
api_obj_ctor->PrototypeTemplate()->Set(
11801228
isolate, "overloaded_add_all_32bit_int_no_sig",
11811229
FunctionTemplate::NewWithCFunctionOverloads(
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
@@ -898,6 +898,14 @@
898898
'wasm/compare-exchange64-stress': [SKIP],
899899
}], # 'system == macos'
900900

901+
##############################################################################
902+
['system == macos and arch == arm64', {
903+
# BUG(v8:13171): The following tests a function that shouldn't be optimized
904+
# on M1 hardware, unless a proper fix for the stack corruption is
905+
# implemented (see linked issue).
906+
'compiler/fast-api-calls-8args': [FAIL],
907+
}], # 'system == macos and arch == arm64'
908+
901909
##############################################################################
902910
['system == windows', {
903911
# Too slow with turbo fan.

0 commit comments

Comments
 (0)