Commit Graph

54 Commits

Author SHA1 Message Date
Lars Knoll 32f6315d6d Make better use of the remaining memory before calling GC
Some slots still have free memory available. If we only
need to allocate a small object, check if we can split up
one of these slots before giving up and starting a GC
cycle.

Change-Id: I11fb9d53c607274dbb5fd0bc02088ed94bfe7c4e
Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
2017-02-13 15:36:06 +00:00
Lars Knoll 66b58804a3 Fix a bug in Chunk::sortIntoBins()
The bug lead to us not sorting all freed memory into
the bins for the allocator to find. The lead to memory
being 'lost' in the garbage collector.

Add an assertion that checks for lost memory when
we're running with aggressive GC.

Also make sure we don't run GC twice in a row when
aggressive GC is enabled.

Change-Id: I4fb6732acce8a2e66258fa70fb7d8f1f939cfd9f
Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
2017-02-13 15:36:03 +00:00
Lars Knoll a56809dcfd Get rid of the inline member data in Object
Instead allocate a MemberData at the same time as the
object if required. Turns out this is faster now,
and significantly simplifies some of our internal logic
to access member properties.

In addition, we can properly setup the inline member size
to use the full extent of the memory reserved by the
memory manager. This avoid some needless reallocations of
MemberData objects.

Change-Id: I36daeeaf6df16f2268103662fc78d600b4058ef8
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-25 08:30:59 +00:00
Lars Knoll d8c6bf2dc1 Let allocData/allocString return 0 initialized memory
There's no point in having the memset inline. In theory, the
compiler could optimize by combining this with later on inline
initialization code, in practice this doesn't happen anyway,
and we have some options of avoiding or combing the memsets
in the allocator.

Change-Id: I4502ef947ae235223726269821f9482ad62e1070
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-25 08:30:54 +00:00
Lars Knoll 8acf7385f3 Get rid of MemoryManager::Data
Inline the few remaining members into the MemoryManager
class itself.

Change-Id: If5fef74581daa89df3e8cc237329c27395ce2289
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-25 08:30:51 +00:00
Lars Knoll a31a5a43b3 New garbage collector
This is a block based allocator. We allocate HeapItems
from 64k Chunks (except for huge items that get their
own chunk). The allocator is block based, and aims to
defragment when sweep'ing the blocks.

The mark bit is now stored in the Chunk header, not
inline in the object anymore.

Change-Id: I2845f8b73dd496911ba50b868d54d144501d41e4
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-25 08:30:43 +00:00
Lars Knoll 8cdd25357d New allocator for huge items
Use a new Chunk based allocator for very large items.

Change-Id: Ie61a72efb6340cd9ef54e4fdd957d7ca36c8729f
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-25 08:30:39 +00:00
Lars Knoll a325b21e1b Allocate simple call contexts from a special allocator
We used to allocate those on the C stack, but this doesn't work
anymore with the new GC, as the mark bit is not stored inside the
object anymore.

Instead use a special allocator for these contexts that operates like a
stack.

Change-Id: I381ac3914ca866945312a1e79883aefe72662d2c
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-25 08:30:36 +00:00
Lars Knoll 90f055dbb4 Implement an allocator for Chunks
Change-Id: I7c054cda95d016ce8bb0b341730378afc15a3522
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-25 08:30:31 +00:00
Lars Knoll 550b71da1f Always allocate in 64k chunks
Cleans up the code a bit in preparation of the new GC. Has minimal
effect on performance these days.

Change-Id: Ifa6afea9acf8b6f086412e7eab7fa37c5387c624
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-25 08:30:28 +00:00
Lars Knoll 94e6106d35 Simplify handling of non GC managed heap data
Let the destroy() method in QV4::String clean up the
unmanaged heap size instead of having a special hook in
the code that sweeps the GC heap.

Change-Id: I989ee99604f0cc67b896d3acc94e200dd5e56a60
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2017-01-22 11:50:36 +00:00
Lars Knoll d2eaf438ac Get rid of the GCBlocker
It's a hack we needed when we still had a conservative GC, but
it is not required anymore. The only thing we still need is the
protection against running the GC recursively.

Change-Id: I55cd51d4929c828db5b61b38e781467c5bf77314
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-12-28 14:49:59 +00:00
Lars Knoll 6b64154953 Clean up duplicated checks whether a Value is a Managed
Change-Id: Ib044be254dbb41bd9fb4a6e0baa3bd3c007e6a2a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-11-29 19:59:58 +00:00
Simon Hausmann 0426400424 Merge remote-tracking branch 'origin/5.6' into 5.8
Change-Id: I175b27337b534c0b8f46a4a792d2c43cde73ffc4
2016-10-13 14:40:30 +02:00
Erik Verbruggen 9d2169a2d8 V4: Fix usage of QV4::Value tags/types
These two were mixed, but have completely different values.

