Commit Graph

483 Commits

Author SHA1 Message Date
Erik Verbruggen 702c4247d7 V4: Pass scope around as parameters inside the runtime.
The implementation of many (or all) runtime functions consist of first
creating a QV4::Scope, which saves and restores the JS stack pointer.
It also prevents tail-calls because of that restoring behavior. In many
cases it suffices to do that at the entry-point of the runtime.

The return value of a JS function call is now also stored in the scope.
Previously, all return values were stored in a ScopedValue, got loaded
on return, and immediately stored in another ScopedValue in the caller.
This resulted in a lot of stores, where now there is only one store
needed, and no extra ScopedValue for every function.

Change-Id: I13d80fc0ce72c5702ef1536d41d12f710c5914fa
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-06-22 11:07:05 +00:00
Liang Qi 4d2f743baa Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
	src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp

Change-Id: I26d6435a29cac3840bb567ade5149c2562a94bf9
2016-06-13 19:06:06 +02:00
Liang Qi 0932a59971 Merge remote-tracking branch 'origin/5.6' into 5.7
Part of 0e053528 was reverted in the merge, about lastTimestamp. It
will be applied later in separate commit.

qmltest::shadersource-dynamic-sourceobject::test_endresult() was
blacklisted on linux.

Conflicts:
	.qmake.conf
	tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp
	tests/auto/qmltest/BLACKLIST
	tests/auto/qmltest/qmltest.pro

Task-number: QTBUG-53590
Task-number: QTBUG-53971
Change-Id: I48af90b49a3c7b29de16f4178a04807f8bc05130
2016-06-10 10:06:39 +02:00
Erik Verbruggen dbf7efde1e V4: Mirror jsAlloc behavior at stack allocation.
Allocating from the JS stack will zero out the memory, and thus indicate
to valgrind that memory is not uninitialized. By first marking the whole
stack as uninitialized and only then allocating 2 entries, the behavior
for those two entries will now match the allocation behavior. This
fixes a false positive when using valgrind.

Change-Id: Icdb5279e1cfbfe6b5c385cc42c556edf721fa74b
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
2016-05-27 10:04:59 +00:00
Liang Qi 8ae479a8ea Merge remote-tracking branch 'origin/5.7' into dev
Conflicts:
	src/qml/jsruntime/qv4engine_p.h
	src/qml/jsruntime/qv4runtime_p.h
	src/qml/qml/qqmldelayedcallqueue.cpp
	src/qml/qml/qqmlvaluetypewrapper.cpp
	src/qml/qml/qqmlvmemetaobject.cpp
	src/qml/qml/v8/qv8engine_p.h
	tests/auto/quick/qquicktext/tst_qquicktext.cpp

Change-Id: I3f0608c7beb88088cbbef4d0db59920f56deaea9
2016-05-24 14:00:39 +02:00
Erik Verbruggen 607320ca9f V4: allow inlining of ExecutionEngine::{qml,js}Engine()
All other changes are just to be able to include qv8engine_p.h in
qv4engine_p.h

Change-Id: I71ba2ec42cdc20d5c7d97a74b99b4d1ada1a5ed8
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-05-20 13:44:13 +00:00
Liang Qi 63ec33e79c Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
	src/plugins/qmltooling/qmldbg_profiler/qqmlprofilerservice.cpp
	src/qml/jsruntime/qv4engine.cpp
	src/qml/jsruntime/qv4engine_p.h

Change-Id: I89ffccd699bee675732758d039e22224b275d60d
2016-05-19 20:41:34 +02:00
Simon Hausmann 72515ebe5a Fix crashes when incubating objects asynchronously with initial properties
This is a regression from commit 94e337fa95 where
we accidentally ended up not having a calling QML context set anymore when
initializing the properties on newly incubated objects as provided by the
caller. The QML context is necessary as for example when we set a URL property,
the URL can be relative and it will be resolved to the base url of the context
when written, such as in in QQmlPropertyPrivate::write.

Change-Id: I1d896381fc92f653a7d76f4d82174bca48828f5e
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-05-18 10:08:30 +00:00
Erik Verbruggen 74f75a3a12 V4: Limit call depth by count, not by checking the native stack.
Getting the native stack size can be really expensive. For example, on
Linux/x86_64 (Ubuntu 15.04), it is at least 200,000 instructions for a
single-threaded application. With more threads (like qmlscene) it typically
ends up around 1M(!) instructions. Worse, it is called twice in the
ExecutionEngine constructor.

So, now we limit the depth of JavaScript calls to a fixed number, 1234 by
default. This can be changed by setting the environment variable
QV4_MAX_CALL_DEPTH to the desired depth.

Change-Id: Ic13c8efb2769e64fbc73deee6f6fa39d7c0b7af5
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-05-11 11:11:34 +00:00
Andy Nichols 60da655dff Merge remote-tracking branch 'origin/5.7' into dev
Change-Id: I57b06e2e98beb010a56dd0593d93e078ecf76eea
2016-04-05 12:11:13 +02:00
Erik Verbruggen 7d51248284 V4: Allow some more functions to be inlined.
Change-Id: If9d1f87fd7cf0b12d2827c4574109234be7e8ab8
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
2016-03-31 11:00:50 +00:00
Nobuaki Sukegawa 3b7e2a69f7 Convert QByteArray in C++ type to ArrayBuffer in QML and vice-versa
Change-Id: Ie4e29a443a17826a3ce4d1e1912bd35dc497ac78
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-03-05 08:26:29 +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
Maurice Kalinowski 9e980750c6 WinRT: Enable JIT for x86/x64 target platforms
This only works for Windows 10 and later.

Setting the "Code Generation" capability in the manifest, WinRT
applications can use JIT for Windows 10 Desktop. Update the Allocator
in regards to this and also update the VirtualProtectFromApp section.

When the engine gets initialized, check for marking an area as
executable. If it fails, fallback to interpreter mode.

This does not affect ARM platforms, as we do not have calling
conventions yet. It is implicitly disabled as V4_ENABLE_JIT is not
defined.

[ChangeLog][WinRT] Enable JIT for x86/x64 targets on Windows 10 and
later.

Change-Id: Ie05add5263f71387c5ce98456b9bec86c6c07ceb
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-01-16 10:33:06 +00:00
Mathias Hasselmann a29c621659 Print warning if JIT is disabled
The wiki will provide information on how to work around the issue.

Change-Id: I4409f5b4af0668ab28197adb8766898124e8cec8
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-01-14 19:05:36 +00:00
Thiago Macieira 65fa1b4c08 Remove prohibited uses of underscore + capital letter
All identifiers starting with an underscore and a capital letter are
reserved to the compiler and must never be used by the user code. Try to
find a better name or, in the worst case, move the underscore to the
last position in these identifiers.

See commit cf63c63d558227fdbef09699c261560e7474f5ea in qtbase for a case
of such an identifier causing a build breakage when the compiler began
treating it specially (it was _Nullable).

Change-Id: I1d0f78915b5942aab07cffff140f9f39c29f0fdf
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2016-01-08 00:09:50 +00:00
Sérgio Martins 49f9797d2a Fix a couple of container detachments
Change-Id: I0def20d858de7721771702907b7a431b5fb90a1f
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-01-05 16:36:02 +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
Ulf Hermann 5c64391fb4 Only set V4 debugger when service is enabled
Otherwise different debug services could steal each other's debugers.

Change-Id: Ic0a50333d21c7d20a7124240ea598f8446400ae3
Reviewed-by: hjk <hjk@theqtcompany.com>
2015-10-15 17:11:50 +00:00
hjk 23f3fcbabc QmlDebug: Split QV4::Debugging::Debugger
... into a pure interface and a QV4::Debugging::V4Debugger implementation.

This is in preparation of a second implementation of this interface
to be used with 'native mixed' debugging.

Change-Id: I3078dcfe4bdee392a2d13ef43a55ca993e7b88d8
Reviewed-by: Ulf Hermann <ulf.hermann@theqtcompany.com>
2015-10-14 13:38:07 +00:00
Lars Knoll 6565e78610 Reduce memory consumption of signal handlers
Move the connect/disconnect methods for signal handlers into
their prototype, so that we don't need to define them per instance
anymore.

Change-Id: Iac1e6d1dd7bce86730dbb6c51e2c3f79713641f7
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-25 08:40:03 +00:00
Lars Knoll c72f973a35 Speed up creation of Array literals
Gives around 10% speedup on the v8 splay benchmark.

Change-Id: I47f64e7b73bde59ac3bdd2c94fc199ecfbbf290e
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-25 08:38:56 +00:00
Lars Knoll ff347ccb09 Fixes to Error objects
Move the name and message property into the prototype as
per JS spec. Only define the message property in the
object itself if the value used for construction is not
undefined.

In addition, clean up creation of the objects and centralize
it in a few template methods.

