Commit Graph

137 Commits

Author SHA1 Message Date
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 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 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
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 7605b92573 Fix compilation
Commit be491913c0 regressed the build with some
compilers that complained that the RegExp fields were uninitialized. Fix is
the same as for the Lookup class.

Change-Id: Ie6b2adf14496d75845f6a9d9b8fc680e61aa1155
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
2016-07-19 08:52:39 +00:00
Simon Hausmann 8f19045ef5 Split out creation of alias properties in the property caches
Similar to the regular property cache creation code, this also has to become a
template function so that it can be run on the compilation units loaded from
disk in the future. What is shared between the code path of a fresh compilation
vs. re-use of a unit from disk is the code to propagate the CompiledData::Alias
entries into entries in the property cache. The code for iterating through the
component spaces and resolving the alias references is not shared.

Change-Id: I04c2a5575310400156b457ae7b709cffecb7455e
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-07-15 20:31:51 +00:00
Simon Hausmann bf5f97e6c6 Fix alias resolution algorithm
The resolution of aliases needs to to be solved in iterations as an alias can
refer to another alias, which may not be created yet in the property cache by
the time we try to perform the resolution. Therefore the alias resolution code
works off a list of pending aliases after the initial pass of resolution. This
also requires the ability to detect circular references.

Change-Id: Id4e159b9c713aa8a8a095759e22e3fac456a38a0
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-07-15 18:51:39 +00:00
BogDan Vatra 0ce892a275 Android: Fix crash
Make sure all the sturcture fileds are aligned

Change-Id: I6f6dad67262e50026f7e86320bcd818a478ebc35
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-07-15 14:39:19 +00:00
Simon Hausmann cf23466f0a Simplify CompiledData::Unit serialization
There are currently two places where we calculate the total size of a
CompiledData::Unit including all of its data, once in its calculateSize()
function and then when constructing the Unit itself. This is error prone when
trying to do changes to the layout, as two places need to be adjusted.  Instead
we can centralize the populating of the entire CompiledData::Unit header, the
calculation of the various offsets as well as the entire size in one shot in a
new generateHeader function. Afterwards we can allocate the final amount of
memory and copy the remaining bytes across and assemble the final data
structure.

Change-Id: Ic26d7812e59d2bee2f45cd72742e3195a56950df
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-07-15 08:58:15 +00:00
Simon Hausmann 3190478663 Remove unused fields in CompiledData::Function
The table for referencing the inner functions is not needed. This also allows
making the function offsets table a local variable.

Change-Id: I3f1a1d6ab8c4f417edeafdc174e5b41d2d2b611b
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-07-14 21:50:28 +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 a25f0ed5d2 Minor cleanup in location handling
Store the line and column in CompiledData::Location as unsigned values.
The qmlSourceCoordinate() function(s) already now act as normalizers,
mapping values <= 0 to 0 as indicator for a missing/invalid line/column.
Valid values start at 1 and therefore there is no need to store negative
values in the location structure.

Coincidentally this also fixes a bunch of warnings about conversions from
signed to unsigned.

Change-Id: Ic69ff395d4991989aede695f2e8c58903f1bd2bf
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-07-13 13:43:33 +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 d18026b007 Moved import cache and type resolution cache code
The code reads mostly from QQmlTypeData internal data structures, so
it's cleaner to move it there - we can remove the getters for these
internal fields.  And it also allows for re-use later when not using the
type compiler.

Change-Id: I36cfaf3f1cecd6c8b223ee08516884a07bc60d6c
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-17 07:38:49 +00:00
Simon Hausmann 2997b7ea99 Added iterator interfaces to QV4::CompiledData::*
These interfaces are required in order to be able to use the
QQmlPropertyCacheCreator template.

Change-Id: I371e7102aac00fd607fc6a8ad7ffc18996608758
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-17 04:03:15 +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 5046012e07 Cleanup: generalize type reference collection code
For loading compilation units from disk we'll have to scan the unit for type
references, in order to correctly load dependencies. In preparation for that
this patch template'izes the loops so that they can work on the Qml IR as well
as on the CompiledData::Object structures.

Change-Id: I32e4e3277e16c5a2d1bf6baf24456c9837c189ff
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-14 08:00:34 +00:00
Simon Hausmann 4f322f7f2c Clean up CompiledData::Function
* We don't need 64 bits for the flags, for now 8 bits are sufficient.
* Removed the unused index member. It's symmetric to the index of the
  function object in the function table anyway.

Change-Id: I18248e8ed79b3c3af87e17689dadf7323d5d9bb3
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-07 03:32:06 +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 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
Simon Hausmann d146b955f5 Remove the custom parser binding bits hash table from QQmlCompiledData
Similary to the other hash tables we can store the actual information about
whether a binding is covered by a custom parser or not straight in the
CompiledData::Binding.

Change-Id: Iab9044af57338cec935d3ef38764d7dc1aa507e8
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-30 07:16:25 +00:00
Simon Hausmann f27d058c11 Centralize deferred binding bit information in CompiledData::Binding
Ultimately the decision which bindings to initialize in a deferred way depends
on the data in the meta-object (deferred property names entry). The hash in
QQmlCompiledData is just caching this information. We are better off storing
this single bit right in the binding itself instead of in a parallel data
structure.

