Commit Graph

81 Commits

Author SHA1 Message Date
Lars Knoll 4c4bddb025 Simplify our breakpoint handling
Only store a Hash of break points in the debugger,
instead of the involved logic that currently adds and
removes break points. Add the current line number to
the Debug statements in the interpreter, and pass them
on to the debugger for checking whether we should really
break.

This adds a slight additional overhead to running inside the
debugger, but greatly simplifies the logic and doesn't require
modifying the bytecode anymore. This in turn opens up the
possibility to run the debugger on JIT generated code later on.

Change-Id: If2a3ae8f8d08b69a3a704cbbe0a84000f917a32e
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-03-07 16:55:12 +01:00
Simon Hausmann 90a7249e70 Determine whether or not an object literal requires a sparse array at compile time
Change-Id: Ieb7f6ee97a4f251f1e2369850ebb9e2931f84ac1
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-02-24 20:41:48 +01:00
Simon Hausmann c78d1052c2 Clean up object literal handling with integral indices
* Object literals with array indices are now created with one
  run-time call, instead of an initial one for non-integral keys
  followed by sub-sequent define_builtin_property calls.

* Cleaned up propert name retrieval. Instead of using a visitor,
  it's easier to define a virtual method on the PropertyName type.  The visitor
  doesn't buy us much as it's not possible to recurse within property names, and
  this way we can use it also from the function scanner to correctly determine
  the number of arguments needed for object literal initalizations.

* Similarly the duplicated/common name member for all property assignments
  has been moved into PropertyName, for convenient access without AST casts.

* Removed now unused builtin_define_property/settergetter functions from IR,
  run-time and moth.

Change-Id: I90d54c81ea5f3f500f4f4a9c14f7caf5135e7f9f
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2014-02-24 20:41:40 +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
Lars Knoll b488308078 Remove add/sub/mul instruction specializations for numbers
These instructions did hurt more than help, as they converted
ints to doubles. Since the regular add/sub/mul runtime methods
have fast paths for both ints and doubles, we're better off
using those instead.

Change-Id: I0b7a6f95818943bfc8a0669c1c56f7db4e7246e0
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-07 10:44:34 +01:00
Lars Knoll aaa8257d98 Specialize CJump into JumpEq and JumpNe
This avoids the bool invert in the instruction
stream, and some additional code in the VME.

Change-Id: I0ea675a2e3d07c1b8c5234b888d8d9683bcee330
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-07 10:44:30 +01:00
Lars Knoll 6b1fdf8dda Remove a memset that is not required
Keep it in debug builds to ease debugging.

Change-Id: I334872d3c0ef30b5f09fb5febfc2129a3b450bca
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-07 10:44:25 +01:00
Lars Knoll 357e034f70 Add specialized instructions for right and left shift
These give a measurable speedup as the critical code
paths are now inline.

Change-Id: I3cee8a432fbe96d66ba1e6bd277a38e624a50c14
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-07 10:44:22 +01:00
Lars Knoll c95d34c25d Remove two unused parameters from VME::run()
These parameters are not used outside the function itself
anymore, so we can safely remove them.

Change-Id: I1694481c05a9927fc78a59ffb7fec43a88e85ac8
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-07 10:44:06 +01:00
Lars Knoll 706a3cfc87 Add a MoveConst instruction to the interpreter
This simplifies and speeds up loading of constants

Change-Id: I05b4f7a34abd4ed6416fa800a31debbb28b37104
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-02-07 10:44:03 +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 4dfe58d27c Add a special Debug instruction to the interpreter and use it
This avoid having to check for the debugger at every instruction
we execute. Instead we only add debug instructions at the beginning
of every line and every basic block when we have a debugger.

