aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-06-27 12:00:44 +0200
committerLars Knoll <lars.knoll@qt.io>2018-07-03 08:08:42 +0000
commit8e7f28339f57d22e4a8bdb30af449151c89d75db (patch)
treee890fcdb4d6219668b4eaa4da9b1955cff09e52d
parent65e799a9dec58b4bde3a085149f8cbcf0f5f3fba (diff)
Smaller refactoring of VME::exec() to preapre for upcoming changes
We'll need a more flexible interface here to support derived constructors properly. There's also quite some code in the generator functions that could benefit from some cleanups. Change-Id: I951b5d2171efa80d52fd6b0155f8f2c78af2f3b5 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/qml/jsruntime/qv4generatorobject.cpp4
-rw-r--r--src/qml/jsruntime/qv4vme_moth.cpp94
-rw-r--r--src/qml/jsruntime/qv4vme_moth_p.h3
3 files changed, 55 insertions, 46 deletions
diff --git a/src/qml/jsruntime/qv4generatorobject.cpp b/src/qml/jsruntime/qv4generatorobject.cpp
index 25da2d0a75..d5ae863856 100644
--- a/src/qml/jsruntime/qv4generatorobject.cpp
+++ b/src/qml/jsruntime/qv4generatorobject.cpp
@@ -132,7 +132,7 @@ ReturnedValue GeneratorFunction::virtualCall(const FunctionObject *f, const Valu
gp->cppFrame.parent = engine->currentStackFrame;
engine->currentStackFrame = &gp->cppFrame;
- Moth::VME::interpret(gp->cppFrame, function->codeData);
+ Moth::VME::interpret(&gp->cppFrame, engine, function->codeData);
gp->state = GeneratorState::SuspendedStart;
engine->currentStackFrame = gp->cppFrame.parent;
@@ -236,7 +236,7 @@ ReturnedValue GeneratorObject::resume(ExecutionEngine *engine, const Value &arg)
gp->cppFrame.jsFrame->accumulator = arg;
Scope scope(engine);
- ScopedValue result(scope, Moth::VME::interpret(gp->cppFrame, code));
+ ScopedValue result(scope, Moth::VME::interpret(&gp->cppFrame, engine, code));
engine->currentStackFrame = gp->cppFrame.parent;
diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp
index 8cdf0937ad..ade2a36ad1 100644
--- a/src/qml/jsruntime/qv4vme_moth.cpp
+++ b/src/qml/jsruntime/qv4vme_moth.cpp
@@ -391,7 +391,7 @@ static bool compareEqualInt(QV4::Value &accumulator, QV4::Value lhs, int rhs)
}
}
-#define STORE_IP() frame.instructionPointer = int(code - function->codeData);
+#define STORE_IP() frame->instructionPointer = int(code - function->codeData);
#define STORE_ACC() accumulator = acc;
#define ACC Primitive::fromReturnedValue(acc)
#define VALUE_TO_INT(i, val) \
@@ -412,6 +412,39 @@ static bool compareEqualInt(QV4::Value &accumulator, QV4::Value lhs, int rhs)
} \
} while (false)
+ReturnedValue VME::exec(CppStackFrame *frame, ExecutionEngine *engine)
+{
+ CHECK_STACK_LIMITS(engine);
+
+ Function *function = frame->v4Function;
+ Profiling::FunctionCallProfiler profiler(engine, function); // start execution profiling
+ QV4::Debugging::Debugger *debugger = engine->debugger();
+
+#ifdef V4_ENABLE_JIT
+ if (debugger == nullptr) {
+ if (function->jittedCode == nullptr) {
+ if (engine->canJIT(function))
+ QV4::JIT::BaselineJIT(function).generate();
+ else
+ ++function->interpreterCallCount;
+ }
+ if (function->jittedCode != nullptr)
+ return function->jittedCode(frame, engine);
+ }
+#endif // V4_ENABLE_JIT
+
+ // interpreter
+ if (debugger)
+ debugger->enteringFunction();
+
+ ReturnedValue result = interpret(frame, engine, function->codeData);
+
+ if (debugger)
+ debugger->leavingFunction(result);
+
+ return result;
+}
+
QV4::ReturnedValue VME::exec(const FunctionObject *fo, const QV4::Value *thisObject, const QV4::Value *argv, int argc, const Value *newTarget)
{
qt_v4ResolvePendingBreakpointsHook();
@@ -467,46 +500,21 @@ QV4::ReturnedValue VME::exec(const FunctionObject *fo, const QV4::Value *thisObj
frame.jsFrame = callData;
engine->currentStackFrame = &frame;
}
- CHECK_STACK_LIMITS(engine);
-
- Profiling::FunctionCallProfiler profiler(engine, function); // start execution profiling
- QV4::Debugging::Debugger *debugger = engine->debugger();
-#ifdef V4_ENABLE_JIT
- if (function->jittedCode == nullptr && debugger == nullptr) {
- if (engine->canJIT(function))
- QV4::JIT::BaselineJIT(function).generate();
- else
- ++function->interpreterCallCount;
- }
-#endif // V4_ENABLE_JIT
+ ReturnedValue result = exec(&frame, engine);
- if (debugger)
- debugger->enteringFunction();
-
- ReturnedValue result;
- if (function->jittedCode != nullptr && debugger == nullptr) {
- result = function->jittedCode(&frame, engine);
- } else {
- // interpreter
- result = interpret(frame, function->codeData);
- }
-
- if (QV4::Debugging::Debugger *debugger = engine->debugger())
- debugger->leavingFunction(result);
engine->currentStackFrame = frame.parent;
engine->jsStackTop = stack;
return result;
}
-QV4::ReturnedValue VME::interpret(CppStackFrame &frame, const char *code)
+QV4::ReturnedValue VME::interpret(CppStackFrame *frame, ExecutionEngine *engine, const char *code)
{
- QV4::Function *function = frame.v4Function;
- QV4::Value &accumulator = frame.jsFrame->accumulator;
+ QV4::Function *function = frame->v4Function;
+ QV4::Value &accumulator = frame->jsFrame->accumulator;
QV4::ReturnedValue acc = accumulator.asReturnedValue();
- Value *stack = reinterpret_cast<Value *>(frame.jsFrame);
- ExecutionEngine *engine = function->internalClass->engine;
+ Value *stack = reinterpret_cast<Value *>(frame->jsFrame);
MOTH_JUMP_TABLE;
@@ -704,7 +712,7 @@ QV4::ReturnedValue VME::interpret(CppStackFrame &frame, const char *code)
MOTH_END_INSTR(LoadIdObject)
MOTH_BEGIN_INSTR(Yield)
- frame.yield = code;
+ frame->yield = code;
return acc;
MOTH_END_INSTR(Yield)
@@ -808,22 +816,22 @@ QV4::ReturnedValue VME::interpret(CppStackFrame &frame, const char *code)
MOTH_END_INSTR(ConstructWithSpread)
MOTH_BEGIN_INSTR(SetUnwindHandler)
- frame.unwindHandler = offset ? code + offset : nullptr;
+ frame->unwindHandler = offset ? code + offset : nullptr;
MOTH_END_INSTR(SetUnwindHandler)
MOTH_BEGIN_INSTR(UnwindDispatch)
CHECK_EXCEPTION;
- if (frame.unwindLevel) {
- --frame.unwindLevel;
- if (frame.unwindLevel)
+ if (frame->unwindLevel) {
+ --frame->unwindLevel;
+ if (frame->unwindLevel)
goto handleUnwind;
- code = frame.unwindLabel;
+ code = frame->unwindLabel;
}
MOTH_END_INSTR(UnwindDispatch)
MOTH_BEGIN_INSTR(UnwindToLabel)
- frame.unwindLevel = level;
- frame.unwindLabel = code + offset;
+ frame->unwindLevel = level;
+ frame->unwindLabel = code + offset;
goto handleUnwind;
MOTH_END_INSTR(UnwindToLabel)
@@ -853,7 +861,7 @@ QV4::ReturnedValue VME::interpret(CppStackFrame &frame, const char *code)
MOTH_END_INSTR(PushCatchContext)
MOTH_BEGIN_INSTR(CreateCallContext)
- stack[CallData::Context] = ExecutionContext::newCallContext(&frame);
+ stack[CallData::Context] = ExecutionContext::newCallContext(frame);
MOTH_END_INSTR(CreateCallContext)
MOTH_BEGIN_INSTR(PushWithContext)
@@ -1371,11 +1379,11 @@ QV4::ReturnedValue VME::interpret(CppStackFrame &frame, const char *code)
MOTH_END_INSTR(LoadQmlImportedScripts)
handleUnwind:
- Q_ASSERT(engine->hasException || frame.unwindLevel);
- if (!frame.unwindHandler) {
+ Q_ASSERT(engine->hasException || frame->unwindLevel);
+ if (!frame->unwindHandler) {
acc = Encode::undefined();
return acc;
}
- code = frame.unwindHandler;
+ code = frame->unwindHandler;
}
}
diff --git a/src/qml/jsruntime/qv4vme_moth_p.h b/src/qml/jsruntime/qv4vme_moth_p.h
index c5c07d92cb..0167e6f5b0 100644
--- a/src/qml/jsruntime/qv4vme_moth_p.h
+++ b/src/qml/jsruntime/qv4vme_moth_p.h
@@ -71,8 +71,9 @@ public:
quintptr d = reinterpret_cast<quintptr>(&data) | 0x1;
return exec(reinterpret_cast<const FunctionObject *>(d), thisObject, argv, argc);
}
+ static QV4::ReturnedValue exec(CppStackFrame *frame, ExecutionEngine *engine);
static QV4::ReturnedValue exec(const FunctionObject *fo, const Value *thisObject, const Value *argv, int argc, const Value *newTarget = nullptr);
- static QV4::ReturnedValue interpret(CppStackFrame &frame, const char *codeEntry);
+ static QV4::ReturnedValue interpret(CppStackFrame *frame, ExecutionEngine *engine, const char *codeEntry);
};
} // namespace Moth