Cleanup code that modifies the JS stack

Change-Id: Ic043e256c3df984bb06c9a16b86573b0173b19a1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
Lars Knoll 2014-12-17 21:07:05 +01:00 committed by Simon Hausmann
parent b50278bda4
commit 45f77a6bfc
5 changed files with 35 additions and 31 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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->() {

View File

@ -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;
}