Commit Graph

116 Commits

Author SHA1 Message Date
Simon Hausmann 5bd11b5a8c Avoid an extra stat() on the source .qml file when loading cache
For timestamp comparison it is not necessary to create another
QFileInfo() object and call exists() and lastModified(), when we can
pass that information through from the type loader.

Change-Id: I225cd36e672f1f390bddb4e6ebfafa3fc1269795
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-03-22 12:17:45 +00:00
Simon Hausmann 53547ee6b3 Clean up qOffsetOf usage
For offsets from CompiledData::Unit we can use C++11's offsetof macro as
the class has standard layout.

Change-Id: I7377294679a9cd79c35486fa34355933271f9251
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-03-17 08:35:58 +00:00
Simon Hausmann 94b52fd93b 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 <lars.knoll@qt.io>
2017-03-17 08:35:51 +00:00
Simon Hausmann e0add0b655 Fix relocation related errors when loading AOT caches
The original directory of the source file the cache was created from -
when generating ahead of time - is unlikely going to be identical to the
final location for example on a deployed device. Therefore when
generating caches ahead of time, don't store the source path, don't
attempt to verify it when loading and don't try to save the cache file
at run-time again.

We still need set the sourceFileIndex at load-time though, in order to
make relative path url resolution work (for example source: "my.png" in
an Image element).

Change-Id: I3d6952f5d0a165cfa2cb400191a9f6ffe6be69f4
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-03-09 08:19:56 +00:00
Simon Hausmann 55e558144d Fix time stamp related errors when loading AOT caches
Cache files created ahead of time do not require a timestamp match
towards the source file. This is because we cannot guarantee that all
transport mechanism from source to deployment preserve the timestamp at
the required resolution (if at all) and the source may also not be
present at all (obfuscated deployment chosen).

For cache files created at run-time however we'll continue to require
time stamp verification.

Change-Id: Ia7cdf3d063edd5bb1e6985089f1a666c970a0bd0
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-03-09 08:19:49 +00:00
Simon Hausmann 84a07bebc9 Fix crash when loading cache files generated ahead of time
The offset of the runtimeStrings array differed between a V4_BOOTSTRAP build
and the regular library build. This is an intermediate fix until QTBUG-58666
is fixed properly.

Change-Id: Id1310ffa82f1079c1acef7730db41186fa62610f
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-03-07 11:47:34 +00:00
Simon Hausmann 1102f6ca7f Fix qmlcachegen command line parameters
Add support for specifying the output file name

Change-Id: I3ec3cecae2334a7640baa928c0739c5521496d2d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-03-07 07:06:28 +00:00
Liang Qi b1fa22c168 Merge remote-tracking branch 'origin/5.8' into 5.9
Conflicts:
	src/qml/compiler/qv4ssa.cpp
	src/quick/accessible/qaccessiblequickview_p.h
	src/quick/items/qquickmousearea.cpp
	src/quick/util/qquickanimatorjob.cpp
	tools/qmlplugindump/main.cpp

Change-Id: I84474cf39895b9b757403971d2e9196e8c9d1809
2017-02-24 11:48:14 +01:00
Simon Hausmann eeb08d9537 Re-do QML type compilation of ahead-of-time generated QML cache files
As we currently lack the ability to do type resolution at AOT cache
generation time, we need to re-do the work after loading the cache file,
making us essentially only re-use the code and avoiding the step of
parsing.

Change-Id: I12844692d4766345d8a313b59d21abf1f868e2d1
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-01-31 17:09:26 +00:00
Kimmo Ollila a92950743f Add fixes for INTEGRITY
Full definitions of types are needed in static_casts.

Change-Id: I028ffc40a76cdb16cb297a181b3d9dfe9d09c945
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-31 13:39:59 +00:00
Simon Hausmann 4dfe1bc5ad Include the interpreter codegen and QML cache saving code in qmldevtools
Change-Id: Ic3f1476b87bfa7ab0c280c928e9ac97f92698336
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-01-28 19:05:03 +00:00
Tasuku Suzuki 6a8eb9ef8d Fix build without features.temporaryfile
Change-Id: I31bcf56ee0c4ec9285dccb356b03b89e8ce8356a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-27 09:20:29 +00:00
Robin Burchell be00fb4bff qml: Rename importCache vars to typeNameCache
This better reflects what it is, and especially removes some confusion in
QQmlTypeCompiler which has a m_importCache member (of type QQmlImports),
which lead to some strange-to-read things like this:

    m_importCache.populateCache(*importCache);

Which is now:

    m_importCache.populateCache(*typeNameCache);

