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 padding[2]; |
49 | MemoryManager *memoryManager = nullptr; |
50 | |
51 | union { |
52 | const void *cppStackBase = nullptr; |
53 | struct { |
54 | qint32 callDepth; |
55 | #if QT_POINTER_SIZE == 8 |
56 | quint32 padding2; |
57 | #endif |
58 | }; |
59 | }; |
60 | const void *cppStackLimit = nullptr; |
61 | |
62 | Object *globalObject = nullptr; |
63 | Value *jsStackLimit = nullptr; |
64 | Value *jsStackBase = nullptr; |
65 | |
66 | IdentifierTable *identifierTable = nullptr; |
67 | |
68 | // Exception handling |
69 | Value *exceptionValue = nullptr; |
70 | |
71 | enum InternalClassType { |
72 | Class_Empty, |
73 | Class_String, |
74 | Class_MemberData, |
75 | Class_SimpleArrayData, |
76 | Class_SparseArrayData, |
77 | Class_ExecutionContext, |
78 | Class_CallContext, |
79 | Class_QmlContext, |
80 | Class_Object, |
81 | Class_ArrayObject, |
82 | Class_FunctionObject, |
83 | Class_ArrowFunction, |
84 | Class_GeneratorFunction, |
85 | Class_GeneratorObject, |
86 | Class_StringObject, |
87 | Class_SymbolObject, |
88 | Class_ScriptFunction, |
89 | Class_ConstructorFunction, |
90 | Class_MemberFunction, |
91 | Class_MemberGeneratorFunction, |
92 | Class_ObjectProto, |
93 | Class_RegExp, |
94 | Class_RegExpObject, |
95 | Class_RegExpExecArray, |
96 | Class_ArgumentsObject, |
97 | Class_StrictArgumentsObject, |
98 | Class_ErrorObject, |
99 | Class_ErrorObjectWithMessage, |
100 | Class_ErrorProto, |
101 | Class_QmlContextWrapper, |
102 | Class_ProxyObject, |
103 | Class_ProxyFunctionObject, |
104 | Class_Symbol, |
105 | NClasses |
106 | }; |
107 | Heap::InternalClass *classes[NClasses]; |
108 | Heap::InternalClass *internalClasses(InternalClassType icType) { return classes[icType]; } |
109 | }; |
110 | |
111 | Q_STATIC_ASSERT(std::is_standard_layout<EngineBase>::value); |
112 | Q_STATIC_ASSERT(offsetof(EngineBase, currentStackFrame) == 0); |
113 | Q_STATIC_ASSERT(offsetof(EngineBase, jsStackTop) == offsetof(EngineBase, currentStackFrame) + QT_POINTER_SIZE); |
114 | Q_STATIC_ASSERT(offsetof(EngineBase, hasException) == offsetof(EngineBase, jsStackTop) + QT_POINTER_SIZE); |
115 | Q_STATIC_ASSERT(offsetof(EngineBase, memoryManager) == offsetof(EngineBase, hasException) + 8); |
116 | Q_STATIC_ASSERT(offsetof(EngineBase, isInterrupted) + sizeof(EngineBase::isInterrupted) <= offsetof(EngineBase, hasException) + 4); |
117 | Q_STATIC_ASSERT(offsetof(EngineBase, globalObject) % QT_POINTER_SIZE == 0); |
118 | |
119 | } |
120 | |
121 | QT_END_NAMESPACE |
122 | |
123 | #endif |
124 | |