Commit Graph

45 Commits

Author SHA1 Message Date
Lars Knoll 2e6e49f829 Move readonly accessors into Heap::ArrayData
these methods don't modify the object, so it's safe to have them
there and this simplifies quite a bit of the code.

Change-Id: I2f591758efba9cb8d17b956bc7c02e2d7a468ea4
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-10 11:00:25 +01:00
Lars Knoll ef73060d05 Operate directly on Heap::ArrayData where possible
Change-Id: I87dfb3e9a07673b5c405619eab8b6ee292d5c097
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-22 07:58:59 +01:00
Lars Knoll c044e33696 Reduce usage of Object::arrayData()
This will simplify porting over to returning Heap::ArrayData
from the method (as required for the new GC).

Change-Id: I5fb9ca7dfeab1aa63cc17c8948ef0966716f1bcb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-22 07:58:46 +01:00
Lars Knoll 9f717b650e Let the memory manager operate on Heap::Base objects, not Managed
Change-Id: Ib5c9b51dbf9c69abeda088094e6348dd545bf3c8
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-21 19:32:52 +01:00
Lars Knoll 2784a68d64 Cleanup destruction of heap objects
Generate the code from a macro instead of duplicating boiler
plate code. Operate on Heap::Base instead of Managed.

Change-Id: I84c5a705980899be3e5b931a093645e50d3923bf
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-21 19:32:23 +01:00
Lars Knoll cd6db04169 Remove ExecutionContext from the array sorting code
Change-Id: I3c59fdb2413664f1c541264a89613a325ecefd2a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-15 13:16:20 +01:00
Lars Knoll 7cc5fb2b53 Cleanup: remove Value::toString/Object overloads taking a context
Change-Id: I4cb63c3cc4eb9bb81f10f9826f80e581b4e1990c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-15 11:25:09 +01:00
Lars Knoll 9bad6eea0f Change signature or runtime methods to take an engine pointer
This makes a lot more sense in the long term and is the
more maintainable solution, once the GC starts moving
objects around in memory

Change-Id: I8f327c0f5b5b0af38c5fe1a217852ee8c4a5c2fc
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-12 12:13:54 +01:00
Lars Knoll ec8f1f68d6 Begin moving the data out of Managed objects
We need to move the Data objects out of the Managed
objects, to avoid lots of trouble because inner classes
can't be forward declared in C++.

Instead move them all into a Heap namespace.

Change-Id: I736af60702b68a1759f4643aa16d64108693dea2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-08 16:39:07 +01:00
Lars Knoll 878b11e0a9 Let markObjects() operate directly on HeapObjects
This decouples things a bit better and helps moving
over to directly store heapobject pointers in other
objects.

Change-Id: I798f922e018b0a3ca6f8768e4a810187f34d82f6
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-04 20:18:18 +01:00
Lars Knoll 486948817b Move the throw methods from ExecutionContext to ExecutionEngine
The methods don't require a context, and thus shouldn't be
implemented there.

Change-Id: If058e0c5067093a4161f2275ac4288aa2bc500f3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-04 20:17:54 +01:00
Lars Knoll 6f6b350976 Cleanup header file dependencies
Change-Id: Ibb4658576a98b53de2eac2474ce4d5b9eb83b6ae
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-04 20:17:23 +01:00
Lars Knoll 0704d2be63 Get rid of !this and similar constructs
The C++ standard doesn't allow calling member functions
on a mull object. Fix all such places, by moving the checks
to the caller where required.

Change-Id: I10fb22acaf0324d8ffd3a6d8e19152e5d32f56bb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-31 15:42:42 +01:00
Lars Knoll e67948823d Don't allocate less memory than required
When switching from a simple to a sparse array,
keep the previously allocated size, to not corrupt
memory.

Change-Id: I33f0fb049a2ad6f24ee3703f2c333855830fe9d2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-31 15:42:17 +01:00
Lars Knoll 57e5407178 Don't check the this pointer for 0 in member functions
This actually violates the C++ standard that defines that
you aren't allowed to call member functions on an invalid
object.

Instead insert the 0 pointer checks on the caller side where
required.

Change-Id: I8be3c3831594bb6482e9ef6de6e590ec437ac0f8
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-27 15:19:12 +01:00
Lars Knoll 8539aa8734 Reduce size of ArrayData by one pointer
The pointer to the real data is not required anymore, as
it always follows the class itself. Like this we save one
pointer of overhead, and one indirection when doing reads
and writes of array data.

Change-Id: If6afdac8e97b57420b50e7b7eb8979f77e8dbbcf
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-27 15:19:10 +01:00
Lars Knoll 51d8f62dac Rework our simple array implementation
Implement the simple array as a circular buffer instead
of an array with head room. This fixes a couple of severe
issues with performance and memory management if the array
is being used as a queue.

Task-number: QTBUG-41421
Change-Id: I146ad8a874407c108aa8fe1eae68e9957e154847
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-27 15:19:08 +01:00
Simon Hausmann 38fe461e2c Merge remote-tracking branch 'origin/5.3' into 5.4
Conflicts:
	.qmake.conf
	src/qml/jsruntime/qv4arraydata.cpp
	src/quick/scenegraph/util/qsgatlastexture.cpp

Change-Id: Ic4c96066d5c37dcf0d5446baed590ea005d445ce
2014-09-08 13:10:21 +02:00
Lars Knoll 2104755659 Fix crashes when calling Array.sort with imperfect sort functions
We can't use std::sort to implement Array.sort. The reason is that
std::sort expects a conformant compare function, and can do weird
things (esp. crash) when the sort function isn't conformant.