Task-number: QTBUG-56471
Change-Id: Ifbf6da3032335ea89bfbc3acde17f64a571b9dc0
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-10-13 10:48:09 +00:00
Liang Qi 102fa9b6db Merge remote-tracking branch 'origin/5.7' into 5.8
Conflicts:
	examples/quick/quickwidgets/quickwidget/main.cpp
	src/qml/jsruntime/qv4jsonobject.cpp
	src/qml/jsruntime/qv4qobjectwrapper.cpp
	src/qml/jsruntime/qv4qobjectwrapper_p.h
	src/qml/qml/qqmlengine.cpp
	src/qml/qml/qqmlpropertycache.cpp
	src/qml/qml/qqmlpropertycache_p.h
	src/quick/items/qquickanimatedsprite.cpp
	src/quick/items/qquickitem.cpp
	src/quick/items/qquickitem.h
	src/quick/items/qquickitem_p.h
	src/quick/items/qquickview_p.h
	src/quick/scenegraph/qsgcontext.cpp
	src/quick/scenegraph/qsgdefaultrendercontext.cpp

Change-Id: I172c6fbff97208f21ed4c8b6db3d1747a889f22b
2016-10-10 16:01:48 +02:00
Erik Verbruggen a6be2d77aa V4: Move zero-initialization of heap items into the header file
This allows for a compiler to do dead-store elimination for zero-
initialized memory that gets overwritten directly after the allocated
chunk is returned.

Change-Id: I6493aae8fdabc2306e7cfa1233f917b1775c4451
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-10-07 12:47:24 +00:00
Erik Verbruggen 57c9d6969a QML: Also check for correct destroy() chaining
Check that the destroy() method of Heap::Base was called when a Managed
object needs destruction. This checks if a call to the parent's
destroy() method was accidentally omitted.

Change-Id: Id025ecd6d4744bf3eab23503fbe317ed2a461138
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-10-06 14:46:21 +00:00
Liang Qi fff4477661 Merge remote-tracking branch 'origin/5.6' into 5.7
Change-Id: I081d9b15796b4133d2ba6f1a862f15b873a4846d
2016-10-05 19:32:12 +02:00
Milian Wolff 59e48836e2 Use QElapsedTimer instead of QTime to measure elapsed time
Getting the current time from QTime is expensive as it adheres
to the locale timezone. To measure elapsed time in a code block,
using the monotonic QElapsedTimer is much faster.

Change-Id: Ibea390d7bc5270a20cf35111dfc919e37be7001e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-10-05 15:49:12 +00:00
Liang Qi 7e609f6d10 Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
	src/qml/compiler/qqmltypecompiler.cpp
	src/qml/compiler/qv4isel_moth.cpp
	src/qml/compiler/qv4ssa_p.h
	src/qml/qml/qqmlobjectcreator.cpp

Change-Id: I8bb7fe773d657f908f20ee5e72c2b9bd643f6260
2016-08-17 10:57:38 +02:00
Liang Qi d54d28981c Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	src/qml/compiler/qv4isel_moth.cpp
	src/qml/compiler/qv4ssa_p.h
	tests/benchmarks/qml/qqmlimage/qqmlimage.pro
	tests/benchmarks/qml/qqmlimage/tst_qqmlimage.cpp

Change-Id: Iad11ce7fdf0c6d200fdebc16a94081bd8069a87a
2016-08-13 00:41:58 +02:00
Liang Qi 5517c63c2e Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
	src/qml/qml/qqmlcomponent.cpp
	tests/auto/quick/scenegraph/tst_scenegraph.cpp

Change-Id: Ibc811b95a57f175ca53337db7bbd1f575a745937
2016-08-09 10:28:48 +02:00
Simon Hausmann 68bfc9332c Fix crash with Component.onDestruction
A call to a handler of Component.onDestruction may end up causing WeakValues
such as QQmlData::jsWrapper to be set again, even though they've been set to
undefined in an earlier iteration of the loop that walks through the weak
references. That in turn may result in invalid object references to objects
that are scheduled for destruction by the collector.

So after calling all destroy handlers for QObjects, reset all of the weak
values again.

Task-number: QTBUG-54939
Change-Id: I00ebabb76274e296fb1bd90d8d3e21dbbb920b57
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-08-05 18:55:39 +00:00
Liang Qi 45f79dc7e5 Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.cpp
	src/plugins/qmltooling/qmldbg_debugger/qv4debugservice.h

