diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-12 23:25:30 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-23 06:53:10 +0100 |
commit | a5e1a7d70b5eb23af4a5f819dc08b6c15aa723f1 (patch) | |
tree | 40ec05f88f96fd085c0add8eb702304dcce8fa61 /src/qml/jsruntime/qv4function.cpp | |
parent | 4333dded89ce2e49f9ef3ef50ff474ec04e284dd (diff) |
Optimize stack frame setup for AOT compiled functions
When called via the metaobject system, parameters and return values are
passed as void*, with accompanying type information in the form of
QMetaType. The same format is expected when calling an AOT
compiled function.
Previously, we would first convert all the parameters to QV4::Value,
just to convert them back the moment we notice that there is an AOT
compiled function. This is wasteful.
This change provides a second call infrastructure that accepts void* and
QMetaType as parameter and return value format, and passes them as-is
all the way to any AOT compiled functions. If there is no AOT compiled
function, the conversion is done when detecting this, rather than when
initiating the call. This also passes the information "ignore return
value" all the way down to the actual function call. If the caller is
not interested in the return value, we don't have to marshal it back at
all.
For now, we only add the extra "callWithMetaTypes" vtable entry to
ArrowFunction. However, other callables could also receive variants
optimized for calling with void*/int rather than V4 values.
This required changing the way how function arguments are stored in the
property cache. We squeeze the return type into
QQmlPropertyCacheMethodArguments now, and we use QMetaType instead of
integers. In turn, we remove some unused bits.
Change-Id: I946e603e623d9d985c54d3a15f6f4b7c7b7d8c60
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4function.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4function.cpp | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp index 8164bae549..348837c3a5 100644 --- a/src/qml/jsruntime/qv4function.cpp +++ b/src/qml/jsruntime/qv4function.cpp @@ -51,26 +51,53 @@ #include <assembler/MacroAssemblerCodeRef.h> #include <private/qv4vme_moth_p.h> #include <private/qqmlglobal_p.h> +#include <private/qv4jscall_p.h> QT_BEGIN_NAMESPACE using namespace QV4; -ReturnedValue Function::call(const Value *thisObject, const Value *argv, int argc, const ExecutionContext *context) { +void Function::call(const Value *thisObject, void **a, const QMetaType *types, int argc, + const ExecutionContext *context) +{ + if (!aotFunction) { + QV4::convertAndCall(context->engine(), thisObject, a, types, argc, + [this, context](const Value *thisObject, const Value *argv, int argc) { + return call(thisObject, argv, argc, context); + }); + return; + } + ExecutionEngine *engine = context->engine(); - CppStackFrame frame; - frame.init(engine, this, argv, argc); + MetaTypesStackFrame frame; + frame.init(this, a, types, argc); frame.setupJSFrame(engine->jsStackTop, Value::undefinedValue(), context->d(), - thisObject ? *thisObject : Value::undefinedValue(), - Value::undefinedValue()); - - frame.push(); + thisObject ? *thisObject : Value::undefinedValue()); + frame.push(engine); engine->jsStackTop += frame.requiredJSStackFrameSize(); + Moth::VME::exec(&frame, engine); + frame.pop(engine); +} - ReturnedValue result = Moth::VME::exec(&frame, engine); - - frame.pop(); +ReturnedValue Function::call(const Value *thisObject, const Value *argv, int argc, const ExecutionContext *context) { + if (aotFunction) { + return QV4::convertAndCall( + context->engine(), aotFunction, thisObject, argv, argc, + [this, context](const Value *thisObject, + void **a, const QMetaType *types, int argc) { + call(thisObject, a, types, argc, context); + }); + } + ExecutionEngine *engine = context->engine(); + JSTypesStackFrame frame; + frame.init(this, argv, argc); + frame.setupJSFrame(engine->jsStackTop, Value::undefinedValue(), context->d(), + thisObject ? *thisObject : Value::undefinedValue()); + engine->jsStackTop += frame.requiredJSStackFrameSize(); + frame.push(engine); + ReturnedValue result = Moth::VME::exec(&frame, engine); + frame.pop(engine); return result; } |