aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-08-16 18:35:29 +0200
committerLars Knoll <lars.knoll@digia.com>2013-08-16 19:22:24 +0200
commita44f92d925a1b0f5fa205706a26d81f07de75c33 (patch)
tree16345975d3058ca04b769b2598f58fa6de1f6f0d /src/qml
parent0f0e7443aea0d9a203b380bec708c485a01450e0 (diff)
Get rid of the functions list in QV4::ExecutionEngine
Change-Id: I97067dbb2819936a1b2029c9f63f0627cb6b8bd2 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/compiler/qv4compileddata.cpp18
-rw-r--r--src/qml/compiler/qv4compileddata_p.h3
-rw-r--r--src/qml/compiler/qv4isel_masm.cpp9
-rw-r--r--src/qml/compiler/qv4isel_masm_p.h2
-rw-r--r--src/qml/jsruntime/qv4debugging.cpp8
-rw-r--r--src/qml/jsruntime/qv4engine.cpp28
-rw-r--r--src/qml/jsruntime/qv4engine_p.h3
-rw-r--r--src/qml/jsruntime/qv4function.cpp2
8 files changed, 41 insertions, 32 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index 59c6a9b7fd..7f02509a80 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -45,11 +45,19 @@
#include <private/qv4function_p.h>
#include <private/qv4lookup_p.h>
#include <private/qv4regexpobject_p.h>
+#include <private/qv4unwindhelper_p.h>
namespace QV4 {
namespace CompiledData {
+namespace {
+ bool functionSortHelper(QV4::Function *lhs, QV4::Function *rhs)
+ {
+ return reinterpret_cast<quintptr>(lhs->code) < reinterpret_cast<quintptr>(rhs->code);
+ }
+}
+
CompilationUnit::~CompilationUnit()
{
engine->compilationUnits.erase(engine->compilationUnits.find(this));
@@ -121,7 +129,13 @@ QV4::Function *CompilationUnit::linkToEngine(ExecutionEngine *engine)
}
}
- return linkBackendToEngine(engine);
+ QV4::Function *entry = linkBackendToEngine(engine);
+
+ runtimeFunctionsSortedByAddress.resize(runtimeFunctions.size());
+ memcpy(runtimeFunctionsSortedByAddress.data(), runtimeFunctions.data(), runtimeFunctions.size() * sizeof(QV4::Function*));
+ qSort(runtimeFunctionsSortedByAddress.begin(), runtimeFunctionsSortedByAddress.end(), functionSortHelper);
+
+ return entry;
}
void CompilationUnit::markObjects()
@@ -130,6 +144,8 @@ void CompilationUnit::markObjects()
runtimeStrings[i]->mark();
for (int i = 0; i < data->regexpTableSize; ++i)
runtimeRegularExpressions[i].mark();
+ for (int i = 0; i < runtimeFunctions.count(); ++i)
+ runtimeFunctions[i]->mark();
}
}
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index 611d916ea8..379766f6de 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -328,7 +328,8 @@ struct CompilationUnit
QV4::Lookup *runtimeLookups;
QV4::Value *runtimeRegularExpressions;
QV4::InternalClass **runtimeClasses;
- QList<QV4::Function *> runtimeFunctions;
+ QVector<QV4::Function *> runtimeFunctions;
+ QVector<QV4::Function *> runtimeFunctionsSortedByAddress;
QV4::Function *linkToEngine(QV4::ExecutionEngine *engine);
diff --git a/src/qml/compiler/qv4isel_masm.cpp b/src/qml/compiler/qv4isel_masm.cpp
index a998e8b197..e0b79acb64 100644
--- a/src/qml/compiler/qv4isel_masm.cpp
+++ b/src/qml/compiler/qv4isel_masm.cpp
@@ -64,6 +64,11 @@ using namespace QQmlJS;
using namespace QQmlJS::MASM;
using namespace QV4;
+CompilationUnit::~CompilationUnit()
+{
+ UnwindHelper::deregisterFunctions(runtimeFunctions);
+}
+
QV4::Function *CompilationUnit::linkBackendToEngine(ExecutionEngine *engine)
{
QV4::Function *rootRuntimeFunction = 0;
@@ -78,14 +83,14 @@ QV4::Function *CompilationUnit::linkBackendToEngine(ExecutionEngine *engine)
(Value (*)(QV4::ExecutionContext *, const uchar *)) codeRefs[i].code().executableAddress(),
codeRefs[i].size());
- UnwindHelper::registerFunction(runtimeFunction);
-
if (compiledFunction == compiledRootFunction) {
assert(!rootRuntimeFunction);
rootRuntimeFunction = runtimeFunction;
}
}
+ UnwindHelper::registerFunctions(runtimeFunctions);
+
return rootRuntimeFunction;
}
diff --git a/src/qml/compiler/qv4isel_masm_p.h b/src/qml/compiler/qv4isel_masm_p.h
index 3cde647293..4461f16b3e 100644
--- a/src/qml/compiler/qv4isel_masm_p.h
+++ b/src/qml/compiler/qv4isel_masm_p.h
@@ -63,6 +63,8 @@ class InstructionSelection;
struct CompilationUnit : public QV4::CompiledData::CompilationUnit
{
+ virtual ~CompilationUnit();
+
virtual QV4::Function *linkBackendToEngine(QV4::ExecutionEngine *engine);
virtual QV4::ExecutableAllocator::ChunkOfPages *chunkForFunction(int functionIndex);
diff --git a/src/qml/jsruntime/qv4debugging.cpp b/src/qml/jsruntime/qv4debugging.cpp
index 3bb031116e..5534305068 100644
--- a/src/qml/jsruntime/qv4debugging.cpp
+++ b/src/qml/jsruntime/qv4debugging.cpp
@@ -185,9 +185,11 @@ void Debugger::pauseAndWait()
void Debugger::applyPendingBreakPoints()
{
- foreach (Function *function, _engine->functions) {
- m_pendingBreakPointsToAdd.applyToFunction(function, /*removeBreakPoints*/false);
- m_pendingBreakPointsToRemove.applyToFunction(function, /*removeBreakPoints*/true);
+ foreach (QV4::CompiledData::CompilationUnit *unit, _engine->compilationUnits) {
+ foreach (Function *function, unit->runtimeFunctions) {
+ m_pendingBreakPointsToAdd.applyToFunction(function, /*removeBreakPoints*/false);
+ m_pendingBreakPointsToRemove.applyToFunction(function, /*removeBreakPoints*/true);
+ }
}
for (BreakPoints::ConstIterator it = m_pendingBreakPointsToAdd.constBegin(),
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 764f3fa45f..36ab994274 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -87,7 +87,6 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory)
, debugger(0)
, globalObject(0)
, globalCode(0)
- , functionsNeedSort(false)
, m_engineId(engineSerial.fetchAndAddOrdered(1))
, regExpCache(0)
, m_multiplyWrappedQObjects(0)
@@ -279,7 +278,6 @@ ExecutionEngine::~ExecutionEngine()
delete identifierTable;
delete bumperPointerAllocator;
delete regExpCache;
- UnwindHelper::deregisterFunctions(functions);
delete regExpAllocator;
delete executableAllocator;
}
@@ -379,8 +377,6 @@ ExecutionContext *ExecutionEngine::pushGlobalContext()
Function *ExecutionEngine::newFunction(const QString &name)
{
Function *f = new Function(this, newIdentifier(name));
- functions.append(f);
- functionsNeedSort = true;
return f;
}
@@ -732,9 +728,6 @@ void ExecutionEngine::markObjects()
c = c->parent;
}
- for (int i = 0; i < functions.size(); ++i)
- functions.at(i)->mark();
-
id_length->mark();
id_prototype->mark();
id_constructor->mark();
@@ -796,11 +789,6 @@ void ExecutionEngine::markObjects()
}
namespace {
- bool functionSortHelper(Function *lhs, Function *rhs)
- {
- return reinterpret_cast<quintptr>(lhs->code) < reinterpret_cast<quintptr>(rhs->code);
- }
-
struct FindHelper
{
bool operator()(Function *function, quintptr pc)
@@ -818,15 +806,15 @@ namespace {
Function *ExecutionEngine::functionForProgramCounter(quintptr pc) const
{
- if (functionsNeedSort) {
- qSort(functions.begin(), functions.end(), functionSortHelper);
- functionsNeedSort = false;
+ for (QSet<QV4::CompiledData::CompilationUnit*>::ConstIterator unitIt = compilationUnits.constBegin(), unitEnd = compilationUnits.constEnd();
+ unitIt != unitEnd; ++unitIt) {
+ const QVector<Function*> &functions = (*unitIt)->runtimeFunctionsSortedByAddress;
+ QVector<Function*>::ConstIterator it = qBinaryFind(functions.constBegin(),
+ functions.constEnd(),
+ pc, FindHelper());
+ if (it != functions.constEnd())
+ return *it;
}
-
- QVector<Function*>::ConstIterator it = qBinaryFind(functions.constBegin(), functions.constEnd(),
- pc, FindHelper());
- if (it != functions.constEnd())
- return *it;
return 0;
}
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index 6a7442db1c..3dfc070f89 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -201,9 +201,6 @@ struct Q_QML_EXPORT ExecutionEngine
String *id_uintMax;
String *id_name;
- mutable QVector<Function *> functions;
- mutable bool functionsNeedSort;
-
QSet<CompiledData::CompilationUnit*> compilationUnits;
quint32 m_engineId;
diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp
index c96935de03..87db58580f 100644
--- a/src/qml/jsruntime/qv4function.cpp
+++ b/src/qml/jsruntime/qv4function.cpp
@@ -53,8 +53,6 @@ using namespace QV4;
Function::~Function()
{
- engine->functions.remove(engine->functions.indexOf(this));
- UnwindHelper::deregisterFunction(this); // ### move to masm compilation unit
}
void Function::init(CompiledData::CompilationUnit *unit, const CompiledData::Function *function, Value (*codePtr)(ExecutionContext *, const uchar *),