Change-Id: I014017b710575b30bf4e0b0228111878f5c73b9a
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:20:18 +00:00
Lars Knoll 13edffa303 Move remaining objects to new constructor syntax
Also disable the old way of constructing objects.

Change-Id: Ib4e69087cd563ae1481da116d6caf97876239798
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:20:13 +00:00
Lars Knoll 2a8de9d8d8 Convert FunctionObjects to new allocation syntax
Change-Id: I269c20abdc7f9eb0d71a2d2d485d622b65405762
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:20:09 +00:00
Lars Knoll b3cdc48914 Simplify new construction scheme
Declare the default prototype and internal class
in the class itself.

Change-Id: I08c2b42aa61a886580061336ae60cef8dedc0f03
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:20:07 +00:00
Lars Knoll 6190b10d1c move error objects over to new construction scheme
Change-Id: I533c7bf90d49aee10b5661fd15a98e013b1169bd
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:20:04 +00:00
Lars Knoll d7e535e99b Convert variant object and ObjectProto
Change-Id: I5ee3b453b74f5832997aca68d04979302f9afac5
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:20:01 +00:00
Lars Knoll 9420eb5c4e Use the new construction scheme for RegExpObjects
Gives around 10% speed improvement on the v8 regexp
benchmark.

Change-Id: Iad37bcbc79ccbfb92f65852b660364c919862a75
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:19:59 +00:00
Lars Knoll 17a0c271e0 Move more objects over to the new allocation scheme
Change-Id: I0241efe10d115f8e4a646f840e47e220eb6cfc18
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:19:56 +00:00
Lars Knoll 833c99db20 Inline property data into the object
Append the part of the objects property data that is
known ad instantiation time to the object itself and
by that avoid creating a separate MemberData. Saves
some memory and should speed up object creation.

Currently implemented only for Object and ArrayObject.

Change-Id: I7693bf2f3a28fb718522398ebb94ac115e021fa4
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-22 08:19:53 +00:00
Lars Knoll fb52dab6b4 Further cleanups
Reduce usage of ScopedContext.

Change-Id: I84a6a7478065de3398fd0b21596ca1308e78ceb3
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 19:12:40 +00:00
Lars Knoll f3efdebc34 Fix typo
Change-Id: I9bfc96096ec5e2c8bd4d3c5bad13fc78ae657962
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 07:37:28 +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 0e6195a85c Cleanup usage of ExecutionEngine::currentContext
Change-Id: Ic79d6da162375928ec25871cd0341daeab6483d2
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 07:37:22 +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 fb059f697a Reduce usage of context->parent
Change-Id: I31bb8019783311a7e6065e2aac7fec67c1120ebf
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 07:37:14 +00:00
Lars Knoll cedd732794 Explicitly push/pop ExecutionContexts
Avoid the implicit push inside the execution context constructor
and rather make this explicit in the code.

Change-Id: I1bb0fb523fddbb273fc666370d619f55f49cd40a
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 07:37:11 +00:00
Lars Knoll b5902bd43a Get rid of the qmlContextObject method
Change-Id: Id8c0d9e15dd85b3818e283ab6769a49bb2e6d0f7
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-09-15 07:37:06 +00:00
Lars Knoll ad55f5fd24 Move the qmlSingletonWrapper method out of the contextwrapper
One more step towards removing the class alltogether.

Change-Id: Ic9f6794eb3c5c6605ee43ad23a6d432ebbf321a1
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-20 20:01:25 +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
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
Lars Knoll b288956817 Use the QmlContext to access properties of the scope object
Add some runtime methods to access properties of the scope
object directly (using the QmlContext), and generate proper
code to call those.

Change-Id: I0b29357c9a3b9ad53ba568ec6cb763e8ecb10f21
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-10 01:21:57 +00:00
Lars Knoll 416c0f3263 Add ability to retrieve and use the QmlContext from our generated code
Our generated code (JIT and interpreter) should operate on the
QML context to retrieve QML related things. That's better than
operating on 4 different temps.

So this commit introduces the QML context as a temp in the
code we generate for QML. The next commits will move things over
to use that context with specialized runtime methods instead of
using generic subscript/get calls on the different subobjects.

Change-Id: Ia05cf339de9cdd23003f35cf78ede17d2590f8de
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-08-10 01:21:48 +00:00
Friedemann Kleint 7da45b21b7 Fix warning about returning address of local variable by MSVC2015 in qv4engine.cpp.
qtdeclarative\src\qml\jsruntime\qv4engine.cpp(179) : warning C4172: returning address of local variable or temporary: dummy

Disable warning as using the address is intended.

Change-Id: Ide894a8dc2fb94f11d0455723c46567c84d91f8d
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-07-17 13:44:21 +00:00
Erik Verbruggen c749f37c83 V4: track C++ heap usage for Strings in the MemoryManager
... and do a GC run when it exceeds a threshold. The issue with Strings
is that they hold on to QString instances that store the real content.
However, the GC only sees the light-weight JS handle, and doesn't take
the size of the backing content into account. So it could happen that
big QStrings accumulate in the heap as long as the GC didn't reach its
threshold.

The newly introduced unmanaged heap threshold is upped by a factor of
two when exceeded, and lowered by a factor of 2 when the used heap space
falls below a quarter of the threshold. Also grow the threshold if there
is enough space after running the GC, but another GC run would be
triggered for the next allocation.

There is a special case for Heap::String::append, because this method
will copy the data from the left and right substrings into a new
QString. To track this, append notifies the memory manager directly of
the new length. The pointer to the memory manager is stored in
Heap::String, growing it from 40 bytes to 48 bytes (which makes it still
fit in the same bucket, so no extra memory is allocated).

Task-number: QTBUG-42002
Change-Id: I71313915e593a9908a2b227b0bc4d768e375ee17
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-07-10 13:52:18 +00:00
Thiago Macieira f35be0bc5a QtQml: Fix const correctness in old style casts
Found with GCC's -Wcast-qual.

Change-Id: Ia0aac2f09e9245339951ffff13c958364a2e9859
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-07-09 00:12:37 +00:00
Lars Knoll 5f162e17ed Cleanup retrieval of scope and context objects
Change-Id: I9c6174181f950bc4f829727dc6acdfe82fa4e894
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-18 18:24:34 +00:00
Lars Knoll f077bf13ef Clean up ExecutionContext's for QML
Create a specialized QmlContext instead of re-using
a call context with a QQmlContextWrapper as activation
object.

This saves some memory and opens up the route to getting
rid of the context wrapper in a future commit.

Change-Id: I1591c73932a08564fddf5137ac05bbc6f31dd4d5
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-18 16:42:58 +00:00
Lars Knoll 64199b0a58 Store a Heap::String pointer in StringObject
Change-Id: I926c5bb2dd4f1613af6737d4200e568f0ec13d58
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-17 09:03:48 +00:00
Lars Knoll a914b18667 Store rootcontext in a GC safe way
Change-Id: If81d638c0ccd2b34df918ae5055e309f4eae031f
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-17 07:40:03 +00:00
Lars Knoll 73093cbe4b Fix some function signatures
Add a const several places and pass values by pointer, not
reference. This allows us to also get rid of some Scope's.

Change-Id: I3b4c29c22511c947d024457e7b8fa2aaa6bec55d
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-15 17:03:21 +00:00
Lars Knoll f468f71571 Get rid of qv4qmlextensions
It only contained the proto for the value type wrapper. Instead
just create it lazily, but reserve space on the js stack for it.

Change-Id: I2301549b6dc4007bd5ac848e1dca25aafd583c4a
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-15 15:27:06 +00:00
Lars Knoll d32849dbe7 Remove explicit marking of the typedarray constructors
These objects live on the JS stack and are thus marked implicitly.

Change-Id: I8295d8096d0a47861e0092c36e16b95db458de3c
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-10 15:01:29 +00:00
Lars Knoll 864988474a Move the StringValue members of ExecutionEngine onto the JS stack
Change-Id: Ib55c05f1730b7659e2f6fee7e1fa79c10c759167
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-06-10 15:01:17 +00:00
Simon Hausmann 9556f6d075 Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
	src/qml/jsruntime/qv4engine_p.h
	src/quick/items/qquickitemsmodule.cpp
	src/quick/items/qquicktext.cpp
	src/quick/util/qquickpixmapcache.cpp
	tests/auto/quick/qquickwindow/tst_qquickwindow.cpp

Change-Id: I90ecaad6a4bfaa4f36149a7463f4d7141f4a516a
2015-06-04 10:28:48 +02:00
Aleix Pol dad48f0e9c Makes it possible to extract all data from a QML DropArea
There's many types that aren't being covered by DropArea API, such as
images. getDataAsString is not acceptable, since fromUtf8 chokes on
reading non-utf8.
This patch introduces getDataAsArrayBuffer method that won't try to convert
the data into a QString and simply pass a QV4::ArrayBuffer, that internally
keeps a QByteArray.