Change-Id: I1e6a9424e7f87d9e4ac1ea387ec70e151106f1c7
2016-08-05 09:02:17 +02:00
Simon Hausmann 0a4cebe6d3 Fix recursion during aggressive GC
With aggressive GC enabled we may end up calling the GC recursively, which does
not work at all, so disable that.

Change-Id: I9ce0abbdb7b2bfa8499b33fd0be0d6e4a5212a15
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
2016-08-04 06:21:40 +00:00
Ulf Hermann 901b975fb5 V4: Don't pass size and pointer through allocation trackers
By not relying on the return value of the macros we can #define them
away later, when compiling with -no-qml-debug

Change-Id: I24d50fa3f5d8e8765a42b050c81ddfae20f20a23
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-07-28 11:03:25 +00:00
Milian Wolff d453275a88 Add heaptrack support to qv4mm pool allocator.
When you build qtdeclarative with CONFIG+=heaptrack then the allocations
from the custom pool allocator can be traced with heaptrack. This works
similar to the existing valgrind support.

Change-Id: Ia988380415083aa1346c84c8c64b49ea3e17b7e2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-06-26 21:11:47 +00:00
Frank Meerkoetter e88500ff25 Increase test coverage for the V4 memory manager
This commit adds a small test that exercises a number of code paths
inside qv4mm.cpp which are normally gated via environment variables.

Change-Id: Ibe959387a9b86ce68df258513446d2165fe06ee2
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-06-20 07:42:08 +00:00
Erik Verbruggen ce08000602 V4: tighten up various casts to check also check type.
All those type conversions assumed that the content of a Value was
either the requested type, or 0 (zero, a null pointer). Now, attempting
to convert e.g. undefined to a string will fail, instead of returning a
weird address.

Change-Id: I0f567cdcc9cc9728d019f17693f4a6007394a9c6
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2016-06-08 08:04:53 +00:00
Erik Verbruggen 2cb3466baa V4: fix all pedantic warnings
- signed/unsigned conversions
- size conversions (i.e. int<->long)
- padding issues inside MemoryManager::Data

Change-Id: I3770de2c187d1520d98e2322d682b3ecc9a14671
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-26 08:59:25 +00:00
Erik Verbruggen 5f3b1e8125 V4: Get more code inlined in the MemoryManager.
Change-Id: I7cf6c5d3458b0c43283e63a7300ee9965ba803fb
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com>
2016-05-25 08:22:40 +00:00
Liang Qi 1e421097f0 Merge remote-tracking branch 'origin/5.6' into dev
Change-Id: Iec1b2de53c275996364c4bab0123ccb3e6e9895e
2016-01-29 13:01:22 +01:00
Jian Liang 3cc589c983 Make sure we destroy all QV4::QObjectWrapper objects
Delay freeing QObjectWrapper Value to MemoryManager::sweep() to make sure
we can destroy all QObjectWrapper objects.
We also keep track of QObjectWrapper in QV4::Heap::ModelObject to make
sure we destory them in QV4::MemoryManager::sweep()

Change-Id: I3a8a3b07faab1f88c2eb746f68aa8d9584b40026
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-01-22 14:07:19 +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
J-P Nurmi 9c4621217f Revert "Fix QtSharedPointer::ExternalRefCountData object leaks"
This reverts commit 839d2d3e23, which has
been causing crashes in qtquickcontrols2 auto tests and making it nearly
impossible to integrate anything over the past few days.

Change-Id: I570b286a067aae5e3c2d8c56ad601e1a6cb58c20
Task-number: QTBUG-50134
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-12-23 18:19:57 +00:00
Jian Liang 839d2d3e23 Fix QtSharedPointer::ExternalRefCountData object leaks
Call destroyObject() for every QV4::Heap::QObectWrapper object in heap in
QV4::MemoryManager::sweep() to make sure the QPointer object contained in
QV4::Heap::QObjectWrapper is properly destructed.
We also keep track of QObjectWrapper in QV4::Heap::ModelObject to make
sure we destory them in QV4::MemoryManager::sweep()

Change-Id: I3b3e96cfc300c2e21ab691762879ac2970afa90c
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-12-18 15:52:43 +00:00
Friedemann Kleint 8848abe69f QML: Sanitize reading environment variables.
Where possible, use qEnvironmentVariableIsSet()/
qEnvironmentVariableIsEmpty() instead of checking on the
return value of qgetenv().
Where the value is required, add a check using one of
qEnvironmentVariableIsSet()/Empty().

Change-Id: Ia8b7534e6f5165bd8a6b4e63ccc139c42dd03056
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2015-10-22 12:40:18 +00:00
Lars Knoll d5d9c3097a Improve algorithm to handle GC of Strings
The old algorithm could lead to excessive garbage collection
in cases where lots of strings are being created.

The new algorithm is a bit more agressive in doubling the GC limit
for string data. This doubles the performance of both the v8 regexp
and splay benchmarks.

