diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-07-27 11:47:53 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-01 09:42:06 +0000 |
commit | e99038b24d8b9f4a8cc503d1e3f789a93a3e8330 (patch) | |
tree | 05a43cf4833f5eba65f54e7fbb61fa49575ba14d /src/qml/compiler/qv4compileddata_p.h | |
parent | 73fc89bb0dbe9a866e7b1cf47a42a85e5042fead (diff) |
Reduce memory consumption when loading AOT generated cache files
Separate the qml data (objects/imports) from the general compilation
unit data. It's only the former that needs to be re-generated as part of
the type re-compilation and by separating it we can allocate memory just
for that and keep using the mmap'ed general unit data for everything
else (including byte code).
Another upside of this change is that it allows eliminating the recently
introduced concept of a backing unit again.
Saves ~149K RAM with the QQC1 gallery.
Task-number: QTBUG-69588
Change-Id: Ie88a4286feb7e2f472f58a28fa5dd6ff0a91c4b6
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compileddata_p.h')
-rw-r--r-- | src/qml/compiler/qv4compileddata_p.h | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index 54c7a242de..c3cc38e193 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -753,6 +753,25 @@ struct Import }; static_assert(sizeof(Import) == 24, "Import structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); +struct QmlUnit +{ + quint32_le nImports; + quint32_le offsetToImports; + quint32_le nObjects; + quint32_le offsetToObjects; + + const Import *importAt(int idx) const { + return reinterpret_cast<const Import*>((reinterpret_cast<const char *>(this)) + offsetToImports + idx * sizeof(Import)); + } + + const Object *objectAt(int idx) const { + const quint32_le *offsetTable = reinterpret_cast<const quint32_le*>((reinterpret_cast<const char *>(this)) + offsetToObjects); + const quint32_le offset = offsetTable[idx]; + return reinterpret_cast<const Object*>(reinterpret_cast<const char*>(this) + offset); + } +}; +static_assert(sizeof(QmlUnit) == 16, "QmlUnit structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); + enum { QmlCompileHashSpace = 48 }; static const char magic_str[] = "qv4cdata"; extern const char qml_compile_hash[QmlCompileHashSpace + 1]; @@ -804,24 +823,14 @@ struct Unit quint32_le sourceFileIndex; quint32_le finalUrlIndex; - /* QML specific fields */ - quint32_le nImports; - quint32_le offsetToImports; - quint32_le nObjects; - quint32_le offsetToObjects; - - quint32_le padding; + quint32_le offsetToQmlUnit; bool verifyHeader(QDateTime expectedSourceTimeStamp, QString *errorString) const; - const Import *importAtInternal(int idx) const { - return reinterpret_cast<const Import*>((reinterpret_cast<const char *>(this)) + offsetToImports + idx * sizeof(Import)); - } + /* QML specific fields */ - const Object *objectAtInternal(int idx) const { - const quint32_le *offsetTable = reinterpret_cast<const quint32_le*>((reinterpret_cast<const char *>(this)) + offsetToObjects); - const quint32_le offset = offsetTable[idx]; - return reinterpret_cast<const Object*>(reinterpret_cast<const char*>(this) + offset); + const QmlUnit *qmlUnit() const { + return reinterpret_cast<const QmlUnit *>(reinterpret_cast<const char *>(this) + offsetToQmlUnit); } bool isSingleton() const { @@ -897,7 +906,7 @@ struct Unit } }; -static_assert(sizeof(Unit) == 216, "Unit structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); +static_assert(sizeof(Unit) == 200, "Unit structure needs to have the expected size to be binary compatible on disk when generated by host compiler and loaded by target"); struct TypeReference { @@ -992,6 +1001,7 @@ Q_STATIC_ASSERT(offsetof(CompilationUnitBase, runtimeRegularExpressions) == offs struct Q_QML_PRIVATE_EXPORT CompilationUnit final : public CompilationUnitBase { const Unit *data = nullptr; + const QmlUnit *qmlData = nullptr; public: CompilationUnit(const Unit *unitData = nullptr); #ifdef V4_BOOTSTRAP @@ -1018,7 +1028,8 @@ public: } const Unit *unitData() const { return data; } - void setUnitData(const Unit *unitData); + void setUnitData(const Unit *unitData, const QmlUnit *qmlUnit = nullptr, + const QString &fileName = QString(), const QString &finalUrlString = QString()); #ifndef V4_BOOTSTRAP QIntrusiveListNode nextCompilationUnit; @@ -1032,8 +1043,8 @@ public: // finalUrl() and finalUrlString() shall be used to resolve further URLs referred to in the code // They are _not_ intercepted and thus represent the "logical" name for the code. - QString fileName() const { return stringAt(data->sourceFileIndex); } - QString finalUrlString() const { return stringAt(data->finalUrlIndex); } + QString fileName() const { return m_fileName; } + QString finalUrlString() const { return m_finalUrlString; } QUrl url() const { if (m_url.isNull) m_url = QUrl(fileName()); return m_url; } QUrl finalUrl() const { @@ -1080,25 +1091,18 @@ public: bool isRegisteredWithEngine = false; QScopedPointer<CompilationUnitMapper> backingFile; - const QV4::CompiledData::Unit *backingUnit = nullptr; QStringList dynamicStrings; // --- interface for QQmlPropertyCacheCreator typedef Object CompiledObject; - int objectCount() const { return data->nObjects; } - const Object *objectAt(int index) const { return data->objectAtInternal(index); } - int importCount() const { return data->nImports; } - const Import *importAt(int index) const { return data->importAtInternal(index); } + int objectCount() const { return qmlData->nObjects; } + const Object *objectAt(int index) const { return qmlData->objectAt(index); } + int importCount() const { return qmlData->nImports; } + const Import *importAt(int index) const { return qmlData->importAt(index); } QString stringAt(int index) const { - if (backingUnit) { - const qint32 backingUnitStringTableSize = backingUnit->stringTableSize; - if (index < backingUnitStringTableSize) - return backingUnit->stringAtInternal(index); - index -= backingUnitStringTableSize; - Q_ASSERT(data->stringTableSize == 0); - return dynamicStrings.at(index); - } + if (uint(index) >= data->stringTableSize) + return dynamicStrings.at(index - data->stringTableSize); return data->stringAtInternal(index); } @@ -1131,13 +1135,18 @@ protected: void linkBackendToEngine(QV4::ExecutionEngine *engine); quint32 totalStringCount() const - { return data->stringTableSize + (backingUnit ? backingUnit->stringTableSize : 0); } + { return data->stringTableSize; } +#else // V4_BOOTSTRAP + QString stringAt(int index) const { return data->stringAtInternal(index); } #endif // V4_BOOTSTRAP private: void destroy(); + QString m_fileName; // initialized from data->sourceFileIndex + QString m_finalUrlString; // initialized from data->finalUrlIndex + QAtomicInt refCount = 1; Q_NEVER_INLINE IdentifierHash createNamedObjectsPerComponent(int componentObjectIndex); |