Change-Id: I65411b3d365ee6c5e13effd9167156771ee08a05
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-05-23 13:52:36 +00:00
Simon Hausmann bf935a5359 Fix MSVC warning about unused variable
Change-Id: I9b2f21dd7cfc82a9da9aa3e4c60d47fa07fdceaf
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2015-05-19 10:53:32 +00:00
Kai Koehne 2cb2c8f9e1 MSVC: Fix compiler warning
Fix compiler warning introduced in commit  d76921e3082cd31:

jsruntime\qv4engine.cpp(1626) : warning C4100: 'v' : unreferenced formal parameter

Change-Id: I1f2b74f8e3fb14019f6e28b407d0336b0812c573
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
2015-05-19 07:40:02 +00:00
Erik Verbruggen d76921e308 QML: fix mixed debug/release build on OSX.
Dyld will take the debug library and link it against the release
versions of the frameworks. (Using the debug versions is an option to
dyld when starting an application.) This requires all symbols in both
debug and release libraries in frameworks to be the same.

Change-Id: I6d96bcdf8577f1dffc63c508cb7adc0db2acc486
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-05-12 08:49:09 +00:00
Simon Hausmann a690648c21 Add protection against "wrong" marking in debug builds
To protect against situations where we accidentally mark an object that belongs
to a different engine - there are many possible entry points - this patch adds
an assertion in debug builds for this situation. When it happens, it will point
more or less directly to the code that tries to push an object to the wrong JS
stack for marking. This helped in the investigation of QTBUG-44895

Change-Id: I311b9ff6d282d52e725044b03a62cd77085536be
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2015-05-08 14:55:32 +00:00
Simon Hausmann 94db5de2ac Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
	tests/auto/quick/qquicktext/tst_qquicktext.cpp

Change-Id: I075e742da8396a268d97d3ab34bcd9e0c0cf001f
2015-04-28 14:29:59 +02:00
Simon Hausmann e2447f9f5f Merge remote-tracking branch 'origin/5.4' into 5.5
Conflicts:
	.qmake.conf
	tests/auto/qml/qqmlxmlhttprequest/tst_qqmlxmlhttprequest.cpp

Change-Id: I715b8a78b74cbe0dcaf599367fd6e08af4858e11
2015-04-27 14:40:00 +02:00
Lars Knoll 590c23b23c Move evalfunction and thrower onto the js stack
Change-Id: I3a0abe13d802aff8998d1c64f86b5a8f98c8335f
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-24 15:21:43 +00:00
Lars Knoll 1af88df072 Move constructor objects onto the js stack
Change-Id: I828c5f7407d90cd5df1a8fd89a0ca35074fbde43
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-24 15:21:36 +00:00
Lars Knoll f9440c704e Move more objects from the v4 engine to the js stack
Convert most of the prototype objects in the v4 engine.

Change-Id: I365f290493c20973bc991b6a383649836e42a16a
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-24 15:21:28 +00:00
Lars Knoll 7501c394d0 Continue the work to move Values inside the v4 engine to the js stack
Started with objectPrototype, the next commits will move more
of them over into the new data structure.

Change-Id: I1a048e95149ce69e4e42094db2dd738ce49b50b8
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-24 15:21:20 +00:00
Lars Knoll 0d54025cd2 Move exceptionValue and globalObject from the Engine onto the JS stack
We'll need to move all GC'ed objects currently stored in ExecutionEngine
onto the JS stack for easier management in a new garbage collection
scheme. This is the start of that change.

Change-Id: Ib3ad8e846875dade8a807ea79f063173d40e4aad
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-24 15:21:08 +00:00
Lars Knoll 0a499043fb Get rid of qv4value_inl_p.h and replace it by qv4typedvalue_p.h
This is a cleaner separation and further reduces include dependencies
in the definitions of our basic data structured.

Change-Id: I18aa86cdea0c0dfbc16075d4d617af97e638811e
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-24 15:20:43 +00:00
Liang Qi 07782f48f4 Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
	src/qml/qml/qqmlbinding.cpp
	src/qml/jsruntime/qv4arraybuffer.cpp
	src/qml/jsruntime/qv4functionobject.cpp

Change-Id: Ic752e9dfd69b282093651c9234c110a49762f06d
2015-04-22 15:32:19 +02:00
Lars Knoll 484abc8159 Get rid of asFunctionObject()
Change-Id: Ib4858376dc0ec57fa473c80696abc66a570c90ec
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-21 13:01:54 +00:00
Lars Knoll b4cb71e9d7 More cleanups
Get rid of Value::asObject(), and pass const Managed pointers
into some more vtable methods.

Change-Id: Ia4f427d5fd8868f77b4015d1ce5424d32bfc2115
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-21 13:01:47 +00:00
Rolf Eike Beer 9934c075c7 QML: do not check stack size if stack grows up
On architectures where the stack grows upwards (i.e. HP PA-RISC) the
stack limit calculation fails because the variables used to check the
offset are usually close to the bottom of the stack, which is in this
case the origin of the stack grows. Since these machines are a rare
obscurity simply assume that everything is fine on these machines. The
few people that are indeed running QML on such machines will probably
be able configure their stack size properly by default.

Task-number: QTBUG-44268
Change-Id: Ia83a39179a0f6e0602ba7a5032d386e12d8d1ba3
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-21 08:52:06 +00:00
Lars Knoll b8dbd08705 Get rid of Value::asDateObject()
Change-Id: I71816a784b5175f600c5a870318b16c0d84c42fb
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-16 20:56:59 +00:00
Lars Knoll 4930941197 Further cleanups
The get and getIndexed vtable methods should take a const Managed
pointer. Start cleaning up the asFoo() methods in Value and Managed
by removing asArrayObject() and asErrorObject().

Change-Id: Ibd49bf20773ef84c15785b7ac37a7bc9fd4745d5
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-04-16 17:44:24 +00:00
Simon Hausmann d22db9e458 Speed up script binding initialization
Don't spend any time repeatedly building the same internal class for the simple
binding functions. We can do that once at engine construction time.

Change-Id: I3777b5bd15ad4a8aaf78ae13bee27e8d8cadc2ee
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2015-04-16 17:14:09 +00:00
Simon Hausmann b220a20552 Speed up value type binding creation
* Avoid calling QMetaType::construct/destruct(typeId, ...) as that requires
  repeated lookups in the type registry. Instead cache the constructor/destructor/etc.
  function addresses in the QQmlValueType singletons as QMetaType
* Allocate memory for the gadget pointer lazily, to accommodate the common case of
  a value type binding by property reference.

Change-Id: I98a3ac73453b8f80027c06401b4f29a9707949d2
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2015-04-16 13:40:17 +00:00
Valery Kotov 175772b3de QML Engine: Share data for ArrayBuffer created from QByteArray.
ExecutionEngine performs shallow copy of internal data for ArrayBuffer
created from QByteArray.

Change-Id: I514cd9708a7fbe9a989937fac62d00b464d7362d
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Reviewed-by: Valery Kotov <kotov.valery@gmail.com>
Reviewed-by: Pasi Keränen <pasi.keranen@digia.com>
2015-04-15 09:27:59 +00:00
Liang Qi c8427a542b Merge remote-tracking branch 'origin/5.5' into dev
Conflicts:
	tests/auto/qml/qqmlitemmodels/testtypes.h

Change-Id: I2f2f3f47fd873ddd4fd027414654a861b56357f4
2015-03-24 22:09:49 +01:00
Christian Strømme 90b06e2773 Fix conversion between char and string.
If a QChar (or char) was used to set a QString property, the
intermediate value used by the QML engine (int), would be
converted to a string representation of the integer and not the actual
character. To avoid this behavior, characters are now stored as string
objects and the string is then converted to the target char type if
possible.
A side effect of this solution is that it is makes it possible to
assign a string to a char property as well, but only if the string
contains exactly one character.

[ChangeLog][QtQml][Important Behavior Changes] Assigning a char to a
string will now create a string with the actual character instead of a
string representation of the character's code-point. A side effect of
this change is that a one-character string also can be assigned to a
character type.

Task-number: QTBUG-44934
Change-Id: Ifd15386933ee11354ee1bbb5598a5f0b00a08616
Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-03-21 11:15:31 +00:00
Lars Knoll 7b7297470c Cleanup some of the casting code
Get rid of value_cast, and move the Managed::as()
method into Value.

Change-Id: I440ac44ae77f4fda1a8a837383fe631f432f6532
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-03-20 11:17:11 +00:00
Simon Hausmann fb0cb17cb5 Merge remote-tracking branch 'origin/5.5' into dev
Change-Id: I6033aba359ac551f450ad517d20a0986bf4655f6
2015-03-17 09:52:19 +01:00
Valery Kotov d988310434 QML Engine: ArrayBuffer XHR response type support
Support for "arraybuffer" response type for QQmlXMLHttpRequest was
added.

[ChangeLog][QtQml][QQmlXMLHttpRequest] QQmlXMLHttpRequest now
supports "arraybuffer" binary response type.