This still allows interrupting the JS execution at any time (as we
can't loop inside a basic block), and single stepping through lines.
But it has no overhead when the debugger is not running and a lot
less when it is running.

Change-Id: Ib17170b42944b608fc6caa1891082205dd2b2763
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
2014-02-05 16:14:56 +01:00
Lars Knoll 3408bd9d08 Use lookups for get/setElement in the interpreter
Significantly speeds up crypto.js

Change-Id: Icd3d59bea3fe4427e93e9e10e3526178e8de859c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-31 23:02:23 +01:00
Lars Knoll 74cc0db2ce Remove unused macro
Change-Id: Ie7044aecad59197fd2cab17d5ddcc7c44ad2ad84
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2014-01-31 23:02:18 +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 f474eede80 Add support for accelerated property access to QML types and namespace support
* Resolve lookups in namespaces at compile time and instruct the SSA optimizer
  to eliminate reads from the namespace (QQmlTypeWrapper) if possible. For example
  access to attached properties of types (i.e. MyNameSpace.ListView.isCurrentItem)
  requires neither reading the namespace nor the type.
* Add support for accelerated lookup of attached properties

Change-Id: Ib0b66404ed7e70e1d4a46a1ac8218743a4cc8608
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-28 13:47:40 +01:00
Simon Hausmann 43f1cc98bf Initial support for accelerated property access to QML singletons and enums
With this patch we determine the meta-object of singletons, propagate it into
the IR and load them separately using a dedicated run-time function. In
addition enums in singletons and QML types are resolved at compile time.

Change-Id: I01ce1288391b476d1c9af669cb2987a44c885703
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-25 22:04:42 +01:00
Simon Hausmann a41764cafb IR Cleanup, resolve ID objects through array subscripts
...instead of a special MEMBER type. This allows removing the
type member from V4IR::Member altogether (and thus unshadow from
V4IR::Expr::type). By not requiring the base of a id lookup
member expression to be a NAME, we can also speed up repeated
id lookups by fetching the id object array wrapper only once
per function.

Change-Id: I3e9b8f498d32ace4a0cc2254f49e02ecc124f79c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-25 22:04:42 +01:00
Lars Knoll 9bf5e87ef0 Use lookups for create_property (ie. new foo.bar)
This is not used that often, but it removes one more place
where we do lookups by name.

Change-Id: I9f798b8b4a64be3fdf3e53090e4288724c9d2b22
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-22 14:54:05 +01:00
Simon Hausmann 7a09200016 Fix property dependency generation for accelerated QML QObject properties
The previous approach of collecting the dependencies through an IR visitor
doesn't work, because it relies on a fixed structure - for example MEMBER(NAME,
prop) - which we can't guarantee (it's usually MEMBER(TEMP, prop)). But it
turns out that we can only pre-calculate dependencies for context, scope or id
properties, so we can do that right away in the QML specific JS codegen, store
that information in the IR function and use it from there in the data structure
generator as well as in the isel as a parameter to getQObjectProperty to tell
the run-time whether capture is required or not.

Change-Id: I33711c3420d6534c653c2a6a4284f0fc12e941cf
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-12 18:20:30 +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 90338de17a Move conversion of this object into generated code
When a non strict mode function uses the this object, we
need to make sure it's being correctly converted into a
object before being accessed. So far this was being done
by ScriptFunction::call. Move this into the generated code to
avoid overhead for methods not using 'this', and simplify our
ScriptFunction::call() implementation.

Change-Id: I739f4a89d29ed8082ce59e48d1523776224fc29d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-11-05 22:23:25 +01:00
Simon Hausmann b5991ce2a6 Avoid exception checks after calls to some run-time functions
We know that some run-time functions won't thrown an exception, so this
patch annotates them with a tricked NoThrowContext* instead of
ExecutionContext*, which allows the masm isel to detect calls to them
and avoid generating the exception handling checks after the call.

Change-Id: Ida1c9497edda14f26e1d6389b0144f6abeeba654
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-11-01 23:01:30 +01:00
Simon Hausmann bbc36ebbc3 Speed up lookups of imported scripts
The QQmlContextData stores the JS objects of imported scripts in a
QList<PersistentValue>. Instead of indexing into that list, this patch changes
ctxt->importedScripts to be a JavaScript array, that in the IR we can index via
subscript.

Change-Id: Ie2c35fb5294a20a0b7084bb51d19671a27195fec
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-31 21:49:21 +01:00
Simon Hausmann f0ad3a5943 Implement loading of resolved imported scripts
We can resolve the use of names that refer to imported scripts at compile
time and load them at run-time by index through context->importedScripts.

Change-Id: I681b19e7d68dbf3b9a68af00b4cea2a9254c2d78
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-31 18:55:14 +01:00
Simon Hausmann b0afac3daf Implement setting of values to resolved QObject properties
After the resolution of a property, we can set it by index at run-time instead
of via name resolution.

Change-Id: I479599dabe343cf9e6582dcda12291aebfcce418
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-31 18:54:59 +01:00
Simon Hausmann 34c85bb56c Initial support for resolving meta-property access for the scope and context objects at QML compile time
This avoids having to do a string lookup for ids and in the import cache at
run-time, before we can do a string hash lookup in the property cache. Instead
we resolve final properties in the context and scope object at compile time and
look them up at run-time using their index instead. The dependencies to these
properties are also tracked separately and recorded in the compiled data.

This is merely the initial patch. There's a lot left to do, such as having
specialized getter and setters for specific property types. Setters are missing
altogether right now and will fall back to name lookup.

