aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@theqtcompany.com>2014-12-17 21:07:05 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2014-12-19 16:30:16 +0100
commit45f77a6bfc05b97e6312a379c63840243b5815f3 (patch)
treec581f59d704c4af1a69a36f7c3bb404d36fc6e90 /src/qml
parentb50278bda4df94550bfbe5663ddebcd4b0f9734f (diff)
Cleanup code that modifies the JS stack
Change-Id: Ic043e256c3df984bb06c9a16b86573b0173b19a1 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/jit/qv4isel_masm.cpp27
-rw-r--r--src/qml/jsruntime/qv4engine_p.h9
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp4
-rw-r--r--src/qml/jsruntime/qv4scopedvalue_p.h13
-rw-r--r--src/qml/jsruntime/qv4vme_moth.cpp13
5 files changed, 35 insertions, 31 deletions
diff --git a/src/qml/jit/qv4isel_masm.cpp b/src/qml/jit/qv4isel_masm.cpp
index e7771f53d2..3894cea0a1 100644
--- a/src/qml/jit/qv4isel_masm.cpp
+++ b/src/qml/jit/qv4isel_masm.cpp
@@ -245,9 +245,30 @@ void InstructionSelection::run(int functionIndex)
#endif
const int locals = _as->stackLayout().calculateJSStackFrameSize();
- _as->loadPtr(Address(Assembler::EngineRegister, qOffsetOf(ExecutionEngine, jsStackTop)), Assembler::LocalsRegister);
- _as->addPtr(Assembler::TrustedImm32(sizeof(QV4::Value)*locals), Assembler::LocalsRegister);
- _as->storePtr(Assembler::LocalsRegister, Address(Assembler::EngineRegister, qOffsetOf(ExecutionEngine, jsStackTop)));
+ if (locals > 0) {
+ _as->loadPtr(Address(Assembler::EngineRegister, qOffsetOf(ExecutionEngine, jsStackTop)), Assembler::LocalsRegister);
+#ifdef VALUE_FITS_IN_REGISTER
+ _as->move(Assembler::TrustedImm64(0), Assembler::ReturnValueRegister);
+ _as->move(Assembler::TrustedImm32(locals), Assembler::ScratchRegister);
+ Assembler::Label loop = _as->label();
+ _as->store64(Assembler::ReturnValueRegister, Assembler::Address(Assembler::LocalsRegister));
+ _as->add64(Assembler::TrustedImm32(8), Assembler::LocalsRegister);
+ Assembler::Jump jump = _as->branchSub32(Assembler::NonZero, Assembler::TrustedImm32(1), Assembler::ScratchRegister);
+ jump.linkTo(loop, _as);
+#else
+ _as->move(Assembler::TrustedImm32(0), Assembler::ReturnValueRegister);
+ _as->move(Assembler::TrustedImm32(locals), Assembler::ScratchRegister);
+ Assembler::Label loop = _as->label();
+ _as->store32(Assembler::ReturnValueRegister, Assembler::Address(Assembler::LocalsRegister));
+ _as->add32(Assembler::TrustedImm32(4), Assembler::LocalsRegister);
+ _as->store32(Assembler::ReturnValueRegister, Assembler::Address(Assembler::LocalsRegister));
+ _as->add32(Assembler::TrustedImm32(4), Assembler::LocalsRegister);
+ Assembler::Jump jump = _as->branchSub32(Assembler::NonZero, Assembler::TrustedImm32(1), Assembler::ScratchRegister);
+ jump.linkTo(loop, _as);
+#endif
+ _as->storePtr(Assembler::LocalsRegister, Address(Assembler::EngineRegister, qOffsetOf(ExecutionEngine, jsStackTop)));
+ }
+
int lastLine = 0;
for (int i = 0, ei = _function->basicBlockCount(); i != ei; ++i) {
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index a7d26f8700..813b5fce5b 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -96,15 +96,6 @@ public:
WTF::PageAllocation *jsStack;
Value *jsStackBase;
- Value *stackPush(uint nValues) {
- Value *ptr = jsStackTop;
- jsStackTop = ptr + nValues;
- return ptr;
- }
- void stackPop(uint nValues) {
- jsStackTop -= nValues;
- }
-
void pushForGC(Heap::Base *m) {
*jsStackTop = m;
++jsStackTop;
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 6a0496d1c5..437de33b3f 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -492,7 +492,7 @@ ReturnedValue SimpleScriptFunction::construct(Managed *that, CallData *callData)
ctx.compilationUnit = f->function()->compilationUnit;
ctx.lookups = ctx.compilationUnit->runtimeLookups;
ctx.outer = f->scope();
- ctx.locals = v4->stackPush(f->varCount());
+ ctx.locals = scope.alloc(f->varCount());
while (callData->argc < (int)f->formalParameterCount()) {
callData->args[callData->argc] = Encode::undefined();
++callData->argc;
@@ -529,7 +529,7 @@ ReturnedValue SimpleScriptFunction::call(Managed *that, CallData *callData)
ctx.compilationUnit = f->function()->compilationUnit;
ctx.lookups = ctx.compilationUnit->runtimeLookups;
ctx.outer = f->scope();
- ctx.locals = v4->stackPush(f->varCount());
+ ctx.locals = scope.alloc(f->varCount());
while (callData->argc < (int)f->formalParameterCount()) {
callData->args[callData->argc] = Encode::undefined();
++callData->argc;
diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h
index 461d499694..6805fc80be 100644
--- a/src/qml/jsruntime/qv4scopedvalue_p.h
+++ b/src/qml/jsruntime/qv4scopedvalue_p.h
@@ -82,11 +82,12 @@ struct Scope {
}
Value *alloc(int nValues) {
- Value *ptr = engine->jsStackTop;
- engine->jsStackTop += nValues;
#ifndef QT_NO_DEBUG
size += nValues;
#endif
+ Value *ptr = engine->jsStackTop;
+ engine->jsStackTop = ptr + nValues;
+ memset(ptr, 0, nValues*sizeof(Value));
return ptr;
}
@@ -111,6 +112,7 @@ struct ScopedValue
ScopedValue(const Scope &scope)
{
ptr = scope.engine->jsStackTop++;
+ ptr->val = 0;
#ifndef QT_NO_DEBUG
++scope.size;
#endif
@@ -372,14 +374,9 @@ struct ScopedCallData {
ScopedCallData(Scope &scope, int argc = 0)
{
int size = qMax(argc, (int)QV4::Global::ReservedArgumentCount) + qOffsetOf(QV4::CallData, args)/sizeof(QV4::Value);
- ptr = reinterpret_cast<CallData *>(scope.engine->stackPush(size));
+ ptr = reinterpret_cast<CallData *>(scope.alloc(size));
ptr->tag = QV4::Value::Integer_Type;
ptr->argc = argc;
-#ifndef QT_NO_DEBUG
- scope.size += size;
- for (int ii = 0; ii < qMax(argc, (int)QV4::Global::ReservedArgumentCount); ++ii)
- ptr->args[ii] = QV4::Primitive::undefinedValue();
-#endif
}
CallData *operator->() {
diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp
index 8372aaa510..eb5fd1bcd8 100644
--- a/src/qml/jsruntime/qv4vme_moth.cpp
+++ b/src/qml/jsruntime/qv4vme_moth.cpp
@@ -143,7 +143,8 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code
const uchar *exceptionHandler = 0;
- QV4::ExecutionContext *context = engine->currentContext();
+ QV4::Scope scope(engine);
+ QV4::ScopedContext context(scope, engine->currentContext());
context->d()->lineNumber = -1;
#ifdef DO_TRACE_INSTR
@@ -292,10 +293,7 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code
MOTH_BEGIN_INSTR(Push)
TRACE(inline, "stack size: %u", instr.value);
stackSize = instr.value;
- stack = context->engine()->stackPush(stackSize);
-#ifndef QT_NO_DEBUG
- memset(stack, 0, stackSize * sizeof(QV4::Value));
-#endif
+ stack = scope.alloc(stackSize);
scopes[1] = stack;
MOTH_END_INSTR(Push)
@@ -613,7 +611,6 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code
MOTH_END_INSTR(BinopContext)
MOTH_BEGIN_INSTR(Ret)
- context->engine()->stackPop(stackSize);
// TRACE(Ret, "returning value %s", result.toString(context)->toQString().toUtf8().constData());
return VALUE(instr.result).asReturnedValue();
MOTH_END_INSTR(Ret)
@@ -665,10 +662,8 @@ QV4::ReturnedValue VME::run(ExecutionEngine *engine, const uchar *code
Q_ASSERT(false);
catchException:
Q_ASSERT(context->engine()->hasException);
- if (!exceptionHandler) {
- context->engine()->stackPop(stackSize);
+ if (!exceptionHandler)
return QV4::Encode::undefined();
- }
code = exceptionHandler;
}