Change-Id: I866e543cc7bc6ab037ffff1ef6628057b73daf90
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-03-09 19:41:41 +00:00
Frederik Gladhorn 6dbf435ca4 Merge remote-tracking branch 'origin/5.5' into dev
Change-Id: I94f8ae93d76bd5c120de25d9c238701afe8bfbd0
2015-03-03 18:13:38 +01:00
Lars Knoll feebac8e70 Move memory management related functionality into it's own folder
Start moving the memory related functionality into it's own folder.
This will simplify refactoring of the GC related functionality later
on.

Change-Id: I70ec6f512af7a7897625afb84d914c17572b0ccd
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-03-02 16:34:16 +00:00
Friedemann Kleint 5163c11952 QtQml: Micro-optimize iterator loops.
Avoid repeated instantiation of end() in loops, use variable instead.

Change-Id: I3bb1c6918cfd16a5dcefbcc03c442e99fe9bf76b
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
2015-02-26 15:13:34 +00:00
Frederik Gladhorn ad67ec26d0 Merge remote-tracking branch 'origin/5.4' into 5.5
Conflicts:
	.qmake.conf
	LICENSE.GPLv2
	examples/qml/networkaccessmanagerfactory/view.qml
	src/qml/jsruntime/qv4runtime.cpp
	src/qml/jsruntime/qv4stringobject.cpp

Change-Id: I5d12f436d60995e51d5c2f59d364e9cbc24f8e32
2015-02-24 17:36:04 +01:00
Jani Heikkinen c5796292ad Update copyright headers
Qt copyrights are now in The Qt Company, so we could update the source
code headers accordingly. In the same go we should also fix the links to
point to qt.io.

Change-Id: I61120571787870c0ed17066afb31779b1e6e30e9
Reviewed-by: Iikka Eklund <iikka.eklund@theqtcompany.com>
2015-02-12 10:28:11 +00:00
Alex Richardson cf6e97119d Don't crash on FreeBSD when computing stack limits
On FreeBSD pthread_attr_t is a pointer and is dereferenced when calling
pthread_attr_get_np() so if we don't initialize it will probably crash.
This is not a problem on glibc systems since there pthread_attr_t is an
opaque union an doesn't need to be allocated using malloc().

Change-Id: I227685ddf9981974ade08aee8917f7262c301787
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2015-01-28 16:13:22 +00:00
Lars Knoll 0c2ab6e20c Store a double in NumberObject
Makes more sense than storing a Value in there.

Change-Id: I2e6ca71477100c1e1639bb89cced4f4049b5e5c2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-23 12:30:41 +01:00
Lars Knoll ef6b4938b9 Cleanups
Simplify some code in BooleanObject
Simplify access to call arguments and thisObject

Change-Id: I2f8e844019bc587385608beb02f05b15f827535c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-23 12:30:38 +01:00
Lars Knoll 3dbf4e9a69 Cleanups
Remove duplicated methods. Remove some mostly unused methods,
and simplify some others.

Change-Id: I605b249e54417bb32c3dfc8e22f2c8b6b684a1e1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-23 12:30:35 +01:00
Lars Knoll 002a5d4303 Get rid of most uses of ValueRef
Instead pass a const Value & into the functions

With our new inheritance structure, we can get rid of ValueRef
and instead simply pass a pointer to a Value again. Pointers to
Values are safe to use again now, as they are now guaranteed to
be in a place where the GC knows about them.

Change-Id: I44c606fde764db3993b8128fd6fb781d3a298e53
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-23 08:07:32 +01:00
Lars Knoll 8209f35b79 Rework QJSValue internals
Use a flagged pointer to either store a pointer to a
QV4::Value (from the persistent storage) or a pointer to
a QVariant in QJSValue::d. Like this we don't need to malloc
to create a QJSValue for most use cases.

Significantly reduces the memory consumption of QJSValue and
speeds it up a lot.

Change-Id: I10902cc4b6cc3f43d3f816875dc6c4bbb6b4490f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-21 18:22:52 +01:00
Lars Knoll d8131513b0 Add C++11 move operators, and a simpler internal constructor
Move semantics should optimize some copy operations on QJSValues,
and the internal constructor will simplify refactoring the
QJSValue class to get rid of the extra allocated private.

Change-Id: I24863b30523af2432aa81ad6b87fda7fe35749c4
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-21 18:22:47 +01:00
Lars Knoll 630f118f04 Move the internalClass pointer into Heap::Object
The other classes that derive from Heap::Base don't need it
at all. So get rid of it there and save a pointer.

Change-Id: I9c5df2e43cd6eeac2e6e41f3d3b8077d3afbc8f2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-21 13:19:02 +01:00
Lars Knoll 85bf8d732b Remove the remaining bit of code that use the vtable in the internalClass
Change-Id: Ia52f0e6db325aab37477d455f163487b319dce29
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-21 13:18:38 +01:00
Lars Knoll 8a23c8a613 Move vtable out of internalClass
We can move the internalClass to Object later on, and such save
having the internalClass on lots of Heap objects.

This commit basically adds and starts making use of a new
vtable pointer in Heap::Base. In addition, the construction
methods in the memory manager now automatically setup the
correct vtable.

Removing the vtable code from InternalClass and moving it into
Object will come in a separate commit

Change-Id: If49e8d73c769bf65bf47fe4dbf8b9546c8019dbc
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-20 13:29:59 +01:00
Lars Knoll 8ffb79bbd2 Refactor persistent values
Use a page wise allocation mechanism for persistent
values. This significantly reduces memory consumption
of persistent values and also improves their performance
a lot.

Change-Id: I8499d2ca5bdd871e029f643ae605a94544558bb5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-16 21:12:49 +01:00
Simon Hausmann 291aea1463 Merge remote-tracking branch 'origin/5.4' into dev
Conflicts:
	.qmake.conf
	src/qml/jsruntime/qv4context_p.h
	src/qml/jsruntime/qv4debugging.cpp
	src/qml/jsruntime/qv4engine.cpp
	src/qml/jsruntime/qv4functionobject_p.h
	src/qml/jsruntime/qv4qobjectwrapper.cpp
	src/quick/scenegraph/shaders/visualization.frag
	tests/auto/qml/qjsengine/tst_qjsengine.cpp

Change-Id: I492e8546c278f80a300a2129e9a29d861e144a30
2015-01-16 12:46:52 +01:00
Lars Knoll 431458b685 Fold the markBit into the internalClass pointer
Change-Id: I79f9286275f833dd01a3193042976d1f86ed5019
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-12 11:04:32 +01:00
Lars Knoll 53e144ae8d Fold the inUse flag into the internalClass pointer
Revert the flag (ie. flag == 0 means the item is used), and fold it
into the second lowest bit of the internalClass/nextFree field.

Change-Id: I7b690fdce00d16aa538fa70a269a755511477c5c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-12 11:04:30 +01:00
Lars Knoll ca977a0c8f Cleanup variant conversion code
Make public methods proper members of the ExecutionEngine, and
move private methods into the .cpp file only.

Change-Id: I3ca49e39bb1c4e559a2c63346e6ae6cfa446147d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-09 10:27:57 +01:00
Lars Knoll 7041eb353a Move the variant conversion methods from qv8engine to qv4::ExecutionEngine
Change-Id: Ibd529ae5cc3ba06f46152e9daa9119a4e7a2561c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-09 10:27:55 +01:00
Lars Knoll bb29bebc8a Get rid of more uses of QV8Engine
Change-Id: I763728b1685e8e68bcf815dda4dd8e5757f59dd2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-08 12:34:22 +01:00
Oleg Shparber 2fe82c505d Use QV4::ScopedObject typedef instead of actual type
Change-Id: I0b68c534ea513a7c230b12114f6b42b069f9864b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-03 23:29:57 +01:00
Oleg Shparber 21d481c209 Use QV4::ScopedContext typedef instead of actual type
Change-Id: I71c6c9cf030e347fbc5e4073e9ca338a9ce95999
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-02 21:29:48 +01:00
Oleg Shparber 29c0102adb Use QV4::ScopedString typedef instead of actual type
Change-Id: I64ecbf6cea463387a70e909ecc5f9165d22a7b0f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-02 21:29:09 +01:00
Lars Knoll 1443b0566e Add a direct accessor to retrieve the JS engine from the ExecutionEngine
Change-Id: I2617143e39f354657e12541f3796a583e9934118
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2015-01-02 21:11:06 +01:00
Lars Knoll e7b66a6058 Make Managed inherit Value
This completes the first milestone towards being able to move
objects across the GC heap.

Change-Id: I8e6ce90254ea767188a31f0dc85b133534c87eb0
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-20 15:16:39 +01:00
Lars Knoll db7b7d4161 Return a Heap object from the getter()/setter() methods of Property
We actually need to put the returned value into a ScopedFunctionObject
before calling it, as the Property could get deleted during the call
leading to a dangling pointer. With a GC that moves objects this will
become even more important.

