Commit Graph

387 Commits

Author SHA1 Message Date
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
Lars Knoll f79df5da07 Convert more methods to return a Returned<>
Change-Id: If294c9c4f574824c308b63a11da1337226180105
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:14:13 +02:00
Lars Knoll e4e90923c9 Convert some methods to use Returned<>
Change-Id: I631606cb5ab3b35b72104e70092a5200dd235fbc
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:14:10 +02:00
Lars Knoll 9dcc12d523 Convert a few more methods in ExecutionEngine to use protected pointers
Change-Id: I2e6b1b9dff52bbd16f35a00152c9ac557f8346eb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:14:08 +02:00
Lars Knoll 49aead7f23 Extend the ReturnedValue mechanism to pointers to Managed objects
Add a Returned<T> that we can return instead of raw pointers
to Managed objects.

Start using the Returned<T> for a few methods.

Also clean up all our classes to use the Q_MANAGED macro instead
of manually defining their vtable.

Change-Id: I0a2962e47f3de955cd2cd8474f8f3fcc9e36d084
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:14:03 +02:00
Lars Knoll 16f92ad85c Convert builtin methods to return a ReturnedValue
Change-Id: I6b75adbf53a5be0deab023d2eed98ce2a7915551
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:13:47 +02:00
Lars Knoll 7d4e61dd82 Rename BuiltinFunctionOld to BuiltinFunction
This is the correct abstraction for a builtin method.
Time to get rid of the 'old' in the name.

Change-Id: Ia386d2cc8ef0e6c269ab24da6fc8ebfac52d7f69
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-18 13:13:44 +02:00
Lars Knoll e6180ecdc2 Properly unwind the js stack for generated code
Surround all calls into generated code with a
try {} catch {} statement that resets the jstack
to the correct position.

Like this we properly unwind the js stack in all cases, and
can also use stricter assertions in our ScopedCallData, etc.
classes to check that the stack is healthy.

Change-Id: I7ca03e06ea55007be683305d9c2a6898cf5fc689
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-11 13:02:00 +02:00
Lars Knoll 1986cf68d0 Create a stack for JS values and use it in the interpreter
First step towards being able to do an exact GC.

Create a stack for JS Values that is separate from the C++
stack.

Use the stack for generated methods (masm and moth).

Change-Id: I80ac0e5b5d86439dda5e9ea2b21fa0c57d8aef22
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-11 13:01:44 +02:00
Erik Verbruggen ce715a34b2 V4: add environment variable QV4_FORCE_INTERPRETER
By setting this variable, the interpreter will always be used, even when
the JIT is available.

Change-Id: I66a439b649fd22e0d10be4f07f1e7be392b012f5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-11 09:42:12 +02:00
Lars Knoll ea0ea907ed Optimize String.replace and RegExp.exec
This speeds up the v8 regexp benchmark by a factor 2.5 :)

Change-Id: Ibd6b18ee28181aa712429cbec4598984e0c69820
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Lars Knoll 6359ab63cd Optimize ScriptFunction::construct() and creation of FunctionObjects
Change-Id: I7df04171a26cbe659e85f14878cc4e51030e8a5a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Lars Knoll 4dbb2ab600 Remove more usages of Object::setPrototype()
Change-Id: I33383baf14e764ce79252a100a6d769bde75331a
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Lars Knoll 3bf081203e Remove more usages of Object::setPrototype()
Change-Id: I8c49f61bc85e3d98dea90bf05db1a3f22d08f7b1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Lars Knoll d8e31c098d Cleanup calls to Object::setPrototype()
Rather use the correct internalClass directly when constructing
the objects.

Change-Id: I8e916f1ce8f83d291c08ca6332fe85b1f57b90b5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Lars Knoll edee5c3dc0 Move prototype pointer into QV4::InternalClass
The prototype is actually the same for most objects. By
moving it into the internal class, we can save 8 bytes
per object, as well as allowing for some future
optimizations.

Also fix a bug in the implementation of the Error
prototype objects.

Change-Id: I4d4b641055f644a9b088f27be34bfdb0446279b7
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Lars Knoll 3ad8b0f0e8 Add the object's prototype to the InternalClass structure
Change-Id: Ifa97d3354a7a7afadf70f9ba540716bd5b1eef44
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Lars Knoll 6c69cdb1af Remove unused arvument from Object constructor
Change-Id: I2c26bd8af9b352baed9b84a6b6401633ded4da85
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Lars Knoll da2f24d8e5 move methods to create a new context into the ExecutionContext class
This avoids one indirection when calling the methods and cleans up
the engine a bit.

Change-Id: I426f41e23f6a7262af95b9807b00920530fef642
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Lars Knoll 29f946cdad Add a SimpleScriptFunction class
Choose whether we use a stack based context for a function, when
the actual closure is generated, not at call time. This speeds up
function calling for leaf functions.

