Commit Graph

98 Commits

Author SHA1 Message Date
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