Falling back to qSort is not possible, as the method has been
deprecated. So add a copy of the qSort implementation here, and
use that one instead.

Fix the sortint test in tst_qqmlecmascript to have a consistent
sort function for strings, as the result of calling sort is
otherwise undefined according to the ecma standard.

Task-number: QTBUG-39072
Change-Id: I0602b3aa1ffa4de5006da58396f166805cf4a5e2
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-09-01 12:23:46 +02:00
Simon Hausmann e9e6f70d35 Merge remote-tracking branch 'origin/5.3' into 5.4
Conflicts:
	src/qml/qml/qqmlobjectcreator_p.h
Change-Id: I60858ddb46866a8fa1a8576bb05b412afeeb4e41
2014-08-26 09:51:56 +02:00
Lars Knoll eadc35f499 Don't use d->instanceModel after free'ing it
prevModel points to d->instanceModel and is being
used further down in the code. So reset the pointer
to 0 after freeing the old instanceModel.

Change-Id: I8854ae3e09c8b2fe50ad311f3dbc7b8ed26805e1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-08-26 05:50:50 +02:00
Jani Heikkinen e7ceacda70 Update license headers and add new licenses
- Renamed LICENSE.LGPL to LICENSE.LGPLv21
- Added LICENSE.LGPLv3 & LICENSE.GPLv2
- Removed LICENSE.GPL

Change-Id: I84a565e2e0caa3b76bf291a7d188a57a4b00e1b0
Reviewed-by: Jani Heikkinen <jani.heikkinen@digia.com>
2014-08-25 11:28:46 +02:00
Simon Hausmann b3fab495f5 Cleanup: Get rid of __data members
These are not needed anymore

Change-Id: Ib834aa294e84ca9fbdd5b6850d5bc172e8b54ba1
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-07-22 13:49:21 +02:00
Simon Hausmann 659e06f3a0 Fix build on Windows
* Add missing exports
* Define otherwise unused ArrayData vtbl - somehow the linker wants to see
the symbols despite them being unused.

Change-Id: I83a7ad4dea89bffc16018093a3cd4f4feecbfa3c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-07-22 13:49:21 +02:00
Simon Hausmann 3110273d1c Ported array data to the new object structure
Change-Id: Ice53925f42924c889d265bcd1e4af7b9bd356fa8
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-07-22 13:49:20 +02:00
Lars Knoll da9d501661 Fix Managed::as<>() method
The as<> casting method was not doing the right thing
in 100% of the cases. It only checked if the object in
question was exactly of the type being asked for. It
however didn't check if the object was derived from the
type.

This commit fixes this by adding a parent chain to the
vtables, that is then being used to check this safely
at runtime.

Change-Id: I9e0b13adbda668aee8c7451e2bb71cd6d4e316d9
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:20 +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 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 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
Lars Knoll 05f17e841f Get rid of different macros for vtable specializations
Detect existence of a a vtable entry at compile time.

Change-Id: Ieed5d34b063184bc4435b22c6685ac0e3fabf493
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:48:54 +02:00
Lars Knoll 4427576fe5 Avoid calling destroy() on most objects
The method is now optional, and we can simply avoid
calling it if all members an object has are themselves
garbage collected.

Change-Id: If560fce051908bcc10409ead1a7d8a5bd5fa71d2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:48:53 +02:00
Simon Hausmann 6bbd173a9c Fix crash in sparse array handling
When re-allocating the sparse array data, make sure to initialize the free list
correctly. Previously this was only done for the first allocation.

Test cases uses an object literal, as that's a reliable way to ensure
a sparse array is created.

Task-number: QTBUG-37892
Change-Id: Ib38cfce50104904af0c980f022c9dbb7461ae5f8
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-03-28 15:07:03 +01:00
Simon Hausmann 156508dbc0 Fix crash when calling concat on an empty array
Make sure to create the array data. The earlier called copyArrayData()
doesn't have to do that.

Task-number: QTBUG-37506
Change-Id: I6671769fcd471234c4c2eaa1614aa61266db0e5c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-03-15 17:33:48 +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 dfed088a50 Fix copying of Property's
Data properties don't contain valid data in the set field
if they are being stored in Objects. Thus we should never
access that field unless we are dealing with accessor
properties.

Change-Id: I19dcbaee7ebd042ae24387f92a93571d75ca578a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-10 21:00:22 +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 28f422ebf5 Move ArrayElementLessThen to qv4arraydata.cpp
This is the only place the class gets used.

Change-Id: Iebb0cba7af30c1b2da68f67596c349d5e20c5053
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-31 11:13:48 +01:00
Simon Hausmann ab2b521987 Allocate the ArrayData object and it's data together
Reduce the amount of allocations required for Arrays, and
allows freeing the array data more easily in the GC.

Change-Id: I3e3213f089c45c83a227038ce444aa60b2735b7f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-24 14:32:37 +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 9fb297a54b Turn ArrayData into a Managed object
Memory manage ArrayData. Once the ArrayData is moved
to be inline inside the object, this will save quite
some time for allocating and freeing arrays.

Change-Id: I19a520161d41bfe3d83f377af0b41db4ac5b99e4
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-23 21:47:27 +01:00
Lars Knoll c1c9ce91b3 Adjust method naming to be closer to Managed
Also make markObjects() virtual, to be in line with
Managed.

Change-Id: I3e7682216660e2027c02c9181e541b12310902f3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-21 08:18:41 +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 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