Commit 7261bf01 authored by Maya Lekova's avatar Maya Lekova Committed by V8 LUCI CQ

[fastcall] Extend the fast API interface with sequences

This CL enhances the interface of the fast C API with constants and
structs necessary for supporting JSArrays, TypedArrays and ArrayBuffers.
It also adds checks for incompatible combinations of argument type/flags.

Bug: chromium:1052746
Change-Id: I032167d0739d33f8151f78574c89d565cb9bd821
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2903147Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74857}
parent 0e6263ec
This diff is collapsed.
...@@ -1269,6 +1269,15 @@ Local<FunctionTemplate> FunctionTemplate::NewWithCFunctionOverloads( ...@@ -1269,6 +1269,15 @@ Local<FunctionTemplate> FunctionTemplate::NewWithCFunctionOverloads(
v8::Local<Signature> signature, int length, ConstructorBehavior behavior, v8::Local<Signature> signature, int length, ConstructorBehavior behavior,
SideEffectType side_effect_type, SideEffectType side_effect_type,
const MemorySpan<const CFunction>& c_function_overloads) { const MemorySpan<const CFunction>& c_function_overloads) {
// TODO(mslekova): Once runtime overload resolution between sequences is
// supported, check that if (c_function_overloads.size() == 2), then
// c_function_overloads.data()[0].
// CanResolveOverload(c_function_overloads.data()[1]). We won't support
// the case where the size is greater than 2 for runtime resolution, until
// we've added support for ArrayBuffers and ArrayBufferViews. OTOH the
// overloads list might contain more than 2 functions with different arity,
// the resolution between which is available at compile time.
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
LOG_API(i_isolate, FunctionTemplate, New); LOG_API(i_isolate, FunctionTemplate, New);
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
......
...@@ -28216,6 +28216,7 @@ TEST(FastApiStackSlot) { ...@@ -28216,6 +28216,7 @@ TEST(FastApiStackSlot) {
// Disable --always_opt, otherwise we haven't generated the necessary // Disable --always_opt, otherwise we haven't generated the necessary
// feedback to go down the "best optimization" path for the fast call. // feedback to go down the "best optimization" path for the fast call.
v8::internal::FLAG_always_opt = false; v8::internal::FLAG_always_opt = false;
v8::internal::FlagList::EnforceFlagImplications();
v8::Isolate* isolate = CcTest::isolate(); v8::Isolate* isolate = CcTest::isolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
...@@ -28267,6 +28268,7 @@ TEST(FastApiCalls) { ...@@ -28267,6 +28268,7 @@ TEST(FastApiCalls) {
// Disable --always_opt, otherwise we haven't generated the necessary // Disable --always_opt, otherwise we haven't generated the necessary
// feedback to go down the "best optimization" path for the fast call. // feedback to go down the "best optimization" path for the fast call.
v8::internal::FLAG_always_opt = false; v8::internal::FLAG_always_opt = false;
v8::internal::FlagList::EnforceFlagImplications();
v8::Isolate* isolate = CcTest::isolate(); v8::Isolate* isolate = CcTest::isolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
...@@ -28725,6 +28727,108 @@ TEST(FastApiCalls) { ...@@ -28725,6 +28727,108 @@ TEST(FastApiCalls) {
#endif // V8_LITE_MODE #endif // V8_LITE_MODE
} }
namespace {
void FastCallback1TypedArray(v8::Local<v8::Object> receiver, int arg0,
v8::FastApiTypedArray<double> arg1) {
// TODO(mslekova): Use the TypedArray parameter
}
void FastCallback2JSArray(v8::Local<v8::Object> receiver, int arg0,
v8::Local<v8::Array> arg1) {
// TODO(mslekova): Use the JSArray parameter
}
void FastCallback3SwappedParams(v8::Local<v8::Object> receiver,
v8::Local<v8::Array> arg0, int arg1) {}
void FastCallback4Scalar(v8::Local<v8::Object> receiver, int arg0, float arg1) {
}
void FastCallback5DifferentArity(v8::Local<v8::Object> receiver, int arg0,
v8::Local<v8::Array> arg1, float arg2) {}
} // namespace
TEST(FastApiSequenceOverloads) {
#ifndef V8_LITE_MODE
if (i::FLAG_jitless) return;
v8::internal::FLAG_opt = true;
v8::internal::FLAG_turbo_fast_api_calls = true;
v8::internal::FLAG_allow_natives_syntax = true;
// Disable --always_opt, otherwise we haven't generated the necessary
// feedback to go down the "best optimization" path for the fast call.
v8::internal::FLAG_always_opt = false;
v8::internal::FlagList::EnforceFlagImplications();
v8::CFunction typed_array_callback =
v8::CFunctionBuilder()
.Fn(FastCallback1TypedArray)
.Arg<0, v8::CTypeInfo::Flags::kNone>()
.Arg<1, v8::CTypeInfo::Flags::kNone>()
.Arg<2, v8::CTypeInfo::Flags::kAllowSharedBit>()
.Build();
v8::CFunction js_array_callback = v8::CFunctionBuilder()
.Fn(FastCallback2JSArray)
.Arg<0, v8::CTypeInfo::Flags::kNone>()
.Arg<1, v8::CTypeInfo::Flags::kNone>()
.Arg<2, v8::CTypeInfo::Flags::kNone>()
.Build();
// TODO(mslekova): Create a FunctionTemplate with the 2 overloads.
USE(typed_array_callback);
USE(js_array_callback);
#endif // V8_LITE_MODE
}
TEST(FastApiOverloadResolution) {
#ifndef V8_LITE_MODE
if (i::FLAG_jitless) return;
v8::internal::FLAG_opt = true;
v8::internal::FLAG_turbo_fast_api_calls = true;
v8::internal::FLAG_allow_natives_syntax = true;
// Disable --always_opt, otherwise we haven't generated the necessary
// feedback to go down the "best optimization" path for the fast call.
v8::internal::FLAG_always_opt = false;
v8::internal::FlagList::EnforceFlagImplications();
v8::CFunction typed_array_callback =
v8::CFunctionBuilder().Fn(FastCallback1TypedArray).Build();
v8::CFunction js_array_callback =
v8::CFunctionBuilder().Fn(FastCallback2JSArray).Build();
// Check that a general runtime overload resolution is possible.
CHECK_EQ(v8::CFunction::OverloadResolution::kAtRuntime,
typed_array_callback.GetOverloadResolution(&js_array_callback));
v8::CFunction swapped_params_callback =
v8::CFunctionBuilder().Fn(FastCallback3SwappedParams).Build();
// Check that difference in > 1 position is not possible.
CHECK_EQ(
v8::CFunction::OverloadResolution::kImpossible,
typed_array_callback.GetOverloadResolution(&swapped_params_callback));
v8::CFunction scalar_callback =
v8::CFunctionBuilder().Fn(FastCallback4Scalar).Build();
// Check that resolving when there is a scalar at the difference position
// is not possible.
CHECK_EQ(v8::CFunction::OverloadResolution::kImpossible,
typed_array_callback.GetOverloadResolution(&scalar_callback));
v8::CFunction diff_arity_callback =
v8::CFunctionBuilder().Fn(FastCallback5DifferentArity).Build();
// Check that overload resolution between different number of arguments
// is possible.
CHECK_EQ(v8::CFunction::OverloadResolution::kAtCompileTime,
typed_array_callback.GetOverloadResolution(&diff_arity_callback));
#endif // V8_LITE_MODE
}
THREADED_TEST(Recorder_GetContext) { THREADED_TEST(Recorder_GetContext) {
using v8::Context; using v8::Context;
using v8::Local; using v8::Local;
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