Change-Id: I7590dd1ba71ca77a8d964250a0d517156b723f8e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-25 20:21:45 +00:00
Simon Hausmann f43dc181d7 Fix QML cache not being invalidated when source path changes
When somebody renames the directory name underneath a QML file and its
cache file, then we need to re-generate the cache as it contains the
fully path of the source path. That is sometimes used to resolve
relative URLs (such as images) and therefore needs updating (by
re-creating the cache).

Task-number: QTBUG-57644
Change-Id: I9766668859aad8e9d71f278c3f26c0585258c14e
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2017-01-02 09:55:07 +00:00
Lars Knoll e579076bb3 Get rid of most QT_NO_FOO usages
Instead use QT_CONFIG(foo). This change actually detected a few
mis-spelled macros and invalid usages.

Change-Id: I06ac327098dd1a458e6bc379d637b8e2dac52f85
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-11-29 10:10:27 +00:00
Simon Hausmann eb7ec4fb94 Fix handling of qrc:/// urls with disk caching
Use the right function for converting a qrc:/// url to a local path.
QUrl::toLocalFile() gives us an empty path, which prevents us from
getting a time stamp and comparing it against the stamp in the cache
file.

This fixes disk caching with samegame.

Change-Id: Id3eb270f1f7a7f25143d2f075a45f32bdb0384c5
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-11-23 13:06:27 +00:00
Simon Hausmann 2eda16de88 Fix bootstrap and qtquick compiler build
We need to always include the checksum generating code, even if dummy
(for the lack of the md5 code being in the bootstrap library).

Change-Id: I3dd9c585a23ffea9bd7c79dbe6dae29b9f93fa6d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-10-21 12:33:43 +00:00
Simon Hausmann f8918c43e8 Improve QML development experience
With the cache files it is tricky to do changes to the code generator
and it is easy to forget that the cache files need to be re-generated.
So facilitate this, we add the sha1 checksum of the QtQml library to the
checksum embedded in the cache files.

This is currently only implemented on Unixy platforms and it is limited
to developer builds with shared libraries. This is not intended for
release builds.

