diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-07-04 22:23:17 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-07-05 09:07:50 +0000 |
commit | d3a1a9e4fea5f6b623ebd13f43957ebbe5bfabea (patch) | |
tree | a45456e687e70def0065042fae0ed4ccec103fb4 /src | |
parent | 493edae038338320fb29a3eb252f76c2ff24b74f (diff) |
Unify SimpleCallContext and CallContext
Plan is to completely remove the need for the simple call context.
Change-Id: Ie5e4673a6746dc110adbf526e45188f218fd7bfc
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp | 14 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h | 4 | ||||
-rw-r--r-- | src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4context.cpp | 23 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4context_p.h | 69 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4enginebase_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4function_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4functionobject.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4vme_moth.cpp | 2 | ||||
-rw-r--r-- | src/qml/memory/qv4mm_p.h | 4 |
11 files changed, 50 insertions, 78 deletions
diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp index e89b7a63d4..6686e61a1c 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp @@ -55,11 +55,11 @@ QT_BEGIN_NAMESPACE -QV4::SimpleCallContext *QV4DataCollector::findContext(int frame) +QV4::CallContext *QV4DataCollector::findContext(int frame) { QV4::ExecutionContext *ctx = engine()->currentContext; while (ctx) { - QV4::SimpleCallContext *cCtxt = ctx->asSimpleCallContext(); + QV4::CallContext *cCtxt = ctx->asCallContext(); if (cCtxt && cCtxt->d()->v4Function) { if (frame < 1) return cCtxt; @@ -71,7 +71,7 @@ QV4::SimpleCallContext *QV4DataCollector::findContext(int frame) return 0; } -QV4::Heap::SimpleCallContext *QV4DataCollector::findScope(QV4::ExecutionContext *ctxt, int scope) +QV4::Heap::CallContext *QV4DataCollector::findScope(QV4::ExecutionContext *ctxt, int scope) { if (!ctxt) return 0; @@ -81,7 +81,7 @@ QV4::Heap::SimpleCallContext *QV4DataCollector::findScope(QV4::ExecutionContext for (; scope > 0 && ctx; --scope) ctx = ctx->d()->outer; - return (ctx && ctx->d()) ? ctx->asSimpleCallContext()->d() : 0; + return (ctx && ctx->d()) ? ctx->asCallContext()->d() : 0; } QVector<QV4::Heap::ExecutionContext::ContextType> QV4DataCollector::getScopeTypes(int frame) @@ -89,7 +89,7 @@ QVector<QV4::Heap::ExecutionContext::ContextType> QV4DataCollector::getScopeType QVector<QV4::Heap::ExecutionContext::ContextType> types; QV4::Scope scope(engine()); - QV4::SimpleCallContext *sctxt = findContext(frame); + QV4::CallContext *sctxt = findContext(frame); if (!sctxt || sctxt->d()->type < QV4::Heap::ExecutionContext::Type_QmlContext) return types; @@ -340,7 +340,7 @@ QJsonObject QV4DataCollector::buildFrame(const QV4::StackFrame &stackFrame, int QV4::Scope scope(engine()); QV4::ScopedContext ctxt(scope, findContext(frameNr)); while (ctxt) { - if (QV4::SimpleCallContext *cCtxt = ctxt->asSimpleCallContext()) { + if (QV4::CallContext *cCtxt = ctxt->asCallContext()) { if (cCtxt->d()->activation) break; } @@ -348,7 +348,7 @@ QJsonObject QV4DataCollector::buildFrame(const QV4::StackFrame &stackFrame, int } if (ctxt) { - QV4::ScopedValue o(scope, ctxt->asSimpleCallContext()->d()->activation); + QV4::ScopedValue o(scope, ctxt->d()->activation); frame[QLatin1String("receiver")] = toRef(collect(o)); } diff --git a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h index de12e8d527..2c2514a1b3 100644 --- a/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h +++ b/src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h @@ -58,11 +58,11 @@ public: typedef uint Ref; typedef QVector<uint> Refs; - static QV4::Heap::SimpleCallContext *findScope(QV4::ExecutionContext *ctxt, int scope); + static QV4::Heap::CallContext *findScope(QV4::ExecutionContext *ctxt, int scope); static int encodeScopeType(QV4::Heap::ExecutionContext::ContextType scopeType); QVector<QV4::Heap::ExecutionContext::ContextType> getScopeTypes(int frame); - QV4::SimpleCallContext *findContext(int frame); + QV4::CallContext *findContext(int frame); QV4DataCollector(QV4::ExecutionEngine *engine); diff --git a/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp index 5e4a8e3eb1..13425b36c2 100644 --- a/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp +++ b/src/plugins/qmltooling/qmldbg_nativedebugger/qqmlnativedebugservice.cpp @@ -480,7 +480,7 @@ void NativeDebugger::handleVariables(QJsonObject *response, const QJsonObject &a QJsonArray output; QV4::Scope scope(engine); - if (QV4::SimpleCallContext *callContext = executionContext->asSimpleCallContext()) { + if (QV4::CallContext *callContext = executionContext->asCallContext()) { QV4::Value thisObject = callContext->thisObject(); collector.collect(&output, QString(), QStringLiteral("this"), thisObject); QV4::Identifier *const *variables = callContext->variables(); diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index dd05539864..5f552b5515 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -54,7 +54,6 @@ using namespace QV4; DEFINE_MANAGED_VTABLE(ExecutionContext); -DEFINE_MANAGED_VTABLE(SimpleCallContext); DEFINE_MANAGED_VTABLE(CallContext); DEFINE_MANAGED_VTABLE(CatchContext); @@ -127,15 +126,14 @@ void ExecutionContext::createMutableBinding(String *name, bool deletable) while (ctx) { switch (ctx->d()->type) { case Heap::ExecutionContext::Type_CallContext: - case Heap::ExecutionContext::Type_SimpleCallContext: { - Heap::SimpleCallContext *c = static_cast<Heap::SimpleCallContext *>(ctx->d()); + case Heap::ExecutionContext::Type_SimpleCallContext: if (!activation) { + Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d()); if (!c->activation) c->activation.set(scope.engine, scope.engine->newObject()); activation = c->activation; } break; - } case Heap::ExecutionContext::Type_QmlContext: { // this is ugly, as it overrides the inner callcontext, but has to stay as long // as bindings still get their own callcontext @@ -143,8 +141,9 @@ void ExecutionContext::createMutableBinding(String *name, bool deletable) break; } case Heap::ExecutionContext::Type_GlobalContext: { + Q_ASSERT(scope.engine->globalObject->d() == ctx->d()->activation); if (!activation) - activation = scope.engine->globalObject; + activation = ctx->d()->activation; break; } default: @@ -176,22 +175,22 @@ void Heap::CatchContext::init(ExecutionContext *outerContext, String *exceptionV this->exceptionValue.set(internalClass->engine, exceptionValue); } -Identifier * const *SimpleCallContext::formals() const +Identifier * const *CallContext::formals() const { return d()->v4Function ? d()->v4Function->internalClass->nameMap.constData() : 0; } -unsigned int SimpleCallContext::formalCount() const +unsigned int CallContext::formalCount() const { return d()->v4Function ? d()->v4Function->nFormals : 0; } -Identifier * const *SimpleCallContext::variables() const +Identifier * const *CallContext::variables() const { return d()->v4Function ? d()->v4Function->internalClass->nameMap.constData() + d()->v4Function->nFormals : 0; } -unsigned int SimpleCallContext::variableCount() const +unsigned int CallContext::variableCount() const { return d()->v4Function ? d()->v4Function->compiledFunction->nLocals : 0; } @@ -263,7 +262,7 @@ void QV4::ExecutionContext::simpleCall(Scope &scope, CallData *callData, Functio ExecutionContextSaver ctxSaver(scope); - SimpleCallContext::Data *ctx = scope.engine->memoryManager->allocSimpleCallContext(); + CallContext::Data *ctx = scope.engine->memoryManager->allocSimpleCallContext(); ctx->strictMode = function->isStrict(); ctx->callData = callData; @@ -316,7 +315,7 @@ void ExecutionContext::setProperty(String *name, const Value &value) } case Heap::ExecutionContext::Type_CallContext: case Heap::ExecutionContext::Type_SimpleCallContext: { - Heap::SimpleCallContext *c = static_cast<Heap::SimpleCallContext *>(ctx->d()); + Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d()); if (c->v4Function) { uint index = c->v4Function->internalClass->find(id); if (index < UINT_MAX) { @@ -483,7 +482,7 @@ Function *ExecutionContext::getFunction() const Scope scope(engine()); ScopedContext it(scope, this->d()); for (; it; it = it->d()->outer) { - if (const SimpleCallContext *callCtx = it->asSimpleCallContext()) + if (const CallContext *callCtx = it->asCallContext()) return callCtx->d()->v4Function; else if (it->d()->type == Heap::ExecutionContext::Type_CatchContext || it->d()->type == Heap::ExecutionContext::Type_WithContext) diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index e6405350dd..3db9e72acf 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -68,7 +68,6 @@ struct Function; struct Function; struct Identifier; struct CallContext; -struct SimpleCallContext; struct CatchContext; struct QmlContext; struct QQmlContextWrapper; @@ -153,11 +152,13 @@ Q_STATIC_ASSERT(offsetof(ExecutionContextData, compilationUnit) == offsetof(Exec Q_STATIC_ASSERT(offsetof(ExecutionContextData, activation) == offsetof(ExecutionContextData, compilationUnit) + QT_POINTER_SIZE); Q_STATIC_ASSERT(offsetof(ExecutionContextData, lineNumber) == offsetof(ExecutionContextData, activation) + QT_POINTER_SIZE); -#define SimpleCallContextMembers(class, Member) \ - Member(class, NoMark, QV4::Function *, v4Function) +#define CallContextMembers(class, Member) \ + Member(class, NoMark, QV4::Function *, v4Function) \ + Member(class, Pointer, FunctionObject *, function) \ + Member(class, ValueArray, ValueArray, locals) -DECLARE_HEAP_OBJECT(SimpleCallContext, ExecutionContext) { - DECLARE_MARK_TABLE(SimpleCallContext); +DECLARE_HEAP_OBJECT(CallContext, ExecutionContext) { + DECLARE_MARK_TABLE(CallContext); void init(ContextType t = Type_SimpleCallContext) { @@ -167,35 +168,12 @@ DECLARE_HEAP_OBJECT(SimpleCallContext, ExecutionContext) { inline unsigned int formalParameterCount() const; }; -V4_ASSERT_IS_TRIVIAL(SimpleCallContext) -Q_STATIC_ASSERT(std::is_standard_layout<SimpleCallContextData>::value); -Q_STATIC_ASSERT(offsetof(SimpleCallContextData, v4Function) == 0); -Q_STATIC_ASSERT(sizeof(SimpleCallContextData) == QT_POINTER_SIZE); -Q_STATIC_ASSERT(sizeof(SimpleCallContext) == sizeof(ExecutionContext) + sizeof(SimpleCallContextData)); - -#if QT_POINTER_SIZE == 8 -#define CallContextMembers(class, Member) \ - Member(class, Pointer, FunctionObject *, function) \ - Member(class, ValueArray, ValueArray, locals) -#else -#define CallContextMembers(class, Member) \ - Member(class, Pointer, FunctionObject *, function) \ - Member(class, NoMark, void *, padding) \ - Member(class, ValueArray, ValueArray, locals) -#endif - -DECLARE_HEAP_OBJECT(CallContext, SimpleCallContext) { - DECLARE_MARK_TABLE(CallContext); - - using SimpleCallContext::formalParameterCount; -}; - +V4_ASSERT_IS_TRIVIAL(CallContext) Q_STATIC_ASSERT(std::is_standard_layout<CallContextData>::value); -Q_STATIC_ASSERT(offsetof(CallContextData, function) == 0); -// IMPORTANT: we cannot do offsetof(CallContextData, locals) in the JIT as the offset does not scale with -// the pointer size. On 32-bit ARM the offset of the ValueArray is aligned to 8 bytes, on 32-bit x86 for -// example it is not. Therefore we have a padding in place and always have a distance of 8 bytes. -Q_STATIC_ASSERT(offsetof(CallContextData, locals) == offsetof(CallContextData, function) + 8); +Q_STATIC_ASSERT(offsetof(CallContextData, v4Function) == 0); +Q_STATIC_ASSERT(offsetof(CallContextData, function) == QT_POINTER_SIZE); +Q_STATIC_ASSERT(offsetof(CallContextData, locals) == offsetof(CallContextData, function) + QT_POINTER_SIZE); +Q_STATIC_ASSERT(sizeof(CallContext) == sizeof(ExecutionContext) + sizeof(CallContextData)); #define CatchContextMembers(class, Member) \ Member(class, Pointer, String *, exceptionVarName) \ @@ -231,8 +209,8 @@ struct Q_QML_EXPORT ExecutionContext : public Managed ReturnedValue getPropertyAndBase(String *name, Value *base); bool deleteProperty(String *name); - inline SimpleCallContext *asSimpleCallContext(); - inline const SimpleCallContext *asSimpleCallContext() const; + inline CallContext *asCallContext(); + inline const CallContext *asCallContext() const; Function *getFunction() const; @@ -253,10 +231,10 @@ struct Q_QML_EXPORT ExecutionContext : public Managed void simpleCall(Scope &scope, CallData *callData, QV4::Function *function); }; -struct Q_QML_EXPORT SimpleCallContext : public ExecutionContext +struct Q_QML_EXPORT CallContext : public ExecutionContext { - V4_MANAGED(SimpleCallContext, ExecutionContext) - V4_INTERNALCLASS(SimpleCallContext) + V4_MANAGED(CallContext, ExecutionContext) + V4_INTERNALCLASS(CallContext) // formals are in reverse order Identifier * const *formals() const; @@ -267,28 +245,23 @@ struct Q_QML_EXPORT SimpleCallContext : public ExecutionContext inline ReturnedValue argument(int i) const; }; -inline ReturnedValue SimpleCallContext::argument(int i) const { +inline ReturnedValue CallContext::argument(int i) const { return i < argc() ? args()[i].asReturnedValue() : Primitive::undefinedValue().asReturnedValue(); } -struct Q_QML_EXPORT CallContext : public SimpleCallContext -{ - V4_MANAGED(CallContext, SimpleCallContext) -}; - struct CatchContext : public ExecutionContext { V4_MANAGED(CatchContext, ExecutionContext) }; -inline SimpleCallContext *ExecutionContext::asSimpleCallContext() +inline CallContext *ExecutionContext::asCallContext() { - return d()->type >= Heap::ExecutionContext::Type_SimpleCallContext ? static_cast<SimpleCallContext *>(this) : 0; + return d()->type >= Heap::ExecutionContext::Type_SimpleCallContext ? static_cast<CallContext *>(this) : 0; } -inline const SimpleCallContext *ExecutionContext::asSimpleCallContext() const +inline const CallContext *ExecutionContext::asCallContext() const { - return d()->type >= Heap::ExecutionContext::Type_SimpleCallContext ? static_cast<const SimpleCallContext *>(this) : 0; + return d()->type >= Heap::ExecutionContext::Type_SimpleCallContext ? static_cast<const CallContext *>(this) : 0; } } // namespace QV4 diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index f2f032df51..61b8d7e68d 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -192,7 +192,7 @@ ExecutionEngine::ExecutionEngine() internalClasses[Class_SimpleArrayData] = internalClasses[EngineBase::Class_Empty]->changeVTable(QV4::SimpleArrayData::staticVTable()); internalClasses[Class_SparseArrayData] = internalClasses[EngineBase::Class_Empty]->changeVTable(QV4::SparseArrayData::staticVTable()); internalClasses[Class_ExecutionContext] = internalClasses[EngineBase::Class_Empty]->changeVTable(QV4::ExecutionContext::staticVTable()); - internalClasses[Class_SimpleCallContext] = internalClasses[EngineBase::Class_Empty]->changeVTable(QV4::CallContext::staticVTable()); + internalClasses[Class_CallContext] = internalClasses[EngineBase::Class_Empty]->changeVTable(QV4::CallContext::staticVTable()); jsStrings[String_Empty] = newIdentifier(QString()); jsStrings[String_undefined] = newIdentifier(QStringLiteral("undefined")); @@ -896,7 +896,7 @@ QUrl ExecutionEngine::resolvedUrl(const QString &file) QUrl base; ExecutionContext *c = currentContext; while (c) { - SimpleCallContext *callCtx = c->asSimpleCallContext(); + CallContext *callCtx = c->asCallContext(); if (callCtx && callCtx->d()->v4Function) { base.setUrl(callCtx->d()->v4Function->sourceFile()); break; diff --git a/src/qml/jsruntime/qv4enginebase_p.h b/src/qml/jsruntime/qv4enginebase_p.h index 88f9dfd85c..b6ab0b7b68 100644 --- a/src/qml/jsruntime/qv4enginebase_p.h +++ b/src/qml/jsruntime/qv4enginebase_p.h @@ -90,7 +90,7 @@ struct EngineBase { Class_SimpleArrayData, Class_SparseArrayData, Class_ExecutionContext, - Class_SimpleCallContext, + Class_CallContext, Class_Object, Class_ArrayObject, Class_FunctionObject, diff --git a/src/qml/jsruntime/qv4function_p.h b/src/qml/jsruntime/qv4function_p.h index b11c8af94a..db651d2d0c 100644 --- a/src/qml/jsruntime/qv4function_p.h +++ b/src/qml/jsruntime/qv4function_p.h @@ -98,7 +98,7 @@ struct Q_QML_EXPORT Function { }; -inline unsigned int Heap::SimpleCallContext::formalParameterCount() const +inline unsigned int Heap::CallContext::formalParameterCount() const { return v4Function ? v4Function->nFormals : 0; } diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 85a86ee84f..960919b1ff 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -486,7 +486,7 @@ void IndexedBuiltinFunction::call(const Managed *that, Scope &scope, CallData *c ExecutionContextSaver ctxSaver(scope); - SimpleCallContext::Data *ctx = v4->memoryManager->allocSimpleCallContext(); + CallContext::Data *ctx = v4->memoryManager->allocSimpleCallContext(); ctx->strictMode = f->scope()->strictMode; // ### needed? scope or parent context? ctx->callData = callData; v4->pushContext(ctx); diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index ea59be3cf1..911a532236 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -414,7 +414,7 @@ QV4::ReturnedValue VME::exec(ExecutionEngine *engine, const uchar *code) int i = 0; while (scope) { if (scope->type == QV4::Heap::ExecutionContext::Type_SimpleCallContext) { - QV4::Heap::SimpleCallContext *cc = static_cast<QV4::Heap::SimpleCallContext *>(scope); + QV4::Heap::CallContext *cc = static_cast<QV4::Heap::CallContext *>(scope); scopes[2*i + 2] = { cc->callData->args, 0 }; scopes[2*i + 3] = { 0, 0 }; } else if (scope->type == QV4::Heap::ExecutionContext::Type_CallContext) { diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h index 17957d0cd6..5227cf23ad 100644 --- a/src/qml/memory/qv4mm_p.h +++ b/src/qml/memory/qv4mm_p.h @@ -214,8 +214,8 @@ public: QV4::Heap::CallContext *allocSimpleCallContext() { Heap::CallContext *ctxt = stackAllocator.allocate(); - memset(ctxt, 0, sizeof(Heap::SimpleCallContext)); - ctxt->internalClass = SimpleCallContext::defaultInternalClass(engine); + memset(ctxt, 0, sizeof(Heap::CallContext)); + ctxt->internalClass = CallContext::defaultInternalClass(engine); Q_ASSERT(ctxt->internalClass && ctxt->internalClass->vtable); ctxt->init(); return ctxt; |