Change-Id: I43bece6f80eb3501c1291065846e230a59ae8aed
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-20 12:00:04 +01:00
Lars Knoll 2950064286 Use a Heap::FunctionObject to store the thrower function
Change-Id: I6b3f03080f35e39d14b377363f7546a9f7260029
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-20 07:40:02 +01:00
Lars Knoll d3a6412c66 Remove most of the places where getPointer() is used
This is no longer required, and simply uglifies the code

Change-Id: Iba91a1d7735ebe23a43437f137a488423b6eb743
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-20 07:39:55 +01:00
Lars Knoll 4479bb58a4 Store a Heap::EvalFunction pointer in the engine
Change-Id: I002eb8f94e168c9faf1ee3521170dfaf442af1a3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-20 07:39:32 +01:00
Lars Knoll 05bf96997c Return Heap::ExecutionContext for globalContext()
Change-Id: Ide7c81735be4662ff45bf268cfe750ff1f784453
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-19 18:52:07 +01:00
Lars Knoll da2b7576da Return Heap::ExecutionContext for currentContext()
Change-Id: I155ab996e24d7f36761d2ea62a04774e16469b34
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-19 16:30:19 +01:00
Lars Knoll 0de16adf3d Mark JS freed parts of the JS stack as undefined in valgrind
Change-Id: Ibee3d95762bc0a0124b65ad8986ed643b9535529
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-19 16:30:10 +01:00
Lars Knoll 9d2a5ea28a Return a Heap::Object in Object::prototype()
Change-Id: Ice0265ae558ba14497421a5bbf25ee9db76adab5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-17 11:01:10 +01:00
Lars Knoll 8afc1f7fe2 Move prototype back from the vtable into Object
This is the only way we can support a GC that moves
objects around in memory.

Change-Id: I1d168fae4aa9f575b730e469e762bc5b5549b886
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-11 15:52:13 +01:00
Lars Knoll 4322c8d768 Better encapsulate access to the global object
Change-Id: I8a76112d821cb3fc172ba0d16ee8410d39b4422a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-11 08:40:48 +01:00
Lars Knoll ddfe9defa8 Encapsulate accesses to the root context
Change-Id: I668cef1363a5c1a5c5b9a7e138f3bd0338712eea
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-11 08:40:41 +01:00
Erik Verbruggen 8397f640e8 QML Debugging: Fix crash when stepping through try-catch block.
Also fix the stack-trace generation, otherwise the debugger engine would
report a breakpoint hit on the wrong line.

Task-number: QTBUG-42723
Change-Id: I1f655a5174b28a1c9c31c85bbe023fbce5ddbb96
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-12-09 11:55:04 +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
Simon Hausmann f58b5229a3 Fix run-time string handling with regards to the new heap
Changed runtimeStrings to be an array of Heap::String pointers instead of
indirect String pointers. Later that member along with other GC related members
will go into a managed subclass. Meanwhile the generated code no more loads
String pointers directly but just passes the index into the run-time strings to
the run-time functions, which in turn will load the heap string into a scoped
string.

Also replaced the template<T> Value::operator=(T *m) with a non-template
overload that takes a Managed *, in order to help the compiler choose the
non-template operator=(Heap::Base *) overload. This allows removing a bunch
of Value::fromHeapObject calls.

Change-Id: I20415c0549d33cca6813441a2495976b66d4c00e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-11-21 13:08:28 +01:00
Lars Knoll 3dc7b5ddf6 Cleanup exception catching code
Change-Id: I85afd5758f72e19c280dc196601ee145f0c25f01
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-15 13:16:28 +01:00
Simon Hausmann ad342b0524 Changed MemoryManager::alloc<T> to return Heap::T* instead of T*
Change-Id: Iede1ba624d1313fbe2f8e5e979e936f1f32efdc9
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-11-15 00:32:45 +01:00
Simon Hausmann afbf1f74af Ported ExecutionEngine::newString and newIdentifier to Heap::String
Avoid the use of Returned<String> for newString and changed the identifier
table to use Heap::String. This required moving some code back into
Heap::String, but that's code that doesn't call back into the GC, so
allocations and therefore future object moves aren't possible.

Change-Id: I1dca3e9c12a9c56f09419af8cc8cba39fe04f720
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-11-12 20:44:13 +01:00
Simon Hausmann faf13a3aa0 Ported most ExecutionEnginew::new* factory methods away from Returned<T>
We don't need Returned<T> anymore with the QV4:: vs. Heap:: separation.
Eliminating Returned<T> simplifies also some code.

Change-Id: Ic2a9cd3c1a94f2ea37b539d3984d63997121c2b9
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-11-12 17:55:57 +01:00
Lars Knoll f2532fd611 Cleanups
Remove a few reinterpret_cast's

Change-Id: I800b8c41123eaa22cf879571c747b4de0375e8cb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-12 12:13:33 +01:00
Lars Knoll 19ae8cdffe Convert ExecutionContext::parent/outer to use a heap object
Change-Id: I1b8ee831cfcdd5b1904ce24a341f5a796dce41cf
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-12 12:13:03 +01:00
Lars Knoll e552ca0602 Use Heap object for CallData::function member
Change-Id: I5cae1b16c68751da9481a1cdae2601efa2a500a2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-11 05:31:27 +01:00
Lars Knoll a4b8bea95f Use Heap objects as members
Change-Id: I4f447747480fb7e15975b810e2a8623acc9cde61
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-11 03:11:12 +01:00
Lars Knoll 4b850f3d1e Move Data for typedarrays into Heap namespace
Change-Id: I1737423c22e0c68c9eaa14f6d4f5b1e48aea4a77
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-10 17:15:00 +01:00
Lars Knoll ef8ad8234b Move Data of FunctionObject and related classes into Heap
Change-Id: Iadf74f953798c1884e0ec704ccb7c70d971e3273
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-08 19:47:34 +01:00
Lars Knoll 84aae25c0b Refactor ExecutionContexts
Move the Data class out into the Heap namespace.

Change-Id: I2b798deb53812a08155c92a0e6ef2dcd2ea137b8
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-08 16:39:15 +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 6b7c3ea49c Remove most calls to Value::managed()
Change-Id: Id5b1cca542421d749711eff68520a4138ec95531
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-04 20:16:37 +01:00
Simon Hausmann 3f1d0b27a1 Changed Value to store Managed::Data pointers directly
This is a step towards storing direct heap object pointers for the values
on the JS stack, to avoid the costly indirection for data access.

Change-Id: Ibb57ed6cf52a7088bbc95ee04ae3a4cb25b8c045
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-11-04 14:58:30 +01:00
Ulf Hermann beb6667d4e Comment parameters to PageAllocation::allocate()
Change-Id: I8966fbc5f89ce470a0a16fe29086fa6e13ef408e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-30 13:19:51 +01:00
Ulf Hermann 2ffb01b45d Add guard pages around JavaScript stack
Like this we avoid writing to random memory if the stack overflows.

Change-Id: I0e0962daae69904a9ce21b047f3d8c0811c1d09f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-30 13:19:37 +01:00
Lars Knoll a3a44fc164 Basic support for typed arrays
This implements most of the spec required for the
Khronos typed array specification.

It tries to follow ECMAScript 6 as closely as possible,
but currently only implements a subset of the ECMAScript
6 specification.

Addes a test script in tests/manual/v4 to test our
implementation.

Change-Id: I8ec63869500358e088b73240e1f37120ae3cf59a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-29 09:07:36 +01:00
Lars Knoll 868478e92a Implement DataView
The second class that is required for typed
array support.

Change-Id: Idc2dcec7c1eee541f76dc5ab1aea6057ba03cb93
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-29 09:07:12 +01:00
Lars Knoll a2c97406ca Implement ArrayBuffer
This is the first class required to support typed
arrays in our JS engine.

Change-Id: I0fe1e1ca430769c171912dda207cfae772e9b9db
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-10-29 09:06:56 +01:00
Simon Hausmann db44ad2be9 Fix stack size check on systems with less than 256kb stack
We require at least 256 kbytes slack stack space, and if a system is
configured with less (or equal), then the stack size checks fail early on
and strange error message occur during engine startup and execution.

This patch calls the stack check code early on and bails out with an error
message that's more descriptive.

Change-Id: I3263f2f93f62332d08003411e1bb5b3b1140d02b
Task-number: QTBUG-41213
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-09-12 16:06:12 +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 75d8ebb3e6 Merge remote-tracking branch 'origin/5.3' into dev
Conflicts:
	src/qml/compiler/qv4ssa.cpp
	src/qml/jsruntime/qv4arrayobject.cpp
	src/qml/jsruntime/qv4engine.cpp

Change-Id: Ie3ef6202b6a3a8521971e1be10c40c6a2db6989c
2014-07-26 13:21:16 +02:00
Lars Knoll ba8416b80f Do not use mark() when marking ExecutionContexts
Some execution contexts in the parent chain can be allocated
on the C stack instead of the GC heap. Calling mark() on those would
push them onto the GC stack (which is identical to the JS stack).
In rare cases the reference can survive to live into the next call to
gc(), causing invalid accesses to already deleted contexts.

