diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2012-12-19 11:21:06 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-12-19 11:26:23 +0100 |
commit | 278eba11a464d2a2b2b842018508d2e02aac9df1 (patch) | |
tree | 579e3e2aaaab3f0922497abce33602d71e1b3b8c /moth | |
parent | f2e52c5bf26cfcedd0901040dfe1a6c86c5aa146 (diff) |
Change the interpreter's stack frame to be allocated with alloca.
Change-Id: Ia02ad1af3bb0f429a6078029bf7aaee5a17f3413
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'moth')
-rw-r--r-- | moth/moth.pri | 6 | ||||
-rw-r--r-- | moth/qv4mm_moth.cpp | 81 | ||||
-rw-r--r-- | moth/qv4mm_moth.h | 59 | ||||
-rw-r--r-- | moth/qv4vme_moth.cpp | 8 |
4 files changed, 5 insertions, 149 deletions
diff --git a/moth/moth.pri b/moth/moth.pri index 160c1aac00..73bd893286 100644 --- a/moth/moth.pri +++ b/moth/moth.pri @@ -3,13 +3,11 @@ INCLUDEPATH += $$PWD HEADERS += \ $$PWD/qv4isel_moth_p.h \ $$PWD/qv4instr_moth_p.h \ - $$PWD/qv4vme_moth_p.h \ - $$PWD/qv4mm_moth.h + $$PWD/qv4vme_moth_p.h SOURCES += \ $$PWD/qv4isel_moth.cpp \ $$PWD/qv4instr_moth.cpp \ - $$PWD/qv4vme_moth.cpp \ - $$PWD/qv4mm_moth.cpp + $$PWD/qv4vme_moth.cpp #DEFINES += DO_TRACE_INSTR diff --git a/moth/qv4mm_moth.cpp b/moth/qv4mm_moth.cpp deleted file mode 100644 index 44e45fe027..0000000000 --- a/moth/qv4mm_moth.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "qmljs_engine.h" -#include "qv4mm_moth.h" - -#include <QList> - -using namespace QQmlJS; -using namespace QQmlJS::Moth; - -MemoryManager::MemoryManager() -{ - stackFrames.reserve(64); -} - -MemoryManager::~MemoryManager() -{ -} - -VM::Value *MemoryManager::allocStackFrame(std::size_t frameSize) -{ - std::size_t size = frameSize * sizeof(VM::Value); - MMObject *m = alloc(align(size)); - stackFrames.append(m); - return reinterpret_cast<VM::Value *>(&m->data); -} - -void MemoryManager::deallocStackFrame(VM::Value *stackFrame) -{ - MMObject *o = toObject(stackFrame); - for (int i = stackFrames.size() - 1; i >= 0; --i) { - if (stackFrames[i] == o) { - stackFrames.remove(i); - dealloc(o); - return; - } - } - - Q_UNREACHABLE(); -} - -void MemoryManager::collectRootsOnStack(QVector<VM::Object *> &roots) const -{ - for (int i = 0, ei = stackFrames.size(); i < ei; ++i) { - MMObject *m = stackFrames[i]; - VM::Value *frame = reinterpret_cast<VM::Value *>(&m->data); - std::size_t frameSize = (m->info.size - align(sizeof(MMInfo))) / sizeof(VM::Value); - for (std::size_t j = 0; j < frameSize; ++j) { - if (VM::Object *o = frame[j].asObject()) { - roots.append(o); - } - } - } -} diff --git a/moth/qv4mm_moth.h b/moth/qv4mm_moth.h deleted file mode 100644 index a2b1ebd556..0000000000 --- a/moth/qv4mm_moth.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef QV4GC_MOTH_H -#define QV4GC_MOTH_H - -#include "qv4mm.h" - -#include <QVector> - -namespace QQmlJS { -namespace Moth { - -class MemoryManager: public QQmlJS::VM::MemoryManager -{ -public: - MemoryManager(); - ~MemoryManager(); - - VM::Value *allocStackFrame(std::size_t frameSize); - void deallocStackFrame(VM::Value *stackFrame); - -protected: - virtual void collectRootsOnStack(QVector<VM::Object *> &roots) const; - -private: - QVector<MMObject *> stackFrames; -}; - -} // namespace Moth -} // namespace QQmlJS - -#endif // QV4GC_MOTH_H diff --git a/moth/qv4vme_moth.cpp b/moth/qv4vme_moth.cpp index 2a1302f423..0156e4a8da 100644 --- a/moth/qv4vme_moth.cpp +++ b/moth/qv4vme_moth.cpp @@ -2,10 +2,11 @@ #include "qv4instr_moth_p.h" #include "qmljs_value.h" #include "debugging.h" -#include "qv4mm_moth.h" #include <iostream> +#include <alloca.h> + #ifdef DO_TRACE_INSTR # define TRACE_INSTR(I) fprintf(stderr, "executing a %s\n", #I); # define TRACE(n, str, ...) { char buf[4096]; snprintf(buf, 4096, str, __VA_ARGS__); fprintf(stderr, " %s : %s\n", #n, buf); } @@ -103,9 +104,6 @@ public: , code(code) {} - ~FunctionState() - { if (stack) static_cast<MemoryManager *>(context()->engine->memoryManager)->deallocStackFrame(stack); } - virtual VM::Value *temp(unsigned idx) { return stack + idx; } void setStack(VM::Value *stack, unsigned stackSize) @@ -201,7 +199,7 @@ VM::Value VME::operator()(QQmlJS::VM::ExecutionContext *context, const uchar *co MOTH_BEGIN_INSTR(Push) TRACE(inline, "stack size: %u", instr.value); stackSize = instr.value; - stack = static_cast<MemoryManager *>(context->engine->memoryManager)->allocStackFrame(stackSize); + stack = static_cast<VM::Value *>(alloca(stackSize * sizeof(VM::Value))); state.setStack(stack, stackSize); MOTH_END_INSTR(Push) |