Change-Id: Ibcbf3acb5610a7f59b6474e982122df03c1c5298
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Lars Knoll ac1d0075a8 Move call context creation into the ExecutionContext class
Change-Id: Ie66a5892b0e5ab74bead1fcb59ffad5a867e0509
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-02 17:27:36 +02:00
Simon Hausmann e360eaa02f Temporarily collect a map of all functions in the engine
At the moment we collect a lot of compilation units (one per binding
expression!), which for long running QML accumulates and creates a horrible
performance when trying to retrieve back traces. There is work in progress
to reduces the number of units down to one per QML file, and then the
fixed sorted QVector might proof to be a more efficient data structure
for the lookups.

But until that code lands, this patch proposes to use a QMap instead for the
time being, that tracks all functions. This brings down the qtquickcontrols
auto-test run from 2.5 minutes to just under a minute on my machine.

Change-Id: I45bf609055877081daa984de90f291a030f2f24f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-02 14:32:47 +02:00
Simon Hausmann 461892e492 Merge branch 'wip/v4' of ssh://codereview.qt-project.org/qt/qtdeclarative into dev
Conflicts:
	src/qml/compiler/qv4codegen.cpp
	src/qml/compiler/qv4codegen_p.h
	src/qml/compiler/qv4isel_moth.cpp
	src/qml/jsruntime/qv4context_p.h
	src/qml/jsruntime/qv4functionobject.cpp
	src/qml/jsruntime/qv4runtime.cpp
	src/qml/jsruntime/qv4runtime_p.h
	src/qml/jsruntime/qv4script.cpp
	sync.profile

Change-Id: I1d785e2134bffac9553a1c16eed12816cbd1ad2c
2013-08-20 16:54:29 +02:00
Lars Knoll e43b6bd9c7 Remove QV4::DiagnosticMessage
QQmlError provides the same functionality, so let's rather
use that where required. Remove the dependency of
codegen onto the ExecutionContext that was only
required for error handling.

Change-Id: Ib0b61c0e138f89ff989c32996c93c339e4b62223
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-08-20 14:20:44 +02:00
Lars Knoll 091f20de8c Remove unused overload of newCallContext()
Change-Id: I9b9de585b18bf87ea256db36b320a7defdcc4ac8
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-08-17 15:24:56 +02:00
Lars Knoll 51e7447481 Optimize contruction of Arguments objects
Change-Id: If77bff28a25462a6069d646a2594dd903fefb9e5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-08-17 09:26:24 +02:00
Simon Hausmann 3314912318 Eliminate all vm functions on the isel side
Change-Id: I7c0e50498c937ce554b019f98829fa8c5d96c18e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-16 21:38:07 +02:00
Simon Hausmann a44f92d925 Get rid of the functions list in QV4::ExecutionEngine
Change-Id: I97067dbb2819936a1b2029c9f63f0627cb6b8bd2
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-16 19:22:24 +02:00
Simon Hausmann c5c968933b Fix crashes with unmarked runtime strings
Runtime strings are identifiers, but they still require to be marked. Keep
track of all compilation units in the engine (one per file) and mark its
run-time strings.

Change-Id: Ie70b00dfa373c4567279591de2f717e8103c288f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-15 15:28:46 +02:00
Simon Hausmann 3e49617bc6 Move QV4::Function::sourceFile to CompiledFunction
Change-Id: Iacf907c475070bab4a5a1583280f110c089141c4
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-15 09:11:36 +02:00
Simon Hausmann 65aaea88d9 Fix memory leak in identifier table
Change-Id: I8bc393856cad85734160b52dee745509be502247
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-13 12:40:56 +02:00
Simon Hausmann 876080d89d Re-enable JIT
Ooops, an earlier commit accidentally disabled it.

Change-Id: I7b732e0addba8b6403e0d6818d784f267711af42
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
2013-08-12 16:49:02 +02:00
Simon Hausmann 7c2adbbb6c Add reference counting to the VM functions
This reduces memory pressure, keep engine->functions small and thus makes back
trace lookup faster. It became visible for example in the QtQuickControls
auto-tests that use plenty of loaders and we ended up with 30k+ functions.

Change-Id: Iaa5981f44e1e49ad9417a50c1e6a74946090dd28
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-08-12 13:29:27 +02:00
Lars Knoll 3288b87e2f Restructure source code
Move the v4 engine classes from a subdir of qml/qml into
two subdirs (compiler and jsruntime) of the qml module
Remove an unsued qv4syntaxchecker class, and move
the moth code directly into compiler.

Change-Id: I6929bede1f25098e6cb2e68087e779fac16b0c68
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-08-08 12:22:30 +02:00