Change-Id: I709f58de27be9386cf70707c84e4c86c7c303fa7
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-25 16:27:13 +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 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 133ea9d0f1 Convert more objects to the new constructor scheme
Change-Id: I31b2a1ba4a93f0d4bde68eeb94f13e7224c0cd7b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:18 +02:00
Lars Knoll 0fd24cf96e Convert most simple objects to the new constructor scheme
Change-Id: I90042037bc0555771bd98233977c7d2b735bb718
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:18 +02:00
Lars Knoll dba56a752c Convert remaining FunctionObject's to new constructor scheme
Change-Id: I440d5b128d0ee28566ebfa82c2505a4bd97bba6b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:18 +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 45f7120d42 Convert regexps
Change-Id: I5b62a265a7ce363a16b1e14ae93cadbb1ab0cb5b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:17 +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 2c7c791e3f Remove the less often used Ref classes
Change-Id: I9ee531c903317a0f324671d98af1f967b684915c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:12 +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 d33b68e2df Convert specialized ExecutionContext's to new data layout
Change-Id: Ie3aad65e4a10aaa259ae9513f0fcff79dc7e6a39
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:11 +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 42b137bd1e Convert ErrorObject to new storage scheme
Change-Id: I356a9947b87a5cda4eda738d3b6d5d51ee9a98f2
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:49:03 +02:00
Lars Knoll 1019b1cabf Move data of FunctionObject into an inner struct
Change-Id: Ic00b1761565f9f8881b665a3fecca723239e2279
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:48:55 +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 c2ef5bff23 Use Members for storing the bound arguments in BoundFunction
Cleans up the code, and allows us to remove the destructor
for bound function objects.

Change-Id: Id32ac69171f7975ec7679d07d25c0eb6b4ca6fb5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-07-22 13:48:53 +02:00
Ulf Hermann 4d68155848 Properly initialize heap profiler when starting profiling
Change-Id: Ia994464b2150dc9a9185280ae0e2f8c615393310
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-06-12 18:13:45 +02:00
Ulf Hermann ac56e7cda7 Javascript heap profiler
This profiler tracks every memory allocation and deallocation, by the
MemoryManager as well as the V4 VM, and exposes them as a stream of
events to the profiler service.

Change-Id: I85297d498f0a7eb55df5d7829c4b7307de980519
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-06-06 18:18:35 +02:00
Simon Hausmann 52fcb218c3 Fix marking of prototype objects in internal class pool
As per reported bug, we have to protect ourselves against potential loops
and can mark the internal classes much simpler by just walking through
the memory pool they were allocated in.

Task-number: QTBUG-38299
Change-Id: I3ae96e8082e76d06f4321c5aa6d2e9645d2830a0
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-04-28 12:49:53 +02:00
Lars Knoll 8e556778c8 Garbage collect member data
Move the allocated member data into the garbage collected
area, so that we can avoid using malloc/free for it.

Change-Id: I20625efa67ecd60238568742b74854b0c8cb2e3e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-04-04 17:26:20 +02:00
Lars Knoll c0fe2ec596 Optimize construct calls
Optimize construction of the internalClass for the object
being constructed.

Change-Id: Id5fc02c291664ec01c3595ae0acbb6895cc5b147
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-27 20:39:59 +01:00
Lars Knoll 4606bd6683 Optimize construction of SimpleArrayData
Change-Id: I7f8a0ac8a368af23534378e8c31d820b3b9f1f4c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-19 08:14:46 +01:00
Lars Knoll c3fbec3ab9 Small optimization to RegExp
Also add markObjects() calls to all the identifiers we keep
around in the engine. It's probably pure luck this hasn't caused
any issues until now.

Change-Id: Ie31d19793efa53867e4e240ba548070dcde32ec1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-18 09:05:57 +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 b8ca413243 Better way of retrieving the prototype property for FunctionObjects
Make sure FunctionObjects always have the prototype property at
index 0. This way we can speed up the instanceOf operator even more,
and at the same time save 16-28 bytes of memory per FunctionObject.

Change-Id: I8527bc8f9dc7b04a9db8395b5f05bab47ddc21ce
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-07 16:55:12 +01:00
Lars Knoll f836b9837d Remove the name member of FunctionObject
The data is anyway stored in the name property of
the FunctionObject, and is not performance critical.

Change-Id: If1784b0ec6f368bc474c246bb9c2c50d5e56b689
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-07 16:55:12 +01:00
Lars Knoll e4a6c5b3e4 Fix test failure in qqmldebugjs autotest
The debugger should only have one breakpoint that can
be set per line. Nevertheless, we should have proper
line number information available in case we stop at
other places.

We also need a debug instruction before the return
statement, so that step out will always find a last
stopping point in the parent frame.

Change-Id: I86145fc244148f106a4a97ce69ab60b568c8dac6
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-07 16:55:12 +01:00
Lars Knoll 245f5ce7bb Add a Line instruction to the interpreter
This unifies the way we handle line numbers in the
JIT and Interpreter.

Remove the now unused lineNumberMapping code and data.

Change-Id: I1d60b1fbb77e70b531fa73d93410683e84dd1e3c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-07 16:55:12 +01:00
Lars Knoll a6fc758841 Remove unused codeSizes
Change-Id: I13c7d9dda7cd1e771079f6fdaa175008b3a3e0e5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-03 20:23:28 +01:00
Lars Knoll 292fdc9086 Remove nArguments and name from QV4::Function
Saves 12 bytes per Function

Change-Id: I9a495805f9201eb6162a520ff5c2defeb73dc37a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Michael Brasser <michael.brasser@live.com>
2014-03-03 20:23:24 +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
Lars Knoll cad3ba5fd4 Clean up our internal namespaces
QQmlJS::MASM -> QV4::JIT
QQmlJS::V4IR -> QV4::IR

Change-Id: I707e8990459114a699c200fe3c22cec3c8df1afc
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-23 09:39:52 +01:00
Ulf Hermann ebef5a5a68 Satellite profiler for V4
Self-contained profiler for V4. By itself it doesn't have any
connections to qqmlprofilerservice.

Change-Id: I471a6119e07eab9c5f4712a16835be49c8886d1a
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
2014-02-12 21:29:54 +01:00
Friedemann Kleint 33201dc147 Add a function dumping out a GBMI stack trace of the V4 engine.
Add an exported C-function dumping the JS stack trace which can be
invoked by a debugger with the address of an execution context
it finds in a complete stack trace.

Task-number: QTCREATORBUG-11144
Change-Id: I5314f6b24868f12d4f9dedd1c261658957e581ba
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-12 11:23:40 +01:00
Lars Knoll 39d7e330e6 Make the Ref classes not template based
Move to a class hierarchy that mirrors the main classes. This will
allow moving functionality over into the Ref classes, as the current
Managed classes become mainly something that holds the data. This
is required to make objects movable by the GC.

Change-Id: I4ca88ab0e5d8c88c8dc56d51937990500a33e0d9
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-07 10:44:00 +01:00
Lars Knoll 927a46b1af Rename Referenced to ManagedRef
First step of removing the templates here and turning this
into a class hierarchy. This is required, so we can move all
member methods into the Ref classes and make objects movable
during GC.

Change-Id: Ie14af07fd3e72a7d84a528d0042189ff12ba21bb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-07 10:43:57 +01:00
Lars Knoll d89e269866 Smaller performance fixes
Move commonly used variables in the ExecutionEngine
to the beginning of the struct to increase cache locality.
Keep the engine pointer in a register in the interpreter to
save one memory load per instruction.

Change-Id: If2540c66b62685701511f410aff495c0a20ca694
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-05 18:29: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 e37a9eb4a4 Rename some files
Rename qv4value_def_p.h -> qv4value_p.h and qv4value_p.h to
qv4value_inl_p.h.
It makes more sense to have the class definition in the file
that is named after the class and move the inline methods into
a _inl file. Doing this now, as I expect we'll be needing a few
more _inl files soon.

Change-Id: Ib59e9380e9e976254c6b4369574157f39b1b5f51
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-31 11:13:48 +01:00
Simon Hausmann 9a5568a197 Merge "Merge remote-tracking branch 'origin/stable' into dev" into refs/staging/dev 2014-01-24 18:27:50 +01:00
Simon Hausmann 22041acdfe Merge remote-tracking branch 'origin/stable' into dev
Conflicts:
	src/imports/dialogs/qquickmessagedialog.cpp
	src/imports/dialogs/qquickmessagedialog_p.h
	src/qml/debugger/qqmlprofilerservice_p.h
	src/qml/jsruntime/qv4regexpobject.cpp
	tests/auto/qml/debugger/qqmlprofilerservice/qqmlprofilerservice.pro

