From 2666fe4a1440cc798b9db68fcc807450d46069c2 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 27 Jun 2018 14:18:17 +0200 Subject: Move the C++ and JS stack frame definitions into it's own file Change-Id: I86e89e07197aec6071809c2d32bd5c98cb7ac6f6 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4codegen_p.h | 1 + src/qml/compiler/qv4instr_moth.cpp | 1 + src/qml/jit/qv4assembler.cpp | 1 + src/qml/jsapi/qjsengine.cpp | 1 + src/qml/jsruntime/jsruntime.pri | 2 + src/qml/jsruntime/qv4context.cpp | 1 + src/qml/jsruntime/qv4context_p.h | 40 ---------- src/qml/jsruntime/qv4engine.cpp | 32 +------- src/qml/jsruntime/qv4engine_p.h | 30 ------- src/qml/jsruntime/qv4function.cpp | 6 ++ src/qml/jsruntime/qv4function_p.h | 8 +- src/qml/jsruntime/qv4generatorobject_p.h | 1 + src/qml/jsruntime/qv4jscall_p.h | 1 + src/qml/jsruntime/qv4stackframe.cpp | 74 ++++++++++++++++++ src/qml/jsruntime/qv4stackframe_p.h | 130 +++++++++++++++++++++++++++++++ src/qml/qml/qqmlvaluetypewrapper.cpp | 2 +- src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 1 + src/qml/qml/v8/qv8engine_p.h | 1 + 18 files changed, 226 insertions(+), 107 deletions(-) create mode 100644 src/qml/jsruntime/qv4stackframe.cpp create mode 100644 src/qml/jsruntime/qv4stackframe_p.h (limited to 'src') diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h index fb69e46e42..cac8da4e71 100644 --- a/src/qml/compiler/qv4codegen_p.h +++ b/src/qml/compiler/qv4codegen_p.h @@ -66,6 +66,7 @@ #endif #include #include +#include QT_BEGIN_NAMESPACE diff --git a/src/qml/compiler/qv4instr_moth.cpp b/src/qml/compiler/qv4instr_moth.cpp index c3cee9c851..2d2f7bc27f 100644 --- a/src/qml/compiler/qv4instr_moth.cpp +++ b/src/qml/compiler/qv4instr_moth.cpp @@ -39,6 +39,7 @@ #include "qv4instr_moth_p.h" #include +#include using namespace QV4; using namespace QV4::Moth; diff --git a/src/qml/jit/qv4assembler.cpp b/src/qml/jit/qv4assembler.cpp index be6c03ab8f..7d668950d7 100644 --- a/src/qml/jit/qv4assembler.cpp +++ b/src/qml/jit/qv4assembler.cpp @@ -44,6 +44,7 @@ #include "qv4assembler_p.h" #include #include +#include #include #include diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index 846ceeea9c..5fa81ccc2a 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include diff --git a/src/qml/jsruntime/jsruntime.pri b/src/qml/jsruntime/jsruntime.pri index 41870b3e04..ec5803b2df 100644 --- a/src/qml/jsruntime/jsruntime.pri +++ b/src/qml/jsruntime/jsruntime.pri @@ -35,6 +35,7 @@ SOURCES += \ $$PWD/qv4qmlcontext.cpp \ $$PWD/qv4reflect.cpp \ $$PWD/qv4regexpobject.cpp \ + $$PWD/qv4stackframe.cpp \ $$PWD/qv4stringiterator.cpp \ $$PWD/qv4stringobject.cpp \ $$PWD/qv4variantobject.cpp \ @@ -98,6 +99,7 @@ HEADERS += \ $$PWD/qv4reflect_p.h \ $$PWD/qv4regexpobject_p.h \ $$PWD/qv4runtimecodegen_p.h \ + $$PWD/qv4stackframe_p.h \ $$PWD/qv4stringiterator_p.h \ $$PWD/qv4stringobject_p.h \ $$PWD/qv4variantobject_p.h \ diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index 2c4e5f34d4..bb08d2786d 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -48,6 +48,7 @@ #include "qv4errorobject_p.h" #include "qv4string_p.h" #include "qv4qmlcontext_p.h" +#include "qv4stackframe_p.h" using namespace QV4; diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index e2fb18720a..fbb4168e9b 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -57,46 +57,6 @@ QT_BEGIN_NAMESPACE namespace QV4 { -struct CallData -{ - enum Offsets { - Function = 0, - Context = 1, - Accumulator = 2, - This = 3, - NewTarget = 4, - Argc = 5 - }; - - Value function; - Value context; - Value accumulator; - Value thisObject; - Value newTarget; - Value _argc; - - int argc() const { - Q_ASSERT(_argc.isInteger()); - return _argc.int_32(); - } - - void setArgc(int argc) { - Q_ASSERT(argc >= 0); - _argc.setInt_32(argc); - } - - inline ReturnedValue argument(int i) const { - return i < argc() ? args[i].asReturnedValue() : Primitive::undefinedValue().asReturnedValue(); - } - - Value args[1]; - - static Q_DECL_CONSTEXPR int HeaderSize() { return offsetof(CallData, args) / sizeof(QV4::Value); } -}; - -Q_STATIC_ASSERT(std::is_standard_layout::value); -Q_STATIC_ASSERT(offsetof(CallData, thisObject) == CallData::This*sizeof(Value)); -Q_STATIC_ASSERT(offsetof(CallData, args) == 6*sizeof(Value)); namespace Heap { diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 64d6583f60..a482d83a97 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -74,6 +74,7 @@ #include "qv4generatorobject_p.h" #include "qv4reflect_p.h" #include "qv4proxy_p.h" +#include "qv4stackframe_p.h" #if QT_CONFIG(qml_sequence_object) #include "qv4sequenceobject_p.h" @@ -900,37 +901,6 @@ QQmlContextData *ExecutionEngine::callingQmlContext() const return ctx->qml()->context->contextData(); } -QString CppStackFrame::source() const -{ - return v4Function ? v4Function->sourceFile() : QString(); -} - -QString CppStackFrame::function() const -{ - return v4Function ? v4Function->name()->toQString() : QString(); -} - -int CppStackFrame::lineNumber() const -{ - if (!v4Function) - return -1; - - auto findLine = [](const CompiledData::CodeOffsetToLine &entry, uint offset) { - return entry.codeOffset < offset; - }; - - const QV4::CompiledData::Function *cf = v4Function->compiledFunction; - uint offset = instructionPointer; - const CompiledData::CodeOffsetToLine *lineNumbers = cf->lineNumberTable(); - uint nLineNumbers = cf->nLineNumbers; - const CompiledData::CodeOffsetToLine *line = std::lower_bound(lineNumbers, lineNumbers + nLineNumbers, offset, findLine) - 1; - return line->line; -} - -ReturnedValue CppStackFrame::thisObject() const { - return jsFrame->thisObject.asReturnedValue(); -} - StackTrace ExecutionEngine::stackTrace(int frameLimit) const { Scope scope(const_cast(this)); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index a1bd321412..fc0c93eaad 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -56,7 +56,6 @@ #include #include "qv4enginebase_p.h" - #ifndef V4_BOOTSTRAP # include "qv4function_p.h" # include @@ -89,35 +88,6 @@ struct CompilationUnit; struct Function; -struct Q_QML_EXPORT CppStackFrame { - CppStackFrame *parent; - Function *v4Function; - CallData *jsFrame; - const Value *originalArguments; - int originalArgumentsCount; - int instructionPointer; - const char *yield; - const char *unwindHandler; - const char *unwindLabel; - int unwindLevel; - - QString source() const; - QString function() const; - inline QV4::ExecutionContext *context() const { - return static_cast(&jsFrame->context); - } - int lineNumber() const; - - inline QV4::Heap::CallContext *callContext() const { - Heap::ExecutionContext *ctx = static_cast(jsFrame->context).d();\ - while (ctx->type != Heap::ExecutionContext::Type_CallContext) - ctx = ctx->outer; - return static_cast(ctx); - } - ReturnedValue thisObject() const; -}; - - struct Q_QML_EXPORT ExecutionEngine : public EngineBase { diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp index 7883961746..9f442d1d68 100644 --- a/src/qml/jsruntime/qv4function.cpp +++ b/src/qml/jsruntime/qv4function.cpp @@ -47,6 +47,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -125,4 +126,9 @@ void Function::updateInternalClass(ExecutionEngine *engine, const QListlocation.line, compiledFunction->location.column); +} + QT_END_NAMESPACE diff --git a/src/qml/jsruntime/qv4function_p.h b/src/qml/jsruntime/qv4function_p.h index ff2d86b89f..9deccaf72a 100644 --- a/src/qml/jsruntime/qv4function_p.h +++ b/src/qml/jsruntime/qv4function_p.h @@ -51,7 +51,6 @@ // #include "qv4global_p.h" -#include #include #include #include @@ -62,6 +61,8 @@ class MacroAssemblerCodeRef; QT_BEGIN_NAMESPACE +struct QQmlSourceLocation; + namespace QV4 { struct Q_QML_EXPORT Function { @@ -100,10 +101,7 @@ struct Q_QML_EXPORT Function { inline bool isArrowFunction() const { return compiledFunction->flags & CompiledData::Function::IsArrowFunction; } inline bool isGenerator() const { return compiledFunction->flags & CompiledData::Function::IsGenerator; } - QQmlSourceLocation sourceLocation() const - { - return QQmlSourceLocation(sourceFile(), compiledFunction->location.line, compiledFunction->location.column); - } + QQmlSourceLocation sourceLocation() const; Function *nestedFunction() const { diff --git a/src/qml/jsruntime/qv4generatorobject_p.h b/src/qml/jsruntime/qv4generatorobject_p.h index 46227c0df5..331b416856 100644 --- a/src/qml/jsruntime/qv4generatorobject_p.h +++ b/src/qml/jsruntime/qv4generatorobject_p.h @@ -52,6 +52,7 @@ // #include "qv4functionobject_p.h" +#include "qv4stackframe_p.h" QT_BEGIN_NAMESPACE diff --git a/src/qml/jsruntime/qv4jscall_p.h b/src/qml/jsruntime/qv4jscall_p.h index 9b616b755f..307eec9111 100644 --- a/src/qml/jsruntime/qv4jscall_p.h +++ b/src/qml/jsruntime/qv4jscall_p.h @@ -55,6 +55,7 @@ #include "qv4functionobject_p.h" #include "qv4context_p.h" #include "qv4scopedvalue_p.h" +#include "qv4stackframe_p.h" QT_BEGIN_NAMESPACE diff --git a/src/qml/jsruntime/qv4stackframe.cpp b/src/qml/jsruntime/qv4stackframe.cpp new file mode 100644 index 0000000000..a716c53aea --- /dev/null +++ b/src/qml/jsruntime/qv4stackframe.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "qv4stackframe_p.h" +#include + +using namespace QV4; + +QString CppStackFrame::source() const +{ + return v4Function ? v4Function->sourceFile() : QString(); +} + +QString CppStackFrame::function() const +{ + return v4Function ? v4Function->name()->toQString() : QString(); +} + +int CppStackFrame::lineNumber() const +{ + if (!v4Function) + return -1; + + auto findLine = [](const CompiledData::CodeOffsetToLine &entry, uint offset) { + return entry.codeOffset < offset; + }; + + const QV4::CompiledData::Function *cf = v4Function->compiledFunction; + uint offset = instructionPointer; + const CompiledData::CodeOffsetToLine *lineNumbers = cf->lineNumberTable(); + uint nLineNumbers = cf->nLineNumbers; + const CompiledData::CodeOffsetToLine *line = std::lower_bound(lineNumbers, lineNumbers + nLineNumbers, offset, findLine) - 1; + return line->line; +} + +ReturnedValue CppStackFrame::thisObject() const { + return jsFrame->thisObject.asReturnedValue(); +} + diff --git a/src/qml/jsruntime/qv4stackframe_p.h b/src/qml/jsruntime/qv4stackframe_p.h new file mode 100644 index 0000000000..1735d020e0 --- /dev/null +++ b/src/qml/jsruntime/qv4stackframe_p.h @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QV4STACKFRAME_H +#define QV4STACKFRAME_H + +#include +#ifndef V4_BOOTSTRAP +#include +#endif + +QT_BEGIN_NAMESPACE + +namespace QV4 { + +struct CallData +{ + enum Offsets { + Function = 0, + Context = 1, + Accumulator = 2, + This = 3, + NewTarget = 4, + Argc = 5 + }; + + Value function; + Value context; + Value accumulator; + Value thisObject; + Value newTarget; + Value _argc; + + int argc() const { + Q_ASSERT(_argc.isInteger()); + return _argc.int_32(); + } + + void setArgc(int argc) { + Q_ASSERT(argc >= 0); + _argc.setInt_32(argc); + } + + inline ReturnedValue argument(int i) const { + return i < argc() ? args[i].asReturnedValue() : Primitive::undefinedValue().asReturnedValue(); + } + + Value args[1]; + + static Q_DECL_CONSTEXPR int HeaderSize() { return offsetof(CallData, args) / sizeof(QV4::Value); } +}; + +Q_STATIC_ASSERT(std::is_standard_layout::value); +Q_STATIC_ASSERT(offsetof(CallData, thisObject) == CallData::This*sizeof(Value)); +Q_STATIC_ASSERT(offsetof(CallData, args) == 6*sizeof(Value)); + +struct Q_QML_EXPORT CppStackFrame { + CppStackFrame *parent; + Function *v4Function; + CallData *jsFrame; + const Value *originalArguments; + int originalArgumentsCount; + int instructionPointer; + const char *yield; + const char *unwindHandler; + const char *unwindLabel; + int unwindLevel; + +#ifndef V4_BOOTSTRAP + uint requiredJSStackFrameSize() { + return CallData::HeaderSize() + v4Function->compiledFunction->nRegisters; + } +#endif + + QString source() const; + QString function() const; + inline QV4::ExecutionContext *context() const { + return static_cast(&jsFrame->context); + } + int lineNumber() const; + + inline QV4::Heap::CallContext *callContext() const { + Heap::ExecutionContext *ctx = static_cast(jsFrame->context).d();\ + while (ctx->type != Heap::ExecutionContext::Type_CallContext) + ctx = ctx->outer; + return static_cast(ctx); + } + ReturnedValue thisObject() const; +}; + +} + +QT_END_NAMESPACE + +#endif diff --git a/src/qml/qml/qqmlvaluetypewrapper.cpp b/src/qml/qml/qqmlvaluetypewrapper.cpp index 8f61e2377d..1fde5945ba 100644 --- a/src/qml/qml/qqmlvaluetypewrapper.cpp +++ b/src/qml/qml/qqmlvaluetypewrapper.cpp @@ -39,7 +39,6 @@ #include "qqmlvaluetypewrapper_p.h" #include - #include #include #include @@ -49,6 +48,7 @@ #include #include #include +#include #include #include #include diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index e8e35f5e61..e6f68a30b3 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -67,6 +67,7 @@ #include #include #include +#include #include #include diff --git a/src/qml/qml/v8/qv8engine_p.h b/src/qml/qml/v8/qv8engine_p.h index d90f1827fe..23559618ef 100644 --- a/src/qml/qml/v8/qv8engine_p.h +++ b/src/qml/qml/v8/qv8engine_p.h @@ -67,6 +67,7 @@ #include #include #include +#include #include QT_BEGIN_NAMESPACE -- cgit v1.2.3