Commit Graph

145 Commits

Author SHA1 Message Date
Michael Brasser b42c8c4de2 Accelerate property lookups for C++-based QObject singletons.
Change-Id: Icbdf06a077014db5dd57cba42f84591433ec4196
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-08-07 21:36:27 +02:00
Simon Hausmann b393c405b7 Change the object allocation scheme
Instead of allocating the data directly, centralize the object and its ::Data
allocation in one place in the memory manager. This is in preparation for
additional pointer indirection later.

Change-Id: I7880e1e7354b3258b6a8965be378cd09c9467d25
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-07-22 13:49:19 +02:00
Lars Knoll 00a46fa07b Convert Execution contexts to new constructor syntax
Change-Id: I4bc6a61b7a96139353e20871ff7ff007822c64c3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:19 +02:00
Lars Knoll 2eb5416f54 Convert the last Managed types to the new constructor syntax
Change-Id: I11701c586d4715c08feba4650e12904c3fa7ca27
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:19 +02:00
Lars Knoll 903e04dead Convert String to new constructor syntax
Change-Id: I07f7667d3d72a7d72e6717d194de8d7b15435777
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:19 +02:00
Lars Knoll 00fa904911 Convert FunctionObject derived classes to new construction scheme
Change-Id: I0d43a79ed531a9d651bd00866d73113c05d95a09
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:17 +02:00
Lars Knoll 0732e0177e Get rid of CallDataRef
The class didn't really add any value.

Change-Id: Ibd63c9b9b1fa3be6bfe8a70ca7fd4d6bf0c0019c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:14 +02:00
Lars Knoll 57f08e59fc Get rid of all uses of ObjectRef
Change-Id: I705e2362dcda542f56826dadec6b0a6f15848788
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:13 +02:00
Lars Knoll 33593f00e8 Get rid of StringRef
Remove the Ref classes, as they won't be required
anymore once Managed and Managed::Data are separated.

Change-Id: Ic6bec2d5b4ecf2595ce129dbb45bbf6a385138a5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:12 +02:00
Lars Knoll 9744e8bd42 Convert ExecutionContext to new storage scheme
Change-Id: I9fcc13da5360f37cef3149b114ed9263b9b74281
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:11 +02:00
Lars Knoll 43df154aa1 Move ArrayData over to new data layout
Change-Id: Ic51f37bea030b196f0fa35ab21e618447edaa25d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:48:58 +02:00
Lars Knoll 36aa3f9117 Convert the remaining classes in functionobject.h
Change-Id: I7dbc56ca3952772b99681f95f50129204f9d6c7c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:48:56 +02:00
Lars Knoll 393c92a821 Move object data into internal structure
Change-Id: I1fcccd535ed356e736468337bd450270cd290044
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:48:54 +02:00
Lars Knoll b11ec08570 Move Managed data into it's own subclass
This prepares for moving over to a d pointer scheme,
where Managed subclasses don't hold any data directly. This
is required to be able to move over to a modern GC.

Change-Id: I3f59633ac07a7da461bd2d4f0f9f3a8e3b0baf02
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:48:54 +02:00
Holger Hans Peter Freyther a62955472b v4: Delay creating the ScopedValue/ScopedProperty in objectLiteral
Creating a ScopedValue/ScopedProperty is not free. It will use the
ExecutionEngine directly to reserve memory from the JS Stack. In
tests/manual/v4/v8-bench.js and bench-allocate-nonretained.js a lot
of objects are created and the arrayValueCount and the
arrayGetterSetterCount are 0. We can delay the creation for a small
gain.

When generating the code we already know the various sizes and
could already call specialized versions of the creation code. The
gain is not so clear though.

Change-Id: Ic99b241f5506457e57611ad4eba143c56be1f657
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-20 09:51:50 +02:00
Simon Hausmann a885d10a02 Extend the QML bootstrap library by the IR builders
This is among other things needed to fix the qml import scanner to detect
dependencies from .js files correctly.

The patch also fixes the use of Q_QML_EXPORT towards Q_QML_PRIVATE_EXPORT
where appropriate and corrects the wrong include path for the double conversion
code to actually be relative to the file it is included from. This worked by
accident because of other include paths present in the build.