Change-Id: Ic8a43366b44d6970966acbf03b206d0dee00c28d
2014-01-24 18:27:41 +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 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
Alex Blasche 24c43a5748 Make compile on DragonFly BSD.
[ChangeLog][Platform Specific Changes][BSD] Fixed compile errors on
DragonFly BSD and potentially FreeBSD.

Task-number: QTBUG-35867
Change-Id: Iea90b93672c34f8a4b56e9afc4dbfb82cc993548
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-21 12:32:58 +01:00
Simon Hausmann f596553e03 Merge remote-tracking branch 'origin/stable' into dev
Conflicts:
	.qmake.conf
	src/imports/dialogs/DefaultFileDialog.qml
	src/imports/widgets/qquickqfiledialog.cpp

Change-Id: I00de6dd05cb773f01254061d585a82c90b229acd
2014-01-17 07:12:23 +01:00
Albert Astals Cid 14ebfef611 Do not crash if /proc is not mounted
When proc is not mounted pthread_getattr_np fails, so default
to 1MB stack in getStackLimit and to exactGC in MemoryManager

Change-Id: Ic7515fd420f2d39a656808d24a3915a657722891
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-15 10:45:05 +01:00
Lars Knoll 40fd9ff0ff Move Managed::type and some flags into the vtable
Move the type flag into the vtable to free up these
bits in the Managed class, and not have to set them
at object construction time.

As we often need to know whether a Managed object is a
Object, FunctionObject or String, add some bitflags to test
for these to the vtable.

Change-Id: I7d08ca044544debb307b55f124f34cb086ad9e84
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-03 17:09:16 +01:00
Lars Knoll 74ef33c881 Do not call InternalClass::changeVTable directly
vtable changes need to happen when the internal class
is being constructed, not later on.

Change-Id: Ibb9515745c9fc3507a5a90b4cc50a33e2e0d3f99
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-03 17:09:11 +01:00
aavit 0697a94132 Fixes: qml memory corruption on Android
Bionic pthreads reports too small stack size for main thread.

Change-Id: I3d33229e76101a847309c723d534844ffb2d2042
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-12-17 21:36:34 +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 0f32303e5c Remove setVTable calls in performance critical areas
Remove all the calls to setVTable that were in performance
critical parts of the code. This now brings performance
back to the level we had with the vtable inlined in the
Managed objects.

Change-Id: I76317cc5c53b5b700d1d3883b954407142a4c424
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-12-04 09:45:48 +01:00
Lars Knoll fbcd0a22f6 Move the vtable pointer from the object to the internal class
This saves one pointer per object, and willmake other optimizations
easier in the future.

Change-Id: I1324cad31998896b5dc76af3c8a7ee9d86283bfe
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-12-04 09:45:45 +01:00
Lars Knoll 608a960014 Remove unused inline wrapper
The wrapper method for Function::code() was still there
from the times we used C++ exceptions. It's not needed
any more, so get rid of it.

Change-Id: I2ec25fbca71eeef9d7a94a38b5adfa42e4de3a84
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-12-04 09:45:30 +01:00
Lars Knoll 0e864f2814 Initialize variable
Change-Id: I37b14a406ebb9cf87fef20426a94725a2441b7cd
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-12-04 09:45:20 +01:00
Simon Hausmann ee6aa999ab Merge branch 'release' of ssh://codereview.qt-project.org/qt/qtdeclarative into stable
Change-Id: I0bf06be69927d5961f1bdb4948c3572ef6111923
2013-11-26 10:02:56 +01:00
Lars Knoll 85fea8a68b Saner and simpler way to handle line numbers for JITed code
Instead of storing the current instruction pointer in the
ExecutionContext, we might as well directly store the current
line number there.

Leads to simpler code, works cross platform and should also
be faster.

Change-Id: Ifb7897cf8dbe8a962505fe876aa3ed43283ebb06
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-22 14:54:36 +01:00
Lars Knoll bf173fe5da Turn execution contexts into Managed objects
This finally gives proper memory management for ExecutionContexts.
So far they had been garbage collected but where still allocated
using standard malloc/free(). This allows us to collect the
contexts faster and speed up context creation.

Change-Id: I02e642391d55eaa59ab3f4c2720a2ac71259caf4
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-22 14:54:33 +01:00
Andy Nichols 88262738a8 V4 Use getrlimit on Darwin to get the stack size for the main thread
Turns out pthread_get_size does not return the correct size when it is
called from the main thread, so to workaround you call getrlimit instead
Without this change, most QML applications are broken on iOS.

Change-Id: I9a61494de26caa3d7be7e46a991e6d6d0514ce17
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-20 17:53:45 +01:00
Fabian Bumberger d6f9e961ca Fix compilation on QNX
pthread_getattr_np is not available there, so we use the default implementation (1MB stack limit) for now.

Change-Id: Ia1f3cbbcd846998b688541c0b576ef42f22ac8b6
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-19 13:00:45 +01:00
Lars Knoll 965878e88a Limit the amount of memory we allocate on the stack
Setup limits for both the C and the JS stack, and check
them before entering functions. If we run out of space,
throw a RangeError exception.

Be careful and recheck the stack bounds when things go
outside. This catches the case where the engine got
moved to another thread changing the stack boundaries.

Windows currently uses an unsafe fallback implementation,
this needs to be fixed later on.

Task-number: QTBUG-34568

Change-Id: I22fbcbec57b28f9cc8a49e12f1cc6e53e4f07888
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
2013-11-18 11:05:25 +01:00
Erik Verbruggen 0910a577f4 Debugging with V4
Currently missing, but coming in subsequent patches:
- evaluating expressions
- evaluating breakpoint conditions

Change-Id: Ib43f2a3aaa252741ea7ce857a274480feb8741aa
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-10 11:01:35 +01:00
Lars Knoll 412eb94de4 Simplify & speed up function calling
Get rid of the SimpleCallContext, instead simply
use the CallContext data structure, but don't
initialize the unused variables.

Change-Id: I11b311986da180c62c815b516a2c55844156d0ab
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-09 02:01:17 +01:00
Lars Knoll 025365f1dc Refactor marking GC'ed objects
Don't use recursive function calls anymore. Instead, push marked
objects onto the JS stack, and then pop them off when their children
are being marked.

Should reduce stack memory usage, and improves performance by ~5%.

Change-Id: I2d37d97579144fcba87ec8e9fd545dd220c01fbb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-05 18:54:51 +01:00
Erik Verbruggen a79e400150 Fix various compiler warnings in order to remove warn_off in the near future
Change-Id: Ic0492fbe31a1e134674bc6c20381f735dd6d5b7a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-04 02:16:04 +01:00
Lars Knoll d4ff8bd1ec Remove qv4unwindhelper class
This class is not required anymore to generate stack traces, as
we now store the required information in the JS context stack.

Change-Id: I3893c805ca89dda70efde07fdd120e7dfaf3639f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 10:39:08 +01:00
Lars Knoll c4dcc327d9 Cleanup: Remove now unused throwInternal() method
This method was throwing a C++ exception in the old exception
handling and is not needed anymore.

Change-Id: If67696cdbd260225ae60720a1035941fe7e1e650
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 10:39:06 +01:00
Lars Knoll ffcdbfa03f Protect write accesses to objects
Don't write to objects if we have a pending exception to
avoid any side effects.

Change-Id: I9f93a9195a652dbae7033cc6ebb355d5d86e9b5e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 10:39:01 +01:00
Lars Knoll af22149dd8 Avoid side effects when en exception has been thrown.
We don't want to check for exceptions after every single
line on our runtime methods. A better way to handle this
is to add the check in all methods that have direct side
effects (as e.g. writing to a property of the JS stack).

We also need to return whereever we throw an exception.
To simplify the code, ExecutionContext::throwXxx methods now
return a ReturnedValue (always undefined) for convenience.

Change-Id: Ide6c804f819c731a3f14c6c43121d08029c9fb90
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 10:38:59 +01:00
Lars Knoll e0284ab41f Properly propagate parse errors
Replace all try/catch statements used when parsing
with checks for engine->hasException.

Change-Id: I4493cb600d5a3eb095c2003bb88bd031403e47c9
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 10:38:55 +01:00
Lars Knoll 34bf0139c7 Rework IR code generation for try/catch/finally
Simplify the generated code. Add a special block to catch
exceptions thrown inside a catch() statement.

store the exception on the stack when entering finally and
rethrow it at the end. This ensure correct behavior for
break/continue/return statements inside finally.

Don't check for exceptions after calling push_catch_scope
and pop_scope in the JIT'ed code. This can lead to infinite
loops when throwing inside an exception handler.

Change-Id: I67e9325794e2fd25b0773b21e02fbaadb43faab0

Change-Id: Ic1ea9c0c43eec1d49177dc1ab4552a1da04e96fe
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 10:38:48 +01:00
Lars Knoll 5229a8b259 Rework exception handling
Start the work to remove c++ exceptions from our JS
exception handling. Rather rely on engine->hasException.
Check the flag after we return from any runtime call in the
JIT.