Change-Id: If59f31f700254f7e9c6e3384d2fae4e5396fb698
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-10-18 21:09:04 +00:00
Simon Hausmann 2c2c92d999 Fix excessive invalidation of QML disk caches
We use an MD5 checksum over the meta-object data to verify that the
types a QML file depends on haven't changed since the cache was
generated. However when the dependent types are QML types, then the
meta-object data contains dynamically generated type names such as
QMLTYPE_1234, which is non-deterministic. To address this, we resort to
the checksum over the meta-object data only for C++ types (if those
change it's likely an incompatible change) and for QML types use the
fact that all the information about the QML declared types comes from
the QML file only, which means we can in that case simply use a checksum
over the QV4::CompiledData memory chunk.

In addition we need to ensure that the generated CompiledData memory chunk
is deterministic by avoiding any uninitialized bytes (memset) and using
a map instead of a hash for the mapping of object index to object id.

Task-number: QTBUG-55926
Change-Id: I27c840b1960ad36b486198e504b70989c22a3972
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2016-10-18 13:26:50 +00:00
Simon Hausmann b40d005544 Enable disk cache for files coming from resources
By storing the cached data in QStandardPaths::CacheDir + "/qmlcache/"
+ sha1(filename)

Change-Id: I6a8b4ca701019204fff362504697c3dac9f54bf1
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-08-12 16:54:38 +00:00
Simon Hausmann 3cba637ea6 Separate header verification and mmap handling of CompiledData::Unit
...into a separate class. This will make it easier to specialize the
handling for Posix and Windows platforms.

Change-Id: I995538fa8239eac8586c96812086e50b4c19257f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-08-09 09:43:58 +00:00
Simon Hausmann 234e762265 Use on-disk compilation unit if available
If we succeeded in saving the compilation unit to disk, then attempt to use it
right away. This replaces the C++ heap usage for the compilation unit data as
well as the anonymous allocated executable memory with file-backed mmap'ed
memory. That means the memory can be discarded when overall availability is low
and paged in on-demand.

Change-Id: Ide1b1e11752d861eb049a99a26ca12cec5e2502e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2016-08-04 14:32:39 +00:00
Simon Hausmann 01575a22ea Fix interaction of files selectors with disk caching
Make sure to save the .qmlc/.jsc files to the location
determined by the file selectors.

Change-Id: If535bb1e4f0d20ac692b3d8e6d563f77cd00446b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2016-08-04 14:32:11 +00:00
Simon Hausmann d77e544a56 Safeguard disk cache loading with checksum verification
When loading a QML component from the disk cache, compare the checksum
of the dependent types against the checksum when the cache was created.
Any change in the meta-object of a dependent type should trigger a
re-creation discard of the cache and consequent re-creation (in the
test-case).

Unfortunately this also requires extending the existing hack in the unit
test to deal with the low second precision on HFS+ in order to pass the
tests.

Change-Id: Ib8e899347680f7be676788388e9c23a09b0277e3
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2016-08-04 14:32:08 +00:00
Simon Hausmann 0f4b84bc9d Fix build on QNX/Windows/MinGW
Oddly the include order is different and we need to include the header
for the class we use.

Change-Id: If8a7485b8b728b1d3565023f37234912a0e0feea
Reviewed-by: Liang Qi <liang.qi@qt.io>
2016-08-03 15:19:48 +00:00
Simon Hausmann c25c95ba22 Fix endianness in constant handling
When running on a big-endian system, we need to convert the constant values
into big-endian once and then it's possible to access them directly.

Change-Id: I655bad7b7734e3b95e79e5f688f0b4041d0c41c4
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2016-08-03 08:49:16 +00:00
Simon Hausmann 546679658e Don't save compilation units to disk that don't orignate from files
It's asking for trouble and we have no way of verifying that the source
changed.

Change-Id: I2ae2e975ef52142b8a6821b23f99ab3517ae3d49
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2016-08-02 16:17:25 +00:00
Simon Hausmann 54ee6994e6 Add a checksum to the generated QML compilation units
Change-Id: Icd5b1d805059981cbbb4c0eb2a5c842d59223839
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2016-08-02 07:22:26 +00:00
Simon Hausmann fa53d4e354 Cleanup: Move ResolvedTypeReference(Map) one scope up
The class is a candidate for further functionality, it doesn't have
to be nested in CompilationUnit.

Change-Id: I100553160f5ae34f66b9f8ff5df9f636da2ffb67
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2016-08-01 15:28:09 +00:00
Simon Hausmann 4c1a51006e Improve robustness of qml disk caching
Perform various basic checks before proceeding to load an existing cache file,
including the qt version, architecture, data structure version and others.

Change-Id: Ie822b056e944ac120643aad260e97f62616688bf
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2016-07-23 05:18:59 +00:00
Edward Welbourne 6c630da50d V4 CompilationUnit: missing #include for date-time comparison
MinGW's cc got upset at a QDateTime comparison when it only had a
forward declaration of the type.

Change-Id: I0404248cbdfc35610d8465294534bd5201dcf2a2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-07-21 15:18:38 +00:00
Simon Hausmann 6a1667bc4e Improve robustness of qml cache expiry checking
Instead of relying on two time stamps in the file system (source file and cache
file), make the determination on whether the source file is newer than the
cache solely depend on the time stamp of only the source file. This means that
when cache files are stored in archives for example their modification date
does not need to be preserved upon extraction.

Change-Id: I0b4362663868c6fb9bd7e106028161b2d67274d4
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-07-19 18:19:46 +00:00
Simon Hausmann e0e50532d2 Added basic loading of compilation units from disk
This remains hidden behind the QML_DISK_CACHE flag until all backends
support it and the verification code is in place.

Change-Id: Ic77c64e20a2dc4c43473c47640e09f8070237e85
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-07-19 14:50:02 +00:00
Simon Hausmann be491913c0 Fix endian support in compiled data structures
The goal is to make the compiled data structures persistent on disk. In order
to make it possible to create these data structures on a "host" system that may
have a different endianness than the target system, we now make all the word
sized fields little-endian. The template wrappers from QJson provide
zero-overhead access for little-endian machines (the vast majority) while
maintaining a large degree of source compatibility.

Change-Id: I3d30da1fcf3bffb98dbe9337d3a35482fb7b57c8
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-07-14 03:58:57 +00:00
Simon Hausmann 36d4501a08 Fix crash in qmljs
When running in pure JS mode, we may not have a QQmlEngine.

Change-Id: Ibb6e9087312b13cca53cb672a8f5372764cdf515
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-07-13 13:12:12 +00:00
Simon Hausmann c884f85863 Move type compilation independent bits out of QQmlTypeCompiler
The type validation is something that works on the final compilation
unit, so it can be done separately. The same applies to the composite
type registration and object/binding calculation. Both steps will
be shared with compilation units loaded from disk.

Change-Id: I43636d7ac76077c76289d7c1c9eba5e9c6b8239a
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-20 14:15:40 +00:00
Simon Hausmann 8a33d37006 Added basic support for saving compilation units to disk
Hidden behind a QML_DISK_CACHE=1 environment variable we will now attempt to
save a binary representation of the type compilation for Foo.qml next to it called
Foo.qmlc.

Change-Id: I27e800b50cdb186669256fd277578ea1f1e70513
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-17 09:06:01 +00:00
Simon Hausmann 0dfd0a1c09 Move object/binding counter code to CompilationUnit
The code to update the counters operates entirely on data structures
from CompilationUnit, so it makes sense to move it into that class.
Plus - you guessed it - this will also be called when not using the type
compiler in the future.

Change-Id: I644b0914980b799be1020ed74d2791b127bbcf9f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-17 07:38:52 +00:00
Simon Hausmann 0058ac5f28 Clean up property cache array handling
The QQmlPropertyCacheVector in the CompilationUnit encapsulates the
property caches for the objects declared in the QML tree as well as the
bits indicating whether a VME meta-object is needed. The ref-counting
for the caches in that vector was done "manually" and thus error prone.
This patch replaces the vector with a wrapper container that has
explicit move semantics and takes care of the addref() and release()
calls upon insertion, replacement and destruction.

Change-Id: If805fe016f1a1c70e56f8a90909ab87b653ea026
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-16 18:00:35 +00:00
Simon Hausmann e2fd32cf30 More reference counting cleanups
Replace more uses of manual reference counting with automatic counting.

Change-Id: Id3ce13814ac7f13d62562be21e4d59119d099944
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-03 13:24:09 +00:00
Simon Hausmann 4018a91d2f Minor const cleanup
The unit data of QV4::CompiledData::CompilationUnit is read-only, which we
should "enforce" with a const, especially as in the future it may come from a
read-only mmap'ed chunk of memory.

Change-Id: I58dde9fe2494d3cfa52cdc9f612c7fa90b98aa26
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-03 13:24:07 +00:00
Simon Hausmann 1f3f6d3e7d Remove QQmlCompiledData in favor of QV4::CompiledData::CompilationUnit
QQmlCompiledData used to contain the binary data for instantiating QML types in
the QML VME. Nowadays the QML type compiler as well as the JavaScript compiler
create a QV4::CompiledData::CompilationUnit.

Change-Id: I155f62a5ecfb55a3fe230520231b6d8fd5b28ac9
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
2016-06-01 17:33:50 +00:00
Simon Hausmann 3b14f29b8e Ensure that CompilationUnit instances are deleted in the engine thread
When using CompilationUnit with a QML engine, ensure that they are deleted in
the same thread as the QML engine.

Only the QML engine has a secondary thread (not a plain QJSEngine) and there it
may happen that the last refcount drops within the loader thread. For example
when the trimCache() is called within the loader. The destruction of the
CompilationUnit however is not safe to perform in a secondary thread.

Change-Id: Ia0105a8885ec97b0b2159e32e637adbd4e99f016
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-06-01 10:35:21 +00:00
Simon Hausmann 6e86846c9a Remove some dead code
Change-Id: I1f3baa11e7c7860d6052182a1056f5b13d4ce593
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-06-01 10:35:12 +00:00
Simon Hausmann 06467a192b Moved meta-type id members to QV4::CompiledData::CompilationUnit
Change-Id: I808d0a36094e873b69cf24a5b0113e741ff2a25d
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-31 14:29:11 +00:00
Simon Hausmann 2bb309af8b Moved resolved type references over to QV4::CompiledData::CompilationUnit
Change-Id: I99bb37bf4d4aa4aedd8e02a0fb4afb4a908573a6
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2016-05-31 14:28:29 +00:00
Simon Hausmann e5c76615b7 Move dependent scripts to QV4::CompiledData::CompilationUnit
Change-Id: I85e8267ce4cd26ae83fe567357e1368658fdb43d
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-31 06:55:20 +00:00
Simon Hausmann af028f592b Moved object/bindings/customparser counters to CompilationUnit
These allow pre-allocating some arrays when instantiating types.

Change-Id: I2ca4ba4a69429918f03a5ba4c501c763e7ffa8dc
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-31 06:55:13 +00:00
Simon Hausmann 77773997d0 Moved the import cache from QQmlCompiledData to CompilationUnit
Change-Id: I77892919678cb01ba1e697a44122760679a72045
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-31 06:55:07 +00:00
Simon Hausmann 3241573e1a Move property caches from QQmlCompiledData to QV4::CompiledData::CompilationUnit
This makes particularly sense as the binding property data per object that
allows us to avoid a by-name property lookup when instantiating types is also
stored there.

Change-Id: I4d9275c1d8fde252df83eb11a9dfea71e5e9583a
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-31 06:55:02 +00:00