Change-Id: I338583dad2f76300819af8ab0dae8e5724c84430
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-04-23 21:16:46 +02:00
Simon Hausmann 5915a3ec73 Fix typo
creatScriptFunction -> createScriptFunction

Change-Id: Icdb9214b1ae067fa2b8693d50cdac0be9fe6d390
Reviewed-by: Michael Brasser <michael.brasser@live.com>
2014-04-01 06:17:14 +02:00
Lars Knoll 56c5a21cce Don't use scopes in the instanceOf operator
There's no need to use scopes here, as instanceof can't
trigger any calls into the memorymanager. This slightly
speeds up the code.

Change-Id: Ie7f5c8f3982df1e24d21cfc4e0841d479a75c664
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-27 20:39:59 +01:00
Albert Astals Cid fc45fd6983 Don't crash on Runtime::getQmlImportedScripts
Task-number: QTBUG-37303

Change-Id: I083ca0cc3223fe0dbf1c768ad43a0d4927579867
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-24 11:40:10 +01:00
Lars Knoll cfd3eda076 Fixes to for...in statement
Properly convert the argument to an object if
it's not null or undefined as mandated by the
standard.

Add a similar test case for the with statement.

Change-Id: Idd8e245e8dae4803eb0e2010e3d43bb912670444
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-19 08:14:50 +01:00
Lars Knoll 6b425f3182 Minor optimization: Avoid some QString constructors
Change-Id: I51af67e9ba4076216142e05b5de5b2e8f8c526bc
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-18 09:05:57 +01:00
Lars Knoll 8ed6c62dc7 Cleanup our runtime methods
Move all our runtime methods into the QV4::Runtime
struct and give them nicer names without underscores.
Sort them logically and remove a few unused methods.

Change-Id: Ib69b71764ff194d0ba211aac581f9a99734d8180
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-11 08:37:01 +01:00
Lars Knoll af7ca3607c Use an array of Value's for Object::memberData
This cuts the memory required to store properties
in an object in half for the common case. Accessor
properties require two slots inside memberData,
but data properties only one.

Change-Id: I0bab1b88ca9ed5930abf065c77c89985b9ed5320
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-07 21:16:01 +01:00
Michael Brasser a3688bf41f 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>
2014-02-28 19:01:21 +01:00
Simon Hausmann 90a7249e70 Determine whether or not an object literal requires a sparse array at compile time
Change-Id: Ieb7f6ee97a4f251f1e2369850ebb9e2931f84ac1
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-02-24 20:41:48 +01:00
Simon Hausmann c78d1052c2 Clean up object literal handling with integral indices
* Object literals with array indices are now created with one
  run-time call, instead of an initial one for non-integral keys
  followed by sub-sequent define_builtin_property calls.

* Cleaned up propert name retrieval. Instead of using a visitor,
  it's easier to define a virtual method on the PropertyName type.  The visitor
  doesn't buy us much as it's not possible to recurse within property names, and
  this way we can use it also from the function scanner to correctly determine
  the number of arguments needed for object literal initalizations.

* Similarly the duplicated/common name member for all property assignments
  has been moved into PropertyName, for convenient access without AST casts.

* Removed now unused builtin_define_property/settergetter functions from IR,
  run-time and moth.

Change-Id: I90d54c81ea5f3f500f4f4a9c14f7caf5135e7f9f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-02-24 20:41:40 +01:00
Lars Knoll b8bb8d7526 Simplify some runtime code
Simpler code and delivers the same performance.

Change-Id: Ifd0398f0c123f4c21998f518574cf74cd7cf7e09
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-22 10:11:06 +01:00
Simon Hausmann 037ac0f08e Reduce memory usage for object literals with integral keys
Be more aggressive about using sparse arrays for object literals than for
regular array handling, to reduce the memory usage in this use case. The
current heuristic is that indices over 0x1000 switch to sparse, which means a
simple { "3000" : "test" } creates a long vector instead of a sparse array.

Task-number: QTBUG-36803
Change-Id: Id05c76f0f597cd016114cd27ec54effbebe26e48
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-02-16 17:57:02 +01:00
Lars Knoll a78a48c532 Cleanups
Remove SafeValue, it was used to port over to an exact GC. Since
we now have that, we can now safely merge it with QV4::Value
again. Also rename SafeString to StringValue for better naming
consistency.