Implement new try/catch handling code in qv4codegen and
for the JIT that doesn't rely on exceptions. As an added
bonus, we can remove the Try statement in the IR.

Change-Id: Ic95addd6ae03371c43c47e04cac26afdce23a061
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 10:38:45 +01:00
Lars Knoll 9fd4591a61 Remove internal method from public API
QQmlError is public API and shouldn't expose an internal
method.

Change-Id: I7caf06af9340fefec5c96103395fe74acbf19497
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-19 14:59:11 +02:00
Simon Hausmann 12c3579136 Speed up exception propagation
Avoid catch (...) with re-throw as it turns that this is very slow because it
throws a new exception and the unwinder starts from scratch. Instead use stack
allocated objects and cleaning destructors to restore state before continuing
with the propagation of exceptions.

Change-Id: I6d95026bcd60b58cb6258a9dae28623a46739532
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-16 16:03:57 +02:00
Simon Hausmann c1c526aafb Speed up stack trace generation for the JIT
It turns out that in QML it is not unusual that during early binding
evaluations due to the undefined order, the evaluation tries to look up
properties in objects that aren't initialized yet and thus exceptions are
thrown. Eeach thrown exception saves a stack trace, which is expensive to
generate when using the JIT, as it does full stack unwinding.

This patch implements a more light-weight approach by storing the instruction
pointer in the context before leaving JIT generated code.

Change-Id: I95e1cfd01179247dfc2c1df949828f474a23161b
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-16 16:03:54 +02:00
Lars Knoll b538231cb2 Fix GC issues with usage of raw RegExp pointers
Properly protect them through Scoped values.

Change-Id: I5a0a1d5580d55ecff493419baa8959751a65f1d3
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-15 20:57:37 +02:00
Lars Knoll e964fc3426 Fix the remaining objects against self destruction
This makes pretty much all test cases pass with exact
garbage collection.

Change-Id: Ia874e3c17c3984afb7cfe370f9bd3ad8fe46699a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-11 16:01:24 +02:00
Simon Hausmann 7d9780b630 Cleanup exception handling
The code in the Exception class operates entirely on the engine's data,
so move it into ExecutionEngine instead. This eliminates the need for
a QV4::Exception class and catches and old code that tries to still do
catch (Exception &) instead of catch (...)

Change-Id: Ie608bec6af652038aca6c9423c225a4d7eb13b39
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-03 09:24:41 +02:00
Simon Hausmann c860d1399b Change exception handling API
This patch changes the exception handling API in the engine slightly, encapsulating
any use of direct throw statements and catch blocks with concrete types. In the future
we need to be able to change the way these are implemented, in order to ensure that
the correct stack unwinding code is triggered for throw and re-throw.

This patch separates the C++ exception object thrown from the V4 exception
(that includes value, throwing context pointer) and stores the latter inside
the engine.

In order for that to compile, ExecutionEngine::StackTrace and StackFrame had to
move into the QV4 namespace directly.

In addition the syntax for catching exceptions changes from

try {
    ...
} catch (QV4::Exception &ex) {
    ex.accept(context);
    QV4::ScopedValue exceptionValue(scope, ex.value());
}

to

try {
    ...
} catch (...) {
    QV4::ScopedValue exception(scope, context->catchException());
}

Context::catchException() checks if there's a "current" exception in the engine,
and if not assumes that we caught an unrelated exception and consequently re-throws.

partiallyUnwind() is also gone and replaced with rethrowException(), in order to
encapsulate the re-throw.

Lastly, in the future nesting try/catch blocks isn't going to be possible due to
limitations in the common C++ ABI with regards to foreign exceptions.

Change-Id: Ic81c75b057a2147e3176d8e0b4d326c14278b47d
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-02 16:07:33 +02:00
Lars Knoll 1e454c8aa6 Remove more uses of Value
Change-Id: I889e760f75b485a28e1f2a2c26b2337ae9bfafac
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-02 16:07:33 +02:00
Lars Knoll 430dfd326c Fix ObjectIterator API to be GC safe
Change-Id: I3a9c48d53d8dbadcb9b32c00fcef1f89447c4b8c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-02 16:07:33 +02:00
Lars Knoll aacebc74b2 Remove more occurrences of QV4::Value
Change-Id: I66c370680d7e6bee2e73a7a940aa96ab4009ec57
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-30 08:05:38 +02:00
Lars Knoll 62d1b5a08a Fix API for Object::define*Property
use ValueRef instead of const Value &.

Change-Id: I3fd0ca829870db27f036825d713c53dc0600be07
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-28 13:33:58 +02:00
Lars Knoll 112531bc23 Less QV4::Value usage
Fix some usages in qv4engine, and fix return types
in methods in qqmlxmlhttprequest.

Change-Id: I3d6225ca01bf7ea77fcc424914c8392bb6c3a454
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-28 13:33:54 +02:00
Lars Knoll 18d4794e3f Fix Value usage in ErrorObjects
Change-Id: Iaa14ad5a8d3f085843e49195f8f4bb7bb020b9b6
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-28 13:33:43 +02:00
Lars Knoll 150731fc68 Remove more direct QV4::Value usage
Remove Value::fromString(String *), and make
Encode safe against encoding raw Managed * pointers.

Change-Id: Ibca4668e1cbeaf85c78169d14386281659d33ef6
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-28 13:33:39 +02:00
Lars Knoll cf2a253f2f Move Value::fromBool, ... to a new Primitive class
This will simplify finding the remaining direct usages of
QV4::Value that need fixing.

Change-Id: I223099727436d5748027c84c53d9dfc4028e38ed
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-28 13:33:24 +02:00
Lars Knoll 7872b38006 Use SafeValue in more places
Change-Id: Ic15c1419c74f22bd7639ce8746ff11b15240b718
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-28 13:33:19 +02:00
Lars Knoll 0f2cf9074d Fix CallContext to not hold arguments on the C stack anymore
Change-Id: I35f46cce4f243d4b8b2bac9244f8fc26836f413b
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-28 13:33:08 +02:00
Lars Knoll 12fd2ccd3f Fix Persistent/WeakValue API
Don't use unprotected Values in the API anymore.

Change-Id: I8851628227fca374de24701bc8ee0908b5ae3923
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-26 09:05:16 +02:00
Lars Knoll 47bf40dd49 Prevent objects from being collected while in their constructor
While objects are being constructed, we don't have a reference to them
on the JS stack yet. So the constructor needs to protect itself against
being collected by putting the this object onto the JS stack.

Added an environment switch MM_EXACT_GC to test exact garbage
collection.

Change-Id: Ie37665a954de800359c272ffbebbe1488e7a8ace
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Lars Knoll 78b49cf836 Convert the last methods in qv4object_p.h
Change-Id: I4fda83a0832760c277e629d4e658da718c0bf92b
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Lars Knoll 700ba1bcb3 Use a StringRef for Managed::get()
also store "toString" and "valueOf" as identifiers
in the engine and fix two places where we compared
strings the wrong way.

Change-Id: I70612221e72d43ed0e3c496e4209681bf254cded
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Lars Knoll 3c325823a7 Cleanup Object::define*Property API
Change-Id: I99125908a9bc1d41a2642c409af9704def7a0832
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Lars Knoll 8b3623ee7b Start using StringRef for parameter passing
Change-Id: If2c41daeda2862cd1162c5da8163a9d62fe4111d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Lars Knoll 055f71f87d Introduce a Referenced<T> class to pass Objects into methods
Added some convenience typedefs (StringRef, ObjectRef, ReturnedString,
ScopedString, ...)
Used StringRef in newBuiltinFunction() for testing.
Cleaned up the duplicated code for thrower functions.

Change-Id: I7b7676690cbe70d9eabb0a5afd0d922f0be3aefd
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Lars Knoll 2d781c4ca4 Cleanup ExecutionEngine::newBuiltinFunction() usages
And change the return type to be GC safe

Change-Id: I6d7513962370fea4072a3d8c6b2c6f2d1705992e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Lars Knoll e441692b0b Further work towards an exact GC
Add some more convenience in the helper classes
in qscopedvalue_p.h
Make accesses to CallData safer, and change
ExecutionEngine::newObject() to return a safe
pointer.

Change-Id: I980909754ce9681cf6faa1355bab3a1e5d6dd186
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-22 01:06:20 +02:00
Simon Hausmann 57f7545f67 Fix destruction of QV4::CompiledData::CompilationUnit objects
Now that we store them per QML file, they live in the type cache and
can outlive the engine. Therefore the engine needs to free to unlink
any remaining units upon destruction. This needs to be done after the
"death" of the memory manager, which is likely to sweep away any
function objects that also hold a reference to the compilation units.

Change-Id: I3968d5995289e8d2bc1e3abbb1f8be88a0ab4e03
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-20 14:27:39 +02:00