| 1 | // Copyright (C) 2017 The Qt Company Ltd. | 
|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | 
|---|
| 3 | #ifndef QV4ENGINEBASE_P_H | 
|---|
| 4 | #define QV4ENGINEBASE_P_H | 
|---|
| 5 |  | 
|---|
| 6 | // | 
|---|
| 7 | //  W A R N I N G | 
|---|
| 8 | //  ------------- | 
|---|
| 9 | // | 
|---|
| 10 | // This file is not part of the Qt API.  It exists purely as an | 
|---|
| 11 | // implementation detail.  This header file may change from version to | 
|---|
| 12 | // version without notice, or even be removed. | 
|---|
| 13 | // | 
|---|
| 14 | // We mean it. | 
|---|
| 15 | // | 
|---|
| 16 |  | 
|---|
| 17 | #include <private/qv4global_p.h> | 
|---|
| 18 | #include <private/qv4runtimeapi_p.h> | 
|---|
| 19 |  | 
|---|
| 20 | QT_BEGIN_NAMESPACE | 
|---|
| 21 |  | 
|---|
| 22 | namespace QV4 { | 
|---|
| 23 |  | 
|---|
| 24 | struct CppStackFrame; | 
|---|
| 25 |  | 
|---|
| 26 | // Base class for the execution engine | 
|---|
| 27 | struct Q_QML_EXPORT EngineBase { | 
|---|
| 28 |  | 
|---|
| 29 | CppStackFrame *currentStackFrame = nullptr; | 
|---|
| 30 |  | 
|---|
| 31 | Value *jsStackTop = nullptr; | 
|---|
| 32 |  | 
|---|
| 33 | // The JIT expects hasException and isInterrupted to be in the same 32bit word in memory. | 
|---|
| 34 | quint8 hasException = false; | 
|---|
| 35 | // isInterrupted is expected to be set from a different thread | 
|---|
| 36 | #if defined(Q_ATOMIC_INT8_IS_SUPPORTED) | 
|---|
| 37 | QAtomicInteger<quint8> isInterrupted = false; | 
|---|
| 38 | quint16 unused = 0; | 
|---|
| 39 | #elif defined(Q_ATOMIC_INT16_IS_SUPPORTED) | 
|---|
| 40 | quint8 unused = 0; | 
|---|
| 41 | QAtomicInteger<quint16> isInterrupted = false; | 
|---|
| 42 | #else | 
|---|
| 43 | #   error V4 needs either 8bit or 16bit atomics. | 
|---|
| 44 | #endif | 
|---|
| 45 |  | 
|---|
| 46 | quint8 isExecutingInRegExpJIT = false; | 
|---|
| 47 | quint8 isInitialized = false; | 
|---|
| 48 | quint8 inShutdown = false; | 
|---|
| 49 | quint8 isGCOngoing = false; // incremental gc is ongoing (but mutator might be running) | 
|---|
| 50 | MemoryManager *memoryManager = nullptr; | 
|---|
| 51 |  | 
|---|
| 52 | union { | 
|---|
| 53 | const void *cppStackBase = nullptr; | 
|---|
| 54 | struct { | 
|---|
| 55 | qint32 callDepth; | 
|---|
| 56 | #if QT_POINTER_SIZE == 8 | 
|---|
| 57 | quint32 padding2; | 
|---|
| 58 | #endif | 
|---|
| 59 | }; | 
|---|
| 60 | }; | 
|---|
| 61 | const void *cppStackLimit = nullptr; | 
|---|
| 62 |  | 
|---|
| 63 | Object *globalObject = nullptr; | 
|---|
| 64 | Value *jsStackLimit = nullptr; | 
|---|
| 65 | Value *jsStackBase = nullptr; | 
|---|
| 66 |  | 
|---|
| 67 | IdentifierTable *identifierTable = nullptr; | 
|---|
| 68 |  | 
|---|
| 69 | // Exception handling | 
|---|
| 70 | Value *exceptionValue = nullptr; | 
|---|
| 71 |  | 
|---|
| 72 | enum InternalClassType { | 
|---|
| 73 | Class_Empty, | 
|---|
| 74 | Class_String, | 
|---|
| 75 | Class_MemberData, | 
|---|
| 76 | Class_SimpleArrayData, | 
|---|
| 77 | Class_SparseArrayData, | 
|---|
| 78 | Class_ExecutionContext, | 
|---|
| 79 | Class_CallContext, | 
|---|
| 80 | Class_QmlContext, | 
|---|
| 81 | Class_Object, | 
|---|
| 82 | Class_ArrayObject, | 
|---|
| 83 | Class_FunctionObject, | 
|---|
| 84 | Class_ArrowFunction, | 
|---|
| 85 | Class_GeneratorFunction, | 
|---|
| 86 | Class_GeneratorObject, | 
|---|
| 87 | Class_StringObject, | 
|---|
| 88 | Class_SymbolObject, | 
|---|
| 89 | Class_ScriptFunction, | 
|---|
| 90 | Class_ConstructorFunction, | 
|---|
| 91 | Class_MemberFunction, | 
|---|
| 92 | Class_MemberGeneratorFunction, | 
|---|
| 93 | Class_ObjectProto, | 
|---|
| 94 | Class_RegExp, | 
|---|
| 95 | Class_RegExpObject, | 
|---|
| 96 | Class_RegExpExecArray, | 
|---|
| 97 | Class_ArgumentsObject, | 
|---|
| 98 | Class_StrictArgumentsObject, | 
|---|
| 99 | Class_ErrorObject, | 
|---|
| 100 | Class_ErrorObjectWithMessage, | 
|---|
| 101 | Class_ErrorProto, | 
|---|
| 102 | Class_QmlContextWrapper, | 
|---|
| 103 | Class_ProxyObject, | 
|---|
| 104 | Class_ProxyFunctionObject, | 
|---|
| 105 | Class_Symbol, | 
|---|
| 106 | NClasses | 
|---|
| 107 | }; | 
|---|
| 108 | Heap::InternalClass *classes[NClasses]; | 
|---|
| 109 | Heap::InternalClass *internalClasses(InternalClassType icType) { return classes[icType]; } | 
|---|
| 110 | }; | 
|---|
| 111 |  | 
|---|
| 112 | Q_STATIC_ASSERT(std::is_standard_layout<EngineBase>::value); | 
|---|
| 113 | Q_STATIC_ASSERT(offsetof(EngineBase, currentStackFrame) == 0); | 
|---|
| 114 | Q_STATIC_ASSERT(offsetof(EngineBase, jsStackTop) == offsetof(EngineBase, currentStackFrame) + QT_POINTER_SIZE); | 
|---|
| 115 | Q_STATIC_ASSERT(offsetof(EngineBase, hasException) == offsetof(EngineBase, jsStackTop) + QT_POINTER_SIZE); | 
|---|
| 116 | Q_STATIC_ASSERT(offsetof(EngineBase, memoryManager) == offsetof(EngineBase, hasException) + 8); | 
|---|
| 117 | Q_STATIC_ASSERT(offsetof(EngineBase, isInterrupted) + sizeof(EngineBase::isInterrupted) <= offsetof(EngineBase, hasException) + 4); | 
|---|
| 118 | Q_STATIC_ASSERT(offsetof(EngineBase, globalObject) % QT_POINTER_SIZE == 0); | 
|---|
| 119 |  | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | QT_END_NAMESPACE | 
|---|
| 123 |  | 
|---|
| 124 | #endif | 
|---|
| 125 |  | 
|---|