Change-Id: I8553d1bec5134c53996f6b0d758738a0ec8a2e4d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-31 11:13:48 +01:00
Lars Knoll e3219a1f71 Fix a bug in qmljs_set_element and improve it's performance
Avoid expensive function calls for setting indexed properties
in the common case. The spec requires us to read the value before
writing it to check whether it's empty. In that case we need to
fall back to the slow implementation that checks the proto chain.

Change-Id: If278ba81f170d35c18135d2f8661459262e7e606
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-31 11:13:48 +01:00
Lars Knoll c53fef423a Change virtual methods in ArrayData to take Object pointer
Pass a pointer to the underlying object instead of the ArrayData
to virtual methods that modify the arrayData. This prepares
for allocating the ArrayData together with the array itself.

Change-Id: I66fe187f8b1e4d382ab243a518dbde5f18a1d16d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-24 14:32:33 +01:00
Lars Knoll 7d4fc70e70 Split ManagedVTable into two classes
Keep the basic methods in ManagedVTable, but have
the Object related stuff in an ObjectVTable class.

Change-Id: I9b068acf3caef813686227b8d935e7df1a7d1a6e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-21 20:46:50 +01:00
Lars Knoll bf6191f090 Add a SimpleArrayData class
This makes the ArrayData class 'pure virtual'. SimpleArrayData
now contains the implementation of simple arrays. This makes the
separation between simple and sparse arrays a lot cleaner.

It also allows us to move len and offset from the base class into
the SimpleArrayClass. This fixes some bugs where we accessed len
for sparse arrays leading to some buggy behavior.

Added a virtual length() method to ArrayData to query the highes
used index in the Array.

Change-Id: Iab2ba2a48ebe5b7031759eeb4ebe02b4d86233f0
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-20 21:14:31 +01:00
Lars Knoll 5c25379cd1 Save memory on array data
Store a simple vector of Values in the array data,
instead of a Vector of Property's. This halfes the
memory consumption on 64bit and simplifies our code.

If an indexed property gets converted to an accessor
property, we simply convert the ArrayData into a
SparseArrayData.

