[fastcall] Generalize fallback option for fast API calls
Switch the current bool* parameter to a structure that contains the boolean fallback flag and is forward compatible, if we decide to add more options to the fallback call. Fly-by refactoring: moved V8_ENABLE_FP_PARAMS_IN_C_LINKAGE out of a public V8 header file. Bug: chromium:1052746 Change-Id: I844db24cc687c58b3c3bbd84b4d61bb4759bcfc7 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2474775 Commit-Queue: Maya Lekova <mslekova@chromium.org> Reviewed-by: Toon Verwaest <verwaest@chromium.org> Reviewed-by: Georg Neis <neis@chromium.org> Cr-Commit-Position: refs/heads/master@{#70642}
This commit is contained in:
parent
adf5c707c9
commit
4d5e6fb301
@ -37,18 +37,18 @@
|
||||
* declare their method like:
|
||||
*
|
||||
* \code
|
||||
* void FastMethodWithFallback(int param, bool* fallback);
|
||||
* void FastMethodWithFallback(int param, FastApiCallbackOptions* options);
|
||||
* \endcode
|
||||
*
|
||||
* If the callback wants to signal an error condition or to perform an
|
||||
* allocation, it must set *fallback to true and do an early return from
|
||||
* the fast method. Then V8 checks the value of *fallback and if it's true,
|
||||
* falls back to executing the SlowCallback, which is capable of
|
||||
* reporting the error (either by throwing a JS exception or logging to the
|
||||
* console) or doing the allocation. It's the embedder's responsibility to
|
||||
* ensure that the fast callback is idempotent up to the point where error
|
||||
* and fallback conditions are checked, because otherwise executing the slow
|
||||
* callback might produce visible side-effects twice.
|
||||
* allocation, it must set options->fallback to true and do an early return from
|
||||
* the fast method. Then V8 checks the value of options->fallback and if it's
|
||||
* true, falls back to executing the SlowCallback, which is capable of reporting
|
||||
* the error (either by throwing a JS exception or logging to the console) or
|
||||
* doing the allocation. It's the embedder's responsibility to ensure that the
|
||||
* fast callback is idempotent up to the point where error and fallback
|
||||
* conditions are checked, because otherwise executing the slow callback might
|
||||
* produce visible side-effects twice.
|
||||
*
|
||||
* An example for custom embedder type support might employ a way to wrap/
|
||||
* unwrap various C++ types in JSObject instances, e.g:
|
||||
@ -423,6 +423,10 @@ class V8_EXPORT CFunction {
|
||||
};
|
||||
};
|
||||
|
||||
struct FastApiCallbackOptions {
|
||||
bool fallback;
|
||||
};
|
||||
|
||||
} // namespace v8
|
||||
|
||||
#endif // INCLUDE_V8_FAST_API_CALLS_H_
|
||||
|
@ -482,15 +482,6 @@ V8 shared library set USING_V8_SHARED.
|
||||
|
||||
#endif // V8_OS_WIN
|
||||
|
||||
// Support for floating point parameters in calls to C.
|
||||
// It's currently enabled only for the platforms listed below. We don't plan
|
||||
// to add support for IA32, because it has a totally different approach
|
||||
// (using FP stack). As support is added to more platforms, please make sure
|
||||
// to list them here in order to enable tests of this functionality.
|
||||
#if defined(V8_TARGET_ARCH_X64)
|
||||
#define V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
|
||||
#endif // V8CONFIG_H_
|
||||
|
@ -4,9 +4,8 @@
|
||||
|
||||
#include "src/codegen/assembler-inl.h"
|
||||
#include "src/codegen/macro-assembler.h"
|
||||
|
||||
#include "src/compiler/globals.h"
|
||||
#include "src/compiler/linkage.h"
|
||||
|
||||
#include "src/zone/zone.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -5175,9 +5175,15 @@ Node* EffectControlLinearizer::LowerFastApiCall(Node* node) {
|
||||
if (fast_api_call_stack_slot_ == nullptr) {
|
||||
// Add the { fallback } output parameter.
|
||||
int kAlign = 4;
|
||||
int kSize = 4;
|
||||
int kSize = sizeof(v8::FastApiCallbackOptions);
|
||||
// If this check fails, probably you've added new fields to
|
||||
// v8::FastApiCallbackOptions, which means you'll need to write code
|
||||
// that initializes and reads from them too (see the Store and Load to
|
||||
// fast_api_call_stack_slot_ below).
|
||||
CHECK_EQ(kSize, 1);
|
||||
fast_api_call_stack_slot_ = __ StackSlot(kSize, kAlign);
|
||||
}
|
||||
|
||||
// Generate the store to `fast_api_call_stack_slot_`.
|
||||
__ Store(StoreRepresentation(MachineRepresentation::kWord32, kNoWriteBarrier),
|
||||
fast_api_call_stack_slot_, 0, jsgraph()->ZeroConstant());
|
||||
|
@ -71,4 +71,13 @@ inline std::ostream& operator<<(std::ostream& os,
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
// Support for floating point parameters in calls to C.
|
||||
// It's currently enabled only for the platforms listed below. We don't plan
|
||||
// to add support for IA32, because it has a totally different approach
|
||||
// (using FP stack). As support is added to more platforms, please make sure
|
||||
// to list them here in order to enable tests of this functionality.
|
||||
#if defined(V8_TARGET_ARCH_X64)
|
||||
#define V8_ENABLE_FP_PARAMS_IN_C_LINKAGE
|
||||
#endif
|
||||
|
||||
#endif // V8_COMPILER_GLOBALS_H_
|
||||
|
@ -27568,8 +27568,8 @@ DEFINE_OPERATORS_FOR_FLAGS(ApiCheckerResultFlags)
|
||||
template <typename Value, typename Impl>
|
||||
struct BasicApiChecker {
|
||||
static void FastCallback(v8::ApiObject receiver, Value argument,
|
||||
int* fallback) {
|
||||
Impl::FastCallback(receiver, argument, fallback);
|
||||
v8::FastApiCallbackOptions* options) {
|
||||
Impl::FastCallback(receiver, argument, options);
|
||||
}
|
||||
static void FastCallbackNoFallback(v8::ApiObject receiver, Value argument) {
|
||||
Impl::FastCallback(receiver, argument, nullptr);
|
||||
@ -27621,10 +27621,11 @@ struct ApiNumberChecker : BasicApiChecker<T, ApiNumberChecker<T>> {
|
||||
write_to_fallback_(write_to_fallback),
|
||||
args_count_(args_count) {}
|
||||
|
||||
static void FastCallback(v8::ApiObject receiver, T argument, int* fallback) {
|
||||
static void FastCallback(v8::ApiObject receiver, T argument,
|
||||
v8::FastApiCallbackOptions* options) {
|
||||
v8::Object* receiver_obj = reinterpret_cast<v8::Object*>(&receiver);
|
||||
if (!IsValidUnwrapObject(receiver_obj)) {
|
||||
*fallback = 1;
|
||||
options->fallback = 1;
|
||||
return;
|
||||
}
|
||||
ApiNumberChecker<T>* receiver_ptr =
|
||||
@ -27637,8 +27638,8 @@ struct ApiNumberChecker : BasicApiChecker<T, ApiNumberChecker<T>> {
|
||||
// the default behavior expected from the embedder. The value is checked
|
||||
// against after loading it from a stack slot, as defined in
|
||||
// EffectControlLinearizer::LowerFastApiCall.
|
||||
CHECK_EQ(*fallback, 0);
|
||||
*fallback = 1;
|
||||
CHECK_EQ(options->fallback, 0);
|
||||
options->fallback = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -27673,7 +27674,7 @@ struct ApiNumberChecker : BasicApiChecker<T, ApiNumberChecker<T>> {
|
||||
struct UnexpectedObjectChecker
|
||||
: BasicApiChecker<v8::ApiObject, UnexpectedObjectChecker> {
|
||||
static void FastCallback(v8::ApiObject receiver, v8::ApiObject argument,
|
||||
int* fallback) {
|
||||
v8::FastApiCallbackOptions* options) {
|
||||
v8::Object* receiver_obj = reinterpret_cast<v8::Object*>(&receiver);
|
||||
UnexpectedObjectChecker* receiver_ptr =
|
||||
GetInternalField<UnexpectedObjectChecker, kV8WrapperObjectIndex>(
|
||||
|
Loading…
Reference in New Issue
Block a user