From 7efa1e60d24fee9b1745c30965949af78f3fb0f3 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 13 Mar 2017 14:26:07 +0100 Subject: Fix running of 32-bit JIT code generated on 64-bit hosts The offsets of members encoded in JIT generated code differ between 32-bit and 64-bit architectures. This patch moves some of the ExecutionEngine members into a separate standard-layout EngineBase class (in line with the same class in commit 2a554434a571dcefd26cf10ef8c5ae8b3b7d66db and subject to merging). By ensuring that the members are stored at pointer intervals, we can translate from host pointer size to target when generating the code. Task-number: QTBUG-58666 Change-Id: I1c38a7da059826848b80fd9972ed073214501386 Reviewed-by: Qt CI Bot Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4engine.cpp | 4 +--- src/qml/jsruntime/qv4engine_p.h | 6 +----- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index f925c9184c..3f11e51799 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -130,9 +130,7 @@ QQmlEngine *ExecutionEngine::qmlEngine() const qint32 ExecutionEngine::maxCallDepth = -1; ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) - : current(0) - , hasException(false) - , callDepth(0) + : callDepth(0) , memoryManager(new QV4::MemoryManager(this)) , executableAllocator(new QV4::ExecutableAllocator) , regExpAllocator(new QV4::ExecutableAllocator) diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 69aa389c44..6de087a4e2 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -88,7 +88,7 @@ struct CompilationUnit; struct InternalClass; struct InternalClassPool; -struct Q_QML_EXPORT ExecutionEngine +struct Q_QML_EXPORT ExecutionEngine : public EngineBase { private: static qint32 maxCallDepth; @@ -97,10 +97,6 @@ private: friend struct ExecutionContext; friend struct Heap::ExecutionContext; public: - Heap::ExecutionContext *current; - - Value *jsStackTop; - quint32 hasException; qint32 callDepth; MemoryManager *memoryManager; -- cgit v1.2.3 From 8e64fdf246a9076d4044e6c78af29e499f48905c Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 9 Feb 2017 15:53:13 +0100 Subject: Prepare run-time method calling mechanism for cross-compilation The current way of encoding the offsetof() of the method_ members in QV4::Runtime is not portable when cross-compiling from a 64-bit host (where the offsetof would be calculated on) to a 32-bit target (where the offset would be different), or vice versa. In preparation for making this work, this patch first replaces the direct use of the run-time members with use through a void * and an enum for indexing. This gives us some type-safety in some places and will also allow for a translation of the pointer offset from host pointer indexing to target pointer indexes. As a bonus we can avoid going through the engine->runtime indirection in the interpreter altogether and call the static methods right away. Task-number: QTBUG-58666 Change-Id: I3cd6459523923a9719408317fa729bca19c2bf3c Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4arraydata.cpp | 2 +- src/qml/jsruntime/qv4engine_p.h | 6 +- src/qml/jsruntime/qv4runtimeapi_p.h | 392 ++++++++++++++---------------------- src/qml/jsruntime/qv4vme_moth.cpp | 132 ++++++------ 4 files changed, 227 insertions(+), 305 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4arraydata.cpp b/src/qml/jsruntime/qv4arraydata.cpp index d8a7de5466..c29cedaa9b 100644 --- a/src/qml/jsruntime/qv4arraydata.cpp +++ b/src/qml/jsruntime/qv4arraydata.cpp @@ -697,7 +697,7 @@ bool ArrayElementLessThan::operator()(Value v1, Value v2) const callData->thisObject = Primitive::undefinedValue(); callData->args[0] = v1; callData->args[1] = v2; - result = scope.engine->runtime.callValue(scope.engine, m_comparefn, callData); + result = QV4::Runtime::method_callValue(scope.engine, m_comparefn, callData); return result->toNumber() < 0; } diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 6de087a4e2..0492191747 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -97,6 +97,10 @@ private: friend struct ExecutionContext; friend struct Heap::ExecutionContext; public: + // This must be the first member, so that its offset is a multiple of QT_POINTER_SIZE + // as the base class's size is. + Runtime runtime; + qint32 callDepth; MemoryManager *memoryManager; @@ -108,8 +112,6 @@ public: Value *jsStackLimit; - Runtime runtime; - WTF::BumpPointerAllocator *bumperPointerAllocator; // Used by Yarr Regex engine. enum { JSStackLimit = 4*1024*1024 }; diff --git a/src/qml/jsruntime/qv4runtimeapi_p.h b/src/qml/jsruntime/qv4runtimeapi_p.h index 355b7890b6..2c898a1880 100644 --- a/src/qml/jsruntime/qv4runtimeapi_p.h +++ b/src/qml/jsruntime/qv4runtimeapi_p.h @@ -90,256 +90,176 @@ struct ExceptionCheck { }; } // anonymous namespace -#define RUNTIME_METHOD(returnvalue, name, args) \ - typedef returnvalue (*Method_##name)args; \ - enum { Method_##name##_NeedsExceptionCheck = ExceptionCheck::NeedsCheck }; \ - static returnvalue method_##name args; \ - const Method_##name name - -#define INIT_RUNTIME_METHOD(name) \ - name(method_##name) +#define FOR_EACH_RUNTIME_METHOD(F) \ + /* call */ \ + F(ReturnedValue, callGlobalLookup, (ExecutionEngine *engine, uint index, CallData *callData)) \ + F(ReturnedValue, callActivationProperty, (ExecutionEngine *engine, int nameIndex, CallData *callData)) \ + F(ReturnedValue, callQmlScopeObjectProperty, (ExecutionEngine *engine, int propertyIndex, CallData *callData)) \ + F(ReturnedValue, callQmlContextObjectProperty, (ExecutionEngine *engine, int propertyIndex, CallData *callData)) \ + F(ReturnedValue, callProperty, (ExecutionEngine *engine, int nameIndex, CallData *callData)) \ + F(ReturnedValue, callPropertyLookup, (ExecutionEngine *engine, uint index, CallData *callData)) \ + F(ReturnedValue, callElement, (ExecutionEngine *engine, const Value &index, CallData *callData)) \ + F(ReturnedValue, callValue, (ExecutionEngine *engine, const Value &func, CallData *callData)) \ + \ + /* construct */ \ + F(ReturnedValue, constructGlobalLookup, (ExecutionEngine *engine, uint index, CallData *callData)) \ + F(ReturnedValue, constructActivationProperty, (ExecutionEngine *engine, int nameIndex, CallData *callData)) \ + F(ReturnedValue, constructProperty, (ExecutionEngine *engine, int nameIndex, CallData *callData)) \ + F(ReturnedValue, constructPropertyLookup, (ExecutionEngine *engine, uint index, CallData *callData)) \ + F(ReturnedValue, constructValue, (ExecutionEngine *engine, const Value &func, CallData *callData)) \ + \ + /* set & get */ \ + F(void, setActivationProperty, (ExecutionEngine *engine, int nameIndex, const Value &value)) \ + F(void, setProperty, (ExecutionEngine *engine, const Value &object, int nameIndex, const Value &value)) \ + F(void, setElement, (ExecutionEngine *engine, const Value &object, const Value &index, const Value &value)) \ + F(ReturnedValue, getProperty, (ExecutionEngine *engine, const Value &object, int nameIndex)) \ + F(ReturnedValue, getActivationProperty, (ExecutionEngine *engine, int nameIndex)) \ + F(ReturnedValue, getElement, (ExecutionEngine *engine, const Value &object, const Value &index)) \ + \ + /* typeof */ \ + F(ReturnedValue, typeofValue, (ExecutionEngine *engine, const Value &val)) \ + F(ReturnedValue, typeofName, (ExecutionEngine *engine, int nameIndex)) \ + F(ReturnedValue, typeofScopeObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex)) \ + F(ReturnedValue, typeofContextObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex)) \ + F(ReturnedValue, typeofMember, (ExecutionEngine *engine, const Value &base, int nameIndex)) \ + F(ReturnedValue, typeofElement, (ExecutionEngine *engine, const Value &base, const Value &index)) \ + \ + /* delete */ \ + F(ReturnedValue, deleteElement, (ExecutionEngine *engine, const Value &base, const Value &index)) \ + F(ReturnedValue, deleteMember, (ExecutionEngine *engine, const Value &base, int nameIndex)) \ + F(ReturnedValue, deleteMemberString, (ExecutionEngine *engine, const Value &base, String *name)) \ + F(ReturnedValue, deleteName, (ExecutionEngine *engine, int nameIndex)) \ + \ + /* exceptions & scopes */ \ + F(void, throwException, (ExecutionEngine *engine, const Value &value)) \ + F(ReturnedValue, unwindException, (ExecutionEngine *engine)) \ + F(void, pushWithScope, (const Value &o, NoThrowEngine *engine)) \ + F(void, pushCatchScope, (NoThrowEngine *engine, int exceptionVarNameIndex)) \ + F(void, popScope, (NoThrowEngine *engine)) \ + \ + /* closures */ \ + F(ReturnedValue, closure, (ExecutionEngine *engine, int functionId)) \ + \ + /* function header */ \ + F(void, declareVar, (ExecutionEngine *engine, bool deletable, int nameIndex)) \ + F(ReturnedValue, setupArgumentsObject, (ExecutionEngine *engine)) \ + F(void, convertThisToObject, (ExecutionEngine *engine)) \ + \ + /* literals */ \ + F(ReturnedValue, arrayLiteral, (ExecutionEngine *engine, Value *values, uint length)) \ + F(ReturnedValue, objectLiteral, (ExecutionEngine *engine, const Value *args, int classId, int arrayValueCount, int arrayGetterSetterCountAndFlags)) \ + F(ReturnedValue, regexpLiteral, (ExecutionEngine *engine, int id)) \ + \ + /* foreach */ \ + F(ReturnedValue, foreachIterator, (ExecutionEngine *engine, const Value &in)) \ + F(ReturnedValue, foreachNextPropertyName, (const Value &foreach_iterator)) \ + \ + /* unary operators */ \ + F(ReturnedValue, uPlus, (const Value &value)) \ + F(ReturnedValue, uMinus, (const Value &value)) \ + F(ReturnedValue, uNot, (const Value &value)) \ + F(ReturnedValue, complement, (const Value &value)) \ + F(ReturnedValue, increment, (const Value &value)) \ + F(ReturnedValue, decrement, (const Value &value)) \ + \ + /* binary operators */ \ + F(ReturnedValue, instanceof, (ExecutionEngine *engine, const Value &left, const Value &right)) \ + F(ReturnedValue, in, (ExecutionEngine *engine, const Value &left, const Value &right)) \ + F(ReturnedValue, add, (ExecutionEngine *engine, const Value &left, const Value &right)) \ + F(ReturnedValue, addString, (ExecutionEngine *engine, const Value &left, const Value &right)) \ + F(ReturnedValue, bitOr, (const Value &left, const Value &right)) \ + F(ReturnedValue, bitXor, (const Value &left, const Value &right)) \ + F(ReturnedValue, bitAnd, (const Value &left, const Value &right)) \ + F(ReturnedValue, sub, (const Value &left, const Value &right)) \ + F(ReturnedValue, mul, (const Value &left, const Value &right)) \ + F(ReturnedValue, div, (const Value &left, const Value &right)) \ + F(ReturnedValue, mod, (const Value &left, const Value &right)) \ + F(ReturnedValue, shl, (const Value &left, const Value &right)) \ + F(ReturnedValue, shr, (const Value &left, const Value &right)) \ + F(ReturnedValue, ushr, (const Value &left, const Value &right)) \ + F(ReturnedValue, greaterThan, (const Value &left, const Value &right)) \ + F(ReturnedValue, lessThan, (const Value &left, const Value &right)) \ + F(ReturnedValue, greaterEqual, (const Value &left, const Value &right)) \ + F(ReturnedValue, lessEqual, (const Value &left, const Value &right)) \ + F(ReturnedValue, equal, (const Value &left, const Value &right)) \ + F(ReturnedValue, notEqual, (const Value &left, const Value &right)) \ + F(ReturnedValue, strictEqual, (const Value &left, const Value &right)) \ + F(ReturnedValue, strictNotEqual, (const Value &left, const Value &right)) \ + \ + /* comparisons */ \ + F(Bool, compareGreaterThan, (const Value &l, const Value &r)) \ + F(Bool, compareLessThan, (const Value &l, const Value &r)) \ + F(Bool, compareGreaterEqual, (const Value &l, const Value &r)) \ + F(Bool, compareLessEqual, (const Value &l, const Value &r)) \ + F(Bool, compareEqual, (const Value &left, const Value &right)) \ + F(Bool, compareNotEqual, (const Value &left, const Value &right)) \ + F(Bool, compareStrictEqual, (const Value &left, const Value &right)) \ + F(Bool, compareStrictNotEqual, (const Value &left, const Value &right)) \ + \ + F(Bool, compareInstanceof, (ExecutionEngine *engine, const Value &left, const Value &right)) \ + F(Bool, compareIn, (ExecutionEngine *engine, const Value &left, const Value &right)) \ + \ + /* conversions */ \ + F(Bool, toBoolean, (const Value &value)) \ + F(ReturnedValue, toDouble, (const Value &value)) \ + F(int, toInt, (const Value &value)) \ + F(int, doubleToInt, (const double &d)) \ + F(unsigned, toUInt, (const Value &value)) \ + F(unsigned, doubleToUInt, (const double &d)) \ + \ + /* qml */ \ + F(ReturnedValue, getQmlContext, (NoThrowEngine *engine)) \ + F(ReturnedValue, getQmlImportedScripts, (NoThrowEngine *engine)) \ + F(ReturnedValue, getQmlSingleton, (NoThrowEngine *engine, int nameIndex)) \ + F(ReturnedValue, getQmlAttachedProperty, (ExecutionEngine *engine, int attachedPropertiesId, int propertyIndex)) \ + F(ReturnedValue, getQmlScopeObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, bool captureRequired)) \ + F(ReturnedValue, getQmlContextObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, bool captureRequired)) \ + F(ReturnedValue, getQmlQObjectProperty, (ExecutionEngine *engine, const Value &object, int propertyIndex, bool captureRequired)) \ + F(ReturnedValue, getQmlSingletonQObjectProperty, (ExecutionEngine *engine, const Value &object, int propertyIndex, bool captureRequired)) \ + F(ReturnedValue, getQmlIdObject, (ExecutionEngine *engine, const Value &context, uint index)) \ + \ + F(void, setQmlScopeObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, const Value &value)) \ + F(void, setQmlContextObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, const Value &value)) \ + F(void, setQmlQObjectProperty, (ExecutionEngine *engine, const Value &object, int propertyIndex, const Value &value)) struct Q_QML_PRIVATE_EXPORT Runtime { Runtime() - : INIT_RUNTIME_METHOD(callGlobalLookup) - , INIT_RUNTIME_METHOD(callActivationProperty) - , INIT_RUNTIME_METHOD(callQmlScopeObjectProperty) - , INIT_RUNTIME_METHOD(callQmlContextObjectProperty) - , INIT_RUNTIME_METHOD(callProperty) - , INIT_RUNTIME_METHOD(callPropertyLookup) - , INIT_RUNTIME_METHOD(callElement) - , INIT_RUNTIME_METHOD(callValue) - , INIT_RUNTIME_METHOD(constructGlobalLookup) - , INIT_RUNTIME_METHOD(constructActivationProperty) - , INIT_RUNTIME_METHOD(constructProperty) - , INIT_RUNTIME_METHOD(constructPropertyLookup) - , INIT_RUNTIME_METHOD(constructValue) - , INIT_RUNTIME_METHOD(setActivationProperty) - , INIT_RUNTIME_METHOD(setProperty) - , INIT_RUNTIME_METHOD(setElement) - , INIT_RUNTIME_METHOD(getProperty) - , INIT_RUNTIME_METHOD(getActivationProperty) - , INIT_RUNTIME_METHOD(getElement) - , INIT_RUNTIME_METHOD(typeofValue) - , INIT_RUNTIME_METHOD(typeofName) - , INIT_RUNTIME_METHOD(typeofScopeObjectProperty) - , INIT_RUNTIME_METHOD(typeofContextObjectProperty) - , INIT_RUNTIME_METHOD(typeofMember) - , INIT_RUNTIME_METHOD(typeofElement) - , INIT_RUNTIME_METHOD(deleteElement) - , INIT_RUNTIME_METHOD(deleteMember) - , INIT_RUNTIME_METHOD(deleteMemberString) - , INIT_RUNTIME_METHOD(deleteName) - , INIT_RUNTIME_METHOD(throwException) - , INIT_RUNTIME_METHOD(unwindException) - , INIT_RUNTIME_METHOD(pushWithScope) - , INIT_RUNTIME_METHOD(pushCatchScope) - , INIT_RUNTIME_METHOD(popScope) - , INIT_RUNTIME_METHOD(closure) - , INIT_RUNTIME_METHOD(declareVar) - , INIT_RUNTIME_METHOD(setupArgumentsObject) - , INIT_RUNTIME_METHOD(convertThisToObject) - , INIT_RUNTIME_METHOD(arrayLiteral) - , INIT_RUNTIME_METHOD(objectLiteral) - , INIT_RUNTIME_METHOD(regexpLiteral) - , INIT_RUNTIME_METHOD(foreachIterator) - , INIT_RUNTIME_METHOD(foreachNextPropertyName) - , INIT_RUNTIME_METHOD(uPlus) - , INIT_RUNTIME_METHOD(uMinus) - , INIT_RUNTIME_METHOD(uNot) - , INIT_RUNTIME_METHOD(complement) - , INIT_RUNTIME_METHOD(increment) - , INIT_RUNTIME_METHOD(decrement) - , INIT_RUNTIME_METHOD(instanceof) - , INIT_RUNTIME_METHOD(in) - , INIT_RUNTIME_METHOD(add) - , INIT_RUNTIME_METHOD(addString) - , INIT_RUNTIME_METHOD(bitOr) - , INIT_RUNTIME_METHOD(bitXor) - , INIT_RUNTIME_METHOD(bitAnd) - , INIT_RUNTIME_METHOD(sub) - , INIT_RUNTIME_METHOD(mul) - , INIT_RUNTIME_METHOD(div) - , INIT_RUNTIME_METHOD(mod) - , INIT_RUNTIME_METHOD(shl) - , INIT_RUNTIME_METHOD(shr) - , INIT_RUNTIME_METHOD(ushr) - , INIT_RUNTIME_METHOD(greaterThan) - , INIT_RUNTIME_METHOD(lessThan) - , INIT_RUNTIME_METHOD(greaterEqual) - , INIT_RUNTIME_METHOD(lessEqual) - , INIT_RUNTIME_METHOD(equal) - , INIT_RUNTIME_METHOD(notEqual) - , INIT_RUNTIME_METHOD(strictEqual) - , INIT_RUNTIME_METHOD(strictNotEqual) - , INIT_RUNTIME_METHOD(compareGreaterThan) - , INIT_RUNTIME_METHOD(compareLessThan) - , INIT_RUNTIME_METHOD(compareGreaterEqual) - , INIT_RUNTIME_METHOD(compareLessEqual) - , INIT_RUNTIME_METHOD(compareEqual) - , INIT_RUNTIME_METHOD(compareNotEqual) - , INIT_RUNTIME_METHOD(compareStrictEqual) - , INIT_RUNTIME_METHOD(compareStrictNotEqual) - , INIT_RUNTIME_METHOD(compareInstanceof) - , INIT_RUNTIME_METHOD(compareIn) - , INIT_RUNTIME_METHOD(toBoolean) - , INIT_RUNTIME_METHOD(toDouble) - , INIT_RUNTIME_METHOD(toInt) - , INIT_RUNTIME_METHOD(doubleToInt) - , INIT_RUNTIME_METHOD(toUInt) - , INIT_RUNTIME_METHOD(doubleToUInt) - , INIT_RUNTIME_METHOD(getQmlContext) - , INIT_RUNTIME_METHOD(getQmlImportedScripts) - , INIT_RUNTIME_METHOD(getQmlSingleton) - , INIT_RUNTIME_METHOD(getQmlAttachedProperty) - , INIT_RUNTIME_METHOD(getQmlScopeObjectProperty) - , INIT_RUNTIME_METHOD(getQmlContextObjectProperty) - , INIT_RUNTIME_METHOD(getQmlQObjectProperty) - , INIT_RUNTIME_METHOD(getQmlSingletonQObjectProperty) - , INIT_RUNTIME_METHOD(getQmlIdObject) - , INIT_RUNTIME_METHOD(setQmlScopeObjectProperty) - , INIT_RUNTIME_METHOD(setQmlContextObjectProperty) - , INIT_RUNTIME_METHOD(setQmlQObjectProperty) - { } - - // call - RUNTIME_METHOD(ReturnedValue, callGlobalLookup, (ExecutionEngine *engine, uint index, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, callActivationProperty, (ExecutionEngine *engine, int nameIndex, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, callQmlScopeObjectProperty, (ExecutionEngine *engine, int propertyIndex, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, callQmlContextObjectProperty, (ExecutionEngine *engine, int propertyIndex, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, callProperty, (ExecutionEngine *engine, int nameIndex, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, callPropertyLookup, (ExecutionEngine *engine, uint index, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, callElement, (ExecutionEngine *engine, const Value &index, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, callValue, (ExecutionEngine *engine, const Value &func, CallData *callData)); - - // construct - RUNTIME_METHOD(ReturnedValue, constructGlobalLookup, (ExecutionEngine *engine, uint index, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, constructActivationProperty, (ExecutionEngine *engine, int nameIndex, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, constructProperty, (ExecutionEngine *engine, int nameIndex, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, constructPropertyLookup, (ExecutionEngine *engine, uint index, CallData *callData)); - RUNTIME_METHOD(ReturnedValue, constructValue, (ExecutionEngine *engine, const Value &func, CallData *callData)); - - // set & get - RUNTIME_METHOD(void, setActivationProperty, (ExecutionEngine *engine, int nameIndex, const Value &value)); - RUNTIME_METHOD(void, setProperty, (ExecutionEngine *engine, const Value &object, int nameIndex, const Value &value)); - RUNTIME_METHOD(void, setElement, (ExecutionEngine *engine, const Value &object, const Value &index, const Value &value)); - RUNTIME_METHOD(ReturnedValue, getProperty, (ExecutionEngine *engine, const Value &object, int nameIndex)); - RUNTIME_METHOD(ReturnedValue, getActivationProperty, (ExecutionEngine *engine, int nameIndex)); - RUNTIME_METHOD(ReturnedValue, getElement, (ExecutionEngine *engine, const Value &object, const Value &index)); - - // typeof - RUNTIME_METHOD(ReturnedValue, typeofValue, (ExecutionEngine *engine, const Value &val)); - RUNTIME_METHOD(ReturnedValue, typeofName, (ExecutionEngine *engine, int nameIndex)); - RUNTIME_METHOD(ReturnedValue, typeofScopeObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex)); - RUNTIME_METHOD(ReturnedValue, typeofContextObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex)); - RUNTIME_METHOD(ReturnedValue, typeofMember, (ExecutionEngine *engine, const Value &base, int nameIndex)); - RUNTIME_METHOD(ReturnedValue, typeofElement, (ExecutionEngine *engine, const Value &base, const Value &index)); - - // delete - RUNTIME_METHOD(ReturnedValue, deleteElement, (ExecutionEngine *engine, const Value &base, const Value &index)); - RUNTIME_METHOD(ReturnedValue, deleteMember, (ExecutionEngine *engine, const Value &base, int nameIndex)); - RUNTIME_METHOD(ReturnedValue, deleteMemberString, (ExecutionEngine *engine, const Value &base, String *name)); - RUNTIME_METHOD(ReturnedValue, deleteName, (ExecutionEngine *engine, int nameIndex)); - - // exceptions & scopes - RUNTIME_METHOD(void, throwException, (ExecutionEngine *engine, const Value &value)); - RUNTIME_METHOD(ReturnedValue, unwindException, (ExecutionEngine *engine)); - RUNTIME_METHOD(void, pushWithScope, (const Value &o, NoThrowEngine *engine)); - RUNTIME_METHOD(void, pushCatchScope, (NoThrowEngine *engine, int exceptionVarNameIndex)); - RUNTIME_METHOD(void, popScope, (NoThrowEngine *engine)); - - // closures - RUNTIME_METHOD(ReturnedValue, closure, (ExecutionEngine *engine, int functionId)); + { +#define INIT_METHOD(returnvalue, name, args) runtimeMethods[name] = reinterpret_cast(&method_##name); +FOR_EACH_RUNTIME_METHOD(INIT_METHOD) +#undef INIT_METHOD + } - // function header - RUNTIME_METHOD(void, declareVar, (ExecutionEngine *engine, bool deletable, int nameIndex)); - RUNTIME_METHOD(ReturnedValue, setupArgumentsObject, (ExecutionEngine *engine)); - RUNTIME_METHOD(void, convertThisToObject, (ExecutionEngine *engine)); - - // literals - RUNTIME_METHOD(ReturnedValue, arrayLiteral, (ExecutionEngine *engine, Value *values, uint length)); - RUNTIME_METHOD(ReturnedValue, objectLiteral, (ExecutionEngine *engine, const Value *args, int classId, int arrayValueCount, int arrayGetterSetterCountAndFlags)); - RUNTIME_METHOD(ReturnedValue, regexpLiteral, (ExecutionEngine *engine, int id)); - - // foreach - RUNTIME_METHOD(ReturnedValue, foreachIterator, (ExecutionEngine *engine, const Value &in)); - RUNTIME_METHOD(ReturnedValue, foreachNextPropertyName, (const Value &foreach_iterator)); - - // unary operators typedef ReturnedValue (*UnaryOperation)(const Value &value); - RUNTIME_METHOD(ReturnedValue, uPlus, (const Value &value)); - RUNTIME_METHOD(ReturnedValue, uMinus, (const Value &value)); - RUNTIME_METHOD(ReturnedValue, uNot, (const Value &value)); - RUNTIME_METHOD(ReturnedValue, complement, (const Value &value)); - RUNTIME_METHOD(ReturnedValue, increment, (const Value &value)); - RUNTIME_METHOD(ReturnedValue, decrement, (const Value &value)); - - // binary operators typedef ReturnedValue (*BinaryOperation)(const Value &left, const Value &right); typedef ReturnedValue (*BinaryOperationContext)(ExecutionEngine *engine, const Value &left, const Value &right); - RUNTIME_METHOD(ReturnedValue, instanceof, (ExecutionEngine *engine, const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, in, (ExecutionEngine *engine, const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, add, (ExecutionEngine *engine, const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, addString, (ExecutionEngine *engine, const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, bitOr, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, bitXor, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, bitAnd, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, sub, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, mul, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, div, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, mod, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, shl, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, shr, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, ushr, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, greaterThan, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, lessThan, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, greaterEqual, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, lessEqual, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, equal, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, notEqual, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, strictEqual, (const Value &left, const Value &right)); - RUNTIME_METHOD(ReturnedValue, strictNotEqual, (const Value &left, const Value &right)); - - // comparisons - RUNTIME_METHOD(Bool, compareGreaterThan, (const Value &l, const Value &r)); - RUNTIME_METHOD(Bool, compareLessThan, (const Value &l, const Value &r)); - RUNTIME_METHOD(Bool, compareGreaterEqual, (const Value &l, const Value &r)); - RUNTIME_METHOD(Bool, compareLessEqual, (const Value &l, const Value &r)); - RUNTIME_METHOD(Bool, compareEqual, (const Value &left, const Value &right)); - RUNTIME_METHOD(Bool, compareNotEqual, (const Value &left, const Value &right)); - RUNTIME_METHOD(Bool, compareStrictEqual, (const Value &left, const Value &right)); - RUNTIME_METHOD(Bool, compareStrictNotEqual, (const Value &left, const Value &right)); +#define DEFINE_RUNTIME_METHOD_ENUM(returnvalue, name, args) name, + enum RuntimeMethods { + FOR_EACH_RUNTIME_METHOD(DEFINE_RUNTIME_METHOD_ENUM) + RuntimeMethodCount, + InvalidRuntimeMethod = RuntimeMethodCount + }; +#undef DEFINE_RUNTIME_METHOD_ENUM - RUNTIME_METHOD(Bool, compareInstanceof, (ExecutionEngine *engine, const Value &left, const Value &right)); - RUNTIME_METHOD(Bool, compareIn, (ExecutionEngine *engine, const Value &left, const Value &right)); + void *runtimeMethods[RuntimeMethodCount]; - // conversions - RUNTIME_METHOD(Bool, toBoolean, (const Value &value)); - RUNTIME_METHOD(ReturnedValue, toDouble, (const Value &value)); - RUNTIME_METHOD(int, toInt, (const Value &value)); - RUNTIME_METHOD(int, doubleToInt, (const double &d)); - RUNTIME_METHOD(unsigned, toUInt, (const Value &value)); - RUNTIME_METHOD(unsigned, doubleToUInt, (const double &d)); + static uint runtimeMethodOffset(RuntimeMethods method) { return method*QT_POINTER_SIZE; } - // qml - RUNTIME_METHOD(ReturnedValue, getQmlContext, (NoThrowEngine *engine)); - RUNTIME_METHOD(ReturnedValue, getQmlImportedScripts, (NoThrowEngine *engine)); - RUNTIME_METHOD(ReturnedValue, getQmlSingleton, (NoThrowEngine *engine, int nameIndex)); - RUNTIME_METHOD(ReturnedValue, getQmlAttachedProperty, (ExecutionEngine *engine, int attachedPropertiesId, int propertyIndex)); - RUNTIME_METHOD(ReturnedValue, getQmlScopeObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, bool captureRequired)); - RUNTIME_METHOD(ReturnedValue, getQmlContextObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, bool captureRequired)); - RUNTIME_METHOD(ReturnedValue, getQmlQObjectProperty, (ExecutionEngine *engine, const Value &object, int propertyIndex, bool captureRequired)); - RUNTIME_METHOD(ReturnedValue, getQmlSingletonQObjectProperty, (ExecutionEngine *engine, const Value &object, int propertyIndex, bool captureRequired)); - RUNTIME_METHOD(ReturnedValue, getQmlIdObject, (ExecutionEngine *engine, const Value &context, uint index)); +#define RUNTIME_METHOD(returnvalue, name, args) \ + typedef returnvalue (*Method_##name)args; \ + enum { Method_##name##_NeedsExceptionCheck = ExceptionCheck::NeedsCheck }; \ + static returnvalue method_##name args; + FOR_EACH_RUNTIME_METHOD(RUNTIME_METHOD) +#undef RUNTIME_METHOD - RUNTIME_METHOD(void, setQmlScopeObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, const Value &value)); - RUNTIME_METHOD(void, setQmlContextObjectProperty, (ExecutionEngine *engine, const Value &context, int propertyIndex, const Value &value)); - RUNTIME_METHOD(void, setQmlQObjectProperty, (ExecutionEngine *engine, const Value &object, int propertyIndex, const Value &value)); }; -#undef RUNTIME_METHOD -#undef INIT_RUNTIME_METHOD +static_assert(std::is_standard_layout::value, "Runtime needs to be standard layout in order for us to be able to use offsetof"); +static_assert(offsetof(Runtime, runtimeMethods) == 0, "JIT expects this to be the first member"); +static_assert(sizeof(Runtime::BinaryOperation) == sizeof(void*), "JIT expects a function pointer to fit into a regular pointer, for cross-compilation offset translation"); + +#undef FOR_EACH_RUNTIME_METHOD } // namespace QV4 diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index be2772c23f..988b0a03b2 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -455,12 +455,12 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(LoadRegExp) MOTH_BEGIN_INSTR(LoadClosure) - STOREVALUE(instr.result, engine->runtime.closure(engine, instr.value)); + STOREVALUE(instr.result, Runtime::method_closure(engine, instr.value)); MOTH_END_INSTR(LoadClosure) MOTH_BEGIN_INSTR(LoadName) TRACE(inline, "property name = %s", runtimeStrings[instr.name]->toQString().toUtf8().constData()); - STOREVALUE(instr.result, engine->runtime.getActivationProperty(engine, instr.name)); + STOREVALUE(instr.result, Runtime::method_getActivationProperty(engine, instr.name)); MOTH_END_INSTR(LoadName) MOTH_BEGIN_INSTR(GetGlobalLookup) @@ -470,12 +470,12 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_BEGIN_INSTR(StoreName) TRACE(inline, "property name = %s", runtimeStrings[instr.name]->toQString().toUtf8().constData()); - engine->runtime.setActivationProperty(engine, instr.name, VALUE(instr.source)); + Runtime::method_setActivationProperty(engine, instr.name, VALUE(instr.source)); CHECK_EXCEPTION; MOTH_END_INSTR(StoreName) MOTH_BEGIN_INSTR(LoadElement) - STOREVALUE(instr.result, engine->runtime.getElement(engine, VALUE(instr.base), VALUE(instr.index))); + STOREVALUE(instr.result, Runtime::method_getElement(engine, VALUE(instr.base), VALUE(instr.index))); MOTH_END_INSTR(LoadElement) MOTH_BEGIN_INSTR(LoadElementLookup) @@ -484,7 +484,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(LoadElementLookup) MOTH_BEGIN_INSTR(StoreElement) - engine->runtime.setElement(engine, VALUE(instr.base), VALUE(instr.index), VALUE(instr.source)); + Runtime::method_setElement(engine, VALUE(instr.base), VALUE(instr.index), VALUE(instr.source)); CHECK_EXCEPTION; MOTH_END_INSTR(StoreElement) @@ -495,7 +495,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(StoreElementLookup) MOTH_BEGIN_INSTR(LoadProperty) - STOREVALUE(instr.result, engine->runtime.getProperty(engine, VALUE(instr.base), instr.name)); + STOREVALUE(instr.result, Runtime::method_getProperty(engine, VALUE(instr.base), instr.name)); MOTH_END_INSTR(LoadProperty) MOTH_BEGIN_INSTR(GetLookup) @@ -504,7 +504,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(GetLookup) MOTH_BEGIN_INSTR(StoreProperty) - engine->runtime.setProperty(engine, VALUE(instr.base), instr.name, VALUE(instr.source)); + Runtime::method_setProperty(engine, VALUE(instr.base), instr.name, VALUE(instr.source)); CHECK_EXCEPTION; MOTH_END_INSTR(StoreProperty) @@ -515,42 +515,42 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(SetLookup) MOTH_BEGIN_INSTR(StoreQObjectProperty) - engine->runtime.setQmlQObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, VALUE(instr.source)); + Runtime::method_setQmlQObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, VALUE(instr.source)); CHECK_EXCEPTION; MOTH_END_INSTR(StoreQObjectProperty) MOTH_BEGIN_INSTR(LoadQObjectProperty) - STOREVALUE(instr.result, engine->runtime.getQmlQObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, instr.captureRequired)); + STOREVALUE(instr.result, Runtime::method_getQmlQObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, instr.captureRequired)); MOTH_END_INSTR(LoadQObjectProperty) MOTH_BEGIN_INSTR(StoreScopeObjectProperty) - engine->runtime.setQmlScopeObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, VALUE(instr.source)); + Runtime::method_setQmlScopeObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, VALUE(instr.source)); CHECK_EXCEPTION; MOTH_END_INSTR(StoreScopeObjectProperty) MOTH_BEGIN_INSTR(LoadScopeObjectProperty) - STOREVALUE(instr.result, engine->runtime.getQmlScopeObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, instr.captureRequired)); + STOREVALUE(instr.result, Runtime::method_getQmlScopeObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, instr.captureRequired)); MOTH_END_INSTR(LoadScopeObjectProperty) MOTH_BEGIN_INSTR(StoreContextObjectProperty) - engine->runtime.setQmlContextObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, VALUE(instr.source)); + Runtime::method_setQmlContextObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, VALUE(instr.source)); CHECK_EXCEPTION; MOTH_END_INSTR(StoreContextObjectProperty) MOTH_BEGIN_INSTR(LoadContextObjectProperty) - STOREVALUE(instr.result, engine->runtime.getQmlContextObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, instr.captureRequired)); + STOREVALUE(instr.result, Runtime::method_getQmlContextObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, instr.captureRequired)); MOTH_END_INSTR(LoadContextObjectProperty) MOTH_BEGIN_INSTR(LoadIdObject) - STOREVALUE(instr.result, engine->runtime.getQmlIdObject(engine, VALUE(instr.base), instr.index)); + STOREVALUE(instr.result, Runtime::method_getQmlIdObject(engine, VALUE(instr.base), instr.index)); MOTH_END_INSTR(LoadIdObject) MOTH_BEGIN_INSTR(LoadAttachedQObjectProperty) - STOREVALUE(instr.result, engine->runtime.getQmlAttachedProperty(engine, instr.attachedPropertiesId, instr.propertyIndex)); + STOREVALUE(instr.result, Runtime::method_getQmlAttachedProperty(engine, instr.attachedPropertiesId, instr.propertyIndex)); MOTH_END_INSTR(LoadAttachedQObjectProperty) MOTH_BEGIN_INSTR(LoadSingletonQObjectProperty) - STOREVALUE(instr.result, engine->runtime.getQmlSingletonQObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, instr.captureRequired)); + STOREVALUE(instr.result, Runtime::method_getQmlSingletonQObjectProperty(engine, VALUE(instr.base), instr.propertyIndex, instr.captureRequired)); MOTH_END_INSTR(LoadSingletonQObjectProperty) MOTH_BEGIN_INSTR(Push) @@ -576,7 +576,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = QV4::Primitive::undefinedValue(); - STOREVALUE(instr.result, engine->runtime.callValue(engine, VALUE(instr.dest), callData)); + STOREVALUE(instr.result, Runtime::method_callValue(engine, VALUE(instr.dest), callData)); MOTH_END_INSTR(CallValue) MOTH_BEGIN_INSTR(CallProperty) @@ -586,7 +586,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = VALUE(instr.base); - STOREVALUE(instr.result, engine->runtime.callProperty(engine, instr.name, callData)); + STOREVALUE(instr.result, Runtime::method_callProperty(engine, instr.name, callData)); MOTH_END_INSTR(CallProperty) MOTH_BEGIN_INSTR(CallPropertyLookup) @@ -595,7 +595,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = VALUE(instr.base); - STOREVALUE(instr.result, engine->runtime.callPropertyLookup(engine, instr.lookupIndex, callData)); + STOREVALUE(instr.result, Runtime::method_callPropertyLookup(engine, instr.lookupIndex, callData)); MOTH_END_INSTR(CallPropertyLookup) MOTH_BEGIN_INSTR(CallScopeObjectProperty) @@ -605,7 +605,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = VALUE(instr.base); - STOREVALUE(instr.result, engine->runtime.callQmlScopeObjectProperty(engine, instr.index, callData)); + STOREVALUE(instr.result, Runtime::method_callQmlScopeObjectProperty(engine, instr.index, callData)); MOTH_END_INSTR(CallScopeObjectProperty) MOTH_BEGIN_INSTR(CallContextObjectProperty) @@ -615,7 +615,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = VALUE(instr.base); - STOREVALUE(instr.result, engine->runtime.callQmlContextObjectProperty(engine, instr.index, callData)); + STOREVALUE(instr.result, Runtime::method_callQmlContextObjectProperty(engine, instr.index, callData)); MOTH_END_INSTR(CallContextObjectProperty) MOTH_BEGIN_INSTR(CallElement) @@ -624,7 +624,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = VALUE(instr.base); - STOREVALUE(instr.result, engine->runtime.callElement(engine, VALUE(instr.index), callData)); + STOREVALUE(instr.result, Runtime::method_callElement(engine, VALUE(instr.index), callData)); MOTH_END_INSTR(CallElement) MOTH_BEGIN_INSTR(CallActivationProperty) @@ -633,7 +633,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = QV4::Primitive::undefinedValue(); - STOREVALUE(instr.result, engine->runtime.callActivationProperty(engine, instr.name, callData)); + STOREVALUE(instr.result, Runtime::method_callActivationProperty(engine, instr.name, callData)); MOTH_END_INSTR(CallActivationProperty) MOTH_BEGIN_INSTR(CallGlobalLookup) @@ -650,95 +650,95 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(SetExceptionHandler) MOTH_BEGIN_INSTR(CallBuiltinThrow) - engine->runtime.throwException(engine, VALUE(instr.arg)); + Runtime::method_throwException(engine, VALUE(instr.arg)); CHECK_EXCEPTION; MOTH_END_INSTR(CallBuiltinThrow) MOTH_BEGIN_INSTR(CallBuiltinUnwindException) - STOREVALUE(instr.result, engine->runtime.unwindException(engine)); + STOREVALUE(instr.result, Runtime::method_unwindException(engine)); MOTH_END_INSTR(CallBuiltinUnwindException) MOTH_BEGIN_INSTR(CallBuiltinPushCatchScope) - engine->runtime.pushCatchScope(static_cast(engine), instr.name); + Runtime::method_pushCatchScope(static_cast(engine), instr.name); context = engine->currentContext; MOTH_END_INSTR(CallBuiltinPushCatchScope) MOTH_BEGIN_INSTR(CallBuiltinPushScope) - engine->runtime.pushWithScope(VALUE(instr.arg), static_cast(engine)); + Runtime::method_pushWithScope(VALUE(instr.arg), static_cast(engine)); context = engine->currentContext; CHECK_EXCEPTION; MOTH_END_INSTR(CallBuiltinPushScope) MOTH_BEGIN_INSTR(CallBuiltinPopScope) - engine->runtime.popScope(static_cast(engine)); + Runtime::method_popScope(static_cast(engine)); context = engine->currentContext; MOTH_END_INSTR(CallBuiltinPopScope) MOTH_BEGIN_INSTR(CallBuiltinForeachIteratorObject) - STOREVALUE(instr.result, engine->runtime.foreachIterator(engine, VALUE(instr.arg))); + STOREVALUE(instr.result, Runtime::method_foreachIterator(engine, VALUE(instr.arg))); MOTH_END_INSTR(CallBuiltinForeachIteratorObject) MOTH_BEGIN_INSTR(CallBuiltinForeachNextPropertyName) - STOREVALUE(instr.result, engine->runtime.foreachNextPropertyName(VALUE(instr.arg))); + STOREVALUE(instr.result, Runtime::method_foreachNextPropertyName(VALUE(instr.arg))); MOTH_END_INSTR(CallBuiltinForeachNextPropertyName) MOTH_BEGIN_INSTR(CallBuiltinDeleteMember) - STOREVALUE(instr.result, engine->runtime.deleteMember(engine, VALUE(instr.base), instr.member)); + STOREVALUE(instr.result, Runtime::method_deleteMember(engine, VALUE(instr.base), instr.member)); MOTH_END_INSTR(CallBuiltinDeleteMember) MOTH_BEGIN_INSTR(CallBuiltinDeleteSubscript) - STOREVALUE(instr.result, engine->runtime.deleteElement(engine, VALUE(instr.base), VALUE(instr.index))); + STOREVALUE(instr.result, Runtime::method_deleteElement(engine, VALUE(instr.base), VALUE(instr.index))); MOTH_END_INSTR(CallBuiltinDeleteSubscript) MOTH_BEGIN_INSTR(CallBuiltinDeleteName) - STOREVALUE(instr.result, engine->runtime.deleteName(engine, instr.name)); + STOREVALUE(instr.result, Runtime::method_deleteName(engine, instr.name)); MOTH_END_INSTR(CallBuiltinDeleteName) MOTH_BEGIN_INSTR(CallBuiltinTypeofScopeObjectProperty) - STOREVALUE(instr.result, engine->runtime.typeofScopeObjectProperty(engine, VALUE(instr.base), instr.index)); + STOREVALUE(instr.result, Runtime::method_typeofScopeObjectProperty(engine, VALUE(instr.base), instr.index)); MOTH_END_INSTR(CallBuiltinTypeofMember) MOTH_BEGIN_INSTR(CallBuiltinTypeofContextObjectProperty) - STOREVALUE(instr.result, engine->runtime.typeofContextObjectProperty(engine, VALUE(instr.base), instr.index)); + STOREVALUE(instr.result, Runtime::method_typeofContextObjectProperty(engine, VALUE(instr.base), instr.index)); MOTH_END_INSTR(CallBuiltinTypeofMember) MOTH_BEGIN_INSTR(CallBuiltinTypeofMember) - STOREVALUE(instr.result, engine->runtime.typeofMember(engine, VALUE(instr.base), instr.member)); + STOREVALUE(instr.result, Runtime::method_typeofMember(engine, VALUE(instr.base), instr.member)); MOTH_END_INSTR(CallBuiltinTypeofMember) MOTH_BEGIN_INSTR(CallBuiltinTypeofSubscript) - STOREVALUE(instr.result, engine->runtime.typeofElement(engine, VALUE(instr.base), VALUE(instr.index))); + STOREVALUE(instr.result, Runtime::method_typeofElement(engine, VALUE(instr.base), VALUE(instr.index))); MOTH_END_INSTR(CallBuiltinTypeofSubscript) MOTH_BEGIN_INSTR(CallBuiltinTypeofName) - STOREVALUE(instr.result, engine->runtime.typeofName(engine, instr.name)); + STOREVALUE(instr.result, Runtime::method_typeofName(engine, instr.name)); MOTH_END_INSTR(CallBuiltinTypeofName) MOTH_BEGIN_INSTR(CallBuiltinTypeofValue) - STOREVALUE(instr.result, engine->runtime.typeofValue(engine, VALUE(instr.value))); + STOREVALUE(instr.result, Runtime::method_typeofValue(engine, VALUE(instr.value))); MOTH_END_INSTR(CallBuiltinTypeofValue) MOTH_BEGIN_INSTR(CallBuiltinDeclareVar) - engine->runtime.declareVar(engine, instr.isDeletable, instr.varName); + Runtime::method_declareVar(engine, instr.isDeletable, instr.varName); MOTH_END_INSTR(CallBuiltinDeclareVar) MOTH_BEGIN_INSTR(CallBuiltinDefineArray) Q_ASSERT(instr.args + instr.argc <= stackSize); QV4::Value *args = stack + instr.args; - STOREVALUE(instr.result, engine->runtime.arrayLiteral(engine, args, instr.argc)); + STOREVALUE(instr.result, Runtime::method_arrayLiteral(engine, args, instr.argc)); MOTH_END_INSTR(CallBuiltinDefineArray) MOTH_BEGIN_INSTR(CallBuiltinDefineObjectLiteral) QV4::Value *args = stack + instr.args; - STOREVALUE(instr.result, engine->runtime.objectLiteral(engine, args, instr.internalClassId, instr.arrayValueCount, instr.arrayGetterSetterCountAndFlags)); + STOREVALUE(instr.result, Runtime::method_objectLiteral(engine, args, instr.internalClassId, instr.arrayValueCount, instr.arrayGetterSetterCountAndFlags)); MOTH_END_INSTR(CallBuiltinDefineObjectLiteral) MOTH_BEGIN_INSTR(CallBuiltinSetupArgumentsObject) - STOREVALUE(instr.result, engine->runtime.setupArgumentsObject(engine)); + STOREVALUE(instr.result, Runtime::method_setupArgumentsObject(engine)); MOTH_END_INSTR(CallBuiltinSetupArgumentsObject) MOTH_BEGIN_INSTR(CallBuiltinConvertThisToObject) - engine->runtime.convertThisToObject(engine); + Runtime::method_convertThisToObject(engine); CHECK_EXCEPTION; MOTH_END_INSTR(CallBuiltinConvertThisToObject) @@ -748,7 +748,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = QV4::Primitive::undefinedValue(); - STOREVALUE(instr.result, engine->runtime.constructValue(engine, VALUE(instr.func), callData)); + STOREVALUE(instr.result, Runtime::method_constructValue(engine, VALUE(instr.func), callData)); MOTH_END_INSTR(CreateValue) MOTH_BEGIN_INSTR(CreateProperty) @@ -757,7 +757,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = VALUE(instr.base); - STOREVALUE(instr.result, engine->runtime.constructProperty(engine, instr.name, callData)); + STOREVALUE(instr.result, Runtime::method_constructProperty(engine, instr.name, callData)); MOTH_END_INSTR(CreateProperty) MOTH_BEGIN_INSTR(ConstructPropertyLookup) @@ -766,7 +766,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = VALUE(instr.base); - STOREVALUE(instr.result, engine->runtime.constructPropertyLookup(engine, instr.index, callData)); + STOREVALUE(instr.result, Runtime::method_constructPropertyLookup(engine, instr.index, callData)); MOTH_END_INSTR(ConstructPropertyLookup) MOTH_BEGIN_INSTR(CreateActivationProperty) @@ -775,7 +775,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = QV4::Primitive::undefinedValue(); - STOREVALUE(instr.result, engine->runtime.constructActivationProperty(engine, instr.name, callData)); + STOREVALUE(instr.result, Runtime::method_constructActivationProperty(engine, instr.name, callData)); MOTH_END_INSTR(CreateActivationProperty) MOTH_BEGIN_INSTR(ConstructGlobalLookup) @@ -784,7 +784,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; callData->thisObject = QV4::Primitive::undefinedValue(); - STOREVALUE(instr.result, engine->runtime.constructGlobalLookup(engine, instr.index, callData)); + STOREVALUE(instr.result, Runtime::method_constructGlobalLookup(engine, instr.index, callData)); MOTH_END_INSTR(ConstructGlobalLookup) MOTH_BEGIN_INSTR(Jump) @@ -806,7 +806,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(JumpNe) MOTH_BEGIN_INSTR(UNot) - STOREVALUE(instr.result, engine->runtime.uNot(VALUE(instr.source))); + STOREVALUE(instr.result, Runtime::method_uNot(VALUE(instr.source))); MOTH_END_INSTR(UNot) MOTH_BEGIN_INSTR(UNotBool) @@ -815,15 +815,15 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(UNotBool) MOTH_BEGIN_INSTR(UPlus) - STOREVALUE(instr.result, engine->runtime.uPlus(VALUE(instr.source))); + STOREVALUE(instr.result, Runtime::method_uPlus(VALUE(instr.source))); MOTH_END_INSTR(UPlus) MOTH_BEGIN_INSTR(UMinus) - STOREVALUE(instr.result, engine->runtime.uMinus(VALUE(instr.source))); + STOREVALUE(instr.result, Runtime::method_uMinus(VALUE(instr.source))); MOTH_END_INSTR(UMinus) MOTH_BEGIN_INSTR(UCompl) - STOREVALUE(instr.result, engine->runtime.complement(VALUE(instr.source))); + STOREVALUE(instr.result, Runtime::method_complement(VALUE(instr.source))); MOTH_END_INSTR(UCompl) MOTH_BEGIN_INSTR(UComplInt) @@ -831,32 +831,32 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(UComplInt) MOTH_BEGIN_INSTR(Increment) - STOREVALUE(instr.result, engine->runtime.increment(VALUE(instr.source))); + STOREVALUE(instr.result, Runtime::method_increment(VALUE(instr.source))); MOTH_END_INSTR(Increment) MOTH_BEGIN_INSTR(Decrement) - STOREVALUE(instr.result, engine->runtime.decrement(VALUE(instr.source))); + STOREVALUE(instr.result, Runtime::method_decrement(VALUE(instr.source))); MOTH_END_INSTR(Decrement) MOTH_BEGIN_INSTR(Binop) - QV4::Runtime::BinaryOperation op = *reinterpret_cast(reinterpret_cast(&engine->runtime) + instr.alu); + QV4::Runtime::BinaryOperation op = *reinterpret_cast(reinterpret_cast(&engine->runtime.runtimeMethods[instr.alu])); STOREVALUE(instr.result, op(VALUE(instr.lhs), VALUE(instr.rhs))); MOTH_END_INSTR(Binop) MOTH_BEGIN_INSTR(Add) - STOREVALUE(instr.result, engine->runtime.add(engine, VALUE(instr.lhs), VALUE(instr.rhs))); + STOREVALUE(instr.result, Runtime::method_add(engine, VALUE(instr.lhs), VALUE(instr.rhs))); MOTH_END_INSTR(Add) MOTH_BEGIN_INSTR(BitAnd) - STOREVALUE(instr.result, engine->runtime.bitAnd(VALUE(instr.lhs), VALUE(instr.rhs))); + STOREVALUE(instr.result, Runtime::method_bitAnd(VALUE(instr.lhs), VALUE(instr.rhs))); MOTH_END_INSTR(BitAnd) MOTH_BEGIN_INSTR(BitOr) - STOREVALUE(instr.result, engine->runtime.bitOr(VALUE(instr.lhs), VALUE(instr.rhs))); + STOREVALUE(instr.result, Runtime::method_bitOr(VALUE(instr.lhs), VALUE(instr.rhs))); MOTH_END_INSTR(BitOr) MOTH_BEGIN_INSTR(BitXor) - STOREVALUE(instr.result, engine->runtime.bitXor(VALUE(instr.lhs), VALUE(instr.rhs))); + STOREVALUE(instr.result, Runtime::method_bitXor(VALUE(instr.lhs), VALUE(instr.rhs))); MOTH_END_INSTR(BitXor) MOTH_BEGIN_INSTR(Shr) @@ -891,15 +891,15 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(ShlConst) MOTH_BEGIN_INSTR(Mul) - STOREVALUE(instr.result, engine->runtime.mul(VALUE(instr.lhs), VALUE(instr.rhs))); + STOREVALUE(instr.result, Runtime::method_mul(VALUE(instr.lhs), VALUE(instr.rhs))); MOTH_END_INSTR(Mul) MOTH_BEGIN_INSTR(Sub) - STOREVALUE(instr.result, engine->runtime.sub(VALUE(instr.lhs), VALUE(instr.rhs))); + STOREVALUE(instr.result, Runtime::method_sub(VALUE(instr.lhs), VALUE(instr.rhs))); MOTH_END_INSTR(Sub) MOTH_BEGIN_INSTR(BinopContext) - QV4::Runtime::BinaryOperationContext op = *reinterpret_cast(reinterpret_cast(&engine->runtime) + instr.alu); + QV4::Runtime::BinaryOperationContext op = *reinterpret_cast(reinterpret_cast(&engine->runtime.runtimeMethods[instr.alu])); STOREVALUE(instr.result, op(engine, VALUE(instr.lhs), VALUE(instr.rhs))); MOTH_END_INSTR(BinopContext) @@ -930,15 +930,15 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(LoadThis) MOTH_BEGIN_INSTR(LoadQmlContext) - VALUE(instr.result) = engine->runtime.getQmlContext(static_cast(engine)); + VALUE(instr.result) = Runtime::method_getQmlContext(static_cast(engine)); MOTH_END_INSTR(LoadQmlContext) MOTH_BEGIN_INSTR(LoadQmlImportedScripts) - VALUE(instr.result) = engine->runtime.getQmlImportedScripts(static_cast(engine)); + VALUE(instr.result) = Runtime::method_getQmlImportedScripts(static_cast(engine)); MOTH_END_INSTR(LoadQmlImportedScripts) MOTH_BEGIN_INSTR(LoadQmlSingleton) - VALUE(instr.result) = engine->runtime.getQmlSingleton(static_cast(engine), instr.name); + VALUE(instr.result) = Runtime::method_getQmlSingleton(static_cast(engine), instr.name); MOTH_END_INSTR(LoadQmlSingleton) #ifdef MOTH_THREADED_INTERPRETER -- cgit v1.2.3 From 25e40b18d5348064e1b31d491a22c50a2ffb89c3 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 14 Mar 2017 13:32:42 +0100 Subject: Protect CallData usage against cross-compilation word size differences Ensure via static asserts that the members always have the same offsets. Since the class has standard layout, we can also use the C++11 offsetof macro instead of qOffsetOf. Task-number: QTBUG-58666 Change-Id: I7dcecf517c771c7081334cd9d0b7ae133b23b23a Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4context_p.h | 6 ++++++ src/qml/jsruntime/qv4scopedvalue_p.h | 2 +- src/qml/jsruntime/qv4vme_moth.cpp | 26 +++++++++++++------------- 3 files changed, 20 insertions(+), 14 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index bcfee2e1f8..3c779e52a3 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -73,6 +73,8 @@ struct WithContext; struct QmlContext; struct QmlContextWrapper; +// Attention: Make sure that this structure is the same size on 32-bit and 64-bit +// architecture or you'll have to change the JIT code. struct CallData { // below is to be compatible with Value. Initialize tag to 0 @@ -91,6 +93,10 @@ struct CallData Value args[1]; }; +Q_STATIC_ASSERT(std::is_standard_layout::value); +Q_STATIC_ASSERT(offsetof(CallData, thisObject) == 8); +Q_STATIC_ASSERT(offsetof(CallData, args) == 16); + namespace Heap { struct QmlContext; diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index 6775028272..894434be16 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -366,7 +366,7 @@ struct Scoped struct ScopedCallData { ScopedCallData(const Scope &scope, int argc = 0) { - int size = qMax(argc, (int)QV4::Global::ReservedArgumentCount) + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value); + int size = qMax(argc, QV4::Global::ReservedArgumentCount + int(offsetof(QV4::CallData, args)/sizeof(QV4::Value))); ptr = reinterpret_cast(scope.alloc(size)); ptr->tag = QV4::Value::Integer_Type_Internal; ptr->argc = argc; diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index 988b0a03b2..17091819ee 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -571,7 +571,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code } } #endif // DO_TRACE_INSTR - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -581,7 +581,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_BEGIN_INSTR(CallProperty) TRACE(property name, "%s, args=%u, argc=%u, this=%s", qPrintable(runtimeStrings[instr.name]->toQString()), instr.callData, instr.argc, (VALUE(instr.base)).toString(context)->toQString().toUtf8().constData()); - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -590,7 +590,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(CallProperty) MOTH_BEGIN_INSTR(CallPropertyLookup) - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -600,7 +600,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_BEGIN_INSTR(CallScopeObjectProperty) TRACE(property name, "%s, args=%u, argc=%u, this=%s", qPrintable(runtimeStrings[instr.name]->toQString()), instr.callData, instr.argc, (VALUE(instr.base)).toString(context)->toQString().toUtf8().constData()); - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -610,7 +610,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_BEGIN_INSTR(CallContextObjectProperty) TRACE(property name, "%s, args=%u, argc=%u, this=%s", qPrintable(runtimeStrings[instr.name]->toQString()), instr.callData, instr.argc, (VALUE(instr.base)).toString(context)->toQString().toUtf8().constData()); - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -619,7 +619,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(CallContextObjectProperty) MOTH_BEGIN_INSTR(CallElement) - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -628,7 +628,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(CallElement) MOTH_BEGIN_INSTR(CallActivationProperty) - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -637,7 +637,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(CallActivationProperty) MOTH_BEGIN_INSTR(CallGlobalLookup) - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -743,7 +743,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(CallBuiltinConvertThisToObject) MOTH_BEGIN_INSTR(CreateValue) - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -752,7 +752,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(CreateValue) MOTH_BEGIN_INSTR(CreateProperty) - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -761,7 +761,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(CreateProperty) MOTH_BEGIN_INSTR(ConstructPropertyLookup) - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -770,7 +770,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(ConstructPropertyLookup) MOTH_BEGIN_INSTR(CreateActivationProperty) - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; @@ -779,7 +779,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_END_INSTR(CreateActivationProperty) MOTH_BEGIN_INSTR(ConstructGlobalLookup) - Q_ASSERT(instr.callData + instr.argc + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); + Q_ASSERT(instr.callData + instr.argc + offsetof(QV4::CallData, args)/sizeof(QV4::Value) <= stackSize); QV4::CallData *callData = reinterpret_cast(stack + instr.callData); callData->tag = QV4::Value::Integer_Type_Internal; callData->argc = instr.argc; -- cgit v1.2.3 From 720dab7ad0f77b739a12f0e3e7e7178ea16c2e64 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 14 Mar 2017 13:51:27 +0100 Subject: Protect Lookup usage against cross-compilation word size differences The offsets we're taking from Lookup in the code generator are always zero, but with static assertions we can ensure that they stay that way. Task-number: QTBUG-58666 Change-Id: I91e047d2101ba33e36aaada4a5adc75e20fea7d8 Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4lookup_p.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4lookup_p.h b/src/qml/jsruntime/qv4lookup_p.h index c5ee92fedd..2ffb43cce9 100644 --- a/src/qml/jsruntime/qv4lookup_p.h +++ b/src/qml/jsruntime/qv4lookup_p.h @@ -141,6 +141,13 @@ struct Lookup { }; +Q_STATIC_ASSERT(std::is_standard_layout::value); +// Ensure that these offsets are always at this point to keep generated code compatible +// across 32-bit and 64-bit (matters when cross-compiling). +Q_STATIC_ASSERT(offsetof(Lookup, indexedGetter) == 0); +Q_STATIC_ASSERT(offsetof(Lookup, getter) == 0); +Q_STATIC_ASSERT(offsetof(Lookup, engine) == offsetof(Lookup, getter) + QT_POINTER_SIZE); + } QT_END_NAMESPACE -- cgit v1.2.3 From 94b52fd93b8ec31981b097af0b29f39b6b294ce7 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 14 Mar 2017 15:31:06 +0100 Subject: Protect CompilationUnit member usage against word size differences Currently we only use the runtimeStrings offset in JIT generated code, so move that into a standard layout base class and use that instead. Task-number: QTBUG-58666 Change-Id: Id933ba5df3a6990e89886c2b328e9e814ec5e413 Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4context.cpp | 4 ++-- src/qml/jsruntime/qv4context_p.h | 4 ++-- src/qml/jsruntime/qv4runtime.cpp | 6 +++--- src/qml/jsruntime/qv4script_p.h | 2 +- src/qml/jsruntime/qv4vme_moth.cpp | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index 60b90e4bf0..c4a0539750 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -78,8 +78,8 @@ Heap::CallContext *ExecutionContext::newCallContext(Function *function, CallData c->activation = 0; c->compilationUnit = function->compilationUnit; - c->lookups = c->compilationUnit->runtimeLookups; - c->constantTable = c->compilationUnit->constants; + c->lookups = function->compilationUnit->runtimeLookups; + c->constantTable = function->compilationUnit->constants; c->locals = (Value *)((quintptr(c + 1) + 7) & ~7); const CompiledData::Function *compiledFunction = function->compiledFunction; diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index 3c779e52a3..d0496d319e 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -61,7 +61,7 @@ class QQmlContextData; namespace QV4 { namespace CompiledData { -struct CompilationUnit; +struct CompilationUnitBase; struct Function; } @@ -126,7 +126,7 @@ struct ExecutionContext : Base { Pointer outer; Lookup *lookups; const QV4::Value *constantTable; - CompiledData::CompilationUnit *compilationUnit; + CompiledData::CompilationUnitBase *compilationUnit; ContextType type : 8; bool strictMode : 8; diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 6590054bf3..25748720aa 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -300,7 +300,7 @@ void RuntimeHelpers::numberToString(QString *result, double num, int radix) ReturnedValue Runtime::method_closure(ExecutionEngine *engine, int functionId) { - QV4::Function *clos = engine->current->compilationUnit->runtimeFunctions[functionId]; + QV4::Function *clos = static_cast(engine->current->compilationUnit)->runtimeFunctions[functionId]; Q_ASSERT(clos); return FunctionObject::createScriptFunction(engine->currentContext, clos)->asReturnedValue(); } @@ -1301,7 +1301,7 @@ ReturnedValue Runtime::method_arrayLiteral(ExecutionEngine *engine, Value *value ReturnedValue Runtime::method_objectLiteral(ExecutionEngine *engine, const QV4::Value *args, int classId, int arrayValueCount, int arrayGetterSetterCountAndFlags) { Scope scope(engine); - QV4::InternalClass *klass = engine->current->compilationUnit->runtimeClasses[classId]; + QV4::InternalClass *klass = static_cast(engine->current->compilationUnit)->runtimeClasses[classId]; ScopedObject o(scope, engine->newObject(klass, engine->objectPrototype())); { @@ -1413,7 +1413,7 @@ ReturnedValue Runtime::method_getQmlContext(NoThrowEngine *engine) ReturnedValue Runtime::method_regexpLiteral(ExecutionEngine *engine, int id) { - return engine->current->compilationUnit->runtimeRegularExpressions[id].asReturnedValue(); + return static_cast(engine->current->compilationUnit)->runtimeRegularExpressions[id].asReturnedValue(); } ReturnedValue Runtime::method_getQmlQObjectProperty(ExecutionEngine *engine, const Value &object, int propertyIndex, bool captureRequired) diff --git a/src/qml/jsruntime/qv4script_p.h b/src/qml/jsruntime/qv4script_p.h index f96f0254a5..4ebe2dd609 100644 --- a/src/qml/jsruntime/qv4script_p.h +++ b/src/qml/jsruntime/qv4script_p.h @@ -72,7 +72,7 @@ struct ContextStateSaver { bool strictMode; Lookup *lookups; const QV4::Value *constantTable; - CompiledData::CompilationUnit *compilationUnit; + CompiledData::CompilationUnitBase *compilationUnit; int lineNumber; ContextStateSaver(const Scope &scope, ExecutionContext *context) diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index 17091819ee..075a9a4a5d 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -404,7 +404,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code Q_ALLOCA_VAR(QV4::Value*, scopes, sizeof(QV4::Value *)*(2 + 2*scopeDepth)); { - scopes[0] = const_cast(context->d()->compilationUnit->constants); + scopes[0] = const_cast(static_cast(context->d()->compilationUnit)->constants); // stack gets setup in push instruction scopes[1] = 0; QV4::Heap::ExecutionContext *scope = context->d(); @@ -451,7 +451,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code MOTH_BEGIN_INSTR(LoadRegExp) // TRACE(value, "%s", instr.value.toString(context)->toQString().toUtf8().constData()); - VALUE(instr.result) = context->d()->compilationUnit->runtimeRegularExpressions[instr.regExpId]; + VALUE(instr.result) = static_cast(context->d()->compilationUnit)->runtimeRegularExpressions[instr.regExpId]; MOTH_END_INSTR(LoadRegExp) MOTH_BEGIN_INSTR(LoadClosure) -- cgit v1.2.3 From cbdf28b078bbe0ce4136013ecdba1511fc926601 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 14 Mar 2017 17:02:59 +0100 Subject: Protect ExecutionContext member usage against word size differences Ensure the offsets we're taking from ExecutionContext members in the JIT code generator can be translated from host architecture sizes to target architecture, using assertions and a memory layout that we already have in the dev branch with commit 4de7e48ab160dacc7a09360e80264eac4945a8f4. Task-number: QTBUG-58666 Change-Id: I26cdbd1ddb995b116624fab16f7caba5d21c13b5 Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4context_p.h | 41 ++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index d0496d319e..968f625e5c 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -101,7 +101,37 @@ namespace Heap { struct QmlContext; -struct ExecutionContext : Base { +// ### Temporary arrangment until this code hits the dev branch and +// can use the Members macro +struct ExecutionContextData { + CallData *callData; + ExecutionEngine *engine; + ExecutionContext *outer; + Lookup *lookups; + const QV4::Value *constantTable; + CompiledData::CompilationUnitBase *compilationUnit; + // as member of non-pointer size this has to come last to preserve the ability to + // translate offsetof of it between 64-bit and 32-bit. + int lineNumber; +#if QT_POINTER_SIZE == 8 + uint padding_; +#endif +}; + +Q_STATIC_ASSERT(std::is_standard_layout::value); +Q_STATIC_ASSERT(offsetof(ExecutionContextData, callData) == 0); +Q_STATIC_ASSERT(offsetof(ExecutionContextData, engine) == offsetof(ExecutionContextData, callData) + QT_POINTER_SIZE); +Q_STATIC_ASSERT(offsetof(ExecutionContextData, outer) == offsetof(ExecutionContextData, engine) + QT_POINTER_SIZE); +Q_STATIC_ASSERT(offsetof(ExecutionContextData, lookups) == offsetof(ExecutionContextData, outer) + QT_POINTER_SIZE); +Q_STATIC_ASSERT(offsetof(ExecutionContextData, constantTable) == offsetof(ExecutionContextData, lookups) + QT_POINTER_SIZE); +Q_STATIC_ASSERT(offsetof(ExecutionContextData, compilationUnit) == offsetof(ExecutionContextData, constantTable) + QT_POINTER_SIZE); +Q_STATIC_ASSERT(offsetof(ExecutionContextData, lineNumber) == offsetof(ExecutionContextData, compilationUnit) + QT_POINTER_SIZE); + +struct ExecutionContextSizeStruct : public Base, public ExecutionContextData {}; + +struct ExecutionContext : Base, public ExecutionContextData { + static Q_CONSTEXPR size_t baseOffset = sizeof(ExecutionContextSizeStruct) - sizeof(ExecutionContextData); + enum ContextType { Type_GlobalContext = 0x1, Type_CatchContext = 0x2, @@ -120,17 +150,8 @@ struct ExecutionContext : Base { lineNumber = -1; } - CallData *callData; - - ExecutionEngine *engine; - Pointer outer; - Lookup *lookups; - const QV4::Value *constantTable; - CompiledData::CompilationUnitBase *compilationUnit; - ContextType type : 8; bool strictMode : 8; - int lineNumber; }; V4_ASSERT_IS_TRIVIAL(ExecutionContext) -- cgit v1.2.3 From 7a125135e1ef592aa20a29f7aac1a6117a6b1770 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 15 Mar 2017 08:25:56 +0100 Subject: Protect CallContext member usage against word size differences Ensure the offsets we're taking from ExecutionContext members in the JIT code generator can be translated from host architecture sizes to target architecture, using assertions and a memory layout that we already have in the dev branch with commit 4de7e48ab160dacc7a09360e80264eac4945a8f4. Change-Id: I1b26ef265234b05a6e5c8688a8aad2f33cd28783 Task-number: QTBUG-58666 Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4context_p.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index 968f625e5c..c769dcd142 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -150,12 +150,28 @@ struct ExecutionContext : Base, public ExecutionContextData { lineNumber = -1; } - ContextType type : 8; + quint8 type; bool strictMode : 8; +#if QT_POINTER_SIZE == 8 + quint8 padding_[6]; +#else + quint8 padding_[2]; +#endif }; V4_ASSERT_IS_TRIVIAL(ExecutionContext) +Q_STATIC_ASSERT(sizeof(ExecutionContext) == sizeof(Base) + sizeof(ExecutionContextData) + QT_POINTER_SIZE); + +struct CallContextData { + Value *locals; +}; + +Q_STATIC_ASSERT(std::is_standard_layout::value); +Q_STATIC_ASSERT(offsetof(CallContextData, locals) == 0); -struct CallContext : ExecutionContext { +struct CallContextSizeStruct : public ExecutionContext, public CallContextData {}; + +struct CallContext : ExecutionContext, public CallContextData { + static Q_CONSTEXPR size_t baseOffset = sizeof(CallContextSizeStruct) - sizeof(CallContextData); static CallContext *createSimpleContext(ExecutionEngine *v4); void freeSimpleCallContext(); @@ -168,7 +184,6 @@ struct CallContext : ExecutionContext { Pointer function; QV4::Function *v4Function; - Value *locals; Pointer activation; }; V4_ASSERT_IS_TRIVIAL(CallContext) -- cgit v1.2.3 From 4db21fe60e9a852298e12d7fce7b5d2bbde7443e Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Wed, 15 Mar 2017 09:25:52 +0100 Subject: Complete transition to standard layout classes for JIT access Move the Runtime function pointer array into EngineBase so that we can eliminate the last use of qOffsetOf. For improved cache locality the memory manager point is now also located in the EngineBase. Change-Id: I0b3cf44c726aa4fb8db1206cc414a56c2f522a84 Task-number: QTBUG-58666 Reviewed-by: Lars Knoll --- src/qml/jsruntime/qv4engine.cpp | 3 ++- src/qml/jsruntime/qv4engine_p.h | 6 ------ src/qml/jsruntime/qv4global_p.h | 2 -- src/qml/jsruntime/qv4runtime.cpp | 8 ++++++++ src/qml/jsruntime/qv4runtimeapi_p.h | 10 ++-------- src/qml/jsruntime/qv4value_p.h | 2 -- 6 files changed, 12 insertions(+), 19 deletions(-) (limited to 'src/qml/jsruntime') diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 3f11e51799..83b00f0356 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -131,7 +131,6 @@ qint32 ExecutionEngine::maxCallDepth = -1; ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) : callDepth(0) - , memoryManager(new QV4::MemoryManager(this)) , executableAllocator(new QV4::ExecutableAllocator) , regExpAllocator(new QV4::ExecutableAllocator) , currentContext(0) @@ -149,6 +148,8 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) , m_profiler(0) #endif { + memoryManager = new QV4::MemoryManager(this); + if (maxCallDepth == -1) { bool ok = false; maxCallDepth = qEnvironmentVariableIntValue("QV4_MAX_CALL_DEPTH", &ok); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 0492191747..5182f24235 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -54,7 +54,6 @@ #include "private/qv4isel_p.h" #include "qv4managed_p.h" #include "qv4context_p.h" -#include "qv4runtimeapi_p.h" #include #ifndef V4_BOOTSTRAP @@ -97,13 +96,8 @@ private: friend struct ExecutionContext; friend struct Heap::ExecutionContext; public: - // This must be the first member, so that its offset is a multiple of QT_POINTER_SIZE - // as the base class's size is. - Runtime runtime; - qint32 callDepth; - MemoryManager *memoryManager; ExecutableAllocator *executableAllocator; ExecutableAllocator *regExpAllocator; QScopedPointer iselFactory; diff --git a/src/qml/jsruntime/qv4global_p.h b/src/qml/jsruntime/qv4global_p.h index 66861bf697..c2a5e75a1f 100644 --- a/src/qml/jsruntime/qv4global_p.h +++ b/src/qml/jsruntime/qv4global_p.h @@ -89,8 +89,6 @@ inline bool signbit(double d) { return _copysign(1.0, d) < 0; } inline double trunc(double d) { return d > 0 ? floor(d) : ceil(d); } #endif -#define qOffsetOf(s, m) ((size_t)((((char *)&(((s *)64)->m)) - 64))) - // Decide whether to enable or disable the JIT // White list architectures diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 25748720aa..97fd533af2 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -219,6 +219,14 @@ void RuntimeCounters::count(const char *func, uint tag1, uint tag2) #endif // QV4_COUNT_RUNTIME_FUNCTIONS #ifndef V4_BOOTSTRAP + +Runtime::Runtime() +{ +#define INIT_METHOD(returnvalue, name, args) runtimeMethods[name] = reinterpret_cast(&method_##name); +FOR_EACH_RUNTIME_METHOD(INIT_METHOD) +#undef INIT_METHOD +} + void RuntimeHelpers::numberToString(QString *result, double num, int radix) { Q_ASSERT(result); diff --git a/src/qml/jsruntime/qv4runtimeapi_p.h b/src/qml/jsruntime/qv4runtimeapi_p.h index 2c898a1880..302facba06 100644 --- a/src/qml/jsruntime/qv4runtimeapi_p.h +++ b/src/qml/jsruntime/qv4runtimeapi_p.h @@ -56,6 +56,7 @@ QT_BEGIN_NAMESPACE namespace QV4 { +typedef uint Bool; struct NoThrowEngine; namespace { @@ -223,12 +224,7 @@ struct ExceptionCheck { F(void, setQmlQObjectProperty, (ExecutionEngine *engine, const Value &object, int propertyIndex, const Value &value)) struct Q_QML_PRIVATE_EXPORT Runtime { - Runtime() - { -#define INIT_METHOD(returnvalue, name, args) runtimeMethods[name] = reinterpret_cast(&method_##name); -FOR_EACH_RUNTIME_METHOD(INIT_METHOD) -#undef INIT_METHOD - } + Runtime(); typedef ReturnedValue (*UnaryOperation)(const Value &value); typedef ReturnedValue (*BinaryOperation)(const Value &left, const Value &right); @@ -259,8 +255,6 @@ static_assert(std::is_standard_layout::value, "Runtime needs to be stan static_assert(offsetof(Runtime, runtimeMethods) == 0, "JIT expects this to be the first member"); static_assert(sizeof(Runtime::BinaryOperation) == sizeof(void*), "JIT expects a function pointer to fit into a regular pointer, for cross-compilation offset translation"); -#undef FOR_EACH_RUNTIME_METHOD - } // namespace QV4 QT_END_NAMESPACE diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 4ff0565f9b..5662432f0d 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -68,8 +68,6 @@ namespace Heap { struct Base; } -typedef uint Bool; - struct Q_QML_PRIVATE_EXPORT Value { private: -- cgit v1.2.3