Change-Id: If3cb4e7c9454ef4850a615f0935b311c9395b165
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-31 10:50:38 +01:00
Lars Knoll b59751b146 Use lookups in the interpreter
Implement lookup calls for the interpreter. This
significantly reduces overhead by avoiding repeated
name lookups on the same object type.

This doubles the speed of quite a few of the v8
benchmarks, and brings the interpreter up to close
to 40% of the speed of the JIT.

Change-Id: Ie8c2f5b1ca71a7329bc643c3d2158a6301a392ed
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-30 08:29:49 +01:00
Lars Knoll 928a7d3e3e Optimize some unops and binops for moth
Optimize unops for ints/bools and add some
special binops where one side is constant.

Change-Id: I4f5639e36458560e5614371733abaafd94909ab1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-30 08:29:49 +01:00
Lars Knoll 53a6d572e5 Moth: Inline a couple of binops
This gives another 10-15% for v8-bench

Change-Id: Iaea90402179813af23008c35d344fa7f5353cf5f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-30 08:29:49 +01:00
Simon Hausmann ba6fc15d72 Speed up id object lookups
We can resolve lookups for objects referenced by id at QML compile time
and use a run-time helper to extract the id object out of the QML context
data by index instead of name.

Dependencies to id objects are also tracked at compile time and registered
separately before entering the generated function code.

The lookup of id objects is encoded in the IR as special member lookups.
Members will also then in the future be used to for property lookups in context
and scope properties, as well as any other property lookups in QObjects where
we can determine the meta-object.

Change-Id: I36cf3ceb11b51a983da6cad5b61c3bf574acc20a
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-29 21:56:07 +01:00
Lars Knoll c32265bfc5 Inline unary operations in moth
Change-Id: I6e141a425c2b4cc0cd64c7f0011e7028b9147f69
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 21:56:07 +01:00
Lars Knoll 7e69f4160f Rework parameter handling for moth
Get rid of the parameter type, and only store a
scope, that is an index into a SafeValue ** array.
This significantly speeds up loading and saving of
parameters.

Change-Id: I185145f1afd0b8cea461c7ca732ada3ebe39c34c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 14:06:14 +01:00
Lars Knoll 61be39a01b Remove the LoadValue instruction
With the constant table this is exactly the same as a move.
Also renamed MoveTemp to Move, as it not only moves Temps
but also other variables.

Change-Id: I1fccc04314661954179d903519adbc39777395e5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 14:06:11 +01:00
Lars Knoll cfe24c1aa0 Move constants into the compiled data for the interpreter
This makes it possible to remove the Value stored as
part of the instruction stream. Reduces the size of the
instruction stream and will allow to optimize Param lookup.

Change-Id: I23dab5dbed76bf8d62df7042934064d4676bc43d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 14:06:08 +01:00
Simon Hausmann b7878bccde Fix interpreter without computed goto and new exception handling
At the end of an instruction, don't break and run into the unreachable assert,
instead use "continue" to get to the top of the for (;;) loop to resume
execution.

Change-Id: I544104e76cb7a547c050714da1c67cde6f11ba04
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 10:39:11 +01:00
Lars Knoll 4f8df70107 Implement new exception handling for moth
Add the required instructions and check for
exceptions in the engine before storing any
results.

Change-Id: Ibfaf904d659859e8012920270825211ba202c63d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-10-29 10:38:50 +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
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
Erik Verbruggen f9305f9ffa V4: invert conditions when the true block follows the test.
Change-Id: I5044acd4263b71734e4eb5d7e74b1a4a8414741e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-10-03 07:06:35 +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 ac8afca822 Remove some more uses of QV4::Value
All remaining uses should be GC safe now.

Change-Id: I05c962de6ab896f108f70caa1bf937a24e67bfe1
Reviewed-by: Simon Hausmann <simon.hausmann@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
Erik Verbruggen 7c3f891c45 V4: remove inplace operations
Inplace operations are expanded when building the IR, so the neither the
IR, nor the instruction selection backends or runtime need to handle
them.

Change-Id: Id01f9544e137dd52364cf2ed2c10931c31ddfff3
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
2013-09-30 11:28:55 +02:00
Lars Knoll e57c2c8a0a remove more uses of QV4::Value
Change-Id: I11b0b2b7626297e2c98dc77784574da4b59ba8cf
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-30 08:05:48 +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 4d49787af4 Clean up QV4::ExecutionContext
Remove an unused variable, and don't copy runtimeStrings

Change-Id: I2197a7eb82ab3dbefea83cc917567390266f9673
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
2013-09-28 13:33:14 +02:00