Add support in SparseArrayData to allocate double slots
(two Value's) to hold a full Property in case someone
sets an accessor on an indexed property.

Some methods still return a Property*, but this is safe, as
only the first Value in the Property pointer will ever get
accessed if the Property doesn't contain an accessor.

Change-Id: Ic9b0f309b09a2772a328d947a10faaf3be9fe56f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-20 21:14:27 +01:00
Lars Knoll 50d6e51c73 clean up Object::has(Own)Property
hasProperty is now implemented by calling hasOwnProperty
on the proto chain. In addition, it should be slightly
faster and doesn't use API that returns a Property pointer
anymore.

Change-Id: I6312d83ccfed3f0a1a8ec4c72c436a426d6eab44
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-20 21:13:43 +01:00
Lars Knoll 7eff387795 Cleanup: change signature of Object::insertMember()
Methods returning a Property pointer have to be removed, so that
we can move over to store member data requiring only one value for
the common case of data properties.

This will in the long term reduce memory consumption on 64 bit
systems quite a bit.

Change-Id: I78de3794ec7b3bc5db13aa57275d3f08fa9d470a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-09 07:47:22 +01:00
Lars Knoll 459c9a2a88 Rework array handling for JS objects
Split up ArrayData into two classes, one for regular
arrays, one for sparse arrays and cleanly separate
the two cases. Only create array data on demand.

Change-Id: I9ca8d0b53592174f213ba0f20caf93e77dba690a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-09 07:47:06 +01:00
Lars Knoll 5cf95512af Fixes for argument objects
Fix a possible infinite recursion, and a corner
case where we wouldn't set the correct data when
writing to the argument object

Change-Id: Ia64b9f62e9b881e24d74e23d96d5eb27805a126f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-09 07:46:59 +01:00
Lars Knoll c83b9cdd58 Move array data into it's own struct
First step of separating the array data from Object.

Change-Id: I5c857397f0ef53cff0807debdb1e405424e1046a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-03 17:09:23 +01:00
Lars Knoll 9306c05dd1 Encapsulate the current context and fix it's usage
Encapsulate accesses to the current context, and rework
the way we push and pop this context from the context
stack.

Largely a cleanup, but simplifies the code in the long term

Change-Id: I409e378490d0ab027be6a4c01a4031b2ea35c51d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-12-04 09:45:50 +01:00
Lars Knoll 8e25658011 Speedup JS instanceof operator
Cache the prototype of the functionobject, and inline hasInstance.
This removes a vtbl method and speeds things up quite a bit.

Change-Id: Ic68f301f7e09763d445a98bffa2cd201303f902e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-12-04 09:45:25 +01:00
Simon Hausmann f474eede80 Add support for accelerated property access to QML types and namespace support
* Resolve lookups in namespaces at compile time and instruct the SSA optimizer
  to eliminate reads from the namespace (QQmlTypeWrapper) if possible. For example
  access to attached properties of types (i.e. MyNameSpace.ListView.isCurrentItem)
  requires neither reading the namespace nor the type.
* Add support for accelerated lookup of attached properties

Change-Id: Ib0b66404ed7e70e1d4a46a1ac8218743a4cc8608
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-28 13:47:40 +01:00
Simon Hausmann 43f1cc98bf Initial support for accelerated property access to QML singletons and enums
With this patch we determine the meta-object of singletons, propagate it into
the IR and load them separately using a dedicated run-time function. In
addition enums in singletons and QML types are resolved at compile time.

Change-Id: I01ce1288391b476d1c9af669cb2987a44c885703
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-25 22:04:42 +01:00
Simon Hausmann a41764cafb IR Cleanup, resolve ID objects through array subscripts
...instead of a special MEMBER type. This allows removing the
type member from V4IR::Member altogether (and thus unshadow from
V4IR::Expr::type). By not requiring the base of a id lookup
member expression to be a NAME, we can also speed up repeated
id lookups by fetching the id object array wrapper only once
per function.

Change-Id: I3e9b8f498d32ace4a0cc2254f49e02ecc124f79c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-25 22:04:42 +01:00
Lars Knoll 9bf5e87ef0 Use lookups for create_property (ie. new foo.bar)
This is not used that often, but it removes one more place
where we do lookups by name.

Change-Id: I9f798b8b4a64be3fdf3e53090e4288724c9d2b22
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-22 14:54:05 +01:00
Lars Knoll 0dc17ae4d8 Fix === operator for value types
Fix === comparison for urls and other QML value types.

Task-number: QTBUG-33546

Change-Id: I4a7066e6bbc7de7c599fe2c7b2fdfb75e0ff5196
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-15 13:07:52 +01:00
Lars Knoll d8fe3dfde9 Don't crash when trying to assign to null.prop
Fixes a regression introduced during the exception handling
refactoring.

Task-number: QTBUG-34544

Change-Id: Ib751274d759030db3e5d3b1380b30dc07ec85f83
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-15 13:07:11 +01:00
Simon Hausmann 7a09200016 Fix property dependency generation for accelerated QML QObject properties
The previous approach of collecting the dependencies through an IR visitor
doesn't work, because it relies on a fixed structure - for example MEMBER(NAME,
prop) - which we can't guarantee (it's usually MEMBER(TEMP, prop)). But it
turns out that we can only pre-calculate dependencies for context, scope or id
properties, so we can do that right away in the QML specific JS codegen, store
that information in the IR function and use it from there in the data structure
generator as well as in the isel as a parameter to getQObjectProperty to tell
the run-time whether capture is required or not.

Change-Id: I33711c3420d6534c653c2a6a4284f0fc12e941cf
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-12 18:20:30 +01:00
Lars Knoll 83947c2544 Smaller optimisations
Change-Id: Idb35d57801472e73b4e77b83e129dbb2a484b734
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-05 22:23:25 +01:00
Lars Knoll 90338de17a Move conversion of this object into generated code
When a non strict mode function uses the this object, we
need to make sure it's being correctly converted into a
object before being accessed. So far this was being done
by ScriptFunction::call. Move this into the generated code to
avoid overhead for methods not using 'this', and simplify our
ScriptFunction::call() implementation.

Change-Id: I739f4a89d29ed8082ce59e48d1523776224fc29d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-05 22:23:25 +01:00