Change-Id: I2b5cd27c14410b033038a409d5ae03c9636d4f71
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-25 08:39:40 +00:00
Lars Knoll a8ccf32793 Cosmetic improvements to marking of objects during GC
Change-Id: I79a7093c7086ea7f34252f097f18fe7c835053aa
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-25 08:39:20 +00:00
Lars Knoll bf8403d8d4 Avoid a function call when allocation new objects
Change-Id: I5f30d4fc3901fcd77aba4e7601586aa34cc0f5d2
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:20:15 +00:00
Frank Meerkoetter 884097f463 QV4_MM_STATS was missing largeItem details
The output of QV4_MM_STATS was only reporting the items allocated on the
JS HEAP. It was missing out on the LargeItems which are allocated on
the C++ heap.

Change-Id: Ife3d7afd769beb31afd1ed681d503f9811b03b96
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 07:12:55 +00:00
Lars Knoll 830376c962 Rename currentExecutionContext to currentContext
Now that the other method is gone, let's use
the shorter currentContext

Change-Id: I2a6fb3b77f83a1ffdf314ad29081e303d17030ed
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 07:37:26 +00:00
Lars Knoll 3a8d6123d1 Store the stack of executioncontext's on the JS stack
This saves one pointer per allocated execution context.
Now every execution context that is pushed, allocates two
Values on the js stack. One contains the context itself, the
other one the offset to the parent context.

Things are a bit tricky for with and catch scopes, as those
are called from the generated code, and can't open a Scope
anymore. In addition, all methods iterating over the js
stack frames need to work with ExecutionContext pointers,
not ScopedContext's.

Change-Id: I6f3013749d4e73d2fac37973b976ba6029686b82
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 07:37:16 +00:00
Lars Knoll 7dab89a65e Cleanup the ExecutionContextSaver
Always operate on the current context (as that's what we do
in practice anyway).

Change-Id: I4171207a7a86e69aa685754956c0764ac6e152a7
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 07:37:08 +00:00
Simon Hausmann 4876ea6a18 Fix performance of ListModel::get()
When called, the function would return a full-fledged QObject that maps the
list element addressed. It would contain a _copy_ of all values in the list
item and it would create a new meta-object for each list element.

This function exists for the JavaScript API, and therefore we now return a much
more lightweight object. For compatbility reasons it still has to be a QObject,
but the meta-object of it is created on-demand, i.e. only when accessing
properties from the C++ side or when connecting to the changed signal of a
property. Otherwise the JavaScript wrapper will return the live values from the
model without copying them.

Change-Id: Iabf3ca22192d2aee06ae9d4b4cfb2fcde2a021b1
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Michael Brasser <michael.brasser@live.com>
Reviewed-by: Spencer Schumann <spencer.schumann@echostar.com>
2015-08-19 05:03:50 +00:00
Ulf Hermann eb30e3d7ee Merge remote-tracking branch 'origin/5.5' into 5.6
Conflicts:
	src/qml/debugger/qv4debugservice.cpp
	src/qml/jsruntime/qv4value_inl_p.h
	src/qml/jsruntime/qv4value_p.h
	src/qml/memory/qv4mm.cpp
	src/qml/memory/qv4mm_p.h
	src/qml/qml/qqmlnotifier_p.h
	src/qml/qml/qqmlproperty.cpp
	src/quick/items/qquickflickable.cpp
	src/quick/items/qquicktextedit.cpp
	tests/auto/quick/qquickwindow/BLACKLIST

The extra changes in qqmlbinding.cpp are ported from changes to
qqmlproperty.cpp that occurred in parallel with writeBinding() being
moved to qqmlbinding.cpp.

Change-Id: I16d1920abf448c29a01822256f52153651a56356
2015-08-18 10:29:47 +02:00
Frank Meerkoetter 92624025ea Do not sort the vector of chunks
I don't see why the vector needs to be sorted by the base()
addresses of the contained PageAllocations.

Change-Id: I31946a50075c64d01c6de98964ea42ebfc936c68
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-11 20:51:00 +00:00
Lars Knoll c1667cd727 destruct qobject wrappers before sweeping the GC heap
The wrappers emit a destroyed signal, and it's important
that the GC heap is in a well defined state when these signals
are emitted.

Change-Id: I423c4241b1e2fd3de727277d26bbe64f08862193
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-10 07:24:36 +00:00
Lars Knoll 415f55d140 Encapsulate and protect all accesses to the vtable of Heap objects
This is required, so we can safely access the vtable even while
we're marking objects during GC.

Change-Id: I34f56b61b4bca0d0742faf607eb5ab8b2c30685e
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-10 07:24:32 +00:00