Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qv4writebarrier_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QV4WRITEBARRIER_P_H
4#define QV4WRITEBARRIER_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/qv4enginebase_p.h>
19
21
22namespace QV4 {
23struct EngineBase;
25
27
28 static constexpr bool isInsertionBarrier = true;
29
31 {
32 if (engine->isGCOngoing)
34 *slot = value;
35 }
36 Q_QML_EXPORT Q_NEVER_INLINE static void write_slowpath(
39
41 {
42 if (engine->isGCOngoing)
44 *slot = value;
45 }
46 Q_QML_EXPORT Q_NEVER_INLINE static void write_slowpath(
48 Heap::Base **slot, Heap::Base *value);
49
50 // MemoryManager isn't a complete type here, so make Engine a template argument
51 // so that we can still call engine->memoryManager->markStack()
52 template<typename F, typename Engine = EngineBase>
53 static void markCustom(Engine *engine, F &&markFunction) {
54 if (engine->isGCOngoing)
55 (std::forward<F>(markFunction))(engine->memoryManager->markStack());
56 }
57
58 // HeapObjectWrapper(Base) are helper classes to ensure that
59 // we always use a WriteBarrier when setting heap-objects
60 // they are also trivial; if triviality is not required, use Pointer instead
62 {
63 // enum class avoids accidental construction via brace-init
64 enum class PointerWrapper : quintptr {};
66
68 };
69
70 template<typename HeapType>
72 {
73 HeapType *get() const { return reinterpret_cast<HeapType *>(wrapped); }
74 operator HeapType *() const { return get(); }
75 HeapType * operator->() const { return get(); }
76
77 template <typename ConvertibleToHeapType>
78 void set(QV4::EngineBase *engine, ConvertibleToHeapType *heapObject)
79 {
81 if (heapObject)
82 heapObject->mark(ms);
83 });
84 wrapped = static_cast<HeapObjectWrapperBase::PointerWrapper>(quintptr(heapObject));
85 }
86 };
87
88 // all types are trivial; we however want to block copies bypassing the write barrier
89 // therefore, all members use a PhantomTag to reduce the likelihood
90 template<typename HeapType, int PhantomTag>
92
93 /* similar Heap::Pointer, but without the Base conversion (and its inUse assert)
94 and for storing references in engine classes stored on the native heap
95 Stores a "non-owning" reference to a heap-item (in the C++ sense), but should
96 generally mark the heap-item; therefore set goes through a write-barrier
97 */
98 template<typename T>
99 struct Pointer
100 {
101 Pointer() = default;
102 ~Pointer() = default;
103 Q_DISABLE_COPY_MOVE(Pointer)
104 T* operator->() const { return get(); }
105 operator T* () const { return get(); }
106
107 void set(EngineBase *e, T *newVal) {
109 if (newVal)
110 newVal->mark(ms);
111 });
112 ptr = newVal;
113 }
114
115 T* get() const { return ptr; }
116
117
118
119 private:
120 T *ptr = nullptr;
121 };
122};
123
124 // ### this needs to be filled with a real memory fence once marking is concurrent
126
127}
128
130
131#endif
Combined button and popup list for selecting options.
quint64 ReturnedValue
Q_ALWAYS_INLINE void fence()
#define Q_NEVER_INLINE
#define Q_ALWAYS_INLINE
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
size_t quintptr
Definition qtypes.h:167
unsigned long long quint64
Definition qtypes.h:61
static const uint base
Definition qurlidna.cpp:20
QJSEngine engine
[0]
void set(QV4::EngineBase *engine, ConvertibleToHeapType *heapObject)
void set(EngineBase *e, T *newVal)
static Q_ALWAYS_INLINE void write(EngineBase *engine, Heap::Base *base, Heap::Base **slot, Heap::Base *value)
static void markCustom(Engine *engine, F &&markFunction)
static constexpr bool isInsertionBarrier
Q_QML_EXPORT static Q_NEVER_INLINE void write_slowpath(EngineBase *engine, Heap::Base *base, ReturnedValue *slot, ReturnedValue value)
static Q_ALWAYS_INLINE void write(EngineBase *engine, Heap::Base *base, ReturnedValue *slot, ReturnedValue value)