Change-Id: Ib66d3550210af1f882b98b0ba9089391813d69ad
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-30 07:16:17 +00:00
Simon Hausmann e850416fcf Optimize named object handling
By storing the object indices of named objects in the CompiledData::Object of a component,
we can achieve two things:

    (1) We can eliminate the hash of vectors in QQmlCompiledData for the object-to-id mapping
    (2) We can store the mapping from object name to integer object id in the CompilationUnit and
        share it across different QQmlContextData instances (as long as it is not modified).

Also added a new test that verifies the functionality of a .qml file starting
with Component{} itself with object names, something that was previously only
implicitly tested through some of the examples (corkboards.qml for example).

Change-Id: I28c70217222dc0e5252bf5247b7e3fc4def47446
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-26 19:57:55 +00:00
Simon Hausmann 8457ca1b3d Simplify object to id-in-context mapping
By storing the calculated integer id for an id-named object in
CompiledData::Object we can simplify the code and replace a hash table with a
plain vector.

Change-Id: I4a84cdd00e98766d603d152e5a6574b232771a02
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-26 11:33:00 +00:00
Simon Hausmann 899c1ef0f7 Add a flag to CompiledData::Object record component boundaries
This allows simplifying some code and reducing the usage of the objectIndexToId
hash maps.

Change-Id: I1f08d4b224c4f9fa498d90471fa545ae4e4f2af4
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-26 11:32:56 +00:00
Simon Hausmann ec2b2a5f5d Fold QQmlVMEMetaData::Alias::flags into QV4::CompiledData::Alias::flags
We only need one bit, so this is easy to merge.

Change-Id: I98bf882b8c1bf10f2172a9e22331d621985d3ed4
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-24 05:55:06 +00:00
Simon Hausmann 46c6db6f58 Shrink QQmlVMEMetaData::AliasData
We can retrieve the alias property index from the QV4::CompiledData::Alias and the
property type from the property cache (only needed for aliases to value types).

Change-Id: Ibf0cb909a4cd1ce1c2d67b57e1be1de491d4d598
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-24 04:04:26 +00:00
Simon Hausmann 81dfb0bdeb Remove QQmlVMEMetaData::AliasData::contextIdx
We can store the id (in QQmlContextData::idValues) for the alias target in the QV4::CompiledData::Alias.

Change-Id: I3f32648aef28d96ddedff6b3d2cde75969a46fa1
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-23 20:35:10 +00:00
Simon Hausmann b0377f4581 Optimize property/alias data structures
We used to store property declarations and alias declarations in the same
properties array in CompiledData::Object. However at run-time the
QQmlVMEMetaObject implements them separately, using separate data structures
(in the meta-data) and (most importantly) using separate property id segments:
First the properties, then the aliases. By reflecting the same separation in
CompiledData::Object with property arrays and alias arrays, we can pave the way
for getting rid of the meta-data in QQmlVMEMetaObject.

Change-Id: Ia84813fe3da6f3fdbd4d2b16136a8bf11fa175a6
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-23 06:35:16 +00:00
Simon Hausmann 02c384e48d Save a little bit of memory per declared property
We only need one bit for the flags, to save four bytes.

Change-Id: I73cbf8c2ef8b532dfe494b1b31ab242cccc38686
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-20 14:18:36 +00:00
Simon Hausmann 8997e00269 Cleanup
Remove unused virtual function

Change-Id: I728a0f982f2790921e3af5332fa1ee14391239c5
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
2016-05-06 13:06:31 +00:00
Lars Knoll ad8d760dec Save some memory
Change-Id: I866eeba45e30fd5e38541b2de4a2fda5549104a9
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-04-11 12:27:44 +00:00
Jani Heikkinen 45bd04ba73 Updated license headers
From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see
http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/

Updated license headers to use new LGPL header instead of LGPL21 one
(in those files which will be under LGPL v3)

Change-Id: Ic36f1a0a1436fe6ac6eeca8c2375a79857e9cb12
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-01-19 14:53:18 +00:00
Friedemann Kleint 933cff33cb Add missing "We mean it" comments to private headers.
Task-number: QTBUG-48594
Change-Id: Ifc207938de7f0c8995fc712df92665f222612647
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
2015-10-06 15:39:36 +00:00
Simon Hausmann a6fb18f186 Fix uninitialized variables/data
* Initialize the indexOfRootObject member
* When creating the QV4::CompiledData::String objects,
  don't include the one ushort _beyond_ the QString, which
  is random data.

Change-Id: I8fe8a465e2713a385504f217b367a62b70ee5fdf
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2015-04-29 17:40:03 +00:00
Simon Hausmann 3db3c38b10 Speed up property binding initialization on object creation
Avoid repeated string hashing and lookups in the property cache in order to
retrieve the property details when initializing literal and script bindings.
Instead we now cache the property data at type validation time, similar to how
the property data was encoded in the VME instructions in the old engine.

Change-Id: I3957c7c4c3e26dfa97c4880b23940a3755ee90e4
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2015-04-21 06:36:47 +00:00
Simon Hausmann 6767fcfaf2 Fix usage of QtQmlDevTools private headers on OSX with framework builds
Previously this module borrowed its private headers from QtQml, so that
when writing QT += qmldevtools-private, you'd get the private headers from
QtQml. This doesn't work when QtQml is built as a framework.

A cleaner solution is to give this module its headers proper by letting
syncqt create the forwarding headers correctly (and consequently also
include them in make install). In order for this to work, the included
headers themselves cannot include any headers from QtQml, which this
patch also takes care of, through a centralized inclusion of qv4global_p.h.

Change-Id: I9bb8337956a2774cfaca6b338369face6c6ee785
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
2015-03-16 10:27:07 +00:00