aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@live.com>2014-02-27 15:59:39 -0600
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-28 19:01:21 +0100
commita3688bf41fd42befe7ab83a633dbbd71eda56cd9 (patch)
tree042d3b4a4a78f6787a6c641e09ff957b62b40aa5
parent0b2d05093c6fc030d40be8c873ad1e0af9bba8cc (diff)
Improve memory usage in QML/V4 engine.
* Don't create prototype Object for bindings and signal handlers. It is inaccessible and not required. This saves one Object-sized allocation per binding. * Shrink the size of QQmlContextWrapper by removing the v8 member variable. * Shrink the size of QObjectWrapper by moving the destroy identifier to the engine. Change-Id: I76e84e4c0581e97a19d2e959f814ac84d9c431fa Task-number: QTBUG-37134 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
-rw-r--r--src/qml/jsruntime/qv4engine.cpp2
-rw-r--r--src/qml/jsruntime/qv4engine_p.h1
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp8
-rw-r--r--src/qml/jsruntime/qv4functionobject_p.h4
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp8
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper_p.h1
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp2
-rw-r--r--src/qml/qml/qqmlcontextwrapper.cpp7
-rw-r--r--src/qml/qml/qqmlcontextwrapper_p.h3
-rw-r--r--src/qml/qml/qqmlobjectcreator.cpp2
-rw-r--r--src/qml/qml/qqmlvme.cpp4
11 files changed, 21 insertions, 21 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 885186e86b..56ca31c85d 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -246,6 +246,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
id_index = newIdentifier(QStringLiteral("index"));
id_input = newIdentifier(QStringLiteral("input"));
id_toString = newIdentifier(QStringLiteral("toString"));
+ id_destroy = newIdentifier(QStringLiteral("destroy"));
id_valueOf = newIdentifier(QStringLiteral("valueOf"));
ObjectPrototype *objectPrototype = new (memoryManager) ObjectPrototype(InternalClass::create(this, ObjectPrototype::staticVTable(), 0));
@@ -863,6 +864,7 @@ void ExecutionEngine::markObjects()
id_index->mark(this);
id_input->mark(this);
id_toString->mark(this);
+ id_destroy->mark(this);
id_valueOf->mark(this);
objectCtor.mark(this);
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index d8ac750e75..4bf95c4868 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -263,6 +263,7 @@ public:
StringValue id_index;
StringValue id_input;
StringValue id_toString;
+ StringValue id_destroy;
StringValue id_valueOf;
QSet<CompiledData::CompilationUnit*> compilationUnits;
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 07ec94a58d..66e956e43c 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -183,14 +183,14 @@ void FunctionObject::markObjects(Managed *that, ExecutionEngine *e)
Object::markObjects(that, e);
}
-FunctionObject *FunctionObject::creatScriptFunction(ExecutionContext *scope, Function *function)
+FunctionObject *FunctionObject::creatScriptFunction(ExecutionContext *scope, Function *function, bool createProto)
{
if (function->needsActivation() ||
function->compiledFunction->flags & CompiledData::Function::HasCatchOrWith ||
function->compiledFunction->nFormals > QV4::Global::ReservedArgumentCount ||
function->isNamedExpression())
return new (scope->engine->memoryManager) ScriptFunction(scope, function);
- return new (scope->engine->memoryManager) SimpleScriptFunction(scope, function);
+ return new (scope->engine->memoryManager) SimpleScriptFunction(scope, function, createProto);
}
ReturnedValue FunctionObject::protoProperty()
@@ -482,8 +482,8 @@ ReturnedValue ScriptFunction::call(Managed *that, CallData *callData)
DEFINE_OBJECT_VTABLE(SimpleScriptFunction);
-SimpleScriptFunction::SimpleScriptFunction(ExecutionContext *scope, Function *function)
- : FunctionObject(scope, function->name, true)
+SimpleScriptFunction::SimpleScriptFunction(ExecutionContext *scope, Function *function, bool createProto)
+ : FunctionObject(scope, function->name, createProto)
{
setVTable(staticVTable());
diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h
index af4ec024d5..1f5bced8f8 100644
--- a/src/qml/jsruntime/qv4functionobject_p.h
+++ b/src/qml/jsruntime/qv4functionobject_p.h
@@ -137,7 +137,7 @@ struct Q_QML_EXPORT FunctionObject: Object {
return v.asFunctionObject();
}
- static FunctionObject *creatScriptFunction(ExecutionContext *scope, Function *function);
+ static FunctionObject *creatScriptFunction(ExecutionContext *scope, Function *function, bool createProto = true);
ReturnedValue protoProperty();
InternalClass *internalClassForConstructor();
@@ -221,7 +221,7 @@ struct ScriptFunction: FunctionObject {
struct SimpleScriptFunction: FunctionObject {
V4_OBJECT
- SimpleScriptFunction(ExecutionContext *scope, Function *function);
+ SimpleScriptFunction(ExecutionContext *scope, Function *function, bool createProto);
static ReturnedValue construct(Managed *, CallData *callData);
static ReturnedValue call(Managed *that, CallData *callData);
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index 7f4ac22377..14533946e1 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -245,8 +245,6 @@ QObjectWrapper::QObjectWrapper(ExecutionEngine *engine, QObject *object)
Scope scope(engine);
ScopedObject protectThis(scope, this);
-
- m_destroy = engine->newIdentifier(QStringLiteral("destroy"));
}
void QObjectWrapper::initializeBindings(ExecutionEngine *engine)
@@ -282,8 +280,8 @@ ReturnedValue QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextD
QV4::Scope scope(ctx);
QV4::ScopedString name(scope, n);
- if (name->equals(m_destroy) || name->equals(scope.engine->id_toString)) {
- int index = name->equals(m_destroy) ? QV4::QObjectMethod::DestroyMethod : QV4::QObjectMethod::ToStringMethod;
+ if (name->equals(scope.engine->id_destroy) || name->equals(scope.engine->id_toString)) {
+ int index = name->equals(scope.engine->id_destroy) ? QV4::QObjectMethod::DestroyMethod : QV4::QObjectMethod::ToStringMethod;
QV4::ScopedValue method(scope, QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, index));
if (hasProperty)
*hasProperty = true;
@@ -695,7 +693,7 @@ PropertyAttributes QObjectWrapper::query(const Managed *m, StringRef name)
QQmlContextData *qmlContext = QV4::QmlContextWrapper::callingContext(engine);
QQmlPropertyData local;
if (that->findProperty(engine, qmlContext, name, IgnoreRevision, &local)
- || name->equals(const_cast<StringValue &>(that->m_destroy)) || name->equals(engine->id_toString))
+ || name->equals(engine->id_destroy) || name->equals(engine->id_toString))
return QV4::Attr_Data;
else
return QV4::Object::query(m, name);
diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h
index ca38c5b0dc..b11f0af93f 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper_p.h
+++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h
@@ -111,7 +111,6 @@ private:
QQmlPropertyData *findProperty(ExecutionEngine *engine, QQmlContextData *qmlContext, String *name, RevisionMode revisionMode, QQmlPropertyData *local) const;
QPointer<QObject> m_object;
- StringValue m_destroy;
static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty);
static void put(Managed *m, const StringRef name, const ValueRef value);
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index a3ba4b0d75..2b63632780 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -1297,7 +1297,7 @@ ReturnedValue __qmljs_get_imported_scripts(NoThrowContext *ctx)
QV4::ReturnedValue __qmljs_get_qml_singleton(QV4::NoThrowContext *ctx, const QV4::StringRef name)
{
- return ctx->engine->qmlContextObject()->getPointer()->as<QmlContextWrapper>()->qmlSingletonWrapper(name);
+ return ctx->engine->qmlContextObject()->getPointer()->as<QmlContextWrapper>()->qmlSingletonWrapper(ctx->engine->v8Engine, name);
}
void __qmljs_builtin_convert_this_to_object(ExecutionContext *ctx)
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp
index d221e072f7..1660e3aeb1 100644
--- a/src/qml/qml/qqmlcontextwrapper.cpp
+++ b/src/qml/qml/qqmlcontextwrapper.cpp
@@ -63,7 +63,7 @@ DEFINE_OBJECT_VTABLE(QmlContextWrapper);
QmlContextWrapper::QmlContextWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext)
: Object(QV8Engine::getV4(engine)),
- v8(engine), readOnly(true), ownsContext(ownsContext), isNullWrapper(false),
+ readOnly(true), ownsContext(ownsContext), isNullWrapper(false),
context(context), scopeObject(scopeObject), idObjectsWrapper(0)
{
setVTable(staticVTable());
@@ -181,7 +181,7 @@ ReturnedValue QmlContextWrapper::get(Managed *m, const StringRef name, bool *has
// context = context->parent
// }
- QV8Engine *engine = resource->v8;
+ QV8Engine *engine = v4->v8Engine;
QObject *scopeObject = resource->getScopeObject();
@@ -413,7 +413,7 @@ ReturnedValue QmlContextWrapper::idObjectsArray()
return idObjectsWrapper->asReturnedValue();
}
-ReturnedValue QmlContextWrapper::qmlSingletonWrapper(const StringRef &name)
+ReturnedValue QmlContextWrapper::qmlSingletonWrapper(QV8Engine *v8, const StringRef &name)
{
if (!context->imports)
return Encode::undefined();
@@ -423,6 +423,7 @@ ReturnedValue QmlContextWrapper::qmlSingletonWrapper(const StringRef &name)
Q_ASSERT(r.isValid());
Q_ASSERT(r.type);
Q_ASSERT(r.type->isSingleton());
+ Q_ASSERT(v8);
QQmlEngine *e = v8->engine();
QQmlType::SingletonInstanceInfo *siinfo = r.type->singletonInstanceInfo();
diff --git a/src/qml/qml/qqmlcontextwrapper_p.h b/src/qml/qml/qqmlcontextwrapper_p.h
index 0ecec93652..3facf71aa0 100644
--- a/src/qml/qml/qqmlcontextwrapper_p.h
+++ b/src/qml/qml/qqmlcontextwrapper_p.h
@@ -97,9 +97,8 @@ struct Q_QML_EXPORT QmlContextWrapper : Object
static void registerQmlDependencies(ExecutionEngine *context, const CompiledData::Function *compiledFunction);
ReturnedValue idObjectsArray();
- ReturnedValue qmlSingletonWrapper(const StringRef &name);
+ ReturnedValue qmlSingletonWrapper(QV8Engine *e, const StringRef &name);
- QV8Engine *v8; // ### temporary, remove
bool readOnly;
bool ownsContext;
bool isNullWrapper;
diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp
index 7085915faa..32f3fe73fa 100644
--- a/src/qml/qml/qqmlobjectcreator.cpp
+++ b/src/qml/qml/qqmlobjectcreator.cpp
@@ -743,7 +743,7 @@ bool QQmlObjectCreator::setPropertyBinding(QQmlPropertyData *property, const QV4
QV4::Function *runtimeFunction = compiledData->compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex];
QV4::Scope scope(_qmlContext);
- QV4::ScopedFunctionObject function(scope, QV4::FunctionObject::creatScriptFunction(_qmlContext, runtimeFunction));
+ QV4::ScopedFunctionObject function(scope, QV4::FunctionObject::creatScriptFunction(_qmlContext, runtimeFunction, /*createProto*/ false));
if (binding->flags & QV4::CompiledData::Binding::IsSignalHandlerExpression) {
int signalIndex = _propertyCache->methodIndexToSignalIndex(property->coreIndex);
diff --git a/src/qml/qml/qqmlvme.cpp b/src/qml/qml/qqmlvme.cpp
index ce4997fef9..83c1f6595c 100644
--- a/src/qml/qml/qqmlvme.cpp
+++ b/src/qml/qml/qqmlvme.cpp
@@ -800,7 +800,7 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
QV4::Function *runtimeFunction = COMP->compilationUnit->runtimeFunctions[instr.runtimeFunctionIndex];
- tmpValue = QV4::FunctionObject::creatScriptFunction(qmlContext, runtimeFunction);
+ tmpValue = QV4::FunctionObject::creatScriptFunction(qmlContext, runtimeFunction, /*createProto*/ false);
QQmlBoundSignal *bs = new QQmlBoundSignal(target, instr.signalIndex, target, engine);
QQmlBoundSignalExpression *expr =
@@ -862,7 +862,7 @@ QObject *QQmlVME::run(QList<QQmlError> *errors,
QV4::Function *runtimeFunction = COMP->compilationUnit->runtimeFunctions[instr.functionIndex];
- tmpValue = QV4::FunctionObject::creatScriptFunction(qmlContext, runtimeFunction);
+ tmpValue = QV4::FunctionObject::creatScriptFunction(qmlContext, runtimeFunction, /*createProto*/ false);
QQmlBinding *bind = new QQmlBinding(tmpValue, context, CTXT, COMP->name, instr.line, instr